X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Felement.js;h=0243dea37764845c1b25ab6406f1d9de884f4869;hp=48b0d26762b2f985e5eb818639913078112ce531;hb=9afde8772159bd3436f1f5b7862960307710ae5a;hpb=614511639979907ceb0da3614122a4d8eb963ad4 diff --git a/_source/core/dom/element.js b/_source/core/dom/element.js index 48b0d26..0243dea 100644 --- a/_source/core/dom/element.js +++ b/_source/core/dom/element.js @@ -307,12 +307,16 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, /** * Moves the selection focus to this element. + * @param {Boolean} defer Whether to asynchronously defer the + * execution by 100 ms. * @example * var element = CKEDITOR.document.getById( 'myTextarea' ); * element.focus(); */ - focus : function() + focus : ( function() { + function exec() + { // IE throws error if the element is not visible. try { @@ -320,7 +324,16 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, } catch (e) {} - }, + } + + return function( defer ) + { + if ( defer ) + CKEDITOR.tools.setTimeout( exec, 100, this ); + else + exec.call( this ); + }; + })(), /** * Gets the inner HTML of this element. @@ -725,7 +738,10 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, { var attribute = thisAttribs[ i ]; - if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != '_cke_expando' ) ) && attribute.nodeValue != otherElement.getAttribute( attribute.nodeName ) ) + if ( attribute.nodeName == '_moz_dirty' ) + continue; + + if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != 'data-cke-expando' ) ) && attribute.nodeValue != otherElement.getAttribute( attribute.nodeName ) ) return false; } @@ -736,7 +752,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, for ( i = 0 ; i < otherLength ; i++ ) { attribute = otherAttribs[ i ]; - if ( attribute.specified && attribute.nodeName != '_cke_expando' + if ( attribute.specified && attribute.nodeName != 'data-cke-expando' && attribute.nodeValue != this.getAttribute( attribute.nodeName ) ) return false; } @@ -786,7 +802,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, { var child = children.getItem( i ); - if ( child.type == CKEDITOR.NODE_ELEMENT && child.getAttribute( '_cke_bookmark' ) ) + if ( child.type == CKEDITOR.NODE_ELEMENT && child.data( 'cke-bookmark' ) ) continue; if ( child.type == CKEDITOR.NODE_ELEMENT && !child.isEmptyInlineRemoveable() @@ -831,7 +847,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, return true; // Attributes to be ignored. - case '_cke_expando' : + case 'data-cke-expando' : continue; /*jsl:fallthru*/ @@ -851,7 +867,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, attrsNum = attrs.length; // The _moz_dirty attribute might get into the element after pasting (#5455) - var execludeAttrs = { _cke_expando : 1, _moz_dirty : 1 }; + var execludeAttrs = { 'data-cke-expando' : 1, _moz_dirty : 1 }; return attrsNum > 0 && ( attrsNum > 2 || @@ -914,7 +930,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, // queuing them to be moved later. (#5567) var pendingNodes = []; - while ( sibling.getAttribute( '_cke_bookmark' ) + while ( sibling.data( 'cke-bookmark' ) || sibling.isEmptyInlineRemoveable() ) { pendingNodes.push( sibling ); @@ -1480,7 +1496,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, // Replace the node. this.getParent() && this.$.parentNode.replaceChild( newNode.$, this.$ ); - newNode.$._cke_expando = this.$._cke_expando; + newNode.$[ 'data-cke-expando' ] = this.$[ 'data-cke-expando' ]; this.$ = newNode.$; }, @@ -1522,40 +1538,78 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, }, /** - * Update the element's size with box model awareness. - * @name CKEDITOR.dom.element.setSize - * @param {String} type [width|height] - * @param {Number} size The length unit in px. - * @param isBorderBox Apply the {@param width} and {@param height} based on border box model. + * Gets element's direction. Supports both CSS 'direction' prop and 'dir' attr. */ - setSize : ( function() + getDirection : function( useComputed ) { - var sides = { - width : [ "border-left-width", "border-right-width","padding-left", "padding-right" ], - height : [ "border-top-width", "border-bottom-width", "padding-top", "padding-bottom" ] - }; - - return function( type, size, isBorderBox ) - { - if ( typeof size == 'number' ) - { - if ( isBorderBox && !( CKEDITOR.env.ie && CKEDITOR.env.quirks ) ) - { - var adjustment = 0; - for ( var i = 0, len = sides[ type ].length; i < len; i++ ) - adjustment += parseInt( this.getComputedStyle( sides [ type ][ i ] ) || 0, 10 ) || 0; - size -= adjustment; - } - this.setStyle( type, size + 'px' ); - } - }; - })(), + return useComputed ? this.getComputedStyle( 'direction' ) : this.getStyle( 'direction' ) || this.getAttribute( 'dir' ); + }, /** - * Gets element's direction. Supports both CSS 'direction' prop and 'dir' attr. + * Gets, sets and removes custom data to be stored as HTML5 data-* attributes. + * @name CKEDITOR.dom.element.data + * @param {String} name The name of the attribute, execluding the 'data-' part. + * @param {String} [value] The value to set. If set to false, the attribute will be removed. */ - getDirection : function( useComputed ) + data : function ( name, value ) { - return useComputed ? this.getComputedStyle( 'direction' ) : this.getStyle( 'direction' ) || this.getAttribute( 'dir' ); + name = 'data-' + name; + if ( value === undefined ) + return this.getAttribute( name ); + else if ( value === false ) + this.removeAttribute( name ); + else + this.setAttribute( name, value ); } }); + +( function() +{ + var sides = { + width : [ "border-left-width", "border-right-width","padding-left", "padding-right" ], + height : [ "border-top-width", "border-bottom-width", "padding-top", "padding-bottom" ] + }; + + function marginAndPaddingSize( type ) + { + var adjustment = 0; + for ( var i = 0, len = sides[ type ].length; i < len; i++ ) + adjustment += parseInt( this.getComputedStyle( sides [ type ][ i ] ) || 0, 10 ) || 0; + return adjustment; + } + + /** + * Update the element's size with box model awareness. + * @name CKEDITOR.dom.element.setSize + * @param {String} type [width|height] + * @param {Number} size The length unit in px. + * @param isBorderBox Apply the {@param width} and {@param height} based on border box model. + */ + CKEDITOR.dom.element.prototype.setSize = function( type, size, isBorderBox ) + { + if ( typeof size == 'number' ) + { + if ( isBorderBox && !( CKEDITOR.env.ie && CKEDITOR.env.quirks ) ) + size -= marginAndPaddingSize.call( this, type ); + + this.setStyle( type, size + 'px' ); + } + }; + + /** + * Get the element's size, possibly with box model awareness. + * @name CKEDITOR.dom.element.getSize + * @param {String} type [width|height] + * @param {Boolean} contentSize Get the {@param width} or {@param height} based on border box model. + */ + CKEDITOR.dom.element.prototype.getSize = function( type, contentSize ) + { + var size = Math.max( this.$[ 'offset' + CKEDITOR.tools.capitalize( type ) ], + this.$[ 'client' + CKEDITOR.tools.capitalize( type ) ] ) || 0; + + if ( contentSize ) + size -= marginAndPaddingSize.call( this, type ); + + return size; + }; +})();