JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / core / dom / node.js
index 293ce23..90412e4 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -23,21 +23,13 @@ CKEDITOR.dom.node = function( domNode )
 {\r
        if ( domNode )\r
        {\r
-               switch ( domNode.nodeType )\r
-               {\r
-                       // Safari don't consider document as element node type. (#3389)\r
-                       case CKEDITOR.NODE_DOCUMENT :\r
-                               return new CKEDITOR.dom.document( domNode );\r
-\r
-                       case CKEDITOR.NODE_ELEMENT :\r
-                               return new CKEDITOR.dom.element( domNode );\r
-\r
-                       case CKEDITOR.NODE_TEXT :\r
-                               return new CKEDITOR.dom.text( domNode );\r
-               }\r
+               var type = domNode.nodeType == CKEDITOR.NODE_DOCUMENT ? 'document'\r
+                       : domNode.nodeType == CKEDITOR.NODE_ELEMENT ? 'element'\r
+                       : domNode.nodeType == CKEDITOR.NODE_TEXT ? 'text'\r
+                       : domNode.nodeType == CKEDITOR.NODE_COMMENT ? 'comment'\r
+                       : 'domObject';  // Call the base constructor otherwise.\r
 \r
-               // Call the base constructor.\r
-               CKEDITOR.dom.domObject.call( this, domNode );\r
+               return new CKEDITOR.dom[ type ]( domNode );\r
        }\r
 \r
        return this;\r
@@ -352,7 +344,10 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype,
                        do\r
                        {\r
                                previous = previous.previousSibling;\r
-                               retval = previous && new CKEDITOR.dom.node( previous );\r
+\r
+                               // Avoid returning the doc type node.\r
+                               // http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-412266927\r
+                               retval = previous && previous.nodeType != 10 && new CKEDITOR.dom.node( previous );\r
                        }\r
                        while ( retval && evaluator && !evaluator( retval ) )\r
                        return retval;\r
@@ -654,42 +649,43 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype,
                },\r
 \r
                /**\r
-                * Checks if this node is read-only (should not be changed). Additionally\r
-                * it returns the element that defines the read-only state of this node\r
-                * (if present). It may be the node itself or any of its parent\r
-                * nodes.\r
-                * @returns {CKEDITOR.dom.element|Boolean} An element containing\r
-                *              read-only attributes or "false" if none is found.\r
+                * Checks if this node is read-only (should not be changed).\r
+                * @returns {Boolean}\r
                 * @since 3.5\r
                 * @example\r
                 * // For the following HTML:\r
                 * // <div contenteditable="false">Some <b>text</b></div>\r
                 *\r
                 * // If "ele" is the above <div>\r
-                * ele.isReadOnly();  // the <div> element\r
-                *\r
-                * // If "ele" is the above <b>\r
-                * ele.isReadOnly();  // the <div> element\r
+                * ele.isReadOnly();  // true\r
                 */\r
                isReadOnly : function()\r
                {\r
-                       var current = this;\r
-                       while( current )\r
+                       var element = this;\r
+                       if ( this.type != CKEDITOR.NODE_ELEMENT )\r
+                               element = this.getParent();\r
+\r
+                       if ( element && typeof element.$.isContentEditable != 'undefined' )\r
+                               return ! ( element.$.isContentEditable || element.data( 'cke-editable' ) );\r
+                       else\r
                        {\r
-                               if ( current.type == CKEDITOR.NODE_ELEMENT )\r
+                               // Degrade for old browsers which don't support "isContentEditable", e.g. FF3\r
+                               var current = element;\r
+                               while( current )\r
                                {\r
                                        if ( current.is( 'body' ) || !!current.data( 'cke-editable' ) )\r
                                                break;\r
 \r
                                        if ( current.getAttribute( 'contentEditable' ) == 'false' )\r
-                                               return current;\r
+                                               return true;\r
                                        else if ( current.getAttribute( 'contentEditable' ) == 'true' )\r
                                                break;\r
+\r
+                                       current = current.getParent();\r
                                }\r
-                               current = current.getParent();\r
-                       }\r
 \r
-                       return false;\r
+                               return false;\r
+                       }\r
                }\r
        }\r
 );\r