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