2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview Defines the {@link CKEDITOR.dom.document} class, which
\r
8 * represents a DOM document.
\r
12 * Represents a DOM document.
\r
14 * @augments CKEDITOR.dom.domObject
\r
15 * @param {Object} domDocument A native DOM document.
\r
17 * var document = new CKEDITOR.dom.document( document );
\r
19 CKEDITOR.dom.document = function( domDocument )
\r
21 CKEDITOR.dom.domObject.call( this, domDocument );
\r
24 // PACKAGER_RENAME( CKEDITOR.dom.document )
\r
26 CKEDITOR.dom.document.prototype = new CKEDITOR.dom.domObject();
\r
28 CKEDITOR.tools.extend( CKEDITOR.dom.document.prototype,
\r
29 /** @lends CKEDITOR.dom.document.prototype */
\r
32 * Appends a CSS file to the document.
\r
33 * @param {String} cssFileUrl The CSS file URL.
\r
35 * <b>CKEDITOR.document.appendStyleSheet( '/mystyles.css' )</b>;
\r
37 appendStyleSheet : function( cssFileUrl )
\r
39 if ( this.$.createStyleSheet )
\r
40 this.$.createStyleSheet( cssFileUrl );
\r
43 var link = new CKEDITOR.dom.element( 'link' );
\r
51 this.getHead().append( link );
\r
55 appendStyleText : function( cssStyleText )
\r
57 if ( this.$.createStyleSheet )
\r
59 var styleSheet = this.$.createStyleSheet( "" );
\r
60 styleSheet.cssText = cssStyleText ;
\r
64 var style = new CKEDITOR.dom.element( 'style', this );
\r
65 style.append( new CKEDITOR.dom.text( cssStyleText, this ) );
\r
66 this.getHead().append( style );
\r
70 createElement : function( name, attribsAndStyles )
\r
72 var element = new CKEDITOR.dom.element( name, this );
\r
74 if ( attribsAndStyles )
\r
76 if ( attribsAndStyles.attributes )
\r
77 element.setAttributes( attribsAndStyles.attributes );
\r
79 if ( attribsAndStyles.styles )
\r
80 element.setStyles( attribsAndStyles.styles );
\r
86 createText : function( text )
\r
88 return new CKEDITOR.dom.text( text, this );
\r
93 this.getWindow().focus();
\r
97 * Gets and element based on its id.
\r
98 * @param {String} elementId The element id.
\r
99 * @returns {CKEDITOR.dom.element} The element instance, or null if not found.
\r
101 * var element = <b>CKEDITOR.document.getById( 'myElement' )</b>;
\r
102 * alert( element.getId() ); // "myElement"
\r
104 getById : function( elementId )
\r
106 var $ = this.$.getElementById( elementId );
\r
107 return $ ? new CKEDITOR.dom.element( $ ) : null;
\r
110 getByAddress : function( address, normalized )
\r
112 var $ = this.$.documentElement;
\r
114 for ( var i = 0 ; $ && i < address.length ; i++ )
\r
116 var target = address[ i ];
\r
120 $ = $.childNodes[ target ];
\r
124 var currentIndex = -1;
\r
126 for (var j = 0 ; j < $.childNodes.length ; j++ )
\r
128 var candidate = $.childNodes[ j ];
\r
130 if ( normalized === true &&
\r
131 candidate.nodeType == 3 &&
\r
132 candidate.previousSibling &&
\r
133 candidate.previousSibling.nodeType == 3 )
\r
140 if ( currentIndex == target )
\r
148 return $ ? new CKEDITOR.dom.node( $ ) : null;
\r
151 getElementsByTag : function( tagName, namespace )
\r
153 if ( !CKEDITOR.env.ie && namespace )
\r
154 tagName = namespace + ':' + tagName;
\r
155 return new CKEDITOR.dom.nodeList( this.$.getElementsByTagName( tagName ) );
\r
159 * Gets the <head> element for this document.
\r
160 * @returns {CKEDITOR.dom.element} The <head> element.
\r
162 * var element = <b>CKEDITOR.document.getHead()</b>;
\r
163 * alert( element.getName() ); // "head"
\r
165 getHead : function()
\r
167 var head = this.$.getElementsByTagName( 'head' )[0];
\r
168 head = new CKEDITOR.dom.element( head );
\r
171 this.getHead = function()
\r
178 * Gets the <body> element for this document.
\r
179 * @returns {CKEDITOR.dom.element} The <body> element.
\r
181 * var element = <b>CKEDITOR.document.getBody()</b>;
\r
182 * alert( element.getName() ); // "body"
\r
184 getBody : function()
\r
186 var body = new CKEDITOR.dom.element( this.$.body );
\r
189 this.getBody = function()
\r
196 * Gets the DOM document element for this document.
\r
197 * @returns {CKEDITOR.dom.element} The DOM document element.
\r
199 getDocumentElement : function()
\r
201 var documentElement = new CKEDITOR.dom.element( this.$.documentElement );
\r
204 this.getDocumentElement = function()
\r
206 return documentElement;
\r
211 * Gets the window object that holds this document.
\r
212 * @returns {CKEDITOR.dom.window} The window object.
\r
214 getWindow : function()
\r
216 var win = new CKEDITOR.dom.window( this.$.parentWindow || this.$.defaultView );
\r
219 this.getWindow = function()
\r