/*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
CKEDITOR.dom.element.clearAllMarkers = function( database )\r
{\r
for ( var i in database )\r
- CKEDITOR.dom.element.clearMarkers( database, database[i], true );\r
+ CKEDITOR.dom.element.clearMarkers( database, database[i], 1 );\r
};\r
\r
CKEDITOR.dom.element.clearMarkers = function( database, element, removeFromDatabase )\r
\r
/**\r
* Moves the selection focus to this element.\r
+ * @function\r
+ * @param {Boolean} defer Whether to asynchronously defer the\r
+ * execution by 100 ms.\r
* @example\r
* var element = CKEDITOR.document.getById( 'myTextarea' );\r
* <b>element.focus()</b>;\r
*/\r
- focus : function()\r
+ focus : ( function()\r
{\r
+ function exec()\r
+ {\r
// IE throws error if the element is not visible.\r
try\r
{\r
}\r
catch (e)\r
{}\r
- },\r
+ }\r
+\r
+ return function( defer )\r
+ {\r
+ if ( defer )\r
+ CKEDITOR.tools.setTimeout( exec, 100, this );\r
+ else\r
+ exec.call( this );\r
+ };\r
+ })(),\r
\r
/**\r
* Gets the inner HTML of this element.\r
}\r
\r
case 'hspace':\r
- return this.$.hspace;\r
+ case 'value':\r
+ return this.$[ name ];\r
\r
case 'style':\r
// IE does not return inline styles via getAttribute(). See #2947.\r
// Cache the lowercased name inside a closure.\r
var nodeName = this.$.nodeName.toLowerCase();\r
\r
- if ( CKEDITOR.env.ie )\r
+ if ( CKEDITOR.env.ie && ! ( document.documentMode > 8 ) )\r
{\r
var scopeName = this.$.scopeName;\r
if ( scopeName != 'HTML' )\r
var thisLength = thisAttribs.length,\r
otherLength = otherAttribs.length;\r
\r
- if ( !CKEDITOR.env.ie && thisLength != otherLength )\r
- return false;\r
-\r
for ( var i = 0 ; i < thisLength ; i++ )\r
{\r
var attribute = thisAttribs[ i ];\r
\r
- if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != '_cke_expando' ) ) && attribute.nodeValue != otherElement.getAttribute( attribute.nodeName ) )\r
+ if ( attribute.nodeName == '_moz_dirty' )\r
+ continue;\r
+\r
+ if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != 'data-cke-expando' ) ) && attribute.nodeValue != otherElement.getAttribute( attribute.nodeName ) )\r
return false;\r
}\r
\r
for ( i = 0 ; i < otherLength ; i++ )\r
{\r
attribute = otherAttribs[ i ];\r
- if ( attribute.specified && attribute.nodeName != '_cke_expando'\r
+ if ( attribute.specified && attribute.nodeName != 'data-cke-expando'\r
&& attribute.nodeValue != this.getAttribute( attribute.nodeName ) )\r
return false;\r
}\r
},\r
\r
/**\r
- * Indicates that the element has defined attributes.\r
+ * Whether it's an empty inline elements which has no visual impact when removed.\r
+ */\r
+ isEmptyInlineRemoveable : function()\r
+ {\r
+ if ( !CKEDITOR.dtd.$removeEmpty[ this.getName() ] )\r
+ return false;\r
+\r
+ var children = this.getChildren();\r
+ for ( var i = 0, count = children.count(); i < count; i++ )\r
+ {\r
+ var child = children.getItem( i );\r
+\r
+ if ( child.type == CKEDITOR.NODE_ELEMENT && child.data( 'cke-bookmark' ) )\r
+ continue;\r
+\r
+ if ( child.type == CKEDITOR.NODE_ELEMENT && !child.isEmptyInlineRemoveable()\r
+ || child.type == CKEDITOR.NODE_TEXT && CKEDITOR.tools.trim( child.getText() ) )\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ },\r
+\r
+ /**\r
+ * Checks if the element has any defined attributes.\r
+ * @function\r
* @returns {Boolean} True if the element has attributes.\r
* @example\r
- * var element = CKEDITOR.dom.element.createFromHtml( '<div title="Test">Example</div>' );\r
- * alert( <b>element.hasAttributes()</b> ); "true"\r
+ * var element = CKEDITOR.dom.element.createFromHtml( '<div title="Test">Example</div>' );\r
+ * alert( <b>element.hasAttributes()</b> ); // "true"\r
* @example\r
- * var element = CKEDITOR.dom.element.createFromHtml( '<div>Example</div>' );\r
- * alert( <b>element.hasAttributes()</b> ); "false"\r
+ * var element = CKEDITOR.dom.element.createFromHtml( '<div>Example</div>' );\r
+ * alert( <b>element.hasAttributes()</b> ); // "false"\r
*/\r
hasAttributes :\r
CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) ?\r
return true;\r
\r
// Attributes to be ignored.\r
- case '_cke_expando' :\r
+ case 'data-cke-expando' :\r
continue;\r
\r
/*jsl:fallthru*/\r
:\r
function()\r
{\r
- var attributes = this.$.attributes;\r
- return ( attributes.length > 1 || ( attributes.length == 1 && attributes[0].nodeName != '_cke_expando' ) );\r
+ var attrs = this.$.attributes,\r
+ attrsNum = attrs.length;\r
+\r
+ // The _moz_dirty attribute might get into the element after pasting (#5455)\r
+ var execludeAttrs = { 'data-cke-expando' : 1, _moz_dirty : 1 };\r
+\r
+ return attrsNum > 0 &&\r
+ ( attrsNum > 2 ||\r
+ !execludeAttrs[ attrs[0].nodeName ] ||\r
+ ( attrsNum == 2 && !execludeAttrs[ attrs[1].nodeName ] ) );\r
},\r
\r
/**\r
- * Indicates whether a specified attribute is defined for this element.\r
+ * Checks if the specified attribute is defined for this element.\r
* @returns {Boolean} True if the specified attribute is defined.\r
- * @param (String) name The attribute name.\r
+ * @param {String} name The attribute name.\r
* @example\r
*/\r
hasAttribute : function( name )\r
},\r
\r
/**\r
+ * Merges sibling elements that are identical to this one.<br>\r
+ * <br>\r
+ * Identical child elements are also merged. For example:<br>\r
+ * <b><i></i></b><b><i></i></b> => <b><i></i></b>\r
+ * @function\r
+ * @param {Boolean} [inlineOnly] Allow only inline elements to be merged. Defaults to "true".\r
+ */\r
+ mergeSiblings : ( function()\r
+ {\r
+ function mergeElements( element, sibling, isNext )\r
+ {\r
+ if ( sibling && sibling.type == CKEDITOR.NODE_ELEMENT )\r
+ {\r
+ // Jumping over bookmark nodes and empty inline elements, e.g. <b><i></i></b>,\r
+ // queuing them to be moved later. (#5567)\r
+ var pendingNodes = [];\r
+\r
+ while ( sibling.data( 'cke-bookmark' )\r
+ || sibling.isEmptyInlineRemoveable() )\r
+ {\r
+ pendingNodes.push( sibling );\r
+ sibling = isNext ? sibling.getNext() : sibling.getPrevious();\r
+ if ( !sibling || sibling.type != CKEDITOR.NODE_ELEMENT )\r
+ return;\r
+ }\r
+\r
+ if ( element.isIdentical( sibling ) )\r
+ {\r
+ // Save the last child to be checked too, to merge things like\r
+ // <b><i></i></b><b><i></i></b> => <b><i></i></b>\r
+ var innerSibling = isNext ? element.getLast() : element.getFirst();\r
+\r
+ // Move pending nodes first into the target element.\r
+ while( pendingNodes.length )\r
+ pendingNodes.shift().move( element, !isNext );\r
+\r
+ sibling.moveChildren( element, !isNext );\r
+ sibling.remove();\r
+\r
+ // Now check the last inner child (see two comments above).\r
+ if ( innerSibling && innerSibling.type == CKEDITOR.NODE_ELEMENT )\r
+ innerSibling.mergeSiblings();\r
+ }\r
+ }\r
+ }\r
+\r
+ return function( inlineOnly )\r
+ {\r
+ if ( ! ( inlineOnly === false\r
+ || CKEDITOR.dtd.$removeEmpty[ this.getName() ]\r
+ || this.is( 'a' ) ) ) // Merge empty links and anchors also. (#5567)\r
+ {\r
+ return;\r
+ }\r
+\r
+ mergeElements( this, this.getNext(), true );\r
+ mergeElements( this, this.getPrevious() );\r
+ };\r
+ } )(),\r
+\r
+ /**\r
* Shows this element (display it).\r
* @example\r
* var element = CKEDITOR.dom.element.getById( 'myElement' );\r
function()\r
{\r
this.$.style.MozUserSelect = 'none';\r
+ this.on( 'dragstart', function( evt ) { evt.data.preventDefault(); } );\r
}\r
: CKEDITOR.env.webkit ?\r
function()\r
{\r
this.$.style.KhtmlUserSelect = 'none';\r
+ this.on( 'dragstart', function( evt ) { evt.data.preventDefault(); } );\r
}\r
:\r
function()\r
this.moveChildren( newNode );\r
\r
// Replace the node.\r
- this.$.parentNode.replaceChild( newNode.$, this.$ );\r
- newNode.$._cke_expando = this.$._cke_expando;\r
+ this.getParent() && this.$.parentNode.replaceChild( newNode.$, this.$ );\r
+ newNode.$[ 'data-cke-expando' ] = this.$[ 'data-cke-expando' ];\r
this.$ = newNode.$;\r
},\r
\r
if ( !event.data.getTarget().hasClass( 'cke_enable_context_menu' ) )\r
event.data.preventDefault();\r
} );\r
+ },\r
+\r
+ /**\r
+ * Gets element's direction. Supports both CSS 'direction' prop and 'dir' attr.\r
+ */\r
+ getDirection : function( useComputed )\r
+ {\r
+ return useComputed ? this.getComputedStyle( 'direction' ) : this.getStyle( 'direction' ) || this.getAttribute( 'dir' );\r
+ },\r
+\r
+ /**\r
+ * Gets, sets and removes custom data to be stored as HTML5 data-* attributes.\r
+ * @param {String} name The name of the attribute, excluding the 'data-' part.\r
+ * @param {String} [value] The value to set. If set to false, the attribute will be removed.\r
+ * @example\r
+ * element.data( 'extra-info', 'test' ); // appended the attribute data-extra-info="test" to the element\r
+ * alert( element.data( 'extra-info' ) ); // "test"\r
+ * element.data( 'extra-info', false ); // remove the data-extra-info attribute from the element\r
+ */\r
+ data : function ( name, value )\r
+ {\r
+ name = 'data-' + name;\r
+ if ( value === undefined )\r
+ return this.getAttribute( name );\r
+ else if ( value === false )\r
+ this.removeAttribute( name );\r
+ else\r
+ this.setAttribute( name, value );\r
+\r
+ return null;\r
}\r
});\r
+\r
+( function()\r
+{\r
+ var sides = {\r
+ width : [ "border-left-width", "border-right-width","padding-left", "padding-right" ],\r
+ height : [ "border-top-width", "border-bottom-width", "padding-top", "padding-bottom" ]\r
+ };\r
+\r
+ function marginAndPaddingSize( type )\r
+ {\r
+ var adjustment = 0;\r
+ for ( var i = 0, len = sides[ type ].length; i < len; i++ )\r
+ adjustment += parseInt( this.getComputedStyle( sides [ type ][ i ] ) || 0, 10 ) || 0;\r
+ return adjustment;\r
+ }\r
+\r
+ /**\r
+ * Sets the element size considering the box model.\r
+ * @name CKEDITOR.dom.element.prototype.setSize\r
+ * @function\r
+ * @param {String} type The dimension to set. It accepts "width" and "height".\r
+ * @param {Number} size The length unit in px.\r
+ * @param {Boolean} isBorderBox Apply the size based on the border box model.\r
+ */\r
+ CKEDITOR.dom.element.prototype.setSize = function( type, size, isBorderBox )\r
+ {\r
+ if ( typeof size == 'number' )\r
+ {\r
+ if ( isBorderBox && !( CKEDITOR.env.ie && CKEDITOR.env.quirks ) )\r
+ size -= marginAndPaddingSize.call( this, type );\r
+\r
+ this.setStyle( type, size + 'px' );\r
+ }\r
+ };\r
+\r
+ /**\r
+ * Gets the element size, possibly considering the box model.\r
+ * @name CKEDITOR.dom.element.prototype.getSize\r
+ * @function\r
+ * @param {String} type The dimension to get. It accepts "width" and "height".\r
+ * @param {Boolean} isBorderBox Get the size based on the border box model.\r
+ */\r
+ CKEDITOR.dom.element.prototype.getSize = function( type, isBorderBox )\r
+ {\r
+ var size = Math.max( this.$[ 'offset' + CKEDITOR.tools.capitalize( type ) ],\r
+ this.$[ 'client' + CKEDITOR.tools.capitalize( type ) ] ) || 0;\r
+\r
+ if ( isBorderBox )\r
+ size -= marginAndPaddingSize.call( this, type );\r
+\r
+ return size;\r
+ };\r
+})();\r