X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Fnode.js;h=661154550ab0a83efd8b080952a664e8e98fb7c2;hb=614511639979907ceb0da3614122a4d8eb963ad4;hp=30df0a192a85dcef2249d97514c93eee1d0a33e4;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/core/dom/node.js b/_source/core/dom/node.js index 30df0a1..6611545 100644 --- a/_source/core/dom/node.js +++ b/_source/core/dom/node.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -25,6 +25,10 @@ CKEDITOR.dom.node = function( domNode ) { switch ( domNode.nodeType ) { + // Safari don't consider document as element node type. (#3389) + case CKEDITOR.NODE_DOCUMENT : + return new CKEDITOR.dom.document( domNode ); + case CKEDITOR.NODE_ELEMENT : return new CKEDITOR.dom.element( domNode ); @@ -49,6 +53,13 @@ CKEDITOR.dom.node.prototype = new CKEDITOR.dom.domObject(); CKEDITOR.NODE_ELEMENT = 1; /** + * Document node type. + * @constant + * @example + */ +CKEDITOR.NODE_DOCUMENT = 9; + +/** * Text node type. * @constant * @example @@ -194,27 +205,30 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, var parentNode = node.parentNode; var currentIndex = -1; - for ( var i = 0 ; i < parentNode.childNodes.length ; i++ ) + if ( parentNode ) { - var candidate = parentNode.childNodes[i]; - - if ( normalized && - candidate.nodeType == 3 && - candidate.previousSibling && - candidate.previousSibling.nodeType == 3 ) + for ( var i = 0 ; i < parentNode.childNodes.length ; i++ ) { - continue; - } + var candidate = parentNode.childNodes[i]; - currentIndex++; + if ( normalized && + candidate.nodeType == 3 && + candidate.previousSibling && + candidate.previousSibling.nodeType == 3 ) + { + continue; + } - if ( candidate == node ) - break; - } + currentIndex++; - address.unshift( currentIndex ); + if ( candidate == node ) + break; + } + + address.unshift( currentIndex ); + } - node = node.parentNode; + node = parentNode; } return address; @@ -232,7 +246,6 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, var document = new CKEDITOR.dom.document( this.$.ownerDocument || this.$.parentNode.ownerDocument ); return ( - /** @ignore */ this.getDocument = function() { return document; @@ -644,6 +657,45 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, child.parentNode.removeChild( child ) ; } } + }, + + /** + * Checks is this node is read-only (should not be changed). It + * additionaly returns the element, if any, which defines the read-only + * state of this node. It may be the node itself or any of its parent + * nodes. + * @returns {CKEDITOR.dom.element|Boolean} An element containing + * read-only attributes or "false" if none is found. + * @since 3.5 + * @example + * // For the following HTML: + * //
Some text
+ * + * // If "ele" is the above
+ * ele.getReadOnlyRoot(); // the
element + * + * // If "ele" is the above + * ele.getReadOnlyRoot(); // the
element + */ + isReadOnly : function() + { + var current = this; + while( current ) + { + if ( current.type == CKEDITOR.NODE_ELEMENT ) + { + if ( current.is( 'body' ) || current.getCustomData( '_cke_notReadOnly' ) ) + break; + + if ( current.getAttribute( 'contentEditable' ) == 'false' ) + return current; + else if ( current.getAttribute( 'contentEditable' ) == 'true' ) + break; + } + current = current.getParent(); + } + + return false; } } );