JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / core / dom / node.js
index a4188dc..6611545 100644 (file)
@@ -25,6 +25,10 @@ CKEDITOR.dom.node = function( domNode )
        {\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
@@ -49,6 +53,13 @@ CKEDITOR.dom.node.prototype = new CKEDITOR.dom.domObject();
 CKEDITOR.NODE_ELEMENT = 1;\r
 \r
 /**\r
+ * Document node type.\r
+ * @constant\r
+ * @example\r
+ */\r
+CKEDITOR.NODE_DOCUMENT = 9;\r
+\r
+/**\r
  * Text node type.\r
  * @constant\r
  * @example\r
@@ -646,6 +657,45 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype,
                                        child.parentNode.removeChild( child ) ;\r
                                }\r
                        }\r
+               },\r
+\r
+               /**\r
+                * Checks is this node is read-only (should not be changed). It\r
+                * additionaly returns the element, if any, which defines the read-only\r
+                * state of this node. 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
+                * @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.getReadOnlyRoot();  // the <div> element\r
+                *\r
+                * // If "ele" is the above <b>\r
+                * ele.getReadOnlyRoot();  // the <div> element\r
+                */\r
+               isReadOnly : function()\r
+               {\r
+                       var current = this;\r
+                       while( current )\r
+                       {\r
+                               if ( current.type == CKEDITOR.NODE_ELEMENT )\r
+                               {\r
+                                       if ( current.is( 'body' ) || current.getCustomData( '_cke_notReadOnly' ) )\r
+                                               break;\r
+\r
+                                       if ( current.getAttribute( 'contentEditable' ) == 'false' )\r
+                                               return current;\r
+                                       else if ( current.getAttribute( 'contentEditable' ) == 'true' )\r
+                                               break;\r
+                               }\r
+                               current = current.getParent();\r
+                       }\r
+\r
+                       return false;\r
                }\r
        }\r
 );\r