JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0.2
[ckeditor.git] / _source / core / dom / element.js
index 296b84c..534d6e1 100644 (file)
@@ -425,8 +425,16 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                                        break;\r
 \r
                                                case 'checked':\r
-                                                       return this.$.checked;\r
-                                                       break;\r
+                                               {\r
+                                                       var attr = this.$.attributes.getNamedItem( name ),\r
+                                                               attrValue = attr.specified ? attr.nodeValue     // For value given by parser.\r
+                                                                                                                        : this.$.checked;  // For value created via DOM interface.\r
+\r
+                                                       return attrValue ? 'checked' : null;\r
+                                               }\r
+\r
+                                               case 'hspace':\r
+                                                       return this.$.hspace;\r
 \r
                                                case 'style':\r
                                                        // IE does not return inline styles via getAttribute(). See #2947.\r
@@ -627,6 +635,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
 \r
                /**\r
                 * Gets the first child node of this element.\r
+                * @param {Function} evaluator Filtering the result node.\r
                 * @returns {CKEDITOR.dom.node} The first child node or null if not\r
                 *              available.\r
                 * @example\r
@@ -634,10 +643,14 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                 * var first = <b>element.getFirst()</b>;\r
                 * alert( first.getName() );  // "b"\r
                 */\r
-               getFirst : function()\r
+               getFirst : function( evaluator )\r
                {\r
-                       var $ = this.$.firstChild;\r
-                       return $ ? new CKEDITOR.dom.node( $ ) : null;\r
+                       var first = this.$.firstChild,\r
+                               retval = first && new CKEDITOR.dom.node( first );\r
+                       if ( retval && evaluator && !evaluator( retval ) )\r
+                               retval = retval.getNext( evaluator );\r
+\r
+                       return retval;\r
                },\r
 \r
                /**\r
@@ -722,8 +735,8 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                                for ( i = 0 ; i < otherLength ; i++ )\r
                                {\r
                                        attribute = otherAttribs[ i ];\r
-\r
-                                       if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != '_cke_expando' ) ) && attribute.nodeValue != thisAttribs.getAttribute( attribute.nodeName ) )\r
+                                       if ( attribute.specified && attribute.nodeName != '_cke_expando'\r
+                                                       && attribute.nodeValue != this.getAttribute( attribute.nodeName ) )\r
                                                return false;\r
                                }\r
                        }\r
@@ -739,7 +752,24 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                 */\r
                isVisible : function()\r
                {\r
-                       return this.$.offsetWidth && ( this.$.style.visibility != 'hidden' );\r
+                       var isVisible = !!this.$.offsetHeight && this.getComputedStyle( 'visibility' ) != 'hidden',\r
+                               elementWindow,\r
+                               elementWindowFrame;\r
+\r
+                       // Webkit and Opera report non-zero offsetHeight despite that\r
+                       // element is inside an invisible iframe. (#4542)\r
+                       if ( isVisible && ( CKEDITOR.env.webkit || CKEDITOR.env.opera ) )\r
+                       {\r
+                               elementWindow = this.getWindow();\r
+\r
+                               if ( !elementWindow.equals( CKEDITOR.document.getWindow() )\r
+                                               && ( elementWindowFrame = elementWindow.$.frameElement ) )\r
+                               {\r
+                                       isVisible = new CKEDITOR.dom.element( elementWindowFrame ).isVisible();\r
+                               }\r
+                       }\r
+\r
+                       return isVisible;\r
                },\r
 \r
                /**\r
@@ -971,10 +1001,9 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                 */\r
                removeStyle : function( name )\r
                {\r
+                       this.setStyle( name, '' );\r
                        if ( this.$.style.removeAttribute )\r
                                this.$.style.removeAttribute( CKEDITOR.tools.cssStyleToDomStyle( name ) );\r
-                       else\r
-                               this.setStyle( name, '' );\r
 \r
                        if ( !this.$.style.cssText )\r
                                this.removeAttribute( 'style' );\r
@@ -1306,16 +1335,22 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
                        {\r
                                var attribute = attributes[n];\r
 \r
+                               // Lowercase attribute name hard rule is broken for\r
+                               // some attribute on IE, e.g. CHECKED.\r
+                               var attrName = attribute.nodeName.toLowerCase(),\r
+                                       attrValue;\r
+\r
+                               // We can set the type only once, so do it with the proper value, not copying it.\r
+                               if ( attrName in skipAttributes )\r
+                                       continue;\r
+\r
+                               if( attrName == 'checked' && ( attrValue = this.getAttribute( attrName ) ) )\r
+                                       dest.setAttribute( attrName, attrValue );\r
                                // IE BUG: value attribute is never specified even if it exists.\r
-                               if ( attribute.specified ||\r
-                                 ( CKEDITOR.env.ie && attribute.nodeValue && attribute.nodeName.toLowerCase() == 'value' ) )\r
+                               else if ( attribute.specified ||\r
+                                 ( CKEDITOR.env.ie && attribute.nodeValue && attrName == 'value' ) )\r
                                {\r
-                                       var attrName = attribute.nodeName;\r
-                                       // We can set the type only once, so do it with the proper value, not copying it.\r
-                                       if ( attrName in skipAttributes )\r
-                                               continue;\r
-\r
-                                       var attrValue = this.getAttribute( attrName );\r
+                                       attrValue = this.getAttribute( attrName );\r
                                        if ( attrValue === null )\r
                                                attrValue = attribute.nodeValue;\r
 \r