Ticket #2862: 2862_3.patch
File 2862_3.patch, 17.7 KB (added by , 15 years ago) |
---|
-
_source/plugins/fitwindow/plugin.js
1 /* 2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 /** 7 * @fileOverview The "fitwindow" plugin. Enable it will make the editor chrome 8 * being maximized and fullfill the view size. Disable it restore 9 * editor chrome into original size. 10 */ 11 12 (function() 13 { 14 var doc = new CKEDITOR.dom.document( document ), bodyEl = doc.getBody(); 15 16 //Only one editor instance is allowed to be full screen at a time. 17 var hasMaximized = false; 18 19 function fitWindowCommand(editor) 20 { 21 this.editor = editor; 22 CKEDITOR.tools.extend(this, 23 { 24 // elements along with styles. 25 savedAttributes: [], 26 // Keep track of the need-to-restore data 27 restore: 28 { 29 // document content 30 content: '', 31 // selection range bookmark 32 bookmark: null, 33 // scrollbar position 34 scroll: null 35 }, 36 // Whether pending the restoring due to asynchroniz loading of 37 // content. 38 restorePending: false 39 }); 40 } 41 42 fitWindowCommand.prototype = 43 { 44 /** 45 * Save the css style of the element for later restoring. 46 * 47 * @param {CKEDITOR.dom.element} element 48 */ 49 saveStyles : function ( element ) 50 { 51 this.savedAttributes.push( { 52 element : element, 53 attributes : { 54 'class' : element.getAttribute( 'class' ), 55 'style' : element.getAttribute( 'style' ) 56 } 57 } ); 58 }, 59 60 /** 61 * Restore the saved attributes for elements 62 */ 63 restoreAllStyles : function () 64 { 65 var i = 0, l = this.savedAttributes.length, attrs, element; 66 var attrName, attribute; 67 for ( ; i < l ; i++ ) 68 { 69 attrs = this.savedAttributes[ i ].attributes; 70 element = this.savedAttributes[ i ].element; 71 72 for ( attrName in attrs ) 73 { 74 if ( attrs[ attrName ] ) 75 element.setAttribute( attrName, attrs[ attrName ] ); 76 else 77 element.removeAttribute( attrName ); 78 } 79 } 80 }, 81 82 /** 83 * Alter the element style while keep record of the original styles. 84 */ 85 changeStyle : function ( element, styles ) 86 { 87 this.saveStyles( element ); 88 element.setStyles( styles ); 89 }, 90 91 92 /** 93 * Lift the whole editor to became the first child of body element, 94 * OR restore the editor to it's original position. 95 * @param {Boolean} 96 * isRestore 97 */ 98 moveEditor : function ( isRestore ) 99 { 100 var ctEl = this.editor.container; 101 102 if ( isRestore ) 103 { 104 // place right after the CKeditor replacing element. 105 ctEl 106 .insertAfter( CKEDITOR.document.getById( this.editor.name ) ); 107 } 108 else 109 { 110 bodyEl.append( this.editor.container, true ); 111 } 112 }, 113 114 saveSelection : function () 115 { 116 if ( this.editor.mode === 'wysiwyg' ) 117 { 118 var sel = this.editor.document.getSelection(); 119 if ( sel ) 120 { 121 this.restore.bookmark = sel.createBookmarks( true ); 122 } 123 } 124 }, 125 126 restoreSelection : function () 127 { 128 if ( this.restore.bookmark && !this.restorePending ) 129 { 130 var sel = this.editor.document.getSelection(); 131 if ( sel ) 132 { 133 sel.selectBookmarks( this.restore.bookmark ); 134 delete this.restore.bookmark; 135 } 136 } 137 }, 138 139 saveContent : function () 140 { 141 // Kludge: Fix for Gecko and Webkit bug of iframe reloads when moved 142 // around the DOM tree. 143 if ( this.editor.mode === 'wysiwyg' 144 && ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) ) 145 { 146 // Get the dirty content along with bookmark 147 this.restore.content = this.editor.getSnapshot(); 148 this.restorePending = true; 149 } 150 }, 151 152 restoreContent : function () 153 { 154 if ( this.restore.content ) 155 { 156 this.editor.on( 'mode', function() 157 { 158 this.restorePending = false; 159 this.restoreScrollPosition(); 160 this.restoreSelection(); 161 this.editor.removeListener( 'mode', arguments.callee ); 162 delete this.restore.content; 163 }, this ); 164 165 // reload document content 166 this.editor.setMode( 'wysiwyg', true, this.restore.content ); 167 } 168 }, 169 170 saveScrollPosition : function ( ) 171 { 172 if ( CKEDITOR.env.ie && this.editor.mode === 'wysiwyg' ) 173 return; 174 var element = ( this.editor.mode === 'wysiwyg' )? 175 this.editor.document.$.documentElement : 176 this.editor._.modes.source._.getTextArea(); 177 178 element = element.$ || element; 179 this.restore.scroll = { 180 'element' : element, 181 'left' : element.scrollLeft + element.clientWidth, 182 'top' : element.scrollTop + element.clientHeight 183 }; 184 }, 185 186 restoreScrollPosition : function () 187 { 188 if(this.restore.scroll && !this.restorePending) 189 { 190 console.debug('mode1'+this.editor.mode); 191 var element = ( this.editor.mode === 'wysiwyg' ) ? 192 this.editor.document.$.documentElement : 193 this.editor._.modes.source._.getTextArea(); 194 element = element.$ || element; 195 var translatedScroll = 196 { 197 'left' : ( this.restore.scroll.left - element.clientWidth ), 198 'top' : ( this.restore.scroll.top - element.clientHeight ) 199 }; 200 element.scrollLeft = translatedScroll.left; 201 element.scrollTop = translatedScroll.top; 202 delete this.restore.scroll; 203 } 204 }, 205 206 onSave: function() 207 { 208 this.saveSelection(); 209 this.saveContent(); 210 this.saveScrollPosition(); 211 }, 212 onRestore : function() 213 { 214 this.restoreContent(); 215 this.restoreScrollPosition(); 216 this.restoreSelection(); 217 }, 218 exec : function( editor ) 219 { 220 if ( ! ( this.state === CKEDITOR.TRISTATE_DISABLED ) ) 221 { 222 //Begin to tranform 223 if ( this.state === CKEDITOR.TRISTATE_OFF && !hasMaximized ) 224 { 225 this.onSave(); 226 this.moveEditor(); 227 228 // fix IE viewport scrolling 229 if ( CKEDITOR.env.ie ) 230 { 231 232 var view = new CKEDITOR.dom.element( doc.$.documentElement ); 233 this.changeStyle( view, { 234 'overflow' :'hidden' 235 } ); 236 } 237 238 this.changeStyle( bodyEl, { 239 'top' : '0px', 240 'left' : '0px', 241 'height' : '100%', 242 'width' : '100%', 243 'overflow' : 'hidden', 244 'position' : 'absolute', 245 'margin' : '0px' 246 } ); 247 248 if ( CKEDITOR.env.webkit ) 249 { 250 this.changeStyle( editor.container, { 251 'position' : 'absolute', 252 'height' : '100%', 253 'width' : '100%', 254 'z-index' : '10' 255 } ); 256 } 257 258 this.changeStyle( editor.container.getFirst(), { 259 'width' : '100%', 260 // Kludge: Fix IE table over-height on fit parent. 261 'height' : CKEDITOR.env.ie ? '90%' : '100%', 262 'z-index' : '10' 263 } ); 264 265 // Fix IE 'source' mode bug of #2764 266 if( editor.mode == 'source' && CKEDITOR.env.ie ) 267 { 268 var editareaEl = this.editor._.modes.source._.getTextArea(); 269 this.changeStyle( editareaEl, { 270 'width' : editareaEl.getParent().$.clientWidth, 271 'height' : editareaEl.getParent().$.clientHeight 272 } ); 273 } 274 275 this.onRestore(); 276 hasMaximized = true; 277 // refresh command state 278 this.toggleState(); 279 } 280 else if( this.state === CKEDITOR.TRISTATE_ON ) 281 { 282 this.onSave(); 283 this.moveEditor( true ); 284 this.restoreAllStyles(); 285 this.onRestore(); 286 hasMaximized = false; 287 // refresh command state 288 this.toggleState(); 289 } 290 } 291 } 292 }; 293 294 CKEDITOR.plugins.add( 'fitwindow', 295 { 296 requires : [ 'editingblock' ], 297 298 init : function( editor ) 299 { 300 editor.addCommand( 'fitwindow', new fitWindowCommand( editor ) ); 301 editor.ui.addButton( 'Maximize', { 302 lablel :editor.lang.fitWindow, 303 command :'fitwindow' 304 } ); 305 306 if(editor.config.startupFitWindow) 307 { 308 editor.on( 'mode', function() 309 { 310 // defer the execution to avoid DUP event registration in 311 // event-handler. 312 CKEDITOR.tools.setTimeout( function() 313 { 314 editor.getCommand( 'fitwindow' ).exec(); 315 }, 0 ); 316 317 editor.removeListener( 'mode', arguments.callee ); 318 }); 319 } 320 } 321 }); 322 323 })(); 324 325 CKEDITOR.tools.extend( CKEDITOR.config, 326 { 327 startupFitWindow : false 328 } );\ No newline at end of file -
_source/plugins/toolbar/plugin.js
214 214 'Subscript', 'Superscript', '-', 215 215 'SelectAll', 'RemoveFormat', '-', 216 216 'Link', 'Unlink', 'Anchor', '-', 217 'Table', 'Smiley', 'HorizontalRule', 'SpecialChar', 'PageBreak' 217 'Table', 'Smiley', 'HorizontalRule', 'SpecialChar', 'PageBreak', '-', 218 'Maximize' 218 219 ] 219 220 ]; -
_source/plugins/selection/plugin.js
624 624 this.onSelectionSet && this.onSelectionSet(); 625 625 }, 626 626 627 createBookmarks : function( )627 createBookmarks : function( serializable ) 628 628 { 629 629 var retval = [], 630 630 ranges = this.getRanges(); … … 629 629 var retval = [], 630 630 ranges = this.getRanges(); 631 631 for ( var i = 0 ; i < ranges.length ; i++ ) 632 retval.push( ranges[i].createBookmark( ) );632 retval.push( ranges[i].createBookmark( serializable ) ); 633 633 return retval; 634 634 }, 635 635 -
_source/plugins/editingblock/plugin.js
102 102 * // Switch to "source" view. 103 103 * CKEDITOR.instances.editor1.setMode( 'source' ); 104 104 */ 105 CKEDITOR.editor.prototype.setMode = function( mode 105 CKEDITOR.editor.prototype.setMode = function( mode, isReload, reloadData) 106 106 { 107 107 var data, 108 108 holderElement = this.getThemeSpace( 'contents' ), … … 111 111 // Unload the previous mode. 112 112 if ( this.mode ) 113 113 { 114 if ( mode == this.mode)114 if (!isReload && ( mode == this.mode ) ) 115 115 return; 116 116 117 117 var currentMode = getMode( this ); 118 data = currentMode.getData(); 118 if (!isReload) 119 data = currentMode.getData(); 120 else 121 data = reloadData; 122 119 123 currentMode.unload( holderElement ); 120 124 this.mode = ''; 121 125 } -
_source/plugins/sourcearea/plugin.js
22 22 23 23 editor.addMode( 'source', 24 24 { 25 '_': { 26 27 getTextArea : function(){ 28 return textarea; 29 } 30 31 }, 25 32 load : function( holderElement, data ) 26 33 { 27 34 // Create the source area <textarea>. -
_source/skins/default/toolbar.css
310 310 { 311 311 background-position: 0 -880px; 312 312 } 313 .cke_skin_default a.cke_button_fitwindow .cke_icon 314 { 315 background-position: 0 -1040px; 316 } 313 317 314 318 .cke_skin_default a.cke_button_numberedlist .cke_icon 315 319 { -
_source/core/dom/element.js
379 379 380 380 return tabIndex; 381 381 break; 382 383 case 'style' : 384 return this.$.style.cssText; 382 385 } 383 386 384 387 return standard.call( this, name ); … … 846 849 { 847 850 if ( name == 'class' ) 848 851 name = 'className'; 852 else if ( name === 'style' ) 853 { 854 if(this.$.style) 855 this.$.style.cssText = ' '; 856 return; 857 } 849 858 standard.call( this, name ); 850 859 }; 851 860 } -
_source/core/dom/range.js
360 360 return docFrag; 361 361 }, 362 362 363 // This is an "intrusive" way to create a bookmark. It includes <span> tags 364 // in the range boundaries. The advantage of it is that it is possible to 365 // handle DOM mutations when moving back to the bookmark. 366 // Attention: the inclusion of nodes in the DOM is a design choice and 367 // should not be changed as there are other points in the code that may be 368 // using those nodes to perform operations. See GetBookmarkNode. 369 createBookmark : function() 363 /** 364 * Creates a bookmark object, which can be later used to restore the 365 * range by using the moveToBookmark function. 366 * This is an "intrusive" way to create a bookmark. It includes <span> tags 367 * in the range boundaries. The advantage of it is that it is possible to 368 * handle DOM mutations when moving back to the bookmark. 369 * Attention: the inclusion of nodes in the DOM is a design choice and 370 * should not be changed as there are other points in the code that may be 371 * using those nodes to perform operations. See GetBookmarkNode. 372 * @param {Boolean} [serializable] Indicates that the bookmark nodes 373 * must contain ids, which can be used to restore the range even 374 * when these nodes suffer mutations (like a clonation or innerHTML 375 * change). 376 * @returns {Object} And object representing a bookmark. 377 */ 378 createBookmark : function( serializable ) 370 379 { 371 380 var startNode, endNode; 381 var baseId; 372 382 var clone; 373 383 374 384 startNode = this.document.createElement( 'span' ); … … 379 389 // removed during DOM operations. 380 390 startNode.setHtml( ' ' ); 381 391 392 if ( serializable ) 393 { 394 baseId = 'cke_bm_' + CKEDITOR.tools.getNextNumber(); 395 startNode.setAttribute( 'id', baseId + 'S' ); 396 } 397 382 398 // If collapsed, the endNode will not be created. 383 399 if ( !this.collapsed ) 384 400 { … … 385 401 endNode = startNode.clone(); 386 402 endNode.setHtml( ' ' ); 387 403 404 if ( serializable ) 405 endNode.setAttribute( 'id', baseId + 'E' ); 406 388 407 clone = this.clone(); 389 408 clone.collapse(); 390 409 clone.insertNode( endNode ); … … 404 423 this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END ); 405 424 406 425 return { 407 startNode : startNode, 408 endNode : endNode 426 startNode : serializable ? baseId + 'S' : startNode, 427 endNode : serializable ? baseId + 'E' : endNode, 428 serializable : serializable 409 429 }; 410 430 }, 411 431 … … 411 431 412 432 moveToBookmark : function( bookmark ) 413 433 { 434 var serializable = bookmark.serializable, 435 startNode = serializable ? this.document.getById( bookmark.startNode ) : bookmark.startNode, 436 endNode = serializable ? this.document.getById( bookmark.endNode ) : bookmark.endNode; 437 414 438 // Set the range start at the bookmark start node position. 415 this.setStartBefore( bookmark.startNode );439 this.setStartBefore( startNode ); 416 440 417 441 // Remove it, because it may interfere in the setEndBefore call. 418 bookmark.startNode.remove();442 startNode.remove(); 419 443 420 444 // Set the range end at the bookmark end node position, or simply 421 445 // collapse it if it is not available. 422 var endNode = bookmark.endNode;423 446 if ( endNode ) 424 447 { 425 448 this.setEndBefore( endNode ); -
_source/core/command.js
5 5 6 6 CKEDITOR.command = function( editor, commandDefinition ) 7 7 { 8 this.state = CKEDITOR.TRISTATE_OFF;8 this.state = ( 'state' in commandDefinition ) ? commandDefinition.state : CKEDITOR.TRISTATE_OFF; 9 9 10 10 this.exec = function() 11 11 { … … 18 18 CKEDITOR.event.call( this ); 19 19 }; 20 20 21 CKEDITOR.command.prototype = 22 { 23 setState : function( newState ) 24 { 25 // Do nothing if there is no state change. 26 if ( this.state == newState ) 27 return false; 28 29 // Set the new state. 30 this.state = newState; 31 32 // Fire the "state" event, so other parts of the code can react to the 33 // change. 34 this.fire( 'state' ); 35 36 return true; 37 }, 38 39 /* 40 * Toggle the current state of command and refresh. 41 */ 42 toggleState : function() 43 { 44 this.setState( this.state === CKEDITOR.TRISTATE_ON ? 45 CKEDITOR.TRISTATE_OFF 46 : CKEDITOR.TRISTATE_ON ); 47 } 48 } 49 21 50 CKEDITOR.event.implementOn( CKEDITOR.command.prototype ); -
_source/core/config.js
147 147 * config.plugins = 'basicstyles,button,htmldataprocessor,toolbar,wysiwygarea'; 148 148 */ 149 149 150 plugins : 'basicstyles,button,elementspath,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,preview,removeformat,smiley,indent,link,list,sourcearea,table,specialchar,tab,toolbar,wysiwygarea ',150 plugins : 'basicstyles,button,elementspath,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,preview,removeformat,smiley,indent,link,list,sourcearea,table,specialchar,tab,toolbar,wysiwygarea,fitwindow', 151 151 152 152 /** 153 153 * The theme to be used to build the UI.