JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / core / dom / element.js
index 0243dea..5df3d19 100644 (file)
@@ -1,5 +1,5 @@
 /*\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
@@ -307,6 +307,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
 \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
@@ -428,6 +429,13 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                                        name = 'className';\r
                                                        break;\r
 \r
+                                               case 'http-equiv':\r
+                                                       name = 'httpEquiv';\r
+                                                       break;\r
+\r
+                                               case 'name':\r
+                                                       return this.$.name;\r
+\r
                                                case 'tabindex':\r
                                                        var tabIndex = standard.call( this, name );\r
 \r
@@ -452,7 +460,8 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                                }\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
@@ -712,6 +721,9 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
 \r
                isEditable : function()\r
                {\r
+                       if ( this.isReadOnly() )\r
+                               return false;\r
+\r
                        // Get the element name.\r
                        var name = this.getName();\r
 \r
@@ -815,14 +827,15 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                },\r
 \r
                /**\r
-                * Indicates that the element has defined attributes.\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( '&lt;div title="Test"&gt;Example&lt;/div&gt;' );\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( '&lt;div&gt;Example&lt;/div&gt;' );\r
+                * alert( <b>element.hasAttributes()</b> );  // "false"\r
                 */\r
                hasAttributes :\r
                        CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) ?\r
@@ -876,16 +889,33 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                },\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
+               hasAttribute : (function()\r
                {\r
-                       var $attr = this.$.attributes.getNamedItem( name );\r
-                       return !!( $attr && $attr.specified );\r
-               },\r
+                       function standard( name )\r
+                       {\r
+                               var $attr = this.$.attributes.getNamedItem( name );\r
+                               return !!( $attr && $attr.specified );\r
+                       }\r
+\r
+                       return ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 ) ?\r
+                                       function( name )\r
+                                       {\r
+                                               // On IE < 8 the name attribute cannot be retrieved\r
+                                               // right after the element creation and setting the\r
+                                               // name with setAttribute.\r
+                                               if ( name == 'name' )\r
+                                                       return !!this.$.name;\r
+\r
+                                               return standard.call( this, name );\r
+                                       }\r
+                               :\r
+                                       standard;\r
+               })(),\r
 \r
                /**\r
                 * Hides this element (display:none).\r
@@ -920,6 +950,14 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                        }\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
+                * &lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt; =&gt; &lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;\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
@@ -959,11 +997,14 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                }\r
                        }\r
 \r
-                       return function()\r
+                       return function( inlineOnly )\r
                                {\r
-                                       // Merge empty links and anchors also. (#5567)\r
-                                       if ( !( CKEDITOR.dtd.$removeEmpty[ this.getName() ] || this.is( 'a' ) ) )\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
@@ -1021,6 +1062,18 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                        return this;\r
                                };\r
                        }\r
+                       else if ( CKEDITOR.env.ie8Compat && CKEDITOR.env.secure )\r
+                       {\r
+                               return function( name, value )\r
+                               {\r
+                                       // IE8 throws error when setting src attribute to non-ssl value. (#7847)\r
+                                       if ( name == 'src' && value.match( /^http:\/\// ) )\r
+                                               try { standard.apply( this, arguments ); } catch( e ){}\r
+                                       else\r
+                                               standard.apply( this, arguments );\r
+                                       return this;\r
+                               };\r
+                       }\r
                        else\r
                                return standard;\r
                })(),\r
@@ -1542,14 +1595,23 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                 */\r
                getDirection : function( useComputed )\r
                {\r
-                       return useComputed ? this.getComputedStyle( 'direction' ) : this.getStyle( 'direction' ) || this.getAttribute( 'dir' );\r
+                       return useComputed ?\r
+                               this.getComputedStyle( 'direction' )\r
+                                       // Webkit: offline element returns empty direction (#8053).\r
+                                       || this.getDirection()\r
+                                       || this.getDocument().$.dir\r
+                                       || this.getDocument().getBody().getDirection( 1 )\r
+                               : this.getStyle( 'direction' ) || this.getAttribute( 'dir' );\r
                },\r
 \r
                /**\r
                 * Gets, sets and removes custom data to be stored as HTML5 data-* attributes.\r
-                * @name CKEDITOR.dom.element.data\r
-                * @param {String} name The name of the attribute, execluding the 'data-' part.\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
@@ -1560,6 +1622,8 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                this.removeAttribute( name );\r
                        else\r
                                this.setAttribute( name, value );\r
+\r
+                       return null;\r
                }\r
        });\r
 \r
@@ -1579,11 +1643,12 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
        }\r
 \r
        /**\r
-        * Update the element's size with box model awareness.\r
-        * @name CKEDITOR.dom.element.setSize\r
-        * @param {String} type [width|height]\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 isBorderBox Apply the {@param width} and {@param height} based on border box model.\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
@@ -1597,17 +1662,18 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                };\r
 \r
        /**\r
-        * Get the element's size, possibly with box model awareness.\r
-        * @name CKEDITOR.dom.element.getSize\r
-        * @param {String} type [width|height]\r
-        * @param {Boolean} contentSize Get the {@param width} or {@param height} based on border box model.\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, contentSize )\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 ( contentSize )\r
+                       if ( isBorderBox )\r
                                size -= marginAndPaddingSize.call( this, type );\r
 \r
                        return size;\r