JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @fileOverview The "wysiwygarea" plugin. It registers the "wysiwyg" editing\r
8  *              mode, which handles the main editing area space.\r
9  */\r
10 \r
11 (function()\r
12 {\r
13         // List of elements in which has no way to move editing focus outside.\r
14         var nonExitableElementNames = { table:1,pre:1 };\r
15 \r
16         // Matching an empty paragraph at the end of document.\r
17         var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\1>)?\s*(?=$|<\/body>)/gi;\r
18 \r
19         function onInsertHtml( evt )\r
20         {\r
21                 if ( this.mode == 'wysiwyg' )\r
22                 {\r
23                         this.focus();\r
24                         this.fire( 'saveSnapshot' );\r
25 \r
26                         var selection = this.getSelection(),\r
27                                 data = evt.data;\r
28 \r
29                         if ( this.dataProcessor )\r
30                                 data = this.dataProcessor.toHtml( data );\r
31 \r
32                         if ( CKEDITOR.env.ie )\r
33                         {\r
34                                 var selIsLocked = selection.isLocked;\r
35 \r
36                                 if ( selIsLocked )\r
37                                         selection.unlock();\r
38 \r
39                                 var $sel = selection.getNative();\r
40                                 if ( $sel.type == 'Control' )\r
41                                         $sel.clear();\r
42                                 $sel.createRange().pasteHTML( data );\r
43 \r
44                                 if ( selIsLocked )\r
45                                         this.getSelection().lock();\r
46                         }\r
47                         else\r
48                                 this.document.$.execCommand( 'inserthtml', false, data );\r
49 \r
50                         CKEDITOR.tools.setTimeout( function()\r
51                                 {\r
52                                         this.fire( 'saveSnapshot' );\r
53                                 }, 0, this );\r
54                 }\r
55         }\r
56 \r
57         function onInsertElement( evt )\r
58         {\r
59                 if ( this.mode == 'wysiwyg' )\r
60                 {\r
61                         this.focus();\r
62                         this.fire( 'saveSnapshot' );\r
63 \r
64                         var element = evt.data,\r
65                                 elementName = element.getName(),\r
66                                 isBlock = CKEDITOR.dtd.$block[ elementName ];\r
67 \r
68                         var selection = this.getSelection(),\r
69                                 ranges = selection.getRanges();\r
70 \r
71                         var selIsLocked = selection.isLocked;\r
72 \r
73                         if ( selIsLocked )\r
74                                 selection.unlock();\r
75 \r
76                         var range, clone, lastElement, bookmark;\r
77 \r
78                         for ( var i = ranges.length - 1 ; i >= 0 ; i-- )\r
79                         {\r
80                                 range = ranges[ i ];\r
81 \r
82                                 // Remove the original contents.\r
83                                 range.deleteContents();\r
84 \r
85                                 clone = !i && element || element.clone( true );\r
86 \r
87                                 // If we're inserting a block at dtd-violated position, split\r
88                                 // the parent blocks until we reach blockLimit.\r
89                                 var current, dtd;\r
90                                 if ( isBlock )\r
91                                 {\r
92                                         while( ( current = range.getCommonAncestor( false, true ) )\r
93                                                         && ( dtd = CKEDITOR.dtd[ current.getName() ] )\r
94                                                         && !( dtd && dtd [ elementName ] ) )\r
95                                         {\r
96                                                 // Split up inline elements.\r
97                                                 if ( current.getName() in CKEDITOR.dtd.span )\r
98                                                         range.splitElement( current );\r
99                                                 // If we're in an empty block which indicate a new paragraph,\r
100                                                 // simply replace it with the inserting block.(#3664)\r
101                                                 else if ( range.checkStartOfBlock()\r
102                                                          && range.checkEndOfBlock() )\r
103                                                 {\r
104                                                         range.setStartBefore( current );\r
105                                                         range.collapse( true );\r
106                                                         current.remove();\r
107                                                 }\r
108                                                 else\r
109                                                         range.splitBlock();\r
110                                         }\r
111                                 }\r
112 \r
113                                 // Insert the new node.\r
114                                 range.insertNode( clone );\r
115 \r
116                                 // Save the last element reference so we can make the\r
117                                 // selection later.\r
118                                 if ( !lastElement )\r
119                                         lastElement = clone;\r
120                         }\r
121 \r
122                         range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );\r
123 \r
124                         var next = lastElement.getNextSourceNode( true );\r
125                         if ( next && next.type == CKEDITOR.NODE_ELEMENT )\r
126                                 range.moveToElementEditStart( next );\r
127 \r
128                         selection.selectRanges( [ range ] );\r
129 \r
130                         if ( selIsLocked )\r
131                                 this.getSelection().lock();\r
132 \r
133                         // Save snaps after the whole execution completed.\r
134                         // This's a workaround for make DOM modification's happened after\r
135                         // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'\r
136                         // call.\r
137                         CKEDITOR.tools.setTimeout( function(){\r
138                                 this.fire( 'saveSnapshot' );\r
139                         }, 0, this );\r
140                 }\r
141         }\r
142 \r
143         // DOM modification here should not bother dirty flag.(#4385)\r
144         function restoreDirty( editor )\r
145         {\r
146                 if( !editor.checkDirty() )\r
147                         setTimeout( function(){ editor.resetDirty(); } );\r
148         }\r
149 \r
150         var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),\r
151                 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );\r
152 \r
153         function isNotEmpty( node )\r
154         {\r
155                 return isNotWhitespace( node ) && isNotBookmark( node );\r
156         }\r
157 \r
158         function isNbsp( node )\r
159         {\r
160                 return node.type == CKEDITOR.NODE_TEXT\r
161                            && CKEDITOR.tools.trim( node.getText() ).match( /^(?:&nbsp;|\xa0)$/ );\r
162         }\r
163 \r
164         /**\r
165          *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent\r
166          *  non-exitable-block by padding extra br.(#3189)\r
167          */\r
168         function onSelectionChangeFixBody( evt )\r
169         {\r
170                 var editor = evt.editor,\r
171                         path = evt.data.path,\r
172                         blockLimit = path.blockLimit,\r
173                         selection = evt.data.selection,\r
174                         range = selection.getRanges()[0],\r
175                         body = editor.document.getBody(),\r
176                         enterMode = editor.config.enterMode;\r
177 \r
178                 // When enterMode set to block, we'll establing new paragraph only if we're\r
179                 // selecting inline contents right under body. (#3657)\r
180                 if ( enterMode != CKEDITOR.ENTER_BR\r
181                      && range.collapsed\r
182                          && blockLimit.getName() == 'body'\r
183                          && !path.block )\r
184                 {\r
185                         restoreDirty( editor );\r
186                         var fixedBlock = range.fixBlock( true,\r
187                                         editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );\r
188 \r
189                         // For IE, we should remove any filler node which was introduced before.\r
190                         if ( CKEDITOR.env.ie )\r
191                         {\r
192                                 var first = fixedBlock.getFirst( isNotEmpty );\r
193                                 first && isNbsp( first ) && first.remove();\r
194                         }\r
195 \r
196                         // If the fixed block is blank and already followed by a exitable\r
197                         // block, we should revert the fix. (#3684)\r
198                         if( fixedBlock.getOuterHtml().match( emptyParagraphRegexp ) )\r
199                         {\r
200                                 var previousElement = fixedBlock.getPrevious( isNotWhitespace ),\r
201                                         nextElement = fixedBlock.getNext( isNotWhitespace );\r
202 \r
203 \r
204                                 if ( previousElement && previousElement.getName\r
205                                          && !( previousElement.getName() in nonExitableElementNames )\r
206                                          && range.moveToElementEditStart( previousElement )\r
207                                          || nextElement && nextElement.getName\r
208                                            && !( nextElement.getName() in nonExitableElementNames )\r
209                                            && range.moveToElementEditStart( nextElement ) )\r
210                                 {\r
211                                         fixedBlock.remove();\r
212                                 }\r
213                         }\r
214 \r
215                         range.select();\r
216                         // Notify non-IE that selection has changed.\r
217                         if( !CKEDITOR.env.ie )\r
218                                 editor.selectionChange();\r
219                 }\r
220 \r
221                 // All browsers are incapable to moving cursor out of certain non-exitable\r
222                 // blocks (e.g. table, list, pre) at the end of document, make this happen by\r
223                 // place a bogus node there, which would be later removed by dataprocessor.\r
224                 var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );\r
225                 if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )\r
226                 {\r
227                         restoreDirty( editor );\r
228                         if( !CKEDITOR.env.ie )\r
229                                 body.appendBogus();\r
230                         else\r
231                                 body.append( editor.document.createText( '\xa0' ) );\r
232                 }\r
233         }\r
234 \r
235         CKEDITOR.plugins.add( 'wysiwygarea',\r
236         {\r
237                 requires : [ 'editingblock' ],\r
238 \r
239                 init : function( editor )\r
240                 {\r
241                         var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )\r
242                                 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;\r
243 \r
244                         editor.on( 'editingBlockReady', function()\r
245                                 {\r
246                                         var mainElement,\r
247                                                 fieldset,\r
248                                                 iframe,\r
249                                                 isLoadingData,\r
250                                                 isPendingFocus,\r
251                                                 frameLoaded,\r
252                                                 fireMode;\r
253 \r
254                                         // Support for custom document.domain in IE.\r
255                                         var isCustomDomain = CKEDITOR.env.isCustomDomain();\r
256 \r
257                                         // Creates the iframe that holds the editable document.\r
258                                         var createIFrame = function( data )\r
259                                         {\r
260                                                 if ( iframe )\r
261                                                         iframe.remove();\r
262                                                 if ( fieldset )\r
263                                                         fieldset.remove();\r
264 \r
265                                                 frameLoaded = 0;\r
266 \r
267                                                 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +\r
268                                                         ' style="width:100%;height:100%"' +\r
269                                                         ' frameBorder="0"' +\r
270                                                         // Support for custom document.domain in IE.\r
271                                                         ( isCustomDomain ?\r
272                                                                 ' src="javascript:void((function(){' +\r
273                                                                         'document.open();' +\r
274                                                                         'document.domain=\'' + document.domain + '\';' +\r
275                                                                         'document.close();' +\r
276                                                                 '})())"' : '' ) +\r
277                                                         ' tabIndex="-1"' +\r
278                                                         ' allowTransparency="true"' +\r
279                                                         '></iframe>' );\r
280 \r
281                                                 // Register onLoad event for iframe element, which\r
282                                                 // will fill it with content and set custom domain.\r
283                                                 iframe.on( 'load', function( e )\r
284                                                 {\r
285                                                         e.removeListener();\r
286                                                         var doc = iframe.getFrameDocument().$;\r
287 \r
288                                                         // Custom domain handling is needed after each document.open().\r
289                                                         doc.open();\r
290                                                         if ( isCustomDomain )\r
291                                                                 doc.domain = document.domain;\r
292                                                         doc.write( data );\r
293                                                         doc.close();\r
294 \r
295                                                 } );\r
296 \r
297                                                 var accTitle = editor.lang.editorTitle.replace( '%1', editor.name );\r
298 \r
299                                                 if ( CKEDITOR.env.gecko )\r
300                                                 {\r
301                                                         // Accessibility attributes for Firefox.\r
302                                                         mainElement.setAttributes(\r
303                                                                 {\r
304                                                                         role : 'region',\r
305                                                                         title : accTitle\r
306                                                                 } );\r
307                                                         iframe.setAttributes(\r
308                                                                 {\r
309                                                                         role : 'region',\r
310                                                                         title : ' '\r
311                                                                 } );\r
312                                                 }\r
313                                                 else if ( CKEDITOR.env.webkit )\r
314                                                 {\r
315                                                         iframe.setAttribute( 'title', accTitle );       // Safari 4\r
316                                                         iframe.setAttribute( 'name', accTitle );        // Safari 3\r
317                                                 }\r
318                                                 else if ( CKEDITOR.env.ie )\r
319                                                 {\r
320                                                         // Accessibility label for IE.\r
321                                                         fieldset = CKEDITOR.dom.element.createFromHtml(\r
322                                                                 '<fieldset style="height:100%' +\r
323                                                                 ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? ';position:relative' : '' ) +\r
324                                                                 '">' +\r
325                                                                         '<legend style="display:block;width:0;height:0;overflow:hidden;' +\r
326                                                                         ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? 'position:absolute' : '' ) +\r
327                                                                         '">' +\r
328                                                                                 CKEDITOR.tools.htmlEncode( accTitle ) +\r
329                                                                         '</legend>' +\r
330                                                                 '</fieldset>'\r
331                                                                 , CKEDITOR.document );\r
332                                                         iframe.appendTo( fieldset );\r
333                                                         fieldset.appendTo( mainElement );\r
334                                                 }\r
335 \r
336                                                 if ( !CKEDITOR.env.ie )\r
337                                                         mainElement.append( iframe );\r
338                                         };\r
339 \r
340                                         // The script that launches the bootstrap logic on 'domReady', so the document\r
341                                         // is fully editable even before the editing iframe is fully loaded (#4455).\r
342                                         var activationScript =\r
343                                                 '<script id="cke_actscrpt" type="text/javascript">' +\r
344                                                         'window.parent.CKEDITOR._["contentDomReady' + editor.name + '"]( window );' +\r
345                                                 '</script>';\r
346 \r
347                                         // Editing area bootstrap code.\r
348                                         var contentDomReady = function( domWindow )\r
349                                         {\r
350                                                 if ( frameLoaded )\r
351                                                         return;\r
352 \r
353                                                 frameLoaded = 1;\r
354 \r
355                                                 var domDocument = domWindow.document,\r
356                                                         body = domDocument.body;\r
357 \r
358                                                 // Remove this script from the DOM.\r
359                                                 var script = domDocument.getElementById( "cke_actscrpt" );\r
360                                                 script.parentNode.removeChild( script );\r
361 \r
362                                                 delete CKEDITOR._[ 'contentDomReady' + editor.name ];\r
363 \r
364                                                 body.spellcheck = !editor.config.disableNativeSpellChecker;\r
365 \r
366                                                 if ( CKEDITOR.env.ie )\r
367                                                 {\r
368                                                         // Don't display the focus border.\r
369                                                         body.hideFocus = true;\r
370 \r
371                                                         // Disable and re-enable the body to avoid IE from\r
372                                                         // taking the editing focus at startup. (#141 / #523)\r
373                                                         body.disabled = true;\r
374                                                         body.contentEditable = true;\r
375                                                         body.removeAttribute( 'disabled' );\r
376                                                 }\r
377                                                 else\r
378                                                         domDocument.designMode = 'on';\r
379 \r
380                                                 // IE, Opera and Safari may not support it and throw\r
381                                                 // errors.\r
382                                                 try { domDocument.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}\r
383                                                 try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}\r
384 \r
385                                                 domWindow       = editor.window         = new CKEDITOR.dom.window( domWindow );\r
386                                                 domDocument     = editor.document       = new CKEDITOR.dom.document( domDocument );\r
387 \r
388                                                 // Gecko/Webkit need some help when selecting control type elements. (#3448)\r
389                                                 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )\r
390                                                 {\r
391                                                         domDocument.on( 'mousedown', function( ev )\r
392                                                         {\r
393                                                                 var control = ev.data.getTarget();\r
394                                                                 if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )\r
395                                                                         editor.getSelection().selectElement( control );\r
396                                                         } );\r
397                                                 }\r
398 \r
399                                                 // Webkit: avoid from editing form control elements content.\r
400                                                 if ( CKEDITOR.env.webkit )\r
401                                                 {\r
402                                                         // Prevent from tick checkbox/radiobox/select\r
403                                                         domDocument.on( 'click', function( ev )\r
404                                                         {\r
405                                                                 if ( ev.data.getTarget().is( 'input', 'select' ) )\r
406                                                                         ev.data.preventDefault();\r
407                                                         } );\r
408 \r
409                                                         // Prevent from editig textfield/textarea value.\r
410                                                         domDocument.on( 'mouseup', function( ev )\r
411                                                         {\r
412                                                                 if ( ev.data.getTarget().is( 'input', 'textarea' ) )\r
413                                                                         ev.data.preventDefault();\r
414                                                         } );\r
415                                                 }\r
416 \r
417                                                 // IE standard compliant in editing frame doesn't focus the editor when\r
418                                                 // clicking outside actual content, manually apply the focus. (#1659)\r
419                                                 if( CKEDITOR.env.ie\r
420                                                         && domDocument.$.compatMode == 'CSS1Compat' )\r
421                                                 {\r
422                                                         var htmlElement = domDocument.getDocumentElement();\r
423                                                         htmlElement.on( 'mousedown', function( evt )\r
424                                                         {\r
425                                                                 // Setting focus directly on editor doesn't work, we\r
426                                                                 // have to use here a temporary element to 'redirect'\r
427                                                                 // the focus.\r
428                                                                 if ( evt.data.getTarget().equals( htmlElement ) )\r
429                                                                         ieFocusGrabber.focus();\r
430                                                         } );\r
431                                                 }\r
432 \r
433                                                 var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) ?\r
434                                                                 domWindow : domDocument;\r
435 \r
436                                                 focusTarget.on( 'blur', function()\r
437                                                         {\r
438                                                                 editor.focusManager.blur();\r
439                                                         });\r
440 \r
441                                                 focusTarget.on( 'focus', function()\r
442                                                         {\r
443                                                                 // Gecko need a key event to 'wake up' the editing\r
444                                                                 // ability when document is empty.(#3864)\r
445                                                                 if ( CKEDITOR.env.gecko )\r
446                                                                 {\r
447                                                                         var first = body;\r
448                                                                         while( first.firstChild )\r
449                                                                                 first = first.firstChild;\r
450 \r
451                                                                         if( !first.nextSibling\r
452                                                                                 && ( 'BR' == first.tagName )\r
453                                                                                 && first.hasAttribute( '_moz_editor_bogus_node' ) )\r
454                                                                         {\r
455                                                                                 var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );\r
456                                                                                 keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,\r
457                                                                                         false, false, false, 0, 32 );\r
458                                                                                 domDocument.$.dispatchEvent( keyEventSimulate );\r
459                                                                                 var bogusText = domDocument.getBody().getFirst() ;\r
460                                                                                 // Compensate the line maintaining <br> if enterMode is not block.\r
461                                                                                 if ( editor.config.enterMode == CKEDITOR.ENTER_BR )\r
462                                                                                         domDocument.createElement( 'br', { attributes: { '_moz_dirty' : "" } } )\r
463                                                                                                 .replace( bogusText );\r
464                                                                                 else\r
465                                                                                         bogusText.remove();\r
466                                                                         }\r
467                                                                 }\r
468 \r
469                                                                 editor.focusManager.focus();\r
470                                                         });\r
471 \r
472                                                 var keystrokeHandler = editor.keystrokeHandler;\r
473                                                 if ( keystrokeHandler )\r
474                                                         keystrokeHandler.attach( domDocument );\r
475 \r
476                                                 if ( CKEDITOR.env.ie )\r
477                                                 {\r
478                                                         // Cancel default action for backspace in IE on control types. (#4047)\r
479                                                         domDocument.on( 'keydown', function( evt )\r
480                                                         {\r
481                                                                 // Backspace.\r
482                                                                 var control = evt.data.getKeystroke() == 8\r
483                                                                                           && editor.getSelection().getSelectedElement();\r
484                                                                 if ( control )\r
485                                                                 {\r
486                                                                         // Make undo snapshot.\r
487                                                                         editor.fire( 'saveSnapshot' );\r
488                                                                         // Remove manually.\r
489                                                                         control.remove();\r
490                                                                         editor.fire( 'saveSnapshot' );\r
491                                                                         evt.cancel();\r
492                                                                 }\r
493                                                         } );\r
494 \r
495                                                         // PageUp/PageDown scrolling is broken in document\r
496                                                         // with standard doctype, manually fix it. (#4736)\r
497                                                         if( domDocument.$.compatMode == 'CSS1Compat' )\r
498                                                         {\r
499                                                                 var pageUpDownKeys = { 33 : 1, 34 : 1 };\r
500                                                                 domDocument.on( 'keydown', function( evt )\r
501                                                                 {\r
502                                                                         if( evt.data.getKeystroke() in pageUpDownKeys )\r
503                                                                         {\r
504                                                                                 setTimeout( function ()\r
505                                                                                 {\r
506                                                                                         editor.getSelection().scrollIntoView();\r
507                                                                                 }, 0 );\r
508                                                                         }\r
509                                                                 } );\r
510                                                         }\r
511                                                 }\r
512 \r
513                                                 // Adds the document body as a context menu target.\r
514                                                 if ( editor.contextMenu )\r
515                                                         editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );\r
516 \r
517                                                 setTimeout( function()\r
518                                                         {\r
519                                                                 editor.fire( 'contentDom' );\r
520 \r
521                                                                 if ( fireMode )\r
522                                                                 {\r
523                                                                         editor.mode = 'wysiwyg';\r
524                                                                         editor.fire( 'mode' );\r
525                                                                         fireMode = false;\r
526                                                                 }\r
527 \r
528                                                                 isLoadingData = false;\r
529 \r
530                                                                 if ( isPendingFocus )\r
531                                                                 {\r
532                                                                         editor.focus();\r
533                                                                         isPendingFocus = false;\r
534                                                                 }\r
535                                                                 setTimeout( function()\r
536                                                                 {\r
537                                                                         editor.fire( 'dataReady' );\r
538                                                                 }, 0 );\r
539 \r
540                                                                 /*\r
541                                                                  * IE BUG: IE might have rendered the iframe with invisible contents.\r
542                                                                  * (#3623). Push some inconsequential CSS style changes to force IE to\r
543                                                                  * refresh it.\r
544                                                                  *\r
545                                                                  * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not\r
546                                                                  * fix the problem. :(\r
547                                                                  */\r
548                                                                 if ( CKEDITOR.env.ie )\r
549                                                                 {\r
550                                                                         setTimeout( function()\r
551                                                                                 {\r
552                                                                                         if ( editor.document )\r
553                                                                                         {\r
554                                                                                                 var $body = editor.document.$.body;\r
555                                                                                                 $body.runtimeStyle.marginBottom = '0px';\r
556                                                                                                 $body.runtimeStyle.marginBottom = '';\r
557                                                                                         }\r
558                                                                                 }, 1000 );\r
559                                                                 }\r
560                                                         },\r
561                                                         0 );\r
562                                         };\r
563 \r
564                                         editor.addMode( 'wysiwyg',\r
565                                                 {\r
566                                                         load : function( holderElement, data, isSnapshot )\r
567                                                         {\r
568                                                                 mainElement = holderElement;\r
569 \r
570                                                                 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )\r
571                                                                         holderElement.setStyle( 'position', 'relative' );\r
572 \r
573                                                                 // The editor data "may be dirty" after this\r
574                                                                 // point.\r
575                                                                 editor.mayBeDirty = true;\r
576 \r
577                                                                 fireMode = true;\r
578 \r
579                                                                 if ( isSnapshot )\r
580                                                                         this.loadSnapshotData( data );\r
581                                                                 else\r
582                                                                         this.loadData( data );\r
583                                                         },\r
584 \r
585                                                         loadData : function( data )\r
586                                                         {\r
587                                                                 isLoadingData = true;\r
588 \r
589                                                                 var config = editor.config,\r
590                                                                         fullPage = config.fullPage,\r
591                                                                         docType = config.docType;\r
592 \r
593                                                                 // Build the additional stuff to be included into <head>.\r
594                                                                 var headExtra =\r
595                                                                         '<style type="text/css" cke_temp="1">' +\r
596                                                                                 editor._.styles.join( '\n' ) +\r
597                                                                         '</style>';\r
598 \r
599                                                                 !fullPage && ( headExtra =\r
600                                                                         CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +\r
601                                                                         headExtra );\r
602 \r
603                                                                 var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';\r
604 \r
605                                                                 if ( fullPage )\r
606                                                                 {\r
607                                                                         // Search and sweep out the doctype declaration.\r
608                                                                         data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )\r
609                                                                                 {\r
610                                                                                         editor.docType = docType = match;\r
611                                                                                         return '';\r
612                                                                                 });\r
613                                                                 }\r
614 \r
615                                                                 // Get the HTML version of the data.\r
616                                                                 if ( editor.dataProcessor )\r
617                                                                         data = editor.dataProcessor.toHtml( data, fixForBody );\r
618 \r
619                                                                 if ( fullPage )\r
620                                                                 {\r
621                                                                         // Check if the <body> tag is available.\r
622                                                                         if ( !(/<body[\s|>]/).test( data ) )\r
623                                                                                 data = '<body>' + data;\r
624 \r
625                                                                         // Check if the <html> tag is available.\r
626                                                                         if ( !(/<html[\s|>]/).test( data ) )\r
627                                                                                 data = '<html>' + data + '</html>';\r
628 \r
629                                                                         // Check if the <head> tag is available.\r
630                                                                         if ( !(/<head[\s|>]/).test( data ) )\r
631                                                                                 data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;\r
632 \r
633                                                                         // The base must be the first tag in the HEAD, e.g. to get relative\r
634                                                                         // links on styles.\r
635                                                                         baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );\r
636 \r
637                                                                         // Inject the extra stuff into <head>.\r
638                                                                         // Attention: do not change it before testing it well. (V2)\r
639                                                                         // This is tricky... if the head ends with <meta ... content type>,\r
640                                                                         // Firefox will break. But, it works if we place our extra stuff as\r
641                                                                         // the last elements in the HEAD.\r
642                                                                         data = data.replace( /<\/head\s*>/, headExtra + '$&' );\r
643 \r
644                                                                         // Add the DOCTYPE back to it.\r
645                                                                         data = docType + data;\r
646                                                                 }\r
647                                                                 else\r
648                                                                 {\r
649                                                                         data =\r
650                                                                                 config.docType +\r
651                                                                                 '<html dir="' + config.contentsLangDirection + '">' +\r
652                                                                                 '<head>' +\r
653                                                                                         baseTag +\r
654                                                                                         headExtra +\r
655                                                                                 '</head>' +\r
656                                                                                 '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +\r
657                                                                                                   ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +\r
658                                                                                                   '>' +\r
659                                                                                         data +\r
660                                                                                 '</html>';\r
661                                                                 }\r
662 \r
663                                                                 data += activationScript;\r
664 \r
665                                                                 CKEDITOR._[ 'contentDomReady' + editor.name ] = contentDomReady;\r
666                                                                 createIFrame( data );\r
667                                                         },\r
668 \r
669                                                         getData : function()\r
670                                                         {\r
671                                                                 var config = editor.config,\r
672                                                                         fullPage = config.fullPage,\r
673                                                                         docType = fullPage && editor.docType,\r
674                                                                         doc = iframe.getFrameDocument();\r
675 \r
676                                                                 var data = fullPage\r
677                                                                         ? doc.getDocumentElement().getOuterHtml()\r
678                                                                         : doc.getBody().getHtml();\r
679 \r
680                                                                 if ( editor.dataProcessor )\r
681                                                                         data = editor.dataProcessor.toDataFormat( data, fixForBody );\r
682 \r
683                                                                 // Strip the last blank paragraph within document.\r
684                                                                 if ( config.ignoreEmptyParagraph )\r
685                                                                         data = data.replace( emptyParagraphRegexp, '' );\r
686 \r
687                                                                 if ( docType )\r
688                                                                         data = docType + '\n' + data;\r
689 \r
690                                                                 return data;\r
691                                                         },\r
692 \r
693                                                         getSnapshotData : function()\r
694                                                         {\r
695                                                                 return iframe.getFrameDocument().getBody().getHtml();\r
696                                                         },\r
697 \r
698                                                         loadSnapshotData : function( data )\r
699                                                         {\r
700                                                                 iframe.getFrameDocument().getBody().setHtml( data );\r
701                                                         },\r
702 \r
703                                                         unload : function( holderElement )\r
704                                                         {\r
705                                                                 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;\r
706 \r
707                                                                 editor.fire( 'contentDomUnload' );\r
708                                                         },\r
709 \r
710                                                         focus : function()\r
711                                                         {\r
712                                                                 if ( isLoadingData )\r
713                                                                         isPendingFocus = true;\r
714                                                                 else if ( editor.window )\r
715                                                                 {\r
716                                                                         editor.window.focus();\r
717 \r
718                                                                         // Force the selection to happen, in this way\r
719                                                                         // we guarantee the focus will be there. (#4848)\r
720                                                                         if ( CKEDITOR.env.ie )\r
721                                                                         {\r
722                                                                                 try\r
723                                                                                 {\r
724                                                                                         var sel = editor.getSelection();\r
725                                                                                         sel = sel && sel.getNative();\r
726                                                                                         var range = sel && sel.type && sel.createRange();\r
727                                                                                         if ( range )\r
728                                                                                         {\r
729                                                                                                         sel.empty();\r
730                                                                                                         range.select();\r
731                                                                                         }\r
732                                                                                 }\r
733                                                                                 catch (e) {}\r
734                                                                         }\r
735 \r
736                                                                         editor.selectionChange();\r
737                                                                 }\r
738                                                         }\r
739                                                 });\r
740 \r
741                                         editor.on( 'insertHtml', onInsertHtml, null, null, 20 );\r
742                                         editor.on( 'insertElement', onInsertElement, null, null, 20 );\r
743                                         // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)\r
744                                         editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );\r
745                                 });\r
746 \r
747                         // Create an invisible element to grab focus.\r
748                         if( CKEDITOR.env.ie )\r
749                         {\r
750                                 var ieFocusGrabber;\r
751                                 editor.on( 'uiReady', function()\r
752                                 {\r
753                                         ieFocusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(\r
754                                         '<input tabindex="-1" style="position:absolute; left:-10000">' ) );\r
755 \r
756                                         ieFocusGrabber.on( 'focus', function()\r
757                                                 {\r
758                                                         editor.focus();\r
759                                                 } );\r
760                                 } );\r
761                         }\r
762                 }\r
763         });\r
764 \r
765         // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)\r
766         if( CKEDITOR.env.gecko )\r
767         {\r
768                 var topWin = window.top;\r
769 \r
770                 ( function ()\r
771                 {\r
772                         var topBody = topWin.document.body;\r
773 \r
774                         if( !topBody )\r
775                                 topWin.addEventListener( 'load', arguments.callee, false );\r
776                         else\r
777                         {\r
778                                 topBody.setAttribute( 'onpageshow', topBody.getAttribute( 'onpageshow' )\r
779                                                 + ';event.persisted && CKEDITOR.tools.callFunction(' +\r
780                                                 CKEDITOR.tools.addFunction( function()\r
781                                                 {\r
782                                                         var allInstances = CKEDITOR.instances,\r
783                                                                 editor,\r
784                                                                 doc;\r
785                                                         for( var i in allInstances )\r
786                                                         {\r
787                                                                 editor = allInstances[ i ];\r
788                                                                 doc = editor.document;\r
789                                                                 if( doc )\r
790                                                                 {\r
791                                                                         doc.$.designMode = 'off';\r
792                                                                         doc.$.designMode = 'on';\r
793                                                                 }\r
794                                                         }\r
795                                                 } ) + ')' );\r
796                         }\r
797                 } )();\r
798 \r
799         }\r
800 })();\r
801 \r
802 /**\r
803  * Disables the ability of resize objects (image and tables) in the editing\r
804  * area.\r
805  * @type Boolean\r
806  * @default false\r
807  * @example\r
808  * config.disableObjectResizing = true;\r
809  */\r
810 CKEDITOR.config.disableObjectResizing = false;\r
811 \r
812 /**\r
813  * Disables the "table tools" offered natively by the browser (currently\r
814  * Firefox only) to make quick table editing operations, like adding or\r
815  * deleting rows and columns.\r
816  * @type Boolean\r
817  * @default true\r
818  * @example\r
819  * config.disableNativeTableHandles = false;\r
820  */\r
821 CKEDITOR.config.disableNativeTableHandles = true;\r
822 \r
823 /**\r
824  * Disables the built-in spell checker while typing natively available in the\r
825  * browser (currently Firefox and Safari only).<br /><br />\r
826  *\r
827  * Even if word suggestions will not appear in the CKEditor context menu, this\r
828  * feature is useful to help quickly identifying misspelled words.<br /><br />\r
829  *\r
830  * This setting is currently compatible with Firefox only due to limitations in\r
831  * other browsers.\r
832  * @type Boolean\r
833  * @default true\r
834  * @example\r
835  * config.disableNativeSpellChecker = false;\r
836  */\r
837 CKEDITOR.config.disableNativeSpellChecker = true;\r
838 \r
839 /**\r
840  * Whether the editor must output an empty value ("") if it's contents is made\r
841  * by an empty paragraph only.\r
842  * @type Boolean\r
843  * @default true\r
844  * @example\r
845  * config.ignoreEmptyParagraph = false;\r
846  */\r
847 CKEDITOR.config.ignoreEmptyParagraph = true;\r