JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
d3b9e629d459699a04f79e90c68a9112df0d4ce3
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
1 /*\r
2 Copyright (c) 2003-2009, 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         /**\r
14          * List of elements in which has no way to move editing focus outside.\r
15          */\r
16         var nonExitableElementNames = { table:1,pre:1 };\r
17         // Matching an empty paragraph at the end of document.\r
18         var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\1>)?\s*$/gi;\r
19 \r
20         function onInsertHtml( evt )\r
21         {\r
22                 if ( this.mode == 'wysiwyg' )\r
23                 {\r
24                         this.focus();\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         }\r
51 \r
52         function onInsertElement( evt )\r
53         {\r
54                 if ( this.mode == 'wysiwyg' )\r
55                 {\r
56                         this.focus();\r
57                         this.fire( 'saveSnapshot' );\r
58 \r
59                         var element = evt.data,\r
60                                 elementName = element.getName(),\r
61                                 isBlock = CKEDITOR.dtd.$block[ elementName ];\r
62 \r
63                         var selection = this.getSelection(),\r
64                                 ranges = selection.getRanges();\r
65 \r
66                         var selIsLocked = selection.isLocked;\r
67 \r
68                         if ( selIsLocked )\r
69                                 selection.unlock();\r
70 \r
71                         var range, clone, lastElement, bookmark;\r
72 \r
73                         for ( var i = ranges.length - 1 ; i >= 0 ; i-- )\r
74                         {\r
75                                 range = ranges[ i ];\r
76 \r
77                                 // Remove the original contents.\r
78                                 range.deleteContents();\r
79 \r
80                                 clone = !i && element || element.clone( true );\r
81 \r
82                                 // If we're inserting a block at dtd-violated position, split\r
83                                 // the parent blocks until we reach blockLimit.\r
84                                 var current, dtd;\r
85                                 if ( isBlock )\r
86                                 {\r
87                                         while( ( current = range.getCommonAncestor( false, true ) )\r
88                                                         && ( dtd = CKEDITOR.dtd[ current.getName() ] )\r
89                                                         && !( dtd && dtd [ elementName ] ) )\r
90                                         {\r
91                                                 // Split up inline elements.\r
92                                                 if ( current.getName() in CKEDITOR.dtd.span )\r
93                                                         range.splitElement( current );\r
94                                                 // If we're in an empty block which indicate a new paragraph,\r
95                                                 // simply replace it with the inserting block.(#3664)\r
96                                                 else if ( range.checkStartOfBlock()\r
97                                                          && range.checkEndOfBlock() )\r
98                                                 {\r
99                                                         range.setStartBefore( current );\r
100                                                         range.collapse( true );\r
101                                                         current.remove();\r
102                                                 }\r
103                                                 else\r
104                                                         range.splitBlock();\r
105                                         }\r
106                                 }\r
107 \r
108                                 // Insert the new node.\r
109                                 range.insertNode( clone );\r
110 \r
111                                 // Save the last element reference so we can make the\r
112                                 // selection later.\r
113                                 if ( !lastElement )\r
114                                         lastElement = clone;\r
115                         }\r
116 \r
117                         range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );\r
118 \r
119                         var next = lastElement.getNextSourceNode( true );\r
120                         if ( next && next.type == CKEDITOR.NODE_ELEMENT )\r
121                                 range.moveToElementEditStart( next );\r
122 \r
123                         selection.selectRanges( [ range ] );\r
124 \r
125                         if ( selIsLocked )\r
126                                 this.getSelection().lock();\r
127 \r
128                         // Save snaps after the whole execution completed.\r
129                         // This's a workaround for make DOM modification's happened after\r
130                         // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'\r
131                         // call.\r
132                         CKEDITOR.tools.setTimeout( function(){\r
133                                 this.fire( 'saveSnapshot' );\r
134                         }, 0, this );\r
135                 }\r
136         }\r
137 \r
138         // DOM modification here should not bother dirty flag.(#4385)\r
139         function restoreDirty( editor )\r
140         {\r
141                 if( !editor.checkDirty() )\r
142                         setTimeout( function(){ editor.resetDirty(); } );\r
143         }\r
144 \r
145         var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),\r
146                 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );\r
147 \r
148         function isNotEmpty( node )\r
149         {\r
150                 return isNotWhitespace( node ) && isNotBookmark( node );\r
151         }\r
152 \r
153         function isNbsp( node )\r
154         {\r
155                 return node.type == CKEDITOR.NODE_TEXT\r
156                            && CKEDITOR.tools.trim( node.getText() ).match( /^(?:&nbsp;|\xa0)$/ );\r
157         }\r
158 \r
159         /**\r
160          *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent\r
161          *  non-exitable-block by padding extra br.(#3189)\r
162          */\r
163         function onSelectionChangeFixBody( evt )\r
164         {\r
165                 var editor = evt.editor,\r
166                         path = evt.data.path,\r
167                         blockLimit = path.blockLimit,\r
168                         selection = evt.data.selection,\r
169                         range = selection.getRanges()[0],\r
170                         body = editor.document.getBody(),\r
171                         enterMode = editor.config.enterMode;\r
172 \r
173                 // When enterMode set to block, we'll establing new paragraph only if we're\r
174                 // selecting inline contents right under body. (#3657)\r
175                 if ( enterMode != CKEDITOR.ENTER_BR\r
176                      && range.collapsed\r
177                          && blockLimit.getName() == 'body'\r
178                          && !path.block )\r
179                 {\r
180                         restoreDirty( editor );\r
181                         var fixedBlock = range.fixBlock( true,\r
182                                         editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );\r
183 \r
184                         // For IE, we should remove any filler node which was introduced before.\r
185                         if ( CKEDITOR.env.ie )\r
186                         {\r
187                                 var first = fixedBlock.getFirst( isNotEmpty );\r
188                                 first && isNbsp( first ) && first.remove();\r
189                         }\r
190 \r
191                         // If the fixed block is blank and already followed by a exitable\r
192                         // block, we should revert the fix. (#3684)\r
193                         if( fixedBlock.getOuterHtml().match( emptyParagraphRegexp ) )\r
194                         {\r
195                                 var previousElement = fixedBlock.getPrevious( isNotWhitespace ),\r
196                                         nextElement = fixedBlock.getNext( isNotWhitespace );\r
197 \r
198 \r
199                                 if ( previousElement && previousElement.getName\r
200                                          && !( previousElement.getName() in nonExitableElementNames )\r
201                                          && range.moveToElementEditStart( previousElement )\r
202                                          || nextElement && nextElement.getName\r
203                                            && !( nextElement.getName() in nonExitableElementNames )\r
204                                            && range.moveToElementEditStart( nextElement ) )\r
205                                 {\r
206                                         fixedBlock.remove();\r
207                                 }\r
208                         }\r
209 \r
210                         range.select();\r
211                         // Notify non-IE that selection has changed.\r
212                         if( !CKEDITOR.env.ie )\r
213                                 editor.selectionChange();\r
214                 }\r
215 \r
216                 // All browsers are incapable to moving cursor out of certain non-exitable\r
217                 // blocks (e.g. table, list, pre) at the end of document, make this happen by\r
218                 // place a bogus node there, which would be later removed by dataprocessor.\r
219                 var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );\r
220                 if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )\r
221                 {\r
222                         restoreDirty( editor );\r
223                         if( !CKEDITOR.env.ie )\r
224                                 body.appendBogus();\r
225                         else\r
226                                 body.append( editor.document.createText( '\xa0' ) );\r
227                 }\r
228         }\r
229 \r
230         CKEDITOR.plugins.add( 'wysiwygarea',\r
231         {\r
232                 requires : [ 'editingblock' ],\r
233 \r
234                 init : function( editor )\r
235                 {\r
236                         var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )\r
237                                 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;\r
238 \r
239                         editor.on( 'editingBlockReady', function()\r
240                                 {\r
241                                         var mainElement,\r
242                                                 fieldset,\r
243                                                 iframe,\r
244                                                 isLoadingData,\r
245                                                 isPendingFocus,\r
246                                                 frameLoaded,\r
247                                                 fireMode;\r
248 \r
249                                         // Support for custom document.domain in IE.\r
250                                         var isCustomDomain = CKEDITOR.env.isCustomDomain();\r
251 \r
252                                         // Creates the iframe that holds the editable document.\r
253                                         var createIFrame = function()\r
254                                         {\r
255                                                 if ( iframe )\r
256                                                         iframe.remove();\r
257                                                 if ( fieldset )\r
258                                                         fieldset.remove();\r
259 \r
260                                                 frameLoaded = 0;\r
261                                                 // The document domain must be set within the src\r
262                                                 // attribute;\r
263                                                 // Defer the script execution until iframe\r
264                                                 // has been added to main window, this is needed for some\r
265                                                 // browsers which will begin to load the frame content\r
266                                                 // prior to it's presentation in DOM.(#3894)\r
267                                                 var src = 'void( '\r
268                                                                 + ( CKEDITOR.env.gecko ? 'setTimeout' : '' ) + '( function(){' +\r
269                                                                 'document.open();' +\r
270                                                                 ( CKEDITOR.env.ie && isCustomDomain ? 'document.domain="' + document.domain + '";' : '' ) +\r
271                                                                 'document.write( window.parent[ "_cke_htmlToLoad_' + editor.name + '" ] );' +\r
272                                                                 'document.close();' +\r
273                                                                 'window.parent[ "_cke_htmlToLoad_' + editor.name + '" ] = null;' +\r
274                                                                 '}'\r
275                                                                 + ( CKEDITOR.env.gecko ? ', 0 )' : ')()' )\r
276                                                                 + ' )';\r
277 \r
278                                                 // Loading via src attribute does not work in Opera.\r
279                                                 if ( CKEDITOR.env.opera )\r
280                                                         src = 'void(0);';\r
281 \r
282                                                 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +\r
283                                                                 ' style="width:100%;height:100%"' +\r
284                                                                 ' frameBorder="0"' +\r
285                                                                 ' tabIndex="-1"' +\r
286                                                                 ' allowTransparency="true"' +\r
287                                                                 ' src="javascript:' + encodeURIComponent( src ) + '"' +\r
288                                                                 '></iframe>' );\r
289 \r
290                                                 var accTitle = editor.lang.editorTitle.replace( '%1', editor.name );\r
291 \r
292                                                 if ( CKEDITOR.env.gecko )\r
293                                                 {\r
294                                                         // Double checking the iframe will be loaded properly(#4058).\r
295                                                         iframe.on( 'load', function( ev )\r
296                                                         {\r
297                                                                 ev.removeListener();\r
298                                                                 contentDomReady( iframe.$.contentWindow );\r
299                                                         } );\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                                                                 // Get the HTML version of the data.\r
590                                                                 if ( editor.dataProcessor )\r
591                                                                 {\r
592                                                                         data = editor.dataProcessor.toHtml( data, fixForBody );\r
593                                                                 }\r
594 \r
595                                                                 data =\r
596                                                                         editor.config.docType +\r
597                                                                         '<html dir="' + editor.config.contentsLangDirection + '">' +\r
598                                                                         '<head>' +\r
599                                                                                 '<link type="text/css" rel="stylesheet" href="' +\r
600                                                                                 [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +\r
601                                                                                 '">' +\r
602                                                                                 '<style type="text/css" _fcktemp="true">' +\r
603                                                                                         editor._.styles.join( '\n' ) +\r
604                                                                                 '</style>'+\r
605                                                                         '</head>' +\r
606                                                                         '<body>' +\r
607                                                                                 data +\r
608                                                                         '</body>' +\r
609                                                                         '</html>' +\r
610                                                                         activationScript;\r
611 \r
612                                                                 window[ '_cke_htmlToLoad_' + editor.name ] = data;\r
613                                                                 CKEDITOR._[ 'contentDomReady' + editor.name ] = contentDomReady;\r
614                                                                 createIFrame();\r
615 \r
616                                                                 // Opera must use the old method for loading contents.\r
617                                                                 if ( CKEDITOR.env.opera )\r
618                                                                 {\r
619                                                                         var doc = iframe.$.contentWindow.document;\r
620                                                                         doc.open();\r
621                                                                         doc.write( data );\r
622                                                                         doc.close();\r
623                                                                 }\r
624                                                         },\r
625 \r
626                                                         getData : function()\r
627                                                         {\r
628                                                                 var data = iframe.getFrameDocument().getBody().getHtml();\r
629 \r
630                                                                 if ( editor.dataProcessor )\r
631                                                                         data = editor.dataProcessor.toDataFormat( data, fixForBody );\r
632 \r
633                                                                 // Strip the last blank paragraph within document.\r
634                                                                 if ( editor.config.ignoreEmptyParagraph )\r
635                                                                         data = data.replace( emptyParagraphRegexp, '' );\r
636 \r
637                                                                 return data;\r
638                                                         },\r
639 \r
640                                                         getSnapshotData : function()\r
641                                                         {\r
642                                                                 return iframe.getFrameDocument().getBody().getHtml();\r
643                                                         },\r
644 \r
645                                                         loadSnapshotData : function( data )\r
646                                                         {\r
647                                                                 iframe.getFrameDocument().getBody().setHtml( data );\r
648                                                         },\r
649 \r
650                                                         unload : function( holderElement )\r
651                                                         {\r
652                                                                 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;\r
653 \r
654                                                                 editor.fire( 'contentDomUnload' );\r
655                                                         },\r
656 \r
657                                                         focus : function()\r
658                                                         {\r
659                                                                 if ( isLoadingData )\r
660                                                                         isPendingFocus = true;\r
661                                                                 else if ( editor.window )\r
662                                                                 {\r
663                                                                         editor.window.focus();\r
664 \r
665                                                                         // Force the selection to happen, in this way\r
666                                                                         // we guarantee the focus will be there. (#4848)\r
667                                                                         if ( CKEDITOR.env.ie )\r
668                                                                         {\r
669                                                                                 try\r
670                                                                                 {\r
671                                                                                         var sel = editor.getSelection();\r
672                                                                                         sel = sel && sel.getNative();\r
673                                                                                         var range = sel && sel.type && sel.createRange();\r
674                                                                                         if ( range )\r
675                                                                                         {\r
676                                                                                                         sel.empty();\r
677                                                                                                         range.select();\r
678                                                                                         }\r
679                                                                                 }\r
680                                                                                 catch (e) {}\r
681                                                                         }\r
682 \r
683                                                                         editor.selectionChange();\r
684                                                                 }\r
685                                                         }\r
686                                                 });\r
687 \r
688                                         editor.on( 'insertHtml', onInsertHtml, null, null, 20 );\r
689                                         editor.on( 'insertElement', onInsertElement, null, null, 20 );\r
690                                         // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)\r
691                                         editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );\r
692                                 });\r
693 \r
694                         // Create an invisible element to grab focus.\r
695                         if( CKEDITOR.env.ie )\r
696                         {\r
697                                 var ieFocusGrabber;\r
698                                 editor.on( 'uiReady', function()\r
699                                 {\r
700                                         ieFocusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(\r
701                                         '<input tabindex="-1" style="position:absolute; left:-10000">' ) );\r
702 \r
703                                         ieFocusGrabber.on( 'focus', function()\r
704                                                 {\r
705                                                         editor.focus();\r
706                                                 } );\r
707                                 } );\r
708                         }\r
709                 }\r
710         });\r
711 \r
712         // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)\r
713         if( CKEDITOR.env.gecko )\r
714         {\r
715                 var topWin = window.top;\r
716 \r
717                 ( function ()\r
718                 {\r
719                         var topBody = topWin.document.body;\r
720 \r
721                         if( !topBody )\r
722                                 topWin.addEventListener( 'load', arguments.callee, false );\r
723                         else\r
724                         {\r
725                                 topBody.setAttribute( 'onpageshow', topBody.getAttribute( 'onpageshow' )\r
726                                                 + ';event.persisted && CKEDITOR.tools.callFunction(' +\r
727                                                 CKEDITOR.tools.addFunction( function()\r
728                                                 {\r
729                                                         var allInstances = CKEDITOR.instances,\r
730                                                                 editor,\r
731                                                                 doc;\r
732                                                         for( var i in allInstances )\r
733                                                         {\r
734                                                                 editor = allInstances[ i ];\r
735                                                                 doc = editor.document;\r
736                                                                 if( doc )\r
737                                                                 {\r
738                                                                         doc.$.designMode = 'off';\r
739                                                                         doc.$.designMode = 'on';\r
740                                                                 }\r
741                                                         }\r
742                                                 } ) + ')' );\r
743                         }\r
744                 } )();\r
745 \r
746         }\r
747 })();\r
748 \r
749 /**\r
750  * Disables the ability of resize objects (image and tables) in the editing\r
751  * area.\r
752  * @type Boolean\r
753  * @default false\r
754  * @example\r
755  * config.disableObjectResizing = true;\r
756  */\r
757 CKEDITOR.config.disableObjectResizing = false;\r
758 \r
759 /**\r
760  * Disables the "table tools" offered natively by the browser (currently\r
761  * Firefox only) to make quick table editing operations, like adding or\r
762  * deleting rows and columns.\r
763  * @type Boolean\r
764  * @default true\r
765  * @example\r
766  * config.disableNativeTableHandles = false;\r
767  */\r
768 CKEDITOR.config.disableNativeTableHandles = true;\r
769 \r
770 /**\r
771  * Disables the built-in spell checker while typing natively available in the\r
772  * browser (currently Firefox and Safari only).<br /><br />\r
773  *\r
774  * Even if word suggestions will not appear in the CKEditor context menu, this\r
775  * feature is useful to help quickly identifying misspelled words.<br /><br />\r
776  *\r
777  * This setting is currently compatible with Firefox only due to limitations in\r
778  * other browsers.\r
779  * @type Boolean\r
780  * @default true\r
781  * @example\r
782  * config.disableNativeSpellChecker = false;\r
783  */\r
784 CKEDITOR.config.disableNativeSpellChecker = true;\r
785 \r
786 /**\r
787  * Whether the editor must output an empty value ("") if it's contents is made\r
788  * by an empty paragraph only.\r
789  * @type Boolean\r
790  * @default true\r
791  * @example\r
792  * config.ignoreEmptyParagraph = false;\r
793  */\r
794 CKEDITOR.config.ignoreEmptyParagraph = true;\r