X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fstyles%2Fplugin.js;h=1d822d1f55eaa34b81bb03f553645d260e852969;hb=e73319a12b56100b29ef456fd74114fe5519e01c;hp=98b3eba78122934b1fe0cfe1db6dc783896aec9d;hpb=4e70ea24db840898be8cc21c950363a52a2a6aba;p=ckeditor.git diff --git a/_source/plugins/styles/plugin.js b/_source/plugins/styles/plugin.js index 98b3eba..1d822d1 100644 --- a/_source/plugins/styles/plugin.js +++ b/_source/plugins/styles/plugin.js @@ -79,8 +79,8 @@ CKEDITOR.STYLE_OBJECT = 3; (function() { - var blockElements = { address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1 }, - objectElements = { a:1,embed:1,hr:1,img:1,li:1,object:1,ol:1,table:1,td:1,tr:1,th:1,ul:1,dl:1,dt:1,dd:1,form:1}; + var blockElements = { address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1,section:1,header:1,footer:1,nav:1,article:1,aside:1,figure:1,dialog:1,hgroup:1,time:1,meter:1,menu:1,command:1,keygen:1,output:1,progress:1,details:1,datagrid:1,datalist:1 }, + objectElements = { a:1,embed:1,hr:1,img:1,li:1,object:1,ol:1,table:1,td:1,tr:1,th:1,ul:1,dl:1,dt:1,dd:1,form:1,audio:1,video:1 }; var semicolonFixRegex = /\s*(?:;\s*|$)/, varRegex = /#\((.+?)\)/g; @@ -98,7 +98,9 @@ CKEDITOR.STYLE_OBJECT = 3; replaceVariables( styleDefinition.styles, variablesValues ); } - var element = this.element = ( styleDefinition.element || '*' ).toLowerCase(); + var element = this.element = styleDefinition.element ? + ( typeof styleDefinition.element == 'string' ? styleDefinition.element.toLowerCase() : styleDefinition.element ) + : '*'; this.type = blockElements[ element ] ? @@ -108,6 +110,10 @@ CKEDITOR.STYLE_OBJECT = 3; : CKEDITOR.STYLE_INLINE; + // If the 'element' property is an object with a set of possible element, it will be applied like an object style: only to existing elements + if ( typeof this.element == 'object' ) + this.type = CKEDITOR.STYLE_OBJECT; + this._ = { definition : styleDefinition @@ -179,9 +185,12 @@ CKEDITOR.STYLE_OBJECT = 3; && ( element == elementPath.block || element == elementPath.blockLimit ) ) continue; - if( this.type == CKEDITOR.STYLE_OBJECT - && !( element.getName() in objectElements ) ) + if( this.type == CKEDITOR.STYLE_OBJECT ) + { + var name = element.getName(); + if ( !( typeof this.element == 'string' ? name == this.element : name in this.element ) ) continue; + } if ( this.checkElementRemovable( element, true ) ) return true; @@ -213,14 +222,16 @@ CKEDITOR.STYLE_OBJECT = 3; // current style definition. checkElementRemovable : function( element, fullMatch ) { - if ( !element || element.isReadOnly() ) + var def = this._.definition; + + if ( !element || !def.ignoreReadonly && element.isReadOnly() ) return false; - var def = this._.definition, - attribs; + var attribs, + name = element.getName(); // If the element name is the same as the style name. - if ( element.getName() == this.element ) + if ( typeof this.element == 'string' ? name == this.element : name in this.element ) { // If no attributes are defined in the element. if ( !fullMatch && !element.hasAttributes() ) @@ -413,7 +424,8 @@ CKEDITOR.STYLE_OBJECT = 3; var isUnknownElement; // Indicates that fully selected read-only elements are to be included in the styling range. - var includeReadonly = def.includeReadonly; + var ignoreReadonly = def.ignoreReadonly, + includeReadonly = ignoreReadonly || def.includeReadonly; // If the read-only inclusion is not available in the definition, try // to get it from the document data. @@ -437,19 +449,22 @@ CKEDITOR.STYLE_OBJECT = 3; var styleRange; - // Check if the boundaries are inside non stylable elements. - var firstUnstylable = getUnstylableParent( firstNode ), - lastUnstylable = getUnstylableParent( lastNode ); - - // If the first element can't be styled, we'll start processing right - // after its unstylable root. - if ( firstUnstylable ) - currentNode = firstUnstylable.getNextSourceNode( true ); - - // If the last element can't be styled, we'll stop processing on its - // unstylable root. - if ( lastUnstylable ) - lastNode = lastUnstylable; + if ( !ignoreReadonly ) + { + // Check if the boundaries are inside non stylable elements. + var firstUnstylable = getUnstylableParent( firstNode ), + lastUnstylable = getUnstylableParent( lastNode ); + + // If the first element can't be styled, we'll start processing right + // after its unstylable root. + if ( firstUnstylable ) + currentNode = firstUnstylable.getNextSourceNode( true ); + + // If the last element can't be styled, we'll stop processing on its + // unstylable root. + if ( lastUnstylable ) + lastNode = lastUnstylable; + } // Do nothing if the current node now follows the last node to be processed. if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING ) @@ -776,7 +791,7 @@ CKEDITOR.STYLE_OBJECT = 3; breakNodes(); // Now, do the DFS walk. - var currentNode = startNode.getNext(); + var currentNode = startNode; while ( !currentNode.equals( endNode ) ) { /* @@ -829,7 +844,6 @@ CKEDITOR.STYLE_OBJECT = 3; var style = this, def = style._.definition, attributes = def.attributes; - var styles = CKEDITOR.style.getStyleText( def ); // Remove all defined attributes. if ( attributes ) @@ -1510,6 +1524,8 @@ CKEDITOR.STYLE_OBJECT = 3; function applyStyle( document, remove ) { var selection = document.getSelection(), + // Bookmark the range so we can re-select it after processing. + bookmarks = selection.createBookmarks( 1 ), ranges = selection.getRanges(), func = remove ? this.removeFromRange : this.applyToRange, range; @@ -1518,7 +1534,13 @@ CKEDITOR.STYLE_OBJECT = 3; while ( ( range = iterator.getNextRange() ) ) func.call( this, range ); - selection.selectRanges( ranges ); + if ( bookmarks.length == 1 && bookmarks[ 0 ].collapsed ) + { + selection.selectRanges( ranges ); + document.getById( bookmarks[ 0 ].startNode ).remove(); + } + else + selection.selectBookmarks( bookmarks ); document.removeCustomData( 'doc_processing_style' ); }