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