--- /dev/null
+/*\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * @fileOverview Defines the {@link CKEDITOR.dom.document} class, which\r
+ * represents a DOM document.\r
+ */\r
+\r
+/**\r
+ * Represents a DOM document.\r
+ * @constructor\r
+ * @augments CKEDITOR.dom.domObject\r
+ * @param {Object} domDocument A native DOM document.\r
+ * @example\r
+ * var document = new CKEDITOR.dom.document( document );\r
+ */\r
+CKEDITOR.dom.document = function( domDocument )\r
+{\r
+ CKEDITOR.dom.domObject.call( this, domDocument );\r
+};\r
+\r
+// PACKAGER_RENAME( CKEDITOR.dom.document )\r
+\r
+CKEDITOR.dom.document.prototype = new CKEDITOR.dom.domObject();\r
+\r
+CKEDITOR.tools.extend( CKEDITOR.dom.document.prototype,\r
+ /** @lends CKEDITOR.dom.document.prototype */\r
+ {\r
+ /**\r
+ * Appends a CSS file to the document.\r
+ * @param {String} cssFileUrl The CSS file URL.\r
+ * @example\r
+ * <b>CKEDITOR.document.appendStyleSheet( '/mystyles.css' )</b>;\r
+ */\r
+ appendStyleSheet : function( cssFileUrl )\r
+ {\r
+ if ( this.$.createStyleSheet )\r
+ this.$.createStyleSheet( cssFileUrl );\r
+ else\r
+ {\r
+ var link = new CKEDITOR.dom.element( 'link' );\r
+ link.setAttributes(\r
+ {\r
+ rel :'stylesheet',\r
+ type : 'text/css',\r
+ href : cssFileUrl\r
+ });\r
+\r
+ this.getHead().append( link );\r
+ }\r
+ },\r
+\r
+ appendStyleText : function( cssStyleText )\r
+ {\r
+ if ( this.$.createStyleSheet )\r
+ {\r
+ var styleSheet = this.$.createStyleSheet( "" );\r
+ styleSheet.cssText = cssStyleText ;\r
+ }\r
+ else\r
+ {\r
+ var style = new CKEDITOR.dom.element( 'style', this );\r
+ style.append( new CKEDITOR.dom.text( cssStyleText, this ) );\r
+ this.getHead().append( style );\r
+ }\r
+ },\r
+\r
+ createElement : function( name, attribsAndStyles )\r
+ {\r
+ var element = new CKEDITOR.dom.element( name, this );\r
+\r
+ if ( attribsAndStyles )\r
+ {\r
+ if ( attribsAndStyles.attributes )\r
+ element.setAttributes( attribsAndStyles.attributes );\r
+\r
+ if ( attribsAndStyles.styles )\r
+ element.setStyles( attribsAndStyles.styles );\r
+ }\r
+\r
+ return element;\r
+ },\r
+\r
+ createText : function( text )\r
+ {\r
+ return new CKEDITOR.dom.text( text, this );\r
+ },\r
+\r
+ focus : function()\r
+ {\r
+ this.getWindow().focus();\r
+ },\r
+\r
+ /**\r
+ * Gets and element based on its id.\r
+ * @param {String} elementId The element id.\r
+ * @returns {CKEDITOR.dom.element} The element instance, or null if not found.\r
+ * @example\r
+ * var element = <b>CKEDITOR.document.getById( 'myElement' )</b>;\r
+ * alert( element.getId() ); // "myElement"\r
+ */\r
+ getById : function( elementId )\r
+ {\r
+ var $ = this.$.getElementById( elementId );\r
+ return $ ? new CKEDITOR.dom.element( $ ) : null;\r
+ },\r
+\r
+ getByAddress : function( address, normalized )\r
+ {\r
+ var $ = this.$.documentElement;\r
+\r
+ for ( var i = 0 ; $ && i < address.length ; i++ )\r
+ {\r
+ var target = address[ i ];\r
+\r
+ if ( !normalized )\r
+ {\r
+ $ = $.childNodes[ target ];\r
+ continue;\r
+ }\r
+\r
+ var currentIndex = -1;\r
+\r
+ for (var j = 0 ; j < $.childNodes.length ; j++ )\r
+ {\r
+ var candidate = $.childNodes[ j ];\r
+\r
+ if ( normalized === true &&\r
+ candidate.nodeType == 3 &&\r
+ candidate.previousSibling &&\r
+ candidate.previousSibling.nodeType == 3 )\r
+ {\r
+ continue;\r
+ }\r
+\r
+ currentIndex++;\r
+\r
+ if ( currentIndex == target )\r
+ {\r
+ $ = candidate;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return $ ? new CKEDITOR.dom.node( $ ) : null;\r
+ },\r
+\r
+ getElementsByTag : function( tagName, namespace )\r
+ {\r
+ if ( !( CKEDITOR.env.ie && ! ( document.documentMode > 8 ) ) && namespace )\r
+ tagName = namespace + ':' + tagName;\r
+ return new CKEDITOR.dom.nodeList( this.$.getElementsByTagName( tagName ) );\r
+ },\r
+\r
+ /**\r
+ * Gets the <head> element for this document.\r
+ * @returns {CKEDITOR.dom.element} The <head> element.\r
+ * @example\r
+ * var element = <b>CKEDITOR.document.getHead()</b>;\r
+ * alert( element.getName() ); // "head"\r
+ */\r
+ getHead : function()\r
+ {\r
+ var head = this.$.getElementsByTagName( 'head' )[0];\r
+ if ( !head )\r
+ head = this.getDocumentElement().append( new CKEDITOR.dom.element( 'head' ), true );\r
+ else\r
+ head = new CKEDITOR.dom.element( head );\r
+\r
+ return (\r
+ this.getHead = function()\r
+ {\r
+ return head;\r
+ })();\r
+ },\r
+\r
+ /**\r
+ * Gets the <body> element for this document.\r
+ * @returns {CKEDITOR.dom.element} The <body> element.\r
+ * @example\r
+ * var element = <b>CKEDITOR.document.getBody()</b>;\r
+ * alert( element.getName() ); // "body"\r
+ */\r
+ getBody : function()\r
+ {\r
+ var body = new CKEDITOR.dom.element( this.$.body );\r
+\r
+ return (\r
+ this.getBody = function()\r
+ {\r
+ return body;\r
+ })();\r
+ },\r
+\r
+ /**\r
+ * Gets the DOM document element for this document.\r
+ * @returns {CKEDITOR.dom.element} The DOM document element.\r
+ */\r
+ getDocumentElement : function()\r
+ {\r
+ var documentElement = new CKEDITOR.dom.element( this.$.documentElement );\r
+\r
+ return (\r
+ this.getDocumentElement = function()\r
+ {\r
+ return documentElement;\r
+ })();\r
+ },\r
+\r
+ /**\r
+ * Gets the window object that holds this document.\r
+ * @returns {CKEDITOR.dom.window} The window object.\r
+ */\r
+ getWindow : function()\r
+ {\r
+ var win = new CKEDITOR.dom.window( this.$.parentWindow || this.$.defaultView );\r
+\r
+ return (\r
+ this.getWindow = function()\r
+ {\r
+ return win;\r
+ })();\r
+ },\r
+\r
+ /**\r
+ * Defines the document contents through document.write. Note that the\r
+ * previous document contents will be lost (cleaned).\r
+ * @since 3.5\r
+ * @param {String} html The HTML defining the document contents.\r
+ * @example\r
+ * document.write(\r
+ * '<html>' +\r
+ * '<head><title>Sample Doc</title></head>' +\r
+ * '<body>Document contents created by code</body>' +\r
+ * '</html>' );\r
+ */\r
+ write : function( html )\r
+ {\r
+ // Don't leave any history log in IE. (#5657)\r
+ this.$.open( 'text/html', 'replace' );\r
+\r
+ // Support for custom document.domain in IE.\r
+ CKEDITOR.env.isCustomDomain() && ( this.$.domain = document.domain );\r
+\r
+ this.$.write( html );\r
+ this.$.close();\r
+ }\r
+ });\r