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