JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @fileOverview The "wysiwygarea" plugin. It registers the "wysiwyg" editing\r
8  *              mode, which handles the main editing area space.\r
9  */\r
10 \r
11 (function()\r
12 {\r
13         // List of elements in which has no way to move editing focus outside.\r
14         var nonExitableElementNames = { table:1,pre:1 };\r
15 \r
16         // Matching an empty paragraph at the end of document.\r
17         var emptyParagraphRegexp = /(^|<body\b[^>]*>)\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi;\r
18 \r
19         var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );\r
20 \r
21         // Elements that could have empty new line around, including table, pre-formatted block, hr, page-break. (#6554)\r
22         function nonExitable( element )\r
23         {\r
24                 return ( element.getName() in nonExitableElementNames )\r
25                                 || element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];\r
26         }\r
27 \r
28         function checkReadOnly( selection )\r
29         {\r
30                 if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )\r
31                         return selection.getSelectedElement().isReadOnly();\r
32                 else\r
33                         return selection.getCommonAncestor().isReadOnly();\r
34         }\r
35 \r
36 \r
37         function onInsert( insertFunc )\r
38         {\r
39                 return function( evt )\r
40                 {\r
41                         if ( this.mode == 'wysiwyg' )\r
42                         {\r
43                                 this.focus();\r
44 \r
45                                 var selection = this.getSelection();\r
46                                 if ( checkReadOnly( selection ) )\r
47                                         return;\r
48 \r
49                                 this.fire( 'saveSnapshot' );\r
50 \r
51                                 insertFunc.call( this, evt.data );\r
52 \r
53                                 // Save snaps after the whole execution completed.\r
54                                 // This's a workaround for make DOM modification's happened after\r
55                                 // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'\r
56                                 // call.\r
57                                 CKEDITOR.tools.setTimeout( function()\r
58                                    {\r
59                                            this.fire( 'saveSnapshot' );\r
60                                    }, 0, this );\r
61                         }\r
62                 };\r
63         }\r
64 \r
65         function doInsertHtml( data )\r
66         {\r
67                 if ( this.dataProcessor )\r
68                         data = this.dataProcessor.toHtml( data );\r
69 \r
70                 var selection = this.getSelection();\r
71                 if ( CKEDITOR.env.ie )\r
72                 {\r
73                         var selIsLocked = selection.isLocked;\r
74 \r
75                         if ( selIsLocked )\r
76                                 selection.unlock();\r
77 \r
78                         var $sel = selection.getNative();\r
79 \r
80                         // Delete control selections to avoid IE bugs on pasteHTML.\r
81                         if ( $sel.type == 'Control' )\r
82                                 $sel.clear();\r
83                                 else if  ( selection.getType() == CKEDITOR.SELECTION_TEXT )\r
84                         {\r
85                                 // Due to IE bugs on handling contenteditable=false blocks\r
86                                 // (#6005), we need to make some checks and eventually\r
87                                 // delete the selection first.\r
88 \r
89                                 var range = selection.getRanges()[0],\r
90                                                 endContainer = range && range.endContainer;\r
91 \r
92                                 if ( endContainer &&\r
93                                                 endContainer.type == CKEDITOR.NODE_ELEMENT &&\r
94                                                 endContainer.getAttribute( 'contenteditable' ) == 'false' &&\r
95                                                 range.checkBoundaryOfElement( endContainer, CKEDITOR.END ) )\r
96                                 {\r
97                                         range.setEndAfter( range.endContainer );\r
98                                         range.deleteContents();\r
99                                 }\r
100                         }\r
101 \r
102                         try\r
103                         {\r
104                                 $sel.createRange().pasteHTML( data );\r
105                         }\r
106                                 catch (e) {}\r
107 \r
108                         if ( selIsLocked )\r
109                                 this.getSelection().lock();\r
110                         }\r
111                 else\r
112                         this.document.$.execCommand( 'inserthtml', false, data );\r
113 \r
114                 // Webkit does not scroll to the cursor position after pasting (#5558)\r
115                 if ( CKEDITOR.env.webkit )\r
116                 {\r
117                         selection = this.getSelection();\r
118                         selection.scrollIntoView();\r
119                 }\r
120         }\r
121 \r
122         function doInsertText( text )\r
123         {\r
124                 var selection = this.getSelection(),\r
125                         mode = selection.getStartElement().hasAscendant( 'pre', true ) ?\r
126                                    CKEDITOR.ENTER_BR : this.config.enterMode,\r
127                         isEnterBrMode = mode == CKEDITOR.ENTER_BR;\r
128 \r
129                 var html = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );\r
130 \r
131                 // Convert leading and trailing whitespaces into &nbsp;\r
132                 html = html.replace( /^[ \t]+|[ \t]+$/g, function( match, offset, s )\r
133                         {\r
134                                 if ( match.length == 1 )        // one space, preserve it\r
135                                         return '&nbsp;';\r
136                                 else if ( !offset )             // beginning of block\r
137                                         return CKEDITOR.tools.repeat( '&nbsp;', match.length - 1 ) + ' ';\r
138                                 else                            // end of block\r
139                                         return ' ' + CKEDITOR.tools.repeat( '&nbsp;', match.length - 1 );\r
140                         } );\r
141 \r
142                 // Convert subsequent whitespaces into &nbsp;\r
143                 html = html.replace( /[ \t]{2,}/g, function ( match )\r
144                    {\r
145                            return CKEDITOR.tools.repeat( '&nbsp;', match.length - 1 ) + ' ';\r
146                    } );\r
147 \r
148                 var paragraphTag = mode == CKEDITOR.ENTER_P ? 'p' : 'div';\r
149 \r
150                 // Two line-breaks create one paragraph.\r
151                 if ( !isEnterBrMode )\r
152                 {\r
153                         html = html.replace( /(\n{2})([\s\S]*?)(?:$|\1)/g,\r
154                                 function( match, group1, text )\r
155                                 {\r
156                                         return '<'+paragraphTag + '>' + text + '</' + paragraphTag + '>';\r
157                                 });\r
158                 }\r
159 \r
160                 // One <br> per line-break.\r
161                 html = html.replace( /\n/g, '<br>' );\r
162 \r
163                 // Compensate padding <br> for non-IE.\r
164                 if ( !( isEnterBrMode || CKEDITOR.env.ie ) )\r
165                 {\r
166                         html = html.replace( new RegExp( '<br>(?=</' + paragraphTag + '>)' ), function( match )\r
167                         {\r
168                                 return CKEDITOR.tools.repeat( match, 2 );\r
169                         } );\r
170                 }\r
171 \r
172                 // Inline styles have to be inherited in Firefox.\r
173                 if ( CKEDITOR.env.gecko || CKEDITOR.env.webkit )\r
174                 {\r
175                         var path = new CKEDITOR.dom.elementPath( selection.getStartElement() ),\r
176                                 context = [];\r
177 \r
178                         for ( var i = 0; i < path.elements.length; i++ )\r
179                         {\r
180                                 var tag = path.elements[ i ].getName();\r
181                                 if ( tag in CKEDITOR.dtd.$inline )\r
182                                         context.unshift( path.elements[ i ].getOuterHtml().match( /^<.*?>/) );\r
183                                 else if ( tag in CKEDITOR.dtd.$block )\r
184                                         break;\r
185                         }\r
186 \r
187                         // Reproduce the context  by preceding the pasted HTML with opening inline tags.\r
188                         html = context.join( '' ) + html;\r
189                 }\r
190 \r
191                 doInsertHtml.call( this, html );\r
192         }\r
193 \r
194         function doInsertElement( element )\r
195         {\r
196                 var selection = this.getSelection(),\r
197                                 ranges = selection.getRanges(),\r
198                                 elementName = element.getName(),\r
199                                 isBlock = CKEDITOR.dtd.$block[ elementName ];\r
200 \r
201                 var selIsLocked = selection.isLocked;\r
202 \r
203                 if ( selIsLocked )\r
204                         selection.unlock();\r
205 \r
206                 var range, clone, lastElement, bookmark;\r
207 \r
208                 for ( var i = ranges.length - 1 ; i >= 0 ; i-- )\r
209                 {\r
210                         range = ranges[ i ];\r
211 \r
212                         // Remove the original contents.\r
213                         range.deleteContents();\r
214 \r
215                         clone = !i && element || element.clone( 1 );\r
216 \r
217                         // If we're inserting a block at dtd-violated position, split\r
218                         // the parent blocks until we reach blockLimit.\r
219                         var current, dtd;\r
220                         if ( isBlock )\r
221                         {\r
222                                 while ( ( current = range.getCommonAncestor( 0, 1 ) )\r
223                                                 && ( dtd = CKEDITOR.dtd[ current.getName() ] )\r
224                                                 && !( dtd && dtd [ elementName ] ) )\r
225                                 {\r
226                                         // Split up inline elements.\r
227                                         if ( current.getName() in CKEDITOR.dtd.span )\r
228                                                 range.splitElement( current );\r
229                                         // If we're in an empty block which indicate a new paragraph,\r
230                                         // simply replace it with the inserting block.(#3664)\r
231                                         else if ( range.checkStartOfBlock()\r
232                                                         && range.checkEndOfBlock() )\r
233                                         {\r
234                                                 range.setStartBefore( current );\r
235                                                 range.collapse( true );\r
236                                                 current.remove();\r
237                                         }\r
238                                         else\r
239                                                 range.splitBlock();\r
240                                 }\r
241                         }\r
242 \r
243                         // Insert the new node.\r
244                         range.insertNode( clone );\r
245 \r
246                         // Save the last element reference so we can make the\r
247                         // selection later.\r
248                         if ( !lastElement )\r
249                                 lastElement = clone;\r
250                 }\r
251 \r
252                 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );\r
253 \r
254                 // If we're inserting a block element immediatelly followed by\r
255                 // another block element, the selection must move there. (#3100,#5436)\r
256                 if ( isBlock )\r
257                 {\r
258                         var next = lastElement.getNext( notWhitespaceEval ),\r
259                                         nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();\r
260 \r
261                         // Check if it's a block element that accepts text.\r
262                         if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )\r
263                                 range.moveToElementEditStart( next );\r
264                 }\r
265 \r
266                 selection.selectRanges( [ range ] );\r
267 \r
268                 if ( selIsLocked )\r
269                         this.getSelection().lock();\r
270         }\r
271 \r
272         // DOM modification here should not bother dirty flag.(#4385)\r
273         function restoreDirty( editor )\r
274         {\r
275                 if ( !editor.checkDirty() )\r
276                         setTimeout( function(){ editor.resetDirty(); }, 0 );\r
277         }\r
278 \r
279         var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),\r
280                 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );\r
281 \r
282         function isNotEmpty( node )\r
283         {\r
284                 return isNotWhitespace( node ) && isNotBookmark( node );\r
285         }\r
286 \r
287         function isNbsp( node )\r
288         {\r
289                 return node.type == CKEDITOR.NODE_TEXT\r
290                            && CKEDITOR.tools.trim( node.getText() ).match( /^(?:&nbsp;|\xa0)$/ );\r
291         }\r
292 \r
293         function restoreSelection( selection )\r
294         {\r
295                 if ( selection.isLocked )\r
296                 {\r
297                         selection.unlock();\r
298                         setTimeout( function() { selection.lock(); }, 0 );\r
299                 }\r
300         }\r
301 \r
302         function isBlankParagraph( block )\r
303         {\r
304                 return block.getOuterHtml().match( emptyParagraphRegexp );\r
305         }\r
306 \r
307         isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );\r
308 \r
309         // Gecko need a key event to 'wake up' the editing\r
310         // ability when document is empty.(#3864, #5781)\r
311         function activateEditing( editor )\r
312         {\r
313                 var win = editor.window,\r
314                         doc = editor.document,\r
315                         body = editor.document.getBody(),\r
316                         bodyChildsNum = body.getChildren().count();\r
317 \r
318                 if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) )\r
319                 {\r
320                         restoreDirty( editor );\r
321 \r
322                         // Memorize scroll position to restore it later (#4472).\r
323                         var hostDocument = editor.element.getDocument();\r
324                         var hostDocumentElement = hostDocument.getDocumentElement();\r
325                         var scrollTop = hostDocumentElement.$.scrollTop;\r
326                         var scrollLeft = hostDocumentElement.$.scrollLeft;\r
327 \r
328                         // Simulating keyboard character input by dispatching a keydown of white-space text.\r
329                         var keyEventSimulate = doc.$.createEvent( "KeyEvents" );\r
330                         keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false,\r
331                                 false, false, false, 0, 32 );\r
332                         doc.$.dispatchEvent( keyEventSimulate );\r
333 \r
334                         if ( scrollTop != hostDocumentElement.$.scrollTop || scrollLeft != hostDocumentElement.$.scrollLeft )\r
335                                 hostDocument.getWindow().$.scrollTo( scrollLeft, scrollTop );\r
336 \r
337                         // Restore the original document status by placing the cursor before a bogus br created (#5021).\r
338                         bodyChildsNum && body.getFirst().remove();\r
339                         doc.getBody().appendBogus();\r
340                         var nativeRange = new CKEDITOR.dom.range( doc );\r
341                         nativeRange.setStartAt( body , CKEDITOR.POSITION_AFTER_START );\r
342                         nativeRange.select();\r
343                 }\r
344         }\r
345 \r
346         /**\r
347          *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent\r
348          *  non-exitable-block by padding extra br.(#3189)\r
349          */\r
350         function onSelectionChangeFixBody( evt )\r
351         {\r
352                 var editor = evt.editor,\r
353                         path = evt.data.path,\r
354                         blockLimit = path.blockLimit,\r
355                         selection = evt.data.selection,\r
356                         range = selection.getRanges()[0],\r
357                         body = editor.document.getBody(),\r
358                         enterMode = editor.config.enterMode;\r
359 \r
360                 CKEDITOR.env.gecko && activateEditing( editor );\r
361 \r
362                 // When enterMode set to block, we'll establing new paragraph only if we're\r
363                 // selecting inline contents right under body. (#3657)\r
364                 if ( enterMode != CKEDITOR.ENTER_BR\r
365                      && range.collapsed\r
366                          && blockLimit.getName() == 'body'\r
367                          && !path.block )\r
368                 {\r
369                         editor.fire( 'updateSnapshot' );\r
370                         restoreDirty( editor );\r
371                         CKEDITOR.env.ie && restoreSelection( selection );\r
372 \r
373                         var fixedBlock = range.fixBlock( true,\r
374                                         editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );\r
375 \r
376                         // For IE, we should remove any filler node which was introduced before.\r
377                         if ( CKEDITOR.env.ie )\r
378                         {\r
379                                 var first = fixedBlock.getFirst( isNotEmpty );\r
380                                 first && isNbsp( first ) && first.remove();\r
381                         }\r
382 \r
383                         // If the fixed block is actually blank and is already followed by an exitable blank\r
384                         // block, we should revert the fix and move into the existed one. (#3684)\r
385                         if ( isBlankParagraph( fixedBlock ) )\r
386                         {\r
387                                 var element = fixedBlock.getNext( isNotWhitespace );\r
388                                 if ( element &&\r
389                                          element.type == CKEDITOR.NODE_ELEMENT &&\r
390                                          !nonExitable( element ) )\r
391                                 {\r
392                                         range.moveToElementEditStart( element );\r
393                                         fixedBlock.remove();\r
394                                 }\r
395                                 else\r
396                                 {\r
397                                         element = fixedBlock.getPrevious( isNotWhitespace );\r
398                                         if ( element &&\r
399                                                  element.type == CKEDITOR.NODE_ELEMENT &&\r
400                                                  !nonExitable( element ) )\r
401                                         {\r
402                                                 range.moveToElementEditEnd( element );\r
403                                                 fixedBlock.remove();\r
404                                         }\r
405                                 }\r
406                         }\r
407 \r
408                         range.select();\r
409                         // Notify non-IE that selection has changed.\r
410                         if ( !CKEDITOR.env.ie )\r
411                                 editor.selectionChange();\r
412                 }\r
413 \r
414                 // All browsers are incapable to moving cursor out of certain non-exitable\r
415                 // blocks (e.g. table, list, pre) at the end of document, make this happen by\r
416                 // place a bogus node there, which would be later removed by dataprocessor.\r
417                 var walkerRange = new CKEDITOR.dom.range( editor.document ),\r
418                         walker = new CKEDITOR.dom.walker( walkerRange );\r
419                 walkerRange.selectNodeContents( body );\r
420                 walker.evaluator = function( node )\r
421                 {\r
422                         return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );\r
423                 };\r
424                 walker.guard = function( node, isMoveout )\r
425                 {\r
426                         return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );\r
427                 };\r
428 \r
429                 if ( walker.previous() )\r
430                 {\r
431                         editor.fire( 'updateSnapshot' );\r
432                         restoreDirty( editor );\r
433                         CKEDITOR.env.ie && restoreSelection( selection );\r
434 \r
435                         var paddingBlock;\r
436                         if ( enterMode != CKEDITOR.ENTER_BR )\r
437                                 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );\r
438                         else\r
439                                 paddingBlock = body;\r
440 \r
441                         if ( !CKEDITOR.env.ie )\r
442                                 paddingBlock.appendBogus();\r
443                 }\r
444         }\r
445 \r
446         CKEDITOR.plugins.add( 'wysiwygarea',\r
447         {\r
448                 requires : [ 'editingblock' ],\r
449 \r
450                 init : function( editor )\r
451                 {\r
452                         var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )\r
453                                 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;\r
454 \r
455                         var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );\r
456 \r
457                         var contentDomReadyHandler;\r
458                         editor.on( 'editingBlockReady', function()\r
459                                 {\r
460                                         var mainElement,\r
461                                                 iframe,\r
462                                                 isLoadingData,\r
463                                                 isPendingFocus,\r
464                                                 frameLoaded,\r
465                                                 fireMode;\r
466 \r
467 \r
468                                         // Support for custom document.domain in IE.\r
469                                         var isCustomDomain = CKEDITOR.env.isCustomDomain();\r
470 \r
471                                         // Creates the iframe that holds the editable document.\r
472                                         var createIFrame = function( data )\r
473                                         {\r
474                                                 if ( iframe )\r
475                                                         iframe.remove();\r
476 \r
477                                                 var src =\r
478                                                         'document.open();' +\r
479 \r
480                                                         // The document domain must be set any time we\r
481                                                         // call document.open().\r
482                                                         ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +\r
483 \r
484                                                         'document.close();';\r
485 \r
486                                                 // With IE, the custom domain has to be taken care at first,\r
487                                                 // for other browers, the 'src' attribute should be left empty to\r
488                                                 // trigger iframe's 'load' event.\r
489                                                 src =\r
490                                                         CKEDITOR.env.air ?\r
491                                                                 'javascript:void(0)' :\r
492                                                         CKEDITOR.env.ie ?\r
493                                                                 'javascript:void(function(){' + encodeURIComponent( src ) + '}())'\r
494                                                         :\r
495                                                                 '';\r
496 \r
497                                                 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +\r
498                                                         ' style="width:100%;height:100%"' +\r
499                                                         ' frameBorder="0"' +\r
500                                                         ' title="' + frameLabel + '"' +\r
501                                                         ' src="' + src + '"' +\r
502                                                         ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +\r
503                                                         ' allowTransparency="true"' +\r
504                                                         '></iframe>' );\r
505 \r
506                                                 // Running inside of Firefox chrome the load event doesn't bubble like in a normal page (#5689)\r
507                                                 if ( document.location.protocol == 'chrome:' )\r
508                                                         CKEDITOR.event.useCapture = true;\r
509 \r
510                                                 // With FF, it's better to load the data on iframe.load. (#3894,#4058)\r
511                                                 iframe.on( 'load', function( ev )\r
512                                                         {\r
513                                                                 frameLoaded = 1;\r
514                                                                 ev.removeListener();\r
515 \r
516                                                                 var doc = iframe.getFrameDocument();\r
517                                                                 doc.write( data );\r
518 \r
519                                                                 CKEDITOR.env.air && contentDomReady( doc.getWindow().$ );\r
520                                                         });\r
521 \r
522                                                 // Reset adjustment back to default (#5689)\r
523                                                 if ( document.location.protocol == 'chrome:' )\r
524                                                         CKEDITOR.event.useCapture = false;\r
525 \r
526                                                 // The container must be visible when creating the iframe in FF (#5956)\r
527                                                 var element = editor.element,\r
528                                                         isHidden = CKEDITOR.env.gecko && !element.isVisible(),\r
529                                                         previousStyles = {};\r
530                                                 if ( isHidden )\r
531                                                 {\r
532                                                         element.show();\r
533                                                         previousStyles = {\r
534                                                                 position : element.getStyle( 'position' ),\r
535                                                                 top : element.getStyle( 'top' )\r
536                                                         };\r
537                                                         element.setStyles( { position : 'absolute', top : '-3000px' } );\r
538                                                 }\r
539 \r
540                                                 mainElement.append( iframe );\r
541 \r
542                                                 if ( isHidden )\r
543                                                 {\r
544                                                         setTimeout( function()\r
545                                                         {\r
546                                                                 element.hide();\r
547                                                                 element.setStyles( previousStyles );\r
548                                                         }, 1000 );\r
549                                                 }\r
550                                         };\r
551 \r
552                                         // The script that launches the bootstrap logic on 'domReady', so the document\r
553                                         // is fully editable even before the editing iframe is fully loaded (#4455).\r
554                                         contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady );\r
555                                         var activationScript =\r
556                                                 '<script id="cke_actscrpt" type="text/javascript" data-cke-temp="1">' +\r
557                                                         ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +\r
558                                                         'window.parent.CKEDITOR.tools.callFunction( ' + contentDomReadyHandler + ', window );' +\r
559                                                 '</script>';\r
560 \r
561                                         // Editing area bootstrap code.\r
562                                         function contentDomReady( domWindow )\r
563                                         {\r
564                                                 if ( !frameLoaded )\r
565                                                         return;\r
566                                                 frameLoaded = 0;\r
567 \r
568                                                 editor.fire( 'ariaWidget', iframe );\r
569 \r
570                                                 var domDocument = domWindow.document,\r
571                                                         body = domDocument.body;\r
572 \r
573                                                 // Remove this script from the DOM.\r
574                                                 var script = domDocument.getElementById( "cke_actscrpt" );\r
575                                                 script && script.parentNode.removeChild( script );\r
576 \r
577                                                 body.spellcheck = !editor.config.disableNativeSpellChecker;\r
578 \r
579                                                 if ( CKEDITOR.env.ie )\r
580                                                 {\r
581                                                         // Don't display the focus border.\r
582                                                         body.hideFocus = true;\r
583 \r
584                                                         // Disable and re-enable the body to avoid IE from\r
585                                                         // taking the editing focus at startup. (#141 / #523)\r
586                                                         body.disabled = true;\r
587                                                         body.contentEditable = true;\r
588                                                         body.removeAttribute( 'disabled' );\r
589                                                 }\r
590                                                 else\r
591                                                 {\r
592                                                         // Avoid opening design mode in a frame window thread,\r
593                                                         // which will cause host page scrolling.(#4397)\r
594                                                         setTimeout( function()\r
595                                                         {\r
596                                                                 // Prefer 'contentEditable' instead of 'designMode'. (#3593)\r
597                                                                 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900\r
598                                                                                 || CKEDITOR.env.opera )\r
599                                                                         domDocument.$.body.contentEditable = true;\r
600                                                                 else if ( CKEDITOR.env.webkit )\r
601                                                                         domDocument.$.body.parentNode.contentEditable = true;\r
602                                                                 else\r
603                                                                         domDocument.$.designMode = 'on';\r
604                                                         }, 0 );\r
605                                                 }\r
606 \r
607                                                 CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );\r
608 \r
609                                                 domWindow       = editor.window = new CKEDITOR.dom.window( domWindow );\r
610                                                 domDocument     = editor.document       = new CKEDITOR.dom.document( domDocument );\r
611 \r
612                                                 domDocument.on( 'dblclick', function( evt )\r
613                                                 {\r
614                                                         var element = evt.data.getTarget(),\r
615                                                                 data = { element : element, dialog : '' };\r
616                                                         editor.fire( 'doubleclick', data );\r
617                                                         data.dialog && editor.openDialog( data.dialog );\r
618                                                 });\r
619 \r
620                                                 // Gecko/Webkit need some help when selecting control type elements. (#3448)\r
621                                                 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera ) )\r
622                                                 {\r
623                                                         domDocument.on( 'mousedown', function( ev )\r
624                                                         {\r
625                                                                 var control = ev.data.getTarget();\r
626                                                                 if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )\r
627                                                                         editor.getSelection().selectElement( control );\r
628                                                         } );\r
629                                                 }\r
630 \r
631                                                 if ( CKEDITOR.env.gecko )\r
632                                                 {\r
633                                                         domDocument.on( 'mouseup', function( ev )\r
634                                                         {\r
635                                                                 if ( ev.data.$.button == 2 )\r
636                                                                 {\r
637                                                                         var target = ev.data.getTarget();\r
638 \r
639                                                                         // Prevent right click from selecting an empty block even\r
640                                                                         // when selection is anchored inside it. (#5845)\r
641                                                                         if ( !target.getOuterHtml().replace( emptyParagraphRegexp, '' ) )\r
642                                                                         {\r
643                                                                                 var range = new CKEDITOR.dom.range( domDocument );\r
644                                                                                 range.moveToElementEditStart( target );\r
645                                                                                 range.select( true );\r
646                                                                         }\r
647                                                                 }\r
648                                                         } );\r
649                                                 }\r
650 \r
651                                                 // Prevent the browser opening links in read-only blocks. (#6032)\r
652                                                 domDocument.on( 'click', function( ev )\r
653                                                         {\r
654                                                                 ev = ev.data;\r
655                                                                 if ( ev.getTarget().is( 'a' ) && ev.$.button != 2 )\r
656                                                                         ev.preventDefault();\r
657                                                         });\r
658 \r
659                                                 // Webkit: avoid from editing form control elements content.\r
660                                                 if ( CKEDITOR.env.webkit )\r
661                                                 {\r
662                                                         // Prevent from tick checkbox/radiobox/select\r
663                                                         domDocument.on( 'click', function( ev )\r
664                                                         {\r
665                                                                 if ( ev.data.getTarget().is( 'input', 'select' ) )\r
666                                                                         ev.data.preventDefault();\r
667                                                         } );\r
668 \r
669                                                         // Prevent from editig textfield/textarea value.\r
670                                                         domDocument.on( 'mouseup', function( ev )\r
671                                                         {\r
672                                                                 if ( ev.data.getTarget().is( 'input', 'textarea' ) )\r
673                                                                         ev.data.preventDefault();\r
674                                                         } );\r
675                                                 }\r
676 \r
677                                                 // IE standard compliant in editing frame doesn't focus the editor when\r
678                                                 // clicking outside actual content, manually apply the focus. (#1659)\r
679                                                 if ( CKEDITOR.env.ie\r
680                                                         && domDocument.$.compatMode == 'CSS1Compat'\r
681                                                                 || CKEDITOR.env.gecko\r
682                                                                 || CKEDITOR.env.opera )\r
683                                                 {\r
684                                                         var htmlElement = domDocument.getDocumentElement();\r
685                                                         htmlElement.on( 'mousedown', function( evt )\r
686                                                         {\r
687                                                                 // Setting focus directly on editor doesn't work, we\r
688                                                                 // have to use here a temporary element to 'redirect'\r
689                                                                 // the focus.\r
690                                                                 if ( evt.data.getTarget().equals( htmlElement ) )\r
691                                                                 {\r
692                                                                         if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )\r
693                                                                                 blinkCursor();\r
694                                                                         focusGrabber.focus();\r
695                                                                 }\r
696                                                         } );\r
697                                                 }\r
698 \r
699                                                 domWindow.on( 'blur', function()\r
700                                                         {\r
701                                                                 editor.focusManager.blur();\r
702                                                         });\r
703 \r
704                                                 var wasFocused;\r
705 \r
706                                                 domWindow.on( 'focus', function()\r
707                                                         {\r
708                                                                 var doc = editor.document;\r
709 \r
710                                                                 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )\r
711                                                                         blinkCursor();\r
712                                                                 else if ( CKEDITOR.env.opera )\r
713                                                                         doc.getBody().focus();\r
714                                                                 // Webkit needs focus for the first time on the HTML element. (#6153)\r
715                                                                 else if ( CKEDITOR.env.webkit )\r
716                                                                 {\r
717                                                                         if ( !wasFocused )\r
718                                                                         {\r
719                                                                                 editor.document.getDocumentElement().focus();\r
720                                                                                 wasFocused = 1;\r
721                                                                         }\r
722                                                                 }\r
723 \r
724                                                                 editor.focusManager.focus();\r
725                                                         });\r
726 \r
727                                                 var keystrokeHandler = editor.keystrokeHandler;\r
728                                                 if ( keystrokeHandler )\r
729                                                         keystrokeHandler.attach( domDocument );\r
730 \r
731                                                 if ( CKEDITOR.env.ie )\r
732                                                 {\r
733                                                         domDocument.getDocumentElement().addClass( domDocument.$.compatMode );\r
734                                                         // Override keystrokes which should have deletion behavior\r
735                                                         //  on control types in IE . (#4047)\r
736                                                         domDocument.on( 'keydown', function( evt )\r
737                                                         {\r
738                                                                 var keyCode = evt.data.getKeystroke();\r
739 \r
740                                                                 // Backspace OR Delete.\r
741                                                                 if ( keyCode in { 8 : 1, 46 : 1 } )\r
742                                                                 {\r
743                                                                         var sel = editor.getSelection(),\r
744                                                                                 control = sel.getSelectedElement();\r
745 \r
746                                                                         if ( control )\r
747                                                                         {\r
748                                                                                 // Make undo snapshot.\r
749                                                                                 editor.fire( 'saveSnapshot' );\r
750 \r
751                                                                                 // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will\r
752                                                                                 // break up the selection, safely manage it here. (#4795)\r
753                                                                                 var bookmark = sel.getRanges()[ 0 ].createBookmark();\r
754                                                                                 // Remove the control manually.\r
755                                                                                 control.remove();\r
756                                                                                 sel.selectBookmarks( [ bookmark ] );\r
757 \r
758                                                                                 editor.fire( 'saveSnapshot' );\r
759 \r
760                                                                                 evt.data.preventDefault();\r
761                                                                         }\r
762                                                                 }\r
763                                                         } );\r
764 \r
765                                                         // PageUp/PageDown scrolling is broken in document\r
766                                                         // with standard doctype, manually fix it. (#4736)\r
767                                                         if ( domDocument.$.compatMode == 'CSS1Compat' )\r
768                                                         {\r
769                                                                 var pageUpDownKeys = { 33 : 1, 34 : 1 };\r
770                                                                 domDocument.on( 'keydown', function( evt )\r
771                                                                 {\r
772                                                                         if ( evt.data.getKeystroke() in pageUpDownKeys )\r
773                                                                         {\r
774                                                                                 setTimeout( function ()\r
775                                                                                 {\r
776                                                                                         editor.getSelection().scrollIntoView();\r
777                                                                                 }, 0 );\r
778                                                                         }\r
779                                                                 } );\r
780                                                         }\r
781                                                 }\r
782 \r
783                                                 // Adds the document body as a context menu target.\r
784                                                 if ( editor.contextMenu )\r
785                                                         editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );\r
786 \r
787                                                 setTimeout( function()\r
788                                                         {\r
789                                                                 editor.fire( 'contentDom' );\r
790 \r
791                                                                 if ( fireMode )\r
792                                                                 {\r
793                                                                         editor.mode = 'wysiwyg';\r
794                                                                         editor.fire( 'mode' );\r
795                                                                         fireMode = false;\r
796                                                                 }\r
797 \r
798                                                                 isLoadingData = false;\r
799 \r
800                                                                 if ( isPendingFocus )\r
801                                                                 {\r
802                                                                         editor.focus();\r
803                                                                         isPendingFocus = false;\r
804                                                                 }\r
805                                                                 setTimeout( function()\r
806                                                                 {\r
807                                                                         editor.fire( 'dataReady' );\r
808                                                                 }, 0 );\r
809 \r
810                                                                 // IE, Opera and Safari may not support it and throw errors.\r
811                                                                 try { editor.document.$.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}\r
812                                                                 try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}\r
813 \r
814                                                                 /*\r
815                                                                  * IE BUG: IE might have rendered the iframe with invisible contents.\r
816                                                                  * (#3623). Push some inconsequential CSS style changes to force IE to\r
817                                                                  * refresh it.\r
818                                                                  *\r
819                                                                  * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not\r
820                                                                  * fix the problem. :(\r
821                                                                  */\r
822                                                                 if ( CKEDITOR.env.ie )\r
823                                                                 {\r
824                                                                         setTimeout( function()\r
825                                                                                 {\r
826                                                                                         if ( editor.document )\r
827                                                                                         {\r
828                                                                                                 var $body = editor.document.$.body;\r
829                                                                                                 $body.runtimeStyle.marginBottom = '0px';\r
830                                                                                                 $body.runtimeStyle.marginBottom = '';\r
831                                                                                         }\r
832                                                                                 }, 1000 );\r
833                                                                 }\r
834                                                         },\r
835                                                         0 );\r
836                                         }\r
837 \r
838                                         editor.addMode( 'wysiwyg',\r
839                                                 {\r
840                                                         load : function( holderElement, data, isSnapshot )\r
841                                                         {\r
842                                                                 mainElement = holderElement;\r
843 \r
844                                                                 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )\r
845                                                                         holderElement.setStyle( 'position', 'relative' );\r
846 \r
847                                                                 // The editor data "may be dirty" after this\r
848                                                                 // point.\r
849                                                                 editor.mayBeDirty = true;\r
850 \r
851                                                                 fireMode = true;\r
852 \r
853                                                                 if ( isSnapshot )\r
854                                                                         this.loadSnapshotData( data );\r
855                                                                 else\r
856                                                                         this.loadData( data );\r
857                                                         },\r
858 \r
859                                                         loadData : function( data )\r
860                                                         {\r
861                                                                 isLoadingData = true;\r
862 \r
863                                                                 var config = editor.config,\r
864                                                                         fullPage = config.fullPage,\r
865                                                                         docType = config.docType;\r
866 \r
867                                                                 // Build the additional stuff to be included into <head>.\r
868                                                                 var headExtra =\r
869                                                                         '<style type="text/css" data-cke-temp="1">' +\r
870                                                                                 editor._.styles.join( '\n' ) +\r
871                                                                         '</style>';\r
872 \r
873                                                                 !fullPage && ( headExtra =\r
874                                                                         CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +\r
875                                                                         headExtra );\r
876 \r
877                                                                 var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" data-cke-temp="1" />' : '';\r
878 \r
879                                                                 if ( fullPage )\r
880                                                                 {\r
881                                                                         // Search and sweep out the doctype declaration.\r
882                                                                         data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )\r
883                                                                                 {\r
884                                                                                         editor.docType = docType = match;\r
885                                                                                         return '';\r
886                                                                                 });\r
887                                                                 }\r
888 \r
889                                                                 // Get the HTML version of the data.\r
890                                                                 if ( editor.dataProcessor )\r
891                                                                         data = editor.dataProcessor.toHtml( data, fixForBody );\r
892 \r
893                                                                 if ( fullPage )\r
894                                                                 {\r
895                                                                         // Check if the <body> tag is available.\r
896                                                                         if ( !(/<body[\s|>]/).test( data ) )\r
897                                                                                 data = '<body>' + data;\r
898 \r
899                                                                         // Check if the <html> tag is available.\r
900                                                                         if ( !(/<html[\s|>]/).test( data ) )\r
901                                                                                 data = '<html>' + data + '</html>';\r
902 \r
903                                                                         // Check if the <head> tag is available.\r
904                                                                         if ( !(/<head[\s|>]/).test( data ) )\r
905                                                                                 data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;\r
906                                                                         else if ( !(/<title[\s|>]/).test( data ) )\r
907                                                                                 data = data.replace( /<head[^>]*>/, '$&<title></title>' ) ;\r
908 \r
909                                                                         // The base must be the first tag in the HEAD, e.g. to get relative\r
910                                                                         // links on styles.\r
911                                                                         baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );\r
912 \r
913                                                                         // Inject the extra stuff into <head>.\r
914                                                                         // Attention: do not change it before testing it well. (V2)\r
915                                                                         // This is tricky... if the head ends with <meta ... content type>,\r
916                                                                         // Firefox will break. But, it works if we place our extra stuff as\r
917                                                                         // the last elements in the HEAD.\r
918                                                                         data = data.replace( /<\/head\s*>/, headExtra + '$&' );\r
919 \r
920                                                                         // Add the DOCTYPE back to it.\r
921                                                                         data = docType + data;\r
922                                                                 }\r
923                                                                 else\r
924                                                                 {\r
925                                                                         data =\r
926                                                                                 config.docType +\r
927                                                                                 '<html dir="' + config.contentsLangDirection + '"' +\r
928                                                                                         ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +\r
929                                                                                 '<head>' +\r
930                                                                                         '<title>' + frameLabel + '</title>' +\r
931                                                                                         baseTag +\r
932                                                                                         headExtra +\r
933                                                                                 '</head>' +\r
934                                                                                 '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +\r
935                                                                                                   ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +\r
936                                                                                                   '>' +\r
937                                                                                         data +\r
938                                                                                 '</html>';\r
939                                                                 }\r
940 \r
941                                                                 data += activationScript;\r
942 \r
943 \r
944                                                                 // The iframe is recreated on each call of setData, so we need to clear DOM objects\r
945                                                                 this.onDispose();\r
946                                                                 createIFrame( data );\r
947                                                         },\r
948 \r
949                                                         getData : function()\r
950                                                         {\r
951                                                                 var config = editor.config,\r
952                                                                         fullPage = config.fullPage,\r
953                                                                         docType = fullPage && editor.docType,\r
954                                                                         doc = iframe.getFrameDocument();\r
955 \r
956                                                                 var data = fullPage\r
957                                                                         ? doc.getDocumentElement().getOuterHtml()\r
958                                                                         : doc.getBody().getHtml();\r
959 \r
960                                                                 if ( editor.dataProcessor )\r
961                                                                         data = editor.dataProcessor.toDataFormat( data, fixForBody );\r
962 \r
963                                                                 // Reset empty if the document contains only one empty paragraph.\r
964                                                                 if ( config.ignoreEmptyParagraph )\r
965                                                                         data = data.replace( emptyParagraphRegexp, function( match, lookback ) { return lookback; } );\r
966 \r
967                                                                 if ( docType )\r
968                                                                         data = docType + '\n' + data;\r
969 \r
970                                                                 return data;\r
971                                                         },\r
972 \r
973                                                         getSnapshotData : function()\r
974                                                         {\r
975                                                                 return iframe.getFrameDocument().getBody().getHtml();\r
976                                                         },\r
977 \r
978                                                         loadSnapshotData : function( data )\r
979                                                         {\r
980                                                                 iframe.getFrameDocument().getBody().setHtml( data );\r
981                                                         },\r
982 \r
983                                                         onDispose : function()\r
984                                                         {\r
985                                                                 if ( !editor.document )\r
986                                                                         return;\r
987 \r
988                                                                 editor.document.getDocumentElement().clearCustomData();\r
989                                                                 editor.document.getBody().clearCustomData();\r
990 \r
991                                                                 editor.window.clearCustomData();\r
992                                                                 editor.document.clearCustomData();\r
993 \r
994                                                                 iframe.clearCustomData();\r
995 \r
996                                                                 /*\r
997                                                                 * IE BUG: When destroying editor DOM with the selection remains inside\r
998                                                                 * editing area would break IE7/8's selection system, we have to put the editing\r
999                                                                 * iframe offline first. (#3812 and #5441)\r
1000                                                                 */\r
1001                                                                 iframe.remove();\r
1002                                                         },\r
1003 \r
1004                                                         unload : function( holderElement )\r
1005                                                         {\r
1006                                                                 this.onDispose();\r
1007 \r
1008                                                                 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;\r
1009 \r
1010                                                                 editor.fire( 'contentDomUnload' );\r
1011                                                         },\r
1012 \r
1013                                                         focus : function()\r
1014                                                         {\r
1015                                                                 var win = editor.window;\r
1016 \r
1017                                                                 if ( isLoadingData )\r
1018                                                                         isPendingFocus = true;\r
1019                                                                 // Temporary solution caused by #6025, supposed be unified by #6154.\r
1020                                                                 else if ( CKEDITOR.env.opera && editor.document )\r
1021                                                                 {\r
1022                                                                         // Required for Opera when switching focus\r
1023                                                                         // from another iframe, e.g. panels. (#6444)\r
1024                                                                         var iframe = editor.window.$.frameElement;\r
1025                                                                         iframe.blur(), iframe.focus();\r
1026                                                                         editor.document.getBody().focus();\r
1027 \r
1028                                                                         editor.selectionChange();\r
1029                                                                 }\r
1030                                                                 else if ( !CKEDITOR.env.opera && win )\r
1031                                                                 {\r
1032                                                                         // AIR needs a while to focus when moving from a link.\r
1033                                                                         CKEDITOR.env.air ? setTimeout( function () { win.focus(); }, 0 ) : win.focus();\r
1034                                                                         editor.selectionChange();\r
1035                                                                 }\r
1036                                                         }\r
1037                                                 });\r
1038 \r
1039                                         editor.on( 'insertHtml', onInsert( doInsertHtml ) , null, null, 20 );\r
1040                                         editor.on( 'insertElement', onInsert( doInsertElement ), null, null, 20 );\r
1041                                         editor.on( 'insertText', onInsert( doInsertText ), null, null, 20 );\r
1042                                         // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)\r
1043                                         editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );\r
1044                                 });\r
1045 \r
1046                         var titleBackup;\r
1047                         // Setting voice label as window title, backup the original one\r
1048                         // and restore it before running into use.\r
1049                         editor.on( 'contentDom', function()\r
1050                                 {\r
1051                                         var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );\r
1052                                         title.data( 'cke-title', editor.document.$.title );\r
1053                                         editor.document.$.title = frameLabel;\r
1054                                 });\r
1055 \r
1056                         // IE8 stricts mode doesn't have 'contentEditable' in effect\r
1057                         // on element unless it has layout. (#5562)\r
1058                         if ( CKEDITOR.env.ie8Compat )\r
1059                         {\r
1060                                 editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );\r
1061 \r
1062                                 var selectors = [];\r
1063                                 for ( var tag in CKEDITOR.dtd.$removeEmpty )\r
1064                                         selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );\r
1065                                 editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );\r
1066                         }\r
1067                         // Set the HTML style to 100% to have the text cursor in affect (#6341)\r
1068                         else if ( CKEDITOR.env.gecko )\r
1069                                 editor.addCss( 'html { height: 100% !important; }' );\r
1070 \r
1071                         // Switch on design mode for a short while and close it after then.\r
1072                         function blinkCursor( retry )\r
1073                         {\r
1074                                 CKEDITOR.tools.tryThese(\r
1075                                         function()\r
1076                                         {\r
1077                                                 editor.document.$.designMode = 'on';\r
1078                                                 setTimeout( function()\r
1079                                                 {\r
1080                                                         editor.document.$.designMode = 'off';\r
1081                                                         if ( CKEDITOR.currentInstance == editor )\r
1082                                                                 editor.document.getBody().focus();\r
1083                                                 }, 50 );\r
1084                                         },\r
1085                                         function()\r
1086                                         {\r
1087                                                 // The above call is known to fail when parent DOM\r
1088                                                 // tree layout changes may break design mode. (#5782)\r
1089                                                 // Refresh the 'contentEditable' is a cue to this.\r
1090                                                 editor.document.$.designMode = 'off';\r
1091                                                 var body = editor.document.getBody();\r
1092                                                 body.setAttribute( 'contentEditable', false );\r
1093                                                 body.setAttribute( 'contentEditable', true );\r
1094                                                 // Try it again once..\r
1095                                                 !retry && blinkCursor( 1 );\r
1096                                         });\r
1097                         }\r
1098 \r
1099                         // Create an invisible element to grab focus.\r
1100                         if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )\r
1101                         {\r
1102                                 var focusGrabber;\r
1103                                 editor.on( 'uiReady', function()\r
1104                                 {\r
1105                                         focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(\r
1106                                                 // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)\r
1107                                                 '<span tabindex="-1" style="position:absolute;" role="presentation"></span>' ) );\r
1108 \r
1109                                         focusGrabber.on( 'focus', function()\r
1110                                                 {\r
1111                                                         editor.focus();\r
1112                                                 } );\r
1113                                 } );\r
1114                                 editor.on( 'destroy', function()\r
1115                                 {\r
1116                                         CKEDITOR.tools.removeFunction( contentDomReadyHandler );\r
1117                                         focusGrabber.clearCustomData();\r
1118                                 } );\r
1119                         }\r
1120 \r
1121                         // Disable form elements editing mode provided by some browers. (#5746)\r
1122                         editor.on( 'insertElement', function ( evt )\r
1123                         {\r
1124                                 var element = evt.data;\r
1125                                 if ( element.type == CKEDITOR.NODE_ELEMENT\r
1126                                                 && ( element.is( 'input' ) || element.is( 'textarea' ) ) )\r
1127                                 {\r
1128                                         if ( !element.isReadOnly() )\r
1129                                         {\r
1130                                                 element.setAttribute( 'contentEditable', false );\r
1131                                                 // We should flag that the element was locked by our code so\r
1132                                                 // it'll be editable by the editor functions (#6046).\r
1133                                                 element.setCustomData( '_cke_notReadOnly', 1 );\r
1134                                         }\r
1135                                 }\r
1136                         });\r
1137 \r
1138                 }\r
1139         });\r
1140 \r
1141         // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)\r
1142         if ( CKEDITOR.env.gecko )\r
1143         {\r
1144                 (function()\r
1145                 {\r
1146                         var body = document.body;\r
1147 \r
1148                         if ( !body )\r
1149                                 window.addEventListener( 'load', arguments.callee, false );\r
1150                         else\r
1151                         {\r
1152                                 var currentHandler = body.getAttribute( 'onpageshow' );\r
1153                                 body.setAttribute( 'onpageshow', ( currentHandler ? currentHandler + ';' : '') +\r
1154                                                         'event.persisted && (function(){' +\r
1155                                                                 'var allInstances = CKEDITOR.instances, editor, doc;' +\r
1156                                                                 'for ( var i in allInstances )' +\r
1157                                                                 '{' +\r
1158                                                                 '       editor = allInstances[ i ];' +\r
1159                                                                 '       doc = editor.document;' +\r
1160                                                                 '       if ( doc )' +\r
1161                                                                 '       {' +\r
1162                                                                 '               doc.$.designMode = "off";' +\r
1163                                                                 '               doc.$.designMode = "on";' +\r
1164                                                                 '       }' +\r
1165                                                                 '}' +\r
1166                                                 '})();' );\r
1167                         }\r
1168                 } )();\r
1169 \r
1170         }\r
1171 })();\r
1172 \r
1173 /**\r
1174  * Disables the ability of resize objects (image and tables) in the editing\r
1175  * area.\r
1176  * @type Boolean\r
1177  * @default false\r
1178  * @example\r
1179  * config.disableObjectResizing = true;\r
1180  */\r
1181 CKEDITOR.config.disableObjectResizing = false;\r
1182 \r
1183 /**\r
1184  * Disables the "table tools" offered natively by the browser (currently\r
1185  * Firefox only) to make quick table editing operations, like adding or\r
1186  * deleting rows and columns.\r
1187  * @type Boolean\r
1188  * @default true\r
1189  * @example\r
1190  * config.disableNativeTableHandles = false;\r
1191  */\r
1192 CKEDITOR.config.disableNativeTableHandles = true;\r
1193 \r
1194 /**\r
1195  * Disables the built-in spell checker while typing natively available in the\r
1196  * browser (currently Firefox and Safari only).<br /><br />\r
1197  *\r
1198  * Even if word suggestions will not appear in the CKEditor context menu, this\r
1199  * feature is useful to help quickly identifying misspelled words.<br /><br />\r
1200  *\r
1201  * This setting is currently compatible with Firefox only due to limitations in\r
1202  * other browsers.\r
1203  * @type Boolean\r
1204  * @default true\r
1205  * @example\r
1206  * config.disableNativeSpellChecker = false;\r
1207  */\r
1208 CKEDITOR.config.disableNativeSpellChecker = true;\r
1209 \r
1210 /**\r
1211  * Whether the editor must output an empty value ("") if it's contents is made\r
1212  * by an empty paragraph only.\r
1213  * @type Boolean\r
1214  * @default true\r
1215  * @example\r
1216  * config.ignoreEmptyParagraph = false;\r
1217  */\r
1218 CKEDITOR.config.ignoreEmptyParagraph = true;\r
1219 \r
1220 /**\r
1221  * Fired when data is loaded and ready for retrieval in an editor instance.\r
1222  * @name CKEDITOR.editor#dataReady\r
1223  * @event\r
1224  */\r