X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Fnode.js;h=32b4c98c1a65fa9f3f0a21b6cb0ef08525c03b13;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hp=293ce2304c3ea388224abfb8831c30c3b4d1bcd6;hpb=f0610347140239143439a511ee2bd48cb784f470;p=ckeditor.git diff --git a/_source/core/dom/node.js b/_source/core/dom/node.js index 293ce23..32b4c98 100644 --- a/_source/core/dom/node.js +++ b/_source/core/dom/node.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -23,21 +23,13 @@ CKEDITOR.dom.node = function( domNode ) { if ( 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 ); - - case CKEDITOR.NODE_TEXT : - return new CKEDITOR.dom.text( domNode ); - } + var type = domNode.nodeType == CKEDITOR.NODE_DOCUMENT ? 'document' + : domNode.nodeType == CKEDITOR.NODE_ELEMENT ? 'element' + : domNode.nodeType == CKEDITOR.NODE_TEXT ? 'text' + : domNode.nodeType == CKEDITOR.NODE_COMMENT ? 'comment' + : 'domObject'; // Call the base constructor otherwise. - // Call the base constructor. - CKEDITOR.dom.domObject.call( this, domNode ); + return new CKEDITOR.dom[ type ]( domNode ); } return this; @@ -114,7 +106,8 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, if ( !cloneId ) node.removeAttribute( 'id', false ); - node.removeAttribute( 'data-cke-expando', false ); + + node[ 'data-cke-expando' ] = undefined; if ( includeChildren ) { @@ -352,7 +345,10 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, do { previous = previous.previousSibling; - retval = previous && new CKEDITOR.dom.node( previous ); + + // Avoid returning the doc type node. + // http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-412266927 + retval = previous && previous.nodeType != 10 && new CKEDITOR.dom.node( previous ); } while ( retval && evaluator && !evaluator( retval ) ) return retval; @@ -654,42 +650,43 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, }, /** - * Checks if this node is read-only (should not be changed). Additionally - * it returns the element that defines the read-only state of this node - * (if present). 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. + * Checks if this node is read-only (should not be changed). + * @returns {Boolean} * @since 3.5 * @example * // For the following HTML: * // <div contenteditable="false">Some <b>text</b></div> * * // If "ele" is the above <div> - * ele.isReadOnly(); // the <div> element - * - * // If "ele" is the above <b> - * ele.isReadOnly(); // the <div> element + * ele.isReadOnly(); // true */ isReadOnly : function() { - var current = this; - while( current ) + var element = this; + if ( this.type != CKEDITOR.NODE_ELEMENT ) + element = this.getParent(); + + if ( element && typeof element.$.isContentEditable != 'undefined' ) + return ! ( element.$.isContentEditable || element.data( 'cke-editable' ) ); + else { - if ( current.type == CKEDITOR.NODE_ELEMENT ) + // Degrade for old browsers which don't support "isContentEditable", e.g. FF3 + var current = element; + while( current ) { if ( current.is( 'body' ) || !!current.data( 'cke-editable' ) ) break; if ( current.getAttribute( 'contentEditable' ) == 'false' ) - return current; + return true; else if ( current.getAttribute( 'contentEditable' ) == 'true' ) break; + + current = current.getParent(); } - current = current.getParent(); - } - return false; + return false; + } } } );