CKEDITOR.dom.document
Represents a DOM document.
var document = new CKEDITOR.dom.document( document );
Filtering
Properties
-
The native DOM object represented by this class instance.
var element = new CKEDITOR.dom.element( 'span' ); alert( element.$.nodeType ); // '1' -
The node type. This is a constant value set to CKEDITOR.NODE_DOCUMENT.
Defaults to
CKEDITOR.NODE_DOCUMENT
Static properties
Methods
-
Creates a domObject class instance.
Parameters
nativeDomObject : ObjectA native DOM object.
Returns
domObject
-
appendStyleSheet( cssFileUrl )CKEDITOR.dom.document#appendStyleSheetAppends a CSS file to the document.
CKEDITOR.document.appendStyleSheet( '/mystyles.css' );Parameters
cssFileUrl : StringThe CSS file URL.
-
appendStyleText( cssStyleText ) → ObjectCKEDITOR.dom.document#appendStyleTextCreates a CSS stylesheet and inserts it into the document.
Parameters
cssStyleText : Object{String} CSS style text.
Returns
ObjectThe created DOM native stylesheet object.
-
Register event handler under the capturing stage on supported target.
-
Removes any data stored in this object. To avoid memory leaks we must assure that there are no references left after the object is no longer needed.
-
createElement( name, [ attributesAndStyles ] ) → elementCKEDITOR.dom.document#createElementCreates a CKEDITOR.dom.element instance in this document.
Parameters
name : StringThe name of the element.
[ attributesAndStyles ] : Object
Returns
element
-
createText( text ) → elementCKEDITOR.dom.document#createTextCreates a CKEDITOR.dom.text instance in this document.
Parameters
text : StringValue of the text node.
Returns
element
-
Predefine some intrinsic properties on a specific event name.
Parameters
name : StringThe event name
meta : Object
-
Determines whether the specified object is equal to the current object.
var doc = new CKEDITOR.dom.document( document ); alert( doc.equals( CKEDITOR.document ) ); // true alert( doc == CKEDITOR.document ); // falseParameters
object : ObjectThe object to compare with the current object.
Returns
Booleantrueif the object is equal.
-
Wrapper for
querySelectorAll. Returns a list of elements within this document that match the specifiedselector.Note: The returned list is not a live collection (like the result of native
querySelectorAll).Parameters
selector : StringA valid CSS selector.
Returns
nodeList
-
Wrapper for
querySelector. Returns the first element within this document that matches the specifiedselector.Parameters
selector : StringA valid CSS selector.
Returns
element
-
Fires an specific event in the object. All registered listeners are called at this point.
someObject.on( 'someEvent', function() { ... } ); someObject.on( 'someEvent', function() { ... } ); someObject.fire( 'someEvent' ); // Both listeners are called. someObject.on( 'someEvent', function( event ) { alert( event.data ); // 'Example' } ); someObject.fire( 'someEvent', 'Example' );Parameters
eventName : StringThe event name to fire.
[ data ] : ObjectData to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editorThe editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | ObjectA boolean indicating that the event is to be canceled, or data returned by one of the listeners.
-
inherited
fireOnce( eventName, [ data ], [ editor ] ) → Boolean | ObjectCKEDITOR.dom.document#fireOnceFires an specific event in the object, releasing all listeners registered to that event. The same listeners are not called again on successive calls of it or of fire.
someObject.on( 'someEvent', function() { ... } ); someObject.fire( 'someEvent' ); // Above listener called. someObject.fireOnce( 'someEvent' ); // Above listener called. someObject.fire( 'someEvent' ); // No listeners called.Parameters
eventName : StringThe event name to fire.
[ data ] : ObjectData to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editorThe editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | ObjectA booloan indicating that the event is to be canceled, or data returned by one of the listeners.
-
focus()CKEDITOR.dom.document#focusMoves the selection focus to this document's window.
-
getActive() → elementCKEDITOR.dom.document#getActiveReturns the element that is currently designated as the active element in the document.
Note: Only one element can be active at a time in a document. An active element does not necessarily have focus, but an element with focus is always the active element in a document.
Returns
elementActive element or
nullif an IE8-9 bug is encountered. See #10030.
-
getBody() → elementCKEDITOR.dom.document#getBodyGets the
<body>element for this document.var element = CKEDITOR.document.getBody(); alert( element.getName() ); // 'body'Returns
elementThe
<body>element.
-
getByAddress( address, [ normalized ] )CKEDITOR.dom.document#getByAddressGets a node based on its address. See CKEDITOR.dom.node.getAddress.
Parameters
address : Array[ normalized ] : Boolean-
Defaults to
false
-
getById( elementId ) → elementCKEDITOR.dom.document#getByIdGets an element based on its ID.
var element = CKEDITOR.document.getById( 'myElement' ); alert( element.getId() ); // 'myElement'Parameters
elementId : StringThe element ID.
Returns
elementThe element instance, or
nullif not found.
-
Gets the value set to a data slot in this object.
var element = new CKEDITOR.dom.element( 'span' ); alert( element.getCustomData( 'hasCustomData' ) ); // e.g. 'true' alert( element.getCustomData( 'nonExistingKey' ) ); // nullParameters
key : StringThe key used to identify the data slot.
Returns
ObjectThis value set to the data slot.
-
getDocumentElement() → elementCKEDITOR.dom.document#getDocumentElementGets the DOM document element for this document.
Returns
elementThe DOM document element.
-
getElementsByTag( tagName ) → nodeListCKEDITOR.dom.document#getElementsByTagGets elements list based on a given tag name.
Parameters
tagName : StringThe element tag name.
Returns
nodeListThe nodes list.
-
getHead() → elementCKEDITOR.dom.document#getHeadGets the
<head>element for this document.var element = CKEDITOR.document.getHead(); alert( element.getName() ); // 'head'Returns
elementThe
<head>element.
-
Gets the private
_object which is bound to the native DOM object using getCustomData.var elementA = new CKEDITOR.dom.element( nativeElement ); elementA.getPrivate().value = 1; ... var elementB = new CKEDITOR.dom.element( nativeElement ); elementB.getPrivate().value; // 1Returns
ObjectThe private object.
-
getSelection() → selectionCKEDITOR.dom.document#getSelectionGets the current selection in context of the document's body element.
var selection = CKEDITOR.instances.editor1.document.getSelection(); alert( selection.getType() );Returns
selectionA selection object.
-
Gets an ID that can be used to identify this DOM object in the running session.
Note: This method does not work on text nodes prior to Internet Explorer 9.
Returns
NumberA unique ID.
-
getWindow() → windowCKEDITOR.dom.document#getWindow -
Checks if there is any listener registered to a given event.
var myListener = function() { ... }; someObject.on( 'someEvent', myListener ); alert( someObject.hasListeners( 'someEvent' ) ); // true alert( someObject.hasListeners( 'noEvent' ) ); // falseParameters
eventName : StringThe event name.
Returns
Boolean
-
inherited
on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → ObjectCKEDITOR.dom.document#onRegisters a listener to a specific event in the current object.
someObject.on( 'someEvent', function() { alert( this == someObject ); // true } ); someObject.on( 'someEvent', function() { alert( this == anotherObject ); // true }, anotherObject ); someObject.on( 'someEvent', function( event ) { alert( event.listenerData ); // 'Example' }, null, 'Example' ); someObject.on( 'someEvent', function() { ... } ); // 2nd called someObject.on( 'someEvent', function() { ... }, null, null, 100 ); // 3rd called someObject.on( 'someEvent', function() { ... }, null, null, 1 ); // 1st calledNote: CKEditor's event system has a limitation that one function cannot be used as a listener for the same event more than once. Hence, to reuse it with multiple listeners, it should be wrapped into additional wrapper function:
function listener( evt ) { ... }; someObject.on( 'someEvent', function() { listener(); } ); someObject.on( 'someEvent', function( evt ) { listener( evt ); } );Parameters
eventName : StringThe event name to which listen.
listenerFunction : FunctionThe function listening to the event. A single CKEDITOR.eventInfo object instanced is passed to this function containing all the event data.
[ scopeObj ] : ObjectThe object used to scope the listener call (the
thisobject). If omitted, the current object is used.[ listenerData ] : ObjectData to be sent as the CKEDITOR.eventInfo.listenerData when calling the listener.
[ priority ] : NumberThe listener priority. Lower priority listeners are called first. Listeners with the same priority value are called in registration order.
Defaults to
10
Returns
ObjectAn object containing the
removeListenerfunction, which can be used to remove the listener at any time.
-
Similiar with on but the listener will be called only once upon the next event firing.
-
Removes any listener set on this object.
To avoid memory leaks we must assure that there are no references left after the object is no longer needed.
-
Removes the value in the data slot under the given
key.Parameters
key : String
Returns
ObjectRemoved value or
nullif not found.
-
Unregisters a listener function from being called at the specified event. No errors are thrown if the listener has not been registered previously.
var myListener = function() { ... }; someObject.on( 'someEvent', myListener ); someObject.fire( 'someEvent' ); // myListener called. someObject.removeListener( 'someEvent', myListener ); someObject.fire( 'someEvent' ); // myListener not called.Parameters
eventName : StringThe event name.
listenerFunction : FunctionThe listener function to unregister.
-
Sets a data slot value for this object. These values are shared by all instances pointing to that same DOM object.
Note: The created data slot is only guaranteed to be available on this unique DOM node, thus any wish to continue access to it from other element clones (either created by clone node or from
innerHtml) will fail. For such usage please use CKEDITOR.dom.element.setAttribute instead.Note: This method does not work on text nodes prior to Internet Explorer 9.
var element = new CKEDITOR.dom.element( 'span' ); element.setCustomData( 'hasCustomData', true );Parameters
key : StringA key used to identify the data slot.
value : ObjectThe value to set to the data slot.
Returns
domObjectThis DOM object instance.
-
Defines the document content through
document.write. Note that the previous document content will be lost (cleaned).document.write( '<html>' + '<head><title>Sample Document</title></head>' + '<body>Document content created by code.</body>' + '</html>' );Parameters
html : StringThe HTML defining the document content.
-
Internet Explorer 8 only method. It returns a document fragment which has all HTML5 elements enabled.
Returns
ObjectDocumentFragment
Static methods
-
Implements the CKEDITOR.event features in an object.
var myObject = { message: 'Example' }; CKEDITOR.event.implementOn( myObject ); myObject.on( 'testEvent', function() { alert( this.message ); } ); myObject.fire( 'testEvent' ); // 'Example'Parameters
targetObject : ObjectThe object into which implement the features.