X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Fdocument.js;fp=_source%2Fcore%2Fdom%2Fdocument.js;h=dd0f9a0f9b57aa3ad96aeb9b087a17af36e5b0d2;hb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;hp=0000000000000000000000000000000000000000;hpb=b93873b6532ee7515fb0d6f8b73176c44fad28f7;p=ckeditor.git
diff --git a/_source/core/dom/document.js b/_source/core/dom/document.js
new file mode 100644
index 0000000..dd0f9a0
--- /dev/null
+++ b/_source/core/dom/document.js
@@ -0,0 +1,210 @@
+/*
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
+For licensing, see LICENSE.html or http://ckeditor.com/license
+*/
+
+/**
+ * @fileOverview Defines the {@link CKEDITOR.dom.document} class, which
+ * represents a DOM document.
+ */
+
+/**
+ * Represents a DOM document.
+ * @constructor
+ * @augments CKEDITOR.dom.domObject
+ * @param {Object} domDocument A native DOM document.
+ * @example
+ * var document = new CKEDITOR.dom.document( document );
+ */
+CKEDITOR.dom.document = function( domDocument )
+{
+ CKEDITOR.dom.domObject.call( this, domDocument );
+};
+
+// PACKAGER_RENAME( CKEDITOR.dom.document )
+
+CKEDITOR.dom.document.prototype = new CKEDITOR.dom.domObject();
+
+CKEDITOR.tools.extend( CKEDITOR.dom.document.prototype,
+ /** @lends CKEDITOR.dom.document.prototype */
+ {
+ /**
+ * Appends a CSS file to the document.
+ * @param {String} cssFileUrl The CSS file URL.
+ * @example
+ * CKEDITOR.document.appendStyleSheet( '/mystyles.css' );
+ */
+ appendStyleSheet : function( cssFileUrl )
+ {
+ if ( this.$.createStyleSheet )
+ this.$.createStyleSheet( cssFileUrl );
+ else
+ {
+ var link = new CKEDITOR.dom.element( 'link' );
+ link.setAttributes(
+ {
+ rel :'stylesheet',
+ type : 'text/css',
+ href : cssFileUrl
+ });
+
+ this.getHead().append( link );
+ }
+ },
+
+ createElement : function( name, attribsAndStyles )
+ {
+ var element = new CKEDITOR.dom.element( name, this );
+
+ if ( attribsAndStyles )
+ {
+ if ( attribsAndStyles.attributes )
+ element.setAttributes( attribsAndStyles.attributes );
+
+ if ( attribsAndStyles.styles )
+ element.setStyles( attribsAndStyles.styles );
+ }
+
+ return element;
+ },
+
+ createText : function( text )
+ {
+ return new CKEDITOR.dom.text( text, this );
+ },
+
+ focus : function()
+ {
+ this.getWindow().focus();
+ },
+
+ /**
+ * Gets and element based on its id.
+ * @param {String} elementId The element id.
+ * @returns {CKEDITOR.dom.element} The element instance, or null if not found.
+ * @example
+ * var element = CKEDITOR.document.getById( 'myElement' );
+ * alert( element.getId() ); // "myElement"
+ */
+ getById : function( elementId )
+ {
+ var $ = this.$.getElementById( elementId );
+ return $ ? new CKEDITOR.dom.element( $ ) : null;
+ },
+
+ getByAddress : function( address, normalized )
+ {
+ var $ = this.$.documentElement;
+
+ for ( var i = 0 ; $ && i < address.length ; i++ )
+ {
+ var target = address[ i ];
+
+ if ( !normalized )
+ {
+ $ = $.childNodes[ target ];
+ continue;
+ }
+
+ var currentIndex = -1;
+
+ for (var j = 0 ; j < $.childNodes.length ; j++ )
+ {
+ var candidate = $.childNodes[ j ];
+
+ if ( normalized === true &&
+ candidate.nodeType == 3 &&
+ candidate.previousSibling &&
+ candidate.previousSibling.nodeType == 3 )
+ {
+ continue;
+ }
+
+ currentIndex++;
+
+ if ( currentIndex == target )
+ {
+ $ = candidate;
+ break;
+ }
+ }
+ }
+
+ return $ ? new CKEDITOR.dom.node( $ ) : null;
+ },
+
+ getElementsByTag : function( tagName, namespace )
+ {
+ if ( !CKEDITOR.env.ie && namespace )
+ tagName = namespace + ':' + tagName;
+ return new CKEDITOR.dom.nodeList( this.$.getElementsByTagName( tagName ) );
+ },
+
+ /**
+ * Gets the <head> element for this document.
+ * @returns {CKEDITOR.dom.element} The <head> element.
+ * @example
+ * var element = CKEDITOR.document.getHead();
+ * alert( element.getName() ); // "head"
+ */
+ getHead : function()
+ {
+ var head = this.$.getElementsByTagName( 'head' )[0];
+ head = new CKEDITOR.dom.element( head );
+
+ return (
+ /** @ignore */
+ this.getHead = function()
+ {
+ return head;
+ })();
+ },
+
+ /**
+ * Gets the <body> element for this document.
+ * @returns {CKEDITOR.dom.element} The <body> element.
+ * @example
+ * var element = CKEDITOR.document.getBody();
+ * alert( element.getName() ); // "body"
+ */
+ getBody : function()
+ {
+ var body = new CKEDITOR.dom.element( this.$.body );
+
+ return (
+ /** @ignore */
+ this.getBody = function()
+ {
+ return body;
+ })();
+ },
+
+ getDocumentElement : function()
+ {
+ var documentElement = new CKEDITOR.dom.element( this.$.documentElement );
+
+ return (
+ /** @ignore */
+ this.getDocumentElement = function()
+ {
+ return documentElement;
+ })();
+ },
+
+ /**
+ * Gets the window object that holds this document.
+ * @returns {CKEDITOR.dom.window} The window object.
+ * @example
+ */
+ getWindow : function()
+ {
+ var win = new CKEDITOR.dom.window( this.$.parentWindow || this.$.defaultView );
+
+ return (
+ /** @ignore */
+ this.getWindow = function()
+ {
+ return win;
+ })();
+ }
+ });