1 /* 2 * CKEditor - The text editor for Internet - http://ckeditor.com 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 */ 21 22 /** 23 * @fileOverview Defines the {@link CKEDITOR.dom.document} class, which 24 * represents a DOM document. 25 */ 26 27 /** 28 * Represents a DOM document. 29 * @constructor 30 * @param {Object} domDocument A native DOM document. 31 * @example 32 * var document = new CKEDITOR.dom.document( document ); 33 */ 34 CKEDITOR.dom.document = function( domDocument ) 35 { 36 this.$ = domDocument; 37 }; 38 39 CKEDITOR.dom.document.prototype = 40 { 41 /** 42 * Appends a CSS file to the document. 43 * @param {String} cssFileUrl The CSS file URL. 44 * @example 45 * <b>CKEDITOR.document.appendStyleSheet( '/mystyles.css' )</b>; 46 */ 47 appendStyleSheet : function( cssFileUrl ) 48 { 49 if ( this.$.createStyleSheet ) 50 this.$.createStyleSheet( cssFileUrl ); 51 else 52 { 53 var link = new CKEDITOR.dom.element( 'link' ); 54 link.setAttributes( 55 { 56 rel :'stylesheet', 57 type : 'text/css', 58 href : cssFileUrl 59 }); 60 61 this.getHead().append( link ); 62 } 63 }, 64 65 /** 66 * Determines whether the specified object is equal to the current object. 67 * @param {Object} object The object to compare with the current object. 68 * @returns {Boolean} "true" if the object is equal. 69 * @example 70 * var doc = new CKEDITOR.dom.document( document ); 71 * alert( doc.equals( CKEDITOR.document ) ); // "true" 72 * alert( doc == CKEDITOR.document ); // "false" 73 */ 74 equals : function( object ) 75 { 76 return ( object && object.$ === this.$ ); 77 }, 78 79 /** 80 * Gets and element based on its id. 81 * @param {String} elementId The element id. 82 * @returns {CKEDITOR.dom.element} The element instance, or null if not found. 83 * @example 84 * var element = <b>CKEDITOR.document.getById( 'myElement' )</b>; 85 * alert( element.getId() ); // "myElement" 86 */ 87 getById : function( elementId ) 88 { 89 var $ = this.$.getElementById( elementId ); 90 return $ ? new CKEDITOR.dom.element( $ ) : null; 91 }, 92 93 /** 94 * Gets the <head> element for this document. 95 * @returns {CKEDITOR.dom.element} The <head> element. 96 * @example 97 * var element = <b>CKEDITOR.document.getHead()</b>; 98 * alert( element.getName() ); // "head" 99 */ 100 getHead : function() 101 { 102 var head = this.$.getElementsByTagName( 'head' )[0]; 103 head = new CKEDITOR.dom.element( head ); 104 105 return ( 106 /** @ignore */ 107 this.getHead = function() 108 { 109 return head; 110 })(); 111 }, 112 113 /** 114 * Gets the <body> element for this document. 115 * @returns {CKEDITOR.dom.element} The <body> element. 116 * @example 117 * var element = <b>CKEDITOR.document.getBody()</b>; 118 * alert( element.getName() ); // "body" 119 */ 120 getBody : function() 121 { 122 var body = new CKEDITOR.dom.element( this.$.body ); 123 124 return ( 125 /** @ignore */ 126 this.getBody = function() 127 { 128 return body; 129 })(); 130 } 131 }; 132