--- /dev/null
+/*\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * @fileOverview The "sourcearea" plugin. It registers the "source" editing\r
+ * mode, which displays the raw data being edited in the editor.\r
+ */\r
+\r
+CKEDITOR.plugins.add( 'sourcearea',\r
+{\r
+ requires : [ 'editingblock' ],\r
+\r
+ init : function( editor )\r
+ {\r
+ var sourcearea = CKEDITOR.plugins.sourcearea,\r
+ win = CKEDITOR.document.getWindow();\r
+\r
+ editor.on( 'editingBlockReady', function()\r
+ {\r
+ var textarea,\r
+ onResize;\r
+\r
+ editor.addMode( 'source',\r
+ {\r
+ load : function( holderElement, data )\r
+ {\r
+ if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )\r
+ holderElement.setStyle( 'position', 'relative' );\r
+\r
+ // Create the source area <textarea>.\r
+ editor.textarea = textarea = new CKEDITOR.dom.element( 'textarea' );\r
+ textarea.setAttributes(\r
+ {\r
+ dir : 'ltr',\r
+ tabIndex : CKEDITOR.env.webkit ? -1 : editor.tabIndex,\r
+ 'role' : 'textbox',\r
+ 'aria-label' : editor.lang.editorTitle.replace( '%1', editor.name )\r
+ });\r
+ textarea.addClass( 'cke_source' );\r
+ textarea.addClass( 'cke_enable_context_menu' );\r
+\r
+ editor.readOnly && textarea.setAttribute( 'readOnly', 'readonly' );\r
+\r
+ var styles =\r
+ {\r
+ // IE7 has overflow the <textarea> from wrapping table cell.\r
+ width : CKEDITOR.env.ie7Compat ? '99%' : '100%',\r
+ height : '100%',\r
+ resize : 'none',\r
+ outline : 'none',\r
+ 'text-align' : 'left'\r
+ };\r
+\r
+ // Having to make <textarea> fixed sized to conque the following bugs:\r
+ // 1. The textarea height/width='100%' doesn't constraint to the 'td' in IE6/7.\r
+ // 2. Unexpected vertical-scrolling behavior happens whenever focus is moving out of editor\r
+ // if text content within it has overflowed. (#4762)\r
+ if ( CKEDITOR.env.ie )\r
+ {\r
+ onResize = function()\r
+ {\r
+ // Holder rectange size is stretched by textarea,\r
+ // so hide it just for a moment.\r
+ textarea.hide();\r
+ textarea.setStyle( 'height', holderElement.$.clientHeight + 'px' );\r
+ textarea.setStyle( 'width', holderElement.$.clientWidth + 'px' );\r
+ // When we have proper holder size, show textarea again.\r
+ textarea.show();\r
+ };\r
+\r
+ editor.on( 'resize', onResize );\r
+ win.on( 'resize', onResize );\r
+ setTimeout( onResize, 0 );\r
+ }\r
+\r
+ // Reset the holder element and append the\r
+ // <textarea> to it.\r
+ holderElement.setHtml( '' );\r
+ holderElement.append( textarea );\r
+ textarea.setStyles( styles );\r
+\r
+ editor.fire( 'ariaWidget', textarea );\r
+\r
+ textarea.on( 'blur', function()\r
+ {\r
+ editor.focusManager.blur();\r
+ });\r
+\r
+ textarea.on( 'focus', function()\r
+ {\r
+ editor.focusManager.focus();\r
+ });\r
+\r
+ // The editor data "may be dirty" after this point.\r
+ editor.mayBeDirty = true;\r
+\r
+ // Set the <textarea> value.\r
+ this.loadData( data );\r
+\r
+ var keystrokeHandler = editor.keystrokeHandler;\r
+ if ( keystrokeHandler )\r
+ keystrokeHandler.attach( textarea );\r
+\r
+ setTimeout( function()\r
+ {\r
+ editor.mode = 'source';\r
+ editor.fire( 'mode' );\r
+ },\r
+ ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) ? 100 : 0 );\r
+ },\r
+\r
+ loadData : function( data )\r
+ {\r
+ textarea.setValue( data );\r
+ editor.fire( 'dataReady' );\r
+ },\r
+\r
+ getData : function()\r
+ {\r
+ return textarea.getValue();\r
+ },\r
+\r
+ getSnapshotData : function()\r
+ {\r
+ return textarea.getValue();\r
+ },\r
+\r
+ unload : function( holderElement )\r
+ {\r
+ textarea.clearCustomData();\r
+ editor.textarea = textarea = null;\r
+\r
+ if ( onResize )\r
+ {\r
+ editor.removeListener( 'resize', onResize );\r
+ win.removeListener( 'resize', onResize );\r
+ }\r
+\r
+ if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )\r
+ holderElement.removeStyle( 'position' );\r
+ },\r
+\r
+ focus : function()\r
+ {\r
+ textarea.focus();\r
+ }\r
+ });\r
+ });\r
+\r
+ editor.on( 'readOnly', function()\r
+ {\r
+ if ( editor.mode == 'source' )\r
+ {\r
+ if ( editor.readOnly )\r
+ editor.textarea.setAttribute( 'readOnly', 'readonly' );\r
+ else\r
+ editor.textarea.removeAttribute( 'readOnly' );\r
+ }\r
+ });\r
+\r
+ editor.addCommand( 'source', sourcearea.commands.source );\r
+\r
+ if ( editor.ui.addButton )\r
+ {\r
+ editor.ui.addButton( 'Source',\r
+ {\r
+ label : editor.lang.source,\r
+ command : 'source'\r
+ });\r
+ }\r
+\r
+ editor.on( 'mode', function()\r
+ {\r
+ editor.getCommand( 'source' ).setState(\r
+ editor.mode == 'source' ?\r
+ CKEDITOR.TRISTATE_ON :\r
+ CKEDITOR.TRISTATE_OFF );\r
+ });\r
+ }\r
+});\r
+\r
+/**\r
+ * Holds the definition of commands an UI elements included with the sourcearea\r
+ * plugin.\r
+ * @example\r
+ */\r
+CKEDITOR.plugins.sourcearea =\r
+{\r
+ commands :\r
+ {\r
+ source :\r
+ {\r
+ modes : { wysiwyg:1, source:1 },\r
+ editorFocus : false,\r
+ readOnly : 1,\r
+ exec : function( editor )\r
+ {\r
+ if ( editor.mode == 'wysiwyg' )\r
+ editor.fire( 'saveSnapshot' );\r
+ editor.getCommand( 'source' ).setState( CKEDITOR.TRISTATE_DISABLED );\r
+ editor.setMode( editor.mode == 'source' ? 'wysiwyg' : 'source' );\r
+ },\r
+\r
+ canUndo : false\r
+ }\r
+ }\r
+};\r