element. - * alert( !!CKEDITOR.dtd[ 'p' ][ 'div' ] ); // false - * - * // Check if
can be contained in a
is a block element. - * alert( !!CKEDITOR.dtd.$block[ 'p' ] ); // true - * - * @class CKEDITOR.dtd - * @singleton - */ -CKEDITOR.dtd = (function() { - 'use strict'; - - var X = CKEDITOR.tools.extend, - // Subtraction rest of sets, from the first set. - Y = function( source, removed ) { - var substracted = CKEDITOR.tools.clone( source ); - for ( var i = 1; i < arguments.length; i++ ) { - removed = arguments[ i ]; - for( var name in removed ) - delete substracted[ name ]; - } - return substracted; - }; - - // Phrasing elements. - // P = { a:1,em:1,strong:1,small:1,abbr:1,dfn:1,i:1,b:1,s:1,u:1,code:1,'var':1,samp:1,kbd:1,sup:1,sub:1,q:1,cite:1,span:1,bdo:1,bdi:1,br:1,wbr:1,ins:1,del:1,img:1,embed:1,object:1,iframe:1,map:1,area:1,script:1,noscript:1,ruby:1,video:1,audio:1,input:1,textarea:1,select:1,button:1,label:1,output:1,keygen:1,progress:1,command:1,canvas:1,time:1,meter:1,detalist:1 }, - - // Flow elements. - // F = { a:1,p:1,hr:1,pre:1,ul:1,ol:1,dl:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hgroup:1,address:1,blockquote:1,ins:1,del:1,object:1,map:1,noscript:1,section:1,nav:1,article:1,aside:1,header:1,footer:1,video:1,audio:1,figure:1,table:1,form:1,fieldset:1,menu:1,canvas:1,details:1 }, - - // Text can be everywhere. - // X( P, T ); - // Flow elements set consists of phrasing elements set. - // X( F, P ); - - var P = {}, F = {}, - // Intersection of flow elements set and phrasing elements set. - PF = { a:1,abbr:1,area:1,audio:1,b:1,bdi:1,bdo:1,br:1,button:1,canvas:1,cite:1,code:1,command:1,datalist:1,del:1,dfn:1,em:1,embed:1,i:1,iframe:1,img:1,input:1,ins:1,kbd:1,keygen:1,label:1,map:1,mark:1,meter:1,noscript:1,object:1,output:1,progress:1,q:1,ruby:1,s:1,samp:1,script:1,select:1,small:1,span:1,strong:1,sub:1,sup:1,textarea:1,time:1,u:1,'var':1,video:1,wbr:1 }, - // F - PF (Flow Only). - FO = { address:1,article:1,aside:1,blockquote:1,details:1,div:1,dl:1,fieldset:1,figure:1,footer:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,header:1,hgroup:1,hr:1,menu:1,nav:1,ol:1,p:1,pre:1,section:1,table:1,ul:1 }, - // Metadata elements. - M = { command:1,link:1,meta:1,noscript:1,script:1,style:1 }, - // Empty. - E = {}, - // Text. - T = { '#':1 }, - - // Deprecated phrasing elements. - DP = { acronym:1,applet:1,basefont:1,big:1,font:1,isindex:1,strike:1,style:1,tt:1 }, // TODO remove "style". - // Deprecated flow only elements. - DFO = { center:1,dir:1,noframes:1 }; - - // Phrasing elements := PF + T + DP - X( P, PF, T, DP ); - // Flow elements := FO + P + DFO - X( F, FO, P, DFO ); - - var dtd = { - a: Y( P, { a:1,button:1 } ), // Treat as normal inline element (not a transparent one). - abbr: P, - address: F, - area: E, - article: X( { style:1 }, F ), - aside: X( { style:1 }, F ), - audio: X( { source:1,track:1 }, F ), - b: P, - base: E, - bdi: P, - bdo: P, - blockquote: F, - body: F, - br: E, - button: Y( P, { a:1,button:1 } ), - canvas: P, // Treat as normal inline element (not a transparent one). - caption: F, - cite: P, - code: P, - col: E, - colgroup: { col:1 }, - command: E, - datalist: X( { option:1 }, P ), - dd: F, - del: P, // Treat as normal inline element (not a transparent one). - details: X( { summary:1 }, F ), - dfn: P, - div: X( { style:1 }, F ), - dl: { dt:1,dd:1 }, - dt: F, - em: P, - embed: E, - fieldset: X( { legend:1 }, F ), - figcaption: F, - figure: X( { figcaption:1 }, F ), - footer: F, - form: F, - h1: P, - h2: P, - h3: P, - h4: P, - h5: P, - h6: P, - head: X( { title:1,base:1 }, M ), - header: F, - hgroup: { h1:1,h2:1,h3:1,h4:1,h5:1,h6:1 }, - hr: E, - html: X( { head:1,body:1 }, F, M ), // Head and body are optional... - i: P, - iframe: T, - img: E, - input: E, - ins: P, // Treat as normal inline element (not a transparent one). - kbd: P, - keygen: E, - label: P, - legend: P, - li: F, - link: E, - map: F, - mark: P, // Treat as normal inline element (not a transparent one). - menu: X( { li:1 }, F ), - meta: E, - meter: Y( P, { meter:1 } ), - nav: F, - noscript: X( { link:1,meta:1,style:1 }, P ), // Treat as normal inline element (not a transparent one). - object: X( { param:1 }, P ), // Treat as normal inline element (not a transparent one). - ol: { li:1 }, - optgroup: { option:1 }, - option: T, - output: P, - p: P, - param: E, - pre: P, - progress: Y( P, { progress:1 } ), - q: P, - rp: P, - rt: P, - ruby: X( { rp:1,rt:1 }, P ), - s: P, - samp: P, - script: T, - section: X( { style:1 }, F ), - select: { optgroup:1,option:1 }, - small: P, - source: E, - span: P, - strong: P, - style: T, - sub: P, - summary: P, - sup: P, - table: { caption:1,colgroup:1,thead:1,tfoot:1,tbody:1,tr:1 }, - tbody: { tr:1 }, - td: F, - textarea: T, - tfoot: { tr:1 }, - th: F, - thead: { tr:1 }, - time: Y( P, { time:1 } ), - title: T, - tr: { th:1,td:1 }, - track: E, - u: P, - ul: { li:1 }, - 'var': P, - video: X( { source:1,track:1 }, F ), - wbr: E, - - // Deprecated tags. - acronym: P, - applet: X( { param:1 }, F ), - basefont: E, - big: P, - center: F, - dialog: E, - dir: { li:1 }, - font: P, - isindex: E, - noframes: F, - strike: P, - tt: P - }; - - X( dtd, { - /** - * List of block elements, like `
` or `
`.
- */
- $tableContent: { caption:1,col:1,colgroup:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1 },
-
- /**
- * List of "transparent" elements. See [W3C's definition of "transparent" element](http://dev.w3.org/html5/markup/terminology.html#transparent).
- */
- $transparent: { a:1,audio:1,canvas:1,del:1,ins:1,map:1,noscript:1,object:1,video:1 },
-
- /**
- * List of elements that are not to exist standalone that must live under it's parent element.
- */
- $intermediate: { caption:1,colgroup:1,dd:1,dt:1,figcaption:1,legend:1,li:1,optgroup:1,option:1,rp:1,rt:1,summary:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1 }
- } );
-
- return dtd;
-})();
-
-// PACKAGER_RENAME( CKEDITOR.dtd )
-/**
- * Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.html or http://ckeditor.com/license
- */
-
-/**
- * @fileOverview Defines the {@link CKEDITOR.dom.event} class, which
- * represents the a native DOM event object.
- */
-
-/**
- * Represents a native DOM event object.
- *
- * @class
- * @constructor Creates an event class instance.
- * @param {Object} domEvent A native DOM event object.
- */
-CKEDITOR.dom.event = function( domEvent ) {
- /**
- * The native DOM event object represented by this class instance.
- *
- * @readonly
- */
- this.$ = domEvent;
-};
-
-CKEDITOR.dom.event.prototype = {
- /**
- * Gets the key code associated to the event.
- *
- * alert( event.getKey() ); // '65' is 'a' has been pressed
- *
- * @returns {Number} The key code.
- */
- getKey: function() {
- return this.$.keyCode || this.$.which;
- },
-
- /**
- * Gets a number represeting the combination of the keys pressed during the
- * event. It is the sum with the current key code and the {@link CKEDITOR#CTRL},
- * {@link CKEDITOR#SHIFT} and {@link CKEDITOR#ALT} constants.
- *
- * alert( event.getKeystroke() == 65 ); // 'a' key
- * alert( event.getKeystroke() == CKEDITOR.CTRL + 65 ); // CTRL + 'a' key
- * alert( event.getKeystroke() == CKEDITOR.CTRL + CKEDITOR.SHIFT + 65 ); // CTRL + SHIFT + 'a' key
- *
- * @returns {Number} The number representing the keys combination.
- */
- getKeystroke: function() {
- var keystroke = this.getKey();
-
- if ( this.$.ctrlKey || this.$.metaKey )
- keystroke += CKEDITOR.CTRL;
-
- if ( this.$.shiftKey )
- keystroke += CKEDITOR.SHIFT;
-
- if ( this.$.altKey )
- keystroke += CKEDITOR.ALT;
-
- return keystroke;
- },
-
- /**
- * Prevents the original behavior of the event to happen. It can optionally
- * stop propagating the event in the event chain.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.on( 'click', function( ev ) {
- * // The DOM event object is passed by the 'data' property.
- * var domEvent = ev.data;
- * // Prevent the click to chave any effect in the element.
- * domEvent.preventDefault();
- * } );
- *
- * @param {Boolean} [stopPropagation=false] Stop propagating this event in the
- * event chain.
- */
- preventDefault: function( stopPropagation ) {
- var $ = this.$;
- if ( $.preventDefault )
- $.preventDefault();
- else
- $.returnValue = false;
-
- if ( stopPropagation )
- this.stopPropagation();
- },
-
- /**
- * Stops this event propagation in the event chain.
- */
- stopPropagation: function() {
- var $ = this.$;
- if ( $.stopPropagation )
- $.stopPropagation();
- else
- $.cancelBubble = true;
- },
-
- /**
- * Returns the DOM node where the event was targeted to.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.on( 'click', function( ev ) {
- * // The DOM event object is passed by the 'data' property.
- * var domEvent = ev.data;
- * // Add a CSS class to the event target.
- * domEvent.getTarget().addClass( 'clicked' );
- * } );
- *
- * @returns {CKEDITOR.dom.node} The target DOM node.
- */
- getTarget: function() {
- var rawNode = this.$.target || this.$.srcElement;
- return rawNode ? new CKEDITOR.dom.node( rawNode ) : null;
- },
-
- /**
- * Returns an integer value that indicates the current processing phase of an event.
- * For browsers that doesn't support event phase, {@link CKEDITOR#EVENT_PHASE_AT_TARGET} is always returned.
- *
- * @returns {Number} One of {@link CKEDITOR#EVENT_PHASE_CAPTURING},
- * {@link CKEDITOR#EVENT_PHASE_AT_TARGET}, or {@link CKEDITOR#EVENT_PHASE_BUBBLING}.
- */
- getPhase: function() {
- return this.$.eventPhase || 2;
- },
-
- /**
- * Retrieves the coordinates of the mouse pointer relative to the top-left
- * corner of the document, in mouse related event.
- *
- * element.on( 'mousemouse', function( ev ) {
- * var pageOffset = ev.data.getPageOffset();
- * alert( pageOffset.x ); // page offset X
- * alert( pageOffset.y ); // page offset Y
- * } );
- *
- * @returns {Object} The object contains the position.
- * @returns {Number} return.x
- * @returns {Number} return.y
- */
- getPageOffset : function() {
- var doc = this.getTarget().getDocument().$;
- var pageX = this.$.pageX || this.$.clientX + ( doc.documentElement.scrollLeft || doc.body.scrollLeft );
- var pageY = this.$.pageY || this.$.clientY + ( doc.documentElement.scrollTop || doc.body.scrollTop );
- return { x : pageX, y : pageY };
- }
-};
-
-// For the followind constants, we need to go over the Unicode boundaries
-// (0x10FFFF) to avoid collision.
-
-/**
- * CTRL key (0x110000).
- *
- * @readonly
- * @property {Number} [=0x110000]
- * @member CKEDITOR
- */
-CKEDITOR.CTRL = 0x110000;
-
-/**
- * SHIFT key (0x220000).
- *
- * @readonly
- * @property {Number} [=0x220000]
- * @member CKEDITOR
- */
-CKEDITOR.SHIFT = 0x220000;
-
-/**
- * ALT key (0x440000).
- *
- * @readonly
- * @property {Number} [=0x440000]
- * @member CKEDITOR
- */
-CKEDITOR.ALT = 0x440000;
-
-/**
- * Capturing phase.
- *
- * @readonly
- * @property {Number} [=1]
- * @member CKEDITOR
- */
-CKEDITOR.EVENT_PHASE_CAPTURING = 1;
-
-/**
- * Event at target.
- *
- * @readonly
- * @property {Number} [=2]
- * @member CKEDITOR
- */
-CKEDITOR.EVENT_PHASE_AT_TARGET = 2;
-
-/**
- * Bubbling phase.
- *
- * @readonly
- * @property {Number} [=3]
- * @member CKEDITOR
- */
-CKEDITOR.EVENT_PHASE_BUBBLING = 3;
-/**
- * Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.html or http://ckeditor.com/license
- */
-
-/**
- * @fileOverview Defines the {@link CKEDITOR.editor} class, which is the base
- * for other classes representing DOM objects.
- */
-
-/**
- * Represents a DOM object. This class is not intended to be used directly. It
- * serves as the base class for other classes representing specific DOM
- * objects.
- *
- * @class
- * @mixins CKEDITOR.event
- * @constructor Creates a domObject class instance.
- * @param {Object} nativeDomObject A native DOM object.
- */
-CKEDITOR.dom.domObject = function( nativeDomObject ) {
- if ( nativeDomObject ) {
- /**
- * The native DOM object represented by this class instance.
- *
- * var element = new CKEDITOR.dom.element( 'span' );
- * alert( element.$.nodeType ); // '1'
- *
- * @readonly
- * @property {Object}
- */
- this.$ = nativeDomObject;
- }
-};
-
-CKEDITOR.dom.domObject.prototype = (function() {
- // Do not define other local variables here. We want to keep the native
- // listener closures as clean as possible.
-
- var getNativeListener = function( domObject, eventName ) {
- return function( domEvent ) {
- // In FF, when reloading the page with the editor focused, it may
- // throw an error because the CKEDITOR global is not anymore
- // available. So, we check it here first. (#2923)
- if ( typeof CKEDITOR != 'undefined' )
- domObject.fire( eventName, new CKEDITOR.dom.event( domEvent ) );
- };
- };
-
- return {
-
- /**
- * Get the private `_` object which is bound to the native
- * DOM object using {@link #getCustomData}.
- *
- * var elementA = new CKEDITOR.dom.element( nativeElement );
- * elementA.getPrivate().value = 1;
- * ...
- * var elementB = new CKEDITOR.dom.element( nativeElement );
- * elementB.getPrivate().value; // 1
- *
- * @returns {Object} The private object.
- */
- getPrivate: function() {
- var priv;
-
- // Get the main private object from the custom data. Create it if not defined.
- if ( !( priv = this.getCustomData( '_' ) ) )
- this.setCustomData( '_', ( priv = {} ) );
-
- return priv;
- },
-
- // Docs inherited from event.
- on: function( eventName ) {
- // We customize the "on" function here. The basic idea is that we'll have
- // only one listener for a native event, which will then call all listeners
- // set to the event.
-
- // Get the listeners holder object.
- var nativeListeners = this.getCustomData( '_cke_nativeListeners' );
-
- if ( !nativeListeners ) {
- nativeListeners = {};
- this.setCustomData( '_cke_nativeListeners', nativeListeners );
- }
-
- // Check if we have a listener for that event.
- if ( !nativeListeners[ eventName ] ) {
- var listener = nativeListeners[ eventName ] = getNativeListener( this, eventName );
-
- if ( this.$.addEventListener )
- this.$.addEventListener( eventName, listener, !!CKEDITOR.event.useCapture );
- else if ( this.$.attachEvent )
- this.$.attachEvent( 'on' + eventName, listener );
- }
-
- // Call the original implementation.
- return CKEDITOR.event.prototype.on.apply( this, arguments );
- },
-
- // Docs inherited from event.
- removeListener: function( eventName ) {
- // Call the original implementation.
- CKEDITOR.event.prototype.removeListener.apply( this, arguments );
-
- // If we don't have listeners for this event, clean the DOM up.
- if ( !this.hasListeners( eventName ) ) {
- var nativeListeners = this.getCustomData( '_cke_nativeListeners' );
- var listener = nativeListeners && nativeListeners[ eventName ];
- if ( listener ) {
- if ( this.$.removeEventListener )
- this.$.removeEventListener( eventName, listener, false );
- else if ( this.$.detachEvent )
- this.$.detachEvent( 'on' + eventName, listener );
-
- delete nativeListeners[ eventName ];
- }
- }
- },
-
- /**
- * 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.
- */
- removeAllListeners: function() {
- var nativeListeners = this.getCustomData( '_cke_nativeListeners' );
- for ( var eventName in nativeListeners ) {
- var listener = nativeListeners[ eventName ];
- if ( this.$.detachEvent )
- this.$.detachEvent( 'on' + eventName, listener );
- else if ( this.$.removeEventListener )
- this.$.removeEventListener( eventName, listener, false );
-
- delete nativeListeners[ eventName ];
- }
- }
- };
-})();
-
-(function( domObjectProto ) {
- var customData = {};
-
- CKEDITOR.on( 'reset', function() {
- customData = {};
- });
-
- /**
- * 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 ); // false
- *
- * @param {Object} object The object to compare with the current object.
- * @returns {Boolean} `true` if the object is equal.
- */
- domObjectProto.equals = function( object ) {
- // Try/Catch to avoid IE permission error when object is from different document.
- try {
- return ( object && object.$ === this.$ );
- } catch ( er ) {
- return false;
- }
- };
-
- /**
- * 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 guarantied to be available on this unique dom node,
- * thus any wish to continue access it from other element clones (either created by
- * clone node or from `innerHtml`) will fail, for such usage, please use
- * {@link CKEDITOR.dom.element#setAttribute} instead.
- *
- * var element = new CKEDITOR.dom.element( 'span' );
- * element.setCustomData( 'hasCustomData', true );
- *
- * @param {String} key A key used to identify the data slot.
- * @param {Object} value The value to set to the data slot.
- * @returns {CKEDITOR.dom.domObject} This DOM object instance.
- * @chainable
- */
- domObjectProto.setCustomData = function( key, value ) {
- var expandoNumber = this.getUniqueId(),
- dataSlot = customData[ expandoNumber ] || ( customData[ expandoNumber ] = {} );
-
- dataSlot[ key ] = value;
-
- return this;
- };
-
- /**
- * 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' ) ); // null
- *
- * @param {String} key The key used to identify the data slot.
- * @returns {Object} This value set to the data slot.
- */
- domObjectProto.getCustomData = function( key ) {
- var expandoNumber = this.$[ 'data-cke-expando' ],
- dataSlot = expandoNumber && customData[ expandoNumber ];
-
- return ( dataSlot && key in dataSlot ) ? dataSlot[ key ] : null;
- };
-
- /**
- * Removes the value in data slot under given `key`.
- *
- * @param {String} key
- * @returns {Object} Removed value or `null` if not found.
- */
- domObjectProto.removeCustomData = function( key ) {
- var expandoNumber = this.$[ 'data-cke-expando' ],
- dataSlot = expandoNumber && customData[ expandoNumber ],
- retval, hadKey;
-
- if ( dataSlot ) {
- retval = dataSlot[ key ];
- hadKey = key in dataSlot;
- delete dataSlot[ key ];
- }
-
- return hadKey ? retval : null;
- };
-
- /**
- * Removes any data stored on this object.
- * To avoid memory leaks we must assure that there are no
- * references left after the object is no longer needed.
- */
- domObjectProto.clearCustomData = function() {
- // Clear all event listeners
- this.removeAllListeners();
-
- var expandoNumber = this.$[ 'data-cke-expando' ];
- expandoNumber && delete customData[ expandoNumber ];
- };
-
- /**
- * Gets an ID that can be used to identiquely identify this DOM object in
- * the running session.
- *
- * @returns {Number} A unique ID.
- */
- domObjectProto.getUniqueId = function() {
- return this.$[ 'data-cke-expando' ] || ( this.$[ 'data-cke-expando' ] = CKEDITOR.tools.getNextNumber() );
- };
-
- // Implement CKEDITOR.event.
- CKEDITOR.event.implementOn( domObjectProto );
-
-})( CKEDITOR.dom.domObject.prototype );
-/**
- * Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.html or http://ckeditor.com/license
- */
-
-/**
- * @fileOverview Defines the {@link CKEDITOR.dom.node} class which is the base
- * class for classes that represent DOM nodes.
- */
-
-/**
- * Base class for classes representing DOM nodes. This constructor may return
- * an instance of a class that inherits from this class, like
- * {@link CKEDITOR.dom.element} or {@link CKEDITOR.dom.text}.
- *
- * @class
- * @extends CKEDITOR.dom.domObject
- * @constructor Creates a node class instance.
- * @param {Object} domNode A native DOM node.
- * @see CKEDITOR.dom.element
- * @see CKEDITOR.dom.text
- */
-CKEDITOR.dom.node = function( domNode ) {
- if ( domNode ) {
- var type = domNode.nodeType == CKEDITOR.NODE_DOCUMENT ? 'document' : domNode.nodeType == CKEDITOR.NODE_ELEMENT ? 'element' : domNode.nodeType == CKEDITOR.NODE_TEXT ? 'text' : domNode.nodeType == CKEDITOR.NODE_COMMENT ? 'comment' : domNode.nodeType == CKEDITOR.NODE_DOCUMENT_FRAGMENT ? 'documentFragment' : 'domObject'; // Call the base constructor otherwise.
-
- return new CKEDITOR.dom[ type ]( domNode );
- }
-
- return this;
-};
-
-CKEDITOR.dom.node.prototype = new CKEDITOR.dom.domObject();
-
-/**
- * Element node type.
- *
- * @readonly
- * @property {Number} [=1]
- * @member CKEDITOR
- */
-CKEDITOR.NODE_ELEMENT = 1;
-
-/**
- * Document node type.
- *
- * @readonly
- * @property {Number} [=9]
- * @member CKEDITOR
- */
-CKEDITOR.NODE_DOCUMENT = 9;
-
-/**
- * Text node type.
- *
- * @readonly
- * @property {Number} [=3]
- * @member CKEDITOR
- */
-CKEDITOR.NODE_TEXT = 3;
-
-/**
- * Comment node type.
- *
- * @readonly
- * @property {Number} [=8]
- * @member CKEDITOR
- */
-CKEDITOR.NODE_COMMENT = 8;
-
-/**
- * Document fragment node type.
- *
- * @readonly
- * @property {Number} [=11]
- * @member CKEDITOR
- */
-CKEDITOR.NODE_DOCUMENT_FRAGMENT = 11;
-
-CKEDITOR.POSITION_IDENTICAL = 0;
-CKEDITOR.POSITION_DISCONNECTED = 1;
-CKEDITOR.POSITION_FOLLOWING = 2;
-CKEDITOR.POSITION_PRECEDING = 4;
-CKEDITOR.POSITION_IS_CONTAINED = 8;
-CKEDITOR.POSITION_CONTAINS = 16;
-
-CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
- /**
- * Makes this node a child of another element.
- *
- * var p = new CKEDITOR.dom.element( 'p' );
- * var strong = new CKEDITOR.dom.element( 'strong' );
- * strong.appendTo( p );
- *
- * // Result: ' '. - * - * @param {CKEDITOR.dom.element} element The target element to which this node will be appended. - * @returns {CKEDITOR.dom.element} The target element. - */ - appendTo: function( element, toStart ) { - element.append( this, toStart ); - return element; - }, - - /** - * Clone this node. - * - * **Note**: Values set by {#setCustomData} won't be available in the clone. - * - * @param {Boolean} [includeChildren=false] If `true` then all node's - * children will be cloned recursively. - * @param {Boolean} [cloneId=false] Whether ID attributes should be cloned too. - * @returns {CKEDITOR.dom.node} Clone of this node. - */ - clone: function( includeChildren, cloneId ) { - var $clone = this.$.cloneNode( includeChildren ); - - var removeIds = function( node ) { - // Reset data-cke-expando only when has been cloned (IE and only for some types of objects). - if ( node['data-cke-expando'] ) - node['data-cke-expando'] = false; - - if ( node.nodeType != CKEDITOR.NODE_ELEMENT ) - return; - if ( !cloneId ) - node.removeAttribute( 'id', false ); - - if ( includeChildren ) { - var childs = node.childNodes; - for ( var i = 0; i < childs.length; i++ ) - removeIds( childs[ i ] ); - } - }; - - // The "id" attribute should never be cloned to avoid duplication. - removeIds( $clone ); - - return new CKEDITOR.dom.node( $clone ); - }, - - /** - * Check if node is preceded by any sibling. - * - * @returns {Boolean} - */ - hasPrevious: function() { - return !!this.$.previousSibling; - }, - - /** - * Check if node is succeeded by any sibling. - * - * @returns {Boolean} - */ - hasNext: function() { - return !!this.$.nextSibling; - }, - - /** - * Inserts this element after a node. - * - * var em = new CKEDITOR.dom.element( 'em' ); - * var strong = new CKEDITOR.dom.element( 'strong' ); - * strong.insertAfter( em ); - * - * // Result: '' - * - * @param {CKEDITOR.dom.node} node The node that will precede this element. - * @returns {CKEDITOR.dom.node} The node preceding this one after insertion. - */ - insertAfter: function( node ) { - node.$.parentNode.insertBefore( this.$, node.$.nextSibling ); - return node; - }, - - /** - * Inserts this element before a node. - * - * var em = new CKEDITOR.dom.element( 'em' ); - * var strong = new CKEDITOR.dom.element( 'strong' ); - * strong.insertBefore( em ); - * - * // result: '' - * - * @param {CKEDITOR.dom.node} node The node that will succeed this element. - * @returns {CKEDITOR.dom.node} The node being inserted. - */ - insertBefore: function( node ) { - node.$.parentNode.insertBefore( this.$, node.$ ); - return node; - }, - - /** - * Inserts node before this node. - * - * var em = new CKEDITOR.dom.element( 'em' ); - * var strong = new CKEDITOR.dom.element( 'strong' ); - * strong.insertBeforeMe( em ); - * - * // result: '' - * - * @param {CKEDITOR.dom.node} node The node that will preceed this element. - * @returns {CKEDITOR.dom.node} The node being inserted. - */ - insertBeforeMe: function( node ) { - this.$.parentNode.insertBefore( node.$, this.$ ); - return node; - }, - - /** - * Retrieves a uniquely identifiable tree address for this node. - * The tree address returned is an array of integers, with each integer - * indicating a child index of a DOM node, starting from - * `document.documentElement`. - * - * For example, assuming `` is the second child - * of `` (`` being the first), - * and we would like to address the third child under the - * fourth child of ``, the tree address returned would be: - * `[1, 3, 2]`. - * - * The tree address cannot be used for finding back the DOM tree node once - * the DOM tree structure has been modified. - * - * @param {Boolean} [normalized=false] See {@link #getIndex}. - * @returns {Array} The address. - */ - getAddress: function( normalized ) { - var address = []; - var $documentElement = this.getDocument().$.documentElement; - var node = this.$; - - while ( node && node != $documentElement ) { - var parentNode = node.parentNode; - - if ( parentNode ) { - // Get the node index. For performance, call getIndex - // directly, instead of creating a new node object. - address.unshift( this.getIndex.call({ $: node }, normalized ) ); - } - - node = parentNode; - } - - return address; - }, - - /** - * Gets the document containing this element. - * - * var element = CKEDITOR.document.getById( 'example' ); - * alert( element.getDocument().equals( CKEDITOR.document ) ); // true - * - * @returns {CKEDITOR.dom.document} The document. - */ - getDocument: function() { - return new CKEDITOR.dom.document( this.$.ownerDocument || this.$.parentNode.ownerDocument ); - }, - - /** - * Get index of a node in an array of its parent.childNodes. - * - * Let's assume having childNodes array: - * - * [ emptyText, element1, text, text, element2 ] - * element1.getIndex(); // 1 - * element1.getIndex( true ); // 0 - * element2.getIndex(); // 4 - * element2.getIndex( true ); // 2 - * - * @param {Boolean} normalized When `true` empty text nodes and one followed - * by another one text node are not counted in. - * @returns {Number} Index of a node. - */ - getIndex: function( normalized ) { - // Attention: getAddress depends on this.$ - // getIndex is called on a plain object: { $ : node } - - var current = this.$, - index = -1, - isNormalizing; - - if ( !this.$.parentNode ) - return index; - - do { - // Bypass blank node and adjacent text nodes. - if ( normalized && current != this.$ && current.nodeType == CKEDITOR.NODE_TEXT && ( isNormalizing || !current.nodeValue ) ) { - continue; - } - - index++; - isNormalizing = current.nodeType == CKEDITOR.NODE_TEXT; - } - while ( ( current = current.previousSibling ) ) - - return index; - }, - - /** - * @todo - */ - getNextSourceNode: function( startFromSibling, nodeType, guard ) { - // If "guard" is a node, transform it in a function. - if ( guard && !guard.call ) { - var guardNode = guard; - guard = function( node ) { - return !node.equals( guardNode ); - }; - } - - var node = ( !startFromSibling && this.getFirst && this.getFirst() ), - parent; - - // Guarding when we're skipping the current element( no children or 'startFromSibling' ). - // send the 'moving out' signal even we don't actually dive into. - if ( !node ) { - if ( this.type == CKEDITOR.NODE_ELEMENT && guard && guard( this, true ) === false ) - return null; - node = this.getNext(); - } - - while ( !node && ( parent = ( parent || this ).getParent() ) ) { - // The guard check sends the "true" paramenter to indicate that - // we are moving "out" of the element. - if ( guard && guard( parent, true ) === false ) - return null; - - node = parent.getNext(); - } - - if ( !node ) - return null; - - if ( guard && guard( node ) === false ) - return null; - - if ( nodeType && nodeType != node.type ) - return node.getNextSourceNode( false, nodeType, guard ); - - return node; - }, - - /** - * @todo - */ - getPreviousSourceNode: function( startFromSibling, nodeType, guard ) { - if ( guard && !guard.call ) { - var guardNode = guard; - guard = function( node ) { - return !node.equals( guardNode ); - }; - } - - var node = ( !startFromSibling && this.getLast && this.getLast() ), - parent; - - // Guarding when we're skipping the current element( no children or 'startFromSibling' ). - // send the 'moving out' signal even we don't actually dive into. - if ( !node ) { - if ( this.type == CKEDITOR.NODE_ELEMENT && guard && guard( this, true ) === false ) - return null; - node = this.getPrevious(); - } - - while ( !node && ( parent = ( parent || this ).getParent() ) ) { - // The guard check sends the "true" paramenter to indicate that - // we are moving "out" of the element. - if ( guard && guard( parent, true ) === false ) - return null; - - node = parent.getPrevious(); - } - - if ( !node ) - return null; - - if ( guard && guard( node ) === false ) - return null; - - if ( nodeType && node.type != nodeType ) - return node.getPreviousSourceNode( false, nodeType, guard ); - - return node; - }, - - /** - * Gets the node that preceed this element in its parent's child list. - * - * var element = CKEDITOR.dom.element.createFromHtml( ' prevExample ' );
- * var first = element.getLast().getPrev();
- * alert( first.getName() ); // 'i'
- *
- * @param {Function} [evaluator] Filtering the result node.
- * @returns {CKEDITOR.dom.node} The previous node or null if not available.
- */
- getPrevious: function( evaluator ) {
- var previous = this.$,
- retval;
- do {
- previous = previous.previousSibling;
-
- // Avoid returning the doc type node.
- // http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-412266927
- retval = previous && previous.nodeType != 10 && new CKEDITOR.dom.node( previous );
- }
- while ( retval && evaluator && !evaluator( retval ) )
- return retval;
- },
-
- /**
- * Gets the node that follows this element in its parent's child list.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( 'Examplenext ' );
- * var last = element.getFirst().getNext();
- * alert( last.getName() ); // 'i'
- *
- * @param {Function} [evaluator] Filtering the result node.
- * @returns {CKEDITOR.dom.node} The next node or null if not available.
- */
- getNext: function( evaluator ) {
- var next = this.$,
- retval;
- do {
- next = next.nextSibling;
- retval = next && new CKEDITOR.dom.node( next );
- }
- while ( retval && evaluator && !evaluator( retval ) )
- return retval;
- },
-
- /**
- * Gets the parent element for this node.
- *
- * var node = editor.document.getBody().getFirst();
- * var parent = node.getParent();
- * alert( node.getName() ); // 'body'
- *
- * @param {Boolean} [allowFragmentParent=false] Consider also parent node that is of
- * fragment type {@link CKEDITOR#NODE_DOCUMENT_FRAGMENT}.
- * @returns {CKEDITOR.dom.element} The parent element.
- */
- getParent: function( allowFragmentParent ) {
- var parent = this.$.parentNode;
- return ( parent && ( parent.nodeType == CKEDITOR.NODE_ELEMENT || allowFragmentParent && parent.nodeType == CKEDITOR.NODE_DOCUMENT_FRAGMENT ) ) ? new CKEDITOR.dom.node( parent ) : null;
- },
-
- /**
- * @todo
- */
- getParents: function( closerFirst ) {
- var node = this;
- var parents = [];
-
- do {
- parents[ closerFirst ? 'push' : 'unshift' ]( node );
- }
- while ( ( node = node.getParent() ) )
-
- return parents;
- },
-
- /**
- * @todo
- */
- getCommonAncestor: function( node ) {
- if ( node.equals( this ) )
- return this;
-
- if ( node.contains && node.contains( this ) )
- return node;
-
- var start = this.contains ? this : this.getParent();
-
- do {
- if ( start.contains( node ) ) return start;
- }
- while ( ( start = start.getParent() ) );
-
- return null;
- },
-
- /**
- * @todo
- */
- getPosition: function( otherNode ) {
- var $ = this.$;
- var $other = otherNode.$;
-
- if ( $.compareDocumentPosition )
- return $.compareDocumentPosition( $other );
-
- // IE and Safari have no support for compareDocumentPosition.
-
- if ( $ == $other )
- return CKEDITOR.POSITION_IDENTICAL;
-
- // Only element nodes support contains and sourceIndex.
- if ( this.type == CKEDITOR.NODE_ELEMENT && otherNode.type == CKEDITOR.NODE_ELEMENT ) {
- if ( $.contains ) {
- if ( $.contains( $other ) )
- return CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING;
-
- if ( $other.contains( $ ) )
- return CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING;
- }
-
- if ( 'sourceIndex' in $ ) {
- return ( $.sourceIndex < 0 || $other.sourceIndex < 0 ) ? CKEDITOR.POSITION_DISCONNECTED : ( $.sourceIndex < $other.sourceIndex ) ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING;
- }
- }
-
- // For nodes that don't support compareDocumentPosition, contains
- // or sourceIndex, their "address" is compared.
-
- var addressOfThis = this.getAddress(),
- addressOfOther = otherNode.getAddress(),
- minLevel = Math.min( addressOfThis.length, addressOfOther.length );
-
- // Determinate preceed/follow relationship.
- for ( var i = 0; i <= minLevel - 1; i++ ) {
- if ( addressOfThis[ i ] != addressOfOther[ i ] ) {
- if ( i < minLevel ) {
- return addressOfThis[ i ] < addressOfOther[ i ] ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING;
- }
- break;
- }
- }
-
- // Determinate contains/contained relationship.
- return ( addressOfThis.length < addressOfOther.length ) ? CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING;
- },
-
- /**
- * Gets the closest ancestor node of this node, specified by its name.
- *
- * // Suppose we have the following HTML structure:
- * // Some text
- * ascendant = node.getAscendant( 'b' ); // ascendant == null
- * ascendant = node.getAscendant( 'b', true ); // ascendant ==
- * ascendant = node.getAscendant( { div:1,p:1 } ); // Searches for the first 'div' or 'p': ascendant ==
- *
- * @since 3.6.1
- * @param {String} reference The name of the ancestor node to search or
- * an object with the node names to search for.
- * @param {Boolean} [includeSelf] Whether to include the current
- * node in the search.
- * @returns {CKEDITOR.dom.node} The located ancestor node or null if not found.
- */
- getAscendant: function( reference, includeSelf ) {
- var $ = this.$,
- name;
-
- if ( !includeSelf )
- $ = $.parentNode;
-
- while ( $ ) {
- if ( $.nodeName && ( name = $.nodeName.toLowerCase(), ( typeof reference == 'string' ? name == reference : name in reference ) ) )
- return new CKEDITOR.dom.node( $ );
-
- try {
- $ = $.parentNode;
- } catch( e ) {
- $ = null;
- }
- }
- return null;
- },
-
- /**
- * @todo
- */
- hasAscendant: function( name, includeSelf ) {
- var $ = this.$;
-
- if ( !includeSelf )
- $ = $.parentNode;
-
- while ( $ ) {
- if ( $.nodeName && $.nodeName.toLowerCase() == name )
- return true;
-
- $ = $.parentNode;
- }
- return false;
- },
-
- /**
- * @todo
- */
- move: function( target, toStart ) {
- target.append( this.remove(), toStart );
- },
-
- /**
- * Removes this node from the document DOM.
- *
- * var element = CKEDITOR.document.getById( 'MyElement' );
- * element.remove();
- *
- * @param {Boolean} [preserveChildren=false] Indicates that the children
- * elements must remain in the document, removing only the outer tags.
- */
- remove: function( preserveChildren ) {
- var $ = this.$;
- var parent = $.parentNode;
-
- if ( parent ) {
- if ( preserveChildren ) {
- // Move all children before the node.
- for ( var child;
- ( child = $.firstChild ); ) {
- parent.insertBefore( $.removeChild( child ), $ );
- }
- }
-
- parent.removeChild( $ );
- }
-
- return this;
- },
-
- /**
- * @todo
- */
- replace: function( nodeToReplace ) {
- this.insertBefore( nodeToReplace );
- nodeToReplace.remove();
- },
-
- /**
- * @todo
- */
- trim: function() {
- this.ltrim();
- this.rtrim();
- },
-
- /**
- * @todo
- */
- ltrim: function() {
- var child;
- while ( this.getFirst && ( child = this.getFirst() ) ) {
- if ( child.type == CKEDITOR.NODE_TEXT ) {
- var trimmed = CKEDITOR.tools.ltrim( child.getText() ),
- originalLength = child.getLength();
-
- if ( !trimmed ) {
- child.remove();
- continue;
- } else if ( trimmed.length < originalLength ) {
- child.split( originalLength - trimmed.length );
-
- // IE BUG: child.remove() may raise JavaScript errors here. (#81)
- this.$.removeChild( this.$.firstChild );
- }
- }
- break;
- }
- },
-
- /**
- * @todo
- */
- rtrim: function() {
- var child;
- while ( this.getLast && ( child = this.getLast() ) ) {
- if ( child.type == CKEDITOR.NODE_TEXT ) {
- var trimmed = CKEDITOR.tools.rtrim( child.getText() ),
- originalLength = child.getLength();
-
- if ( !trimmed ) {
- child.remove();
- continue;
- } else if ( trimmed.length < originalLength ) {
- child.split( trimmed.length );
-
- // IE BUG: child.getNext().remove() may raise JavaScript errors here.
- // (#81)
- this.$.lastChild.parentNode.removeChild( this.$.lastChild );
- }
- }
- break;
- }
-
- if ( !CKEDITOR.env.ie && !CKEDITOR.env.opera ) {
- child = this.$.lastChild;
-
- if ( child && child.type == 1 && child.nodeName.toLowerCase() == 'br' ) {
- // Use "eChildNode.parentNode" instead of "node" to avoid IE bug (#324).
- child.parentNode.removeChild( child );
- }
- }
- },
-
- /**
- * Checks if this node is read-only (should not be changed).
- *
- * **Note:** When `attributeCheck` is not used, this method only work for elements
- * that are already presented in the document, otherwise the result
- * is not guaranteed, it's mainly for performance consideration.
- *
- * // For the following HTML:
- * // Some text
- *
- * // If "ele" is the above
- * element.isReadOnly(); // true
- *
- * @since 3.5
- * @returns {Boolean}
- */
- isReadOnly: function() {
- var element = this;
- if ( this.type != CKEDITOR.NODE_ELEMENT )
- element = this.getParent();
-
- if ( element && typeof element.$.isContentEditable != 'undefined' )
- return !( element.$.isContentEditable || element.data( 'cke-editable' ) );
- else {
- // Degrade for old browsers which don't support "isContentEditable", e.g. FF3
-
- while ( element ) {
- if ( element.data( 'cke-editable' ) )
- break;
-
- if ( element.getAttribute( 'contentEditable' ) == 'false' )
- return true;
- else if ( element.getAttribute( 'contentEditable' ) == 'true' )
- break;
-
- element = element.getParent();
- }
-
- // Reached the root of DOM tree, no editable found.
- return !element;
- }
- }
-});
-/**
- * Copyright (c) 2003-2013, 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 window.
- *
- * var document = new CKEDITOR.dom.window( window );
- *
- * @class
- * @extends CKEDITOR.dom.domObject
- * @constructor Creates a window class instance.
- * @param {Object} domWindow A native DOM window.
- */
-CKEDITOR.dom.window = function( domWindow ) {
- CKEDITOR.dom.domObject.call( this, domWindow );
-};
-
-CKEDITOR.dom.window.prototype = new CKEDITOR.dom.domObject();
-
-CKEDITOR.tools.extend( CKEDITOR.dom.window.prototype, {
- /**
- * Moves the selection focus to this window.
- *
- * var win = new CKEDITOR.dom.window( window );
- * win.focus();
- */
- focus: function() {
- this.$.focus();
- },
-
- /**
- * Gets the width and height of this window's viewable area.
- *
- * var win = new CKEDITOR.dom.window( window );
- * var size = win.getViewPaneSize();
- * alert( size.width );
- * alert( size.height );
- *
- * @returns {Object} An object with the `width` and `height`
- * properties containing the size.
- */
- getViewPaneSize: function() {
- var doc = this.$.document,
- stdMode = doc.compatMode == 'CSS1Compat';
- return {
- width: ( stdMode ? doc.documentElement.clientWidth : doc.body.clientWidth ) || 0,
- height: ( stdMode ? doc.documentElement.clientHeight : doc.body.clientHeight ) || 0
- };
- },
-
- /**
- * Gets the current position of the window's scroll.
- *
- * var win = new CKEDITOR.dom.window( window );
- * var pos = win.getScrollPosition();
- * alert( pos.x );
- * alert( pos.y );
- *
- * @returns {Object} An object with the `x` and `y` properties
- * containing the scroll position.
- */
- getScrollPosition: function() {
- var $ = this.$;
-
- if ( 'pageXOffset' in $ ) {
- return {
- x: $.pageXOffset || 0,
- y: $.pageYOffset || 0
- };
- } else {
- var doc = $.document;
- return {
- x: doc.documentElement.scrollLeft || doc.body.scrollLeft || 0,
- y: doc.documentElement.scrollTop || doc.body.scrollTop || 0
- };
- }
- },
-
- /**
- * Gets the frame element containing this window context.
- *
- * @returns {CKEDITOR.dom.element} The frame element or `null` if not in a frame context.
- */
- getFrame: function() {
- var iframe = this.$.frameElement;
- return iframe ? new CKEDITOR.dom.element.get( iframe ) : null;
- }
-});
-/**
- * Copyright (c) 2003-2013, 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.
- *
- * var document = new CKEDITOR.dom.document( document );
- *
- * @class
- * @extends CKEDITOR.dom.domObject
- * @constructor Creates a document class instance.
- * @param {Object} domDocument A native DOM 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, {
- /**
- * The node type. This is a constant value set to {@link CKEDITOR#NODE_DOCUMENT}.
- *
- * @readonly
- * @property {Number} [=CKEDITOR.NODE_DOCUMENT]
- */
- type: CKEDITOR.NODE_DOCUMENT,
-
- /**
- * Appends a CSS file to the document.
- *
- * CKEDITOR.document.appendStyleSheet( '/mystyles.css' );
- *
- * @param {String} cssFileUrl The CSS file URL.
- */
- 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 );
- }
- },
-
- /**
- * Creates a CSS style sheet and inserts it into the document.
- *
- * @param cssStyleText {String} CSS style text.
- * @returns {Object} The created DOM native style sheet object.
- */
- appendStyleText: function( cssStyleText ) {
- if ( this.$.createStyleSheet ) {
- var styleSheet = this.$.createStyleSheet( "" );
- styleSheet.cssText = cssStyleText;
- } else {
- var style = new CKEDITOR.dom.element( 'style', this );
- style.append( new CKEDITOR.dom.text( cssStyleText, this ) );
- this.getHead().append( style );
- }
-
- return styleSheet || style.$.sheet;
- },
-
- /**
- * Creates {@link CKEDITOR.dom.element} instance in this document.
- *
- * @returns {CKEDITOR.dom.element}
- * @todo
- */
- 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;
- },
-
- /**
- * Creates {@link CKEDITOR.dom.text} instance in this document.
- *
- * @param {String} text Value of the text node.
- * @returns {CKEDITOR.dom.element}
- */
- createText: function( text ) {
- return new CKEDITOR.dom.text( text, this );
- },
-
- /**
- * Moves the selection focus to this document's window.
- */
- focus: function() {
- this.getWindow().focus();
- },
-
- /**
- * Returns 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 {CKEDITOR.dom.element}
- */
- getActive: function() {
- return new CKEDITOR.dom.element( this.$.activeElement );
- },
-
- /**
- * Gets an element based on its id.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * alert( element.getId() ); // 'myElement'
- *
- * @param {String} elementId The element id.
- * @returns {CKEDITOR.dom.element} The element instance, or null if not found.
- */
- getById: function( elementId ) {
- var $ = this.$.getElementById( elementId );
- return $ ? new CKEDITOR.dom.element( $ ) : null;
- },
-
- /**
- * Gets a node based on its address. See {@link CKEDITOR.dom.node#getAddress}.
- *
- * @param {Array} address
- * @param {Boolean} [normalized=false]
- */
- 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;
- },
-
- /**
- * Gets elements list based on given tag name.
- *
- * @param {String} tagName The element tag name.
- * @returns {CKEDITOR.dom.nodeList} The nodes list.
- */
- getElementsByTag: function( tagName, namespace ) {
- if ( !( CKEDITOR.env.ie && !( document.documentMode > 8 ) ) && namespace )
- tagName = namespace + ':' + tagName;
- return new CKEDITOR.dom.nodeList( this.$.getElementsByTagName( tagName ) );
- },
-
- /**
- * Gets the `` element for this document.
- *
- * var element = CKEDITOR.document.getHead();
- * alert( element.getName() ); // 'head'
- *
- * @returns {CKEDITOR.dom.element} The `` element.
- */
- getHead: function() {
- var head = this.$.getElementsByTagName( 'head' )[ 0 ];
- if ( !head )
- head = this.getDocumentElement().append( new CKEDITOR.dom.element( 'head' ), true );
- else
- head = new CKEDITOR.dom.element( head );
-
- return head;
- },
-
- /**
- * Gets the `` element for this document.
- *
- * var element = CKEDITOR.document.getBody();
- * alert( element.getName() ); // 'body'
- *
- * @returns {CKEDITOR.dom.element} The `` element.
- */
- getBody: function() {
- return new CKEDITOR.dom.element( this.$.body );
- },
-
- /**
- * Gets the DOM document element for this document.
- *
- * @returns {CKEDITOR.dom.element} The DOM document element.
- */
- getDocumentElement: function() {
- return new CKEDITOR.dom.element( this.$.documentElement );
- },
-
- /**
- * Gets the window object that holds this document.
- *
- * @returns {CKEDITOR.dom.window} The window object.
- */
- getWindow: function() {
- var win = new CKEDITOR.dom.window( this.$.parentWindow || this.$.defaultView );
-
- return ( this.getWindow = function() {
- return win;
- })();
- },
-
- /**
- * Defines the document contents through document.write. Note that the
- * previous document contents will be lost (cleaned).
- *
- * document.write(
- * '' +
- * '
- * element.addClass( 'classB' ); //
- * element.addClass( 'classA' ); //
- *
- * @param {String} className The name of the class to be added.
- */
- addClass: function( className ) {
- var c = this.$.className;
- if ( c ) {
- var regex = new RegExp( '(?:^|\\s)' + className + '(?:\\s|$)', '' );
- if ( !regex.test( c ) )
- c += ' ' + className;
- }
- this.$.className = c || className;
- },
-
- /**
- * Removes a CSS class name from the elements classes. Other classes
- * remain untouched.
- *
- * var element = new CKEDITOR.dom.element( 'div' );
- * element.addClass( 'classA' ); //
- * element.addClass( 'classB' ); //
- * element.removeClass( 'classA' ); //
- * element.removeClass( 'classB' ); //
- *
- * @chainable
- * @param {String} className The name of the class to remove.
- */
- removeClass: function( className ) {
- var c = this.getAttribute( 'class' );
- if ( c ) {
- var regex = new RegExp( '(?:^|\\s+)' + className + '(?=\\s|$)', 'i' );
- if ( regex.test( c ) ) {
- c = c.replace( regex, '' ).replace( /^\s+/, '' );
-
- if ( c )
- this.setAttribute( 'class', c );
- else
- this.removeAttribute( 'class' );
- }
- }
-
- return this;
- },
-
- /**
- * Checks if element has class name.
- *
- * @param {String} className
- * @returns {Boolean}
- */
- hasClass: function( className ) {
- var regex = new RegExp( '(?:^|\\s+)' + className + '(?=\\s|$)', '' );
- return regex.test( this.getAttribute( 'class' ) );
- },
-
- /**
- * Append a node as a child of this element.
- *
- * var p = new CKEDITOR.dom.element( 'p' );
- *
- * var strong = new CKEDITOR.dom.element( 'strong' );
- * p.append( strong );
- *
- * var em = p.append( 'em' );
- *
- * // Result: ' ' - * - * @param {CKEDITOR.dom.node/String} node The node or element name to be appended. - * @param {Boolean} [toStart=false] Indicates that the element is to be appended at the start. - * @returns {CKEDITOR.dom.node} The appended node. - */ - append: function( node, toStart ) { - if ( typeof node == 'string' ) - node = this.getDocument().createElement( node ); - - if ( toStart ) - this.$.insertBefore( node.$, this.$.firstChild ); - else - this.$.appendChild( node.$ ); - - return node; - }, - - /** - * Append HTML as a child(ren) of this element. - * - * @param {String} html - */ - appendHtml: function( html ) { - if ( !this.$.childNodes.length ) - this.setHtml( html ); - else { - var temp = new CKEDITOR.dom.element( 'div', this.getDocument() ); - temp.setHtml( html ); - temp.moveChildren( this ); - } - }, - - /** - * Append text to this element. - * - * var p = new CKEDITOR.dom.element( 'p' ); - * p.appendText( 'This is' ); - * p.appendText( ' some text' ); - * - * // Result: ' This is some text ' - * - * @param {String} text The text to be appended. - * @returns {CKEDITOR.dom.node} The appended node. - */ - appendText: function( text ) { - if ( this.$.text != undefined ) - this.$.text += text; - else - this.append( new CKEDITOR.dom.text( text ) ); - }, - - /** - * @todo - */ - appendBogus: function() { - var lastChild = this.getLast(); - - // Ignore empty/spaces text. - while ( lastChild && lastChild.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.rtrim( lastChild.getText() ) ) - lastChild = lastChild.getPrevious(); - if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) ) { - var bogus = CKEDITOR.env.opera ? this.getDocument().createText( '' ) : this.getDocument().createElement( 'br' ); - - CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' ); - - this.append( bogus ); - } - }, - - /** - * Breaks one of the ancestor element in the element position, moving - * this element between the broken parts. - * - * // Before breaking: - * // This is some sample test text - * // If "element" is and "parent" is : - * // This is some sample test text - * element.breakParent( parent ); - * - * // Before breaking: - * // This is some sample test text - * // If "element" is and "parent" is : - * // This is some sample test text - * element.breakParent( parent ); - * - * @param {CKEDITOR.dom.element} parent The anscestor element to get broken. - */ - breakParent: function( parent ) { - var range = new CKEDITOR.dom.range( this.getDocument() ); - - // We'll be extracting part of this element, so let's use our - // range to get the correct piece. - range.setStartAfter( this ); - range.setEndAfter( parent ); - - // Extract it. - var docFrag = range.extractContents(); - - // Move the element outside the broken element. - range.insertNode( this.remove() ); - - // Re-insert the extracted piece after the element. - docFrag.insertAfterNode( this ); - }, - - /** - * Checks if this element contains given node. - * - * @method - * @param {CKEDITOR.dom.node} node - * @returns {Boolean} - */ - contains: CKEDITOR.env.ie || CKEDITOR.env.webkit ? - function( node ) { - var $ = this.$; - - return node.type != CKEDITOR.NODE_ELEMENT ? $.contains( node.getParent().$ ) : $ != node.$ && $.contains( node.$ ); - } : function( node ) { - return !!( this.$.compareDocumentPosition( node.$ ) & 16 ); - }, - - /** - * Moves the selection focus to this element. - * - * var element = CKEDITOR.document.getById( 'myTextarea' ); - * element.focus(); - * - * @method - * @param {Boolean} defer Whether to asynchronously defer the - * execution by 100 ms. - */ - focus: (function() { - function exec() { - // IE throws error if the element is not visible. - try { - this.$.focus(); - } catch ( e ) {} - } - - return function( defer ) { - if ( defer ) - CKEDITOR.tools.setTimeout( exec, 100, this ); - else - exec.call( this ); - }; - })(), - - /** - * Gets the inner HTML of this element. - * - * var element = CKEDITOR.dom.element.createFromHtml( 'Example ' );
- * alert( element.getHtml() ); // 'Example'
- *
- * @returns {String} The inner HTML of this element.
- */
- getHtml: function() {
- var retval = this.$.innerHTML;
- // Strip tags in IE. (#3341).
- return CKEDITOR.env.ie ? retval.replace( /<\?[^>]*>/g, '' ) : retval;
- },
-
- /**
- * Gets the outer (inner plus tags) HTML of this element.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( 'Example ' );
- * alert( element.getOuterHtml() ); // 'Example '
- *
- * @returns {String} The outer HTML of this element.
- */
- getOuterHtml: function() {
- if ( this.$.outerHTML ) {
- // IE includes the tag in the outerHTML of
- // namespaced element. So, we must strip it here. (#3341)
- return this.$.outerHTML.replace( /<\?[^>]*>/, '' );
- }
-
- var tmpDiv = this.$.ownerDocument.createElement( 'div' );
- tmpDiv.appendChild( this.$.cloneNode( true ) );
- return tmpDiv.innerHTML;
- },
-
- /**
- * Retrieve the bounding rectangle of the current element, in pixels,
- * relative to the upper-left corner of the browser's client area.
- *
- * @returns {Object} The dimensions of the DOM element including
- * `left`, `top`, `right`, `bottom`, `width` and `height`.
- */
- getClientRect: function() {
- // http://help.dottoro.com/ljvmcrrn.php
- var rect = CKEDITOR.tools.extend( {}, this.$.getBoundingClientRect() );
-
- !rect.width && ( rect.width = rect.right - rect.left );
- !rect.height && ( rect.height = rect.bottom - rect.top );
-
- return rect;
- },
-
- /**
- * Sets the inner HTML of this element.
- *
- * var p = new CKEDITOR.dom.element( 'p' );
- * p.setHtml( 'Inner HTML' );
- *
- * // Result: 'Inner HTML ' - * - * @method - * @param {String} html The HTML to be set for this element. - * @returns {String} The inserted HTML. - */ - setHtml: (function() { - var standard = function( html ) { - return ( this.$.innerHTML = html ); - }; - - if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) { - // old IEs throws error on HTML manipulation (through the "innerHTML" property) - // on the element which resides in an DTD invalid position, e.g. - // fortunately it can be worked around with DOM manipulation. - return function( html ) { - try { return standard.call( this, html ); } - catch ( e ) { - this.$.innerHTML = ''; - - var temp = new CKEDITOR.dom.element( 'body', this.getDocument() ); - temp.$.innerHTML = html; - - var children = temp.getChildren(); - while( children.count() ) - this.append( children.getItem( 0 ) ); - - return html; - } - }; - } else - return standard; - })(), - - /** - * Sets the element contents as plain text. - * - * var element = new CKEDITOR.dom.element( 'div' ); - * element.setText( 'A > B & C < D' ); - * alert( element.innerHTML ); // 'A > B & C < D' - * - * @param {String} text The text to be set. - * @returns {String} The inserted text. - */ - setText: function( text ) { - CKEDITOR.dom.element.prototype.setText = ( this.$.innerText != undefined ) ? - function( text ) { - return this.$.innerText = text; - } : function( text ) { - return this.$.textContent = text; - }; - - return this.setText( text ); - }, - - /** - * Gets the value of an element attribute. - * - * var element = CKEDITOR.dom.element.createFromHtml( '' ); - * alert( element.getAttribute( 'type' ) ); // 'text' - * - * @method - * @param {String} name The attribute name. - * @returns {String} The attribute value or null if not defined. - */ - getAttribute: (function() { - var standard = function( name ) { - return this.$.getAttribute( name, 2 ); - }; - - if ( CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) ) { - return function( name ) { - switch ( name ) { - case 'class': - name = 'className'; - break; - - case 'http-equiv': - name = 'httpEquiv'; - break; - - case 'name': - return this.$.name; - - case 'tabindex': - var tabIndex = standard.call( this, name ); - - // IE returns tabIndex=0 by default for all - // elements. For those elements, - // getAtrribute( 'tabindex', 2 ) returns 32768 - // instead. So, we must make this check to give a - // uniform result among all browsers. - if ( tabIndex !== 0 && this.$.tabIndex === 0 ) - tabIndex = null; - - return tabIndex; - break; - - case 'checked': - { - var attr = this.$.attributes.getNamedItem( name ), - attrValue = attr.specified ? attr.nodeValue // For value given by parser. - : this.$.checked; // For value created via DOM interface. - - return attrValue ? 'checked' : null; - } - - case 'hspace': - case 'value': - return this.$[ name ]; - - case 'style': - // IE does not return inline styles via getAttribute(). See #2947. - return this.$.style.cssText; - - case 'contenteditable': - case 'contentEditable': - return this.$.attributes.getNamedItem( 'contentEditable' ).specified ? this.$.getAttribute( 'contentEditable' ) : null; - } - - return standard.call( this, name ); - }; - } else - return standard; - })(), - - /** - * Gets the nodes list containing all children of this element. - * - * @returns {CKEDITOR.dom.nodeList} - */ - getChildren: function() { - return new CKEDITOR.dom.nodeList( this.$.childNodes ); - }, - - /** - * Gets the current computed value of one of the element CSS style - * properties. - * - * var element = new CKEDITOR.dom.element( 'span' ); - * alert( element.getComputedStyle( 'display' ) ); // 'inline' - * - * @method - * @param {String} propertyName The style property name. - * @returns {String} The property value. - */ - getComputedStyle: CKEDITOR.env.ie ? - function( propertyName ) { - return this.$.currentStyle[ CKEDITOR.tools.cssStyleToDomStyle( propertyName ) ]; - } : function( propertyName ) { - var style = this.getWindow().$.getComputedStyle( this.$, null ); - // Firefox may return null if we call the above on a hidden iframe. (#9117) - return style ? style.getPropertyValue( propertyName ) : ''; - }, - - /** - * Gets the DTD entries for this element. - * - * @returns {Object} An object containing the list of elements accepted - * by this element. - */ - getDtd: function() { - var dtd = CKEDITOR.dtd[ this.getName() ]; - - this.getDtd = function() { - return dtd; - }; - - return dtd; - }, - - /** - * Gets all this element's descendants having given tag name. - * - * @method - * @param {String} tagName - */ - getElementsByTag: CKEDITOR.dom.document.prototype.getElementsByTag, - - /** - * Gets the computed tabindex for this element. - * - * var element = CKEDITOR.document.getById( 'myDiv' ); - * alert( element.getTabIndex() ); // (e.g.) '-1' - * - * @method - * @returns {Number} The tabindex value. - */ - getTabIndex: CKEDITOR.env.ie ? - function() { - var tabIndex = this.$.tabIndex; - - // IE returns tabIndex=0 by default for all elements. In - // those cases we must check that the element really has - // the tabindex attribute set to zero, or it is one of - // those element that should have zero by default. - if ( tabIndex === 0 && !CKEDITOR.dtd.$tabIndex[ this.getName() ] && parseInt( this.getAttribute( 'tabindex' ), 10 ) !== 0 ) - tabIndex = -1; - - return tabIndex; - } : CKEDITOR.env.webkit ? - function() { - var tabIndex = this.$.tabIndex; - - // Safari returns "undefined" for elements that should not - // have tabindex (like a div). So, we must try to get it - // from the attribute. - // https://bugs.webkit.org/show_bug.cgi?id=20596 - if ( tabIndex == undefined ) { - tabIndex = parseInt( this.getAttribute( 'tabindex' ), 10 ); - - // If the element don't have the tabindex attribute, - // then we should return -1. - if ( isNaN( tabIndex ) ) - tabIndex = -1; - } - - return tabIndex; - } : function() { - return this.$.tabIndex; - }, - - /** - * Gets the text value of this element. - * - * Only in IE (which uses innerText), `` will cause linebreaks, - * and sucessive whitespaces (including line breaks) will be reduced to - * a single space. This behavior is ok for us, for now. It may change - * in the future. - * - * var element = CKEDITOR.dom.element.createFromHtml( ' Sample text. ' );
- * alert( element.getText() ); // 'Sample text.'
- *
- * @returns {String} The text value.
- */
- getText: function() {
- return this.$.textContent || this.$.innerText || '';
- },
-
- /**
- * Gets the window object that contains this element.
- *
- * @returns {CKEDITOR.dom.window} The window object.
- */
- getWindow: function() {
- return this.getDocument().getWindow();
- },
-
- /**
- * Gets the value of the `id` attribute of this element.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( '' );
- * alert( element.getId() ); // 'myId'
- *
- * @returns {String} The element id, or null if not available.
- */
- getId: function() {
- return this.$.id || null;
- },
-
- /**
- * Gets the value of the `name` attribute of this element.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( '' );
- * alert( element.getNameAtt() ); // 'myName'
- *
- * @returns {String} The element name, or null if not available.
- */
- getNameAtt: function() {
- return this.$.name || null;
- },
-
- /**
- * Gets the element name (tag name). The returned name is guaranteed to
- * be always full lowercased.
- *
- * var element = new CKEDITOR.dom.element( 'span' );
- * alert( element.getName() ); // 'span'
- *
- * @returns {String} The element name.
- */
- getName: function() {
- // Cache the lowercased name inside a closure.
- var nodeName = this.$.nodeName.toLowerCase();
-
- if ( CKEDITOR.env.ie && !( document.documentMode > 8 ) ) {
- var scopeName = this.$.scopeName;
- if ( scopeName != 'HTML' )
- nodeName = scopeName.toLowerCase() + ':' + nodeName;
- }
-
- return ( this.getName = function() {
- return nodeName;
- })();
- },
-
- /**
- * Gets the value set to this element. This value is usually available
- * for form field elements.
- *
- * @returns {String} The element value.
- */
- getValue: function() {
- return this.$.value;
- },
-
- /**
- * Gets the first child node of this element.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( 'Example ' );
- * var first = element.getFirst();
- * alert( first.getName() ); // 'b'
- *
- * @param {Function} evaluator Filtering the result node.
- * @returns {CKEDITOR.dom.node} The first child node or null if not available.
- */
- getFirst: function( evaluator ) {
- var first = this.$.firstChild,
- retval = first && new CKEDITOR.dom.node( first );
- if ( retval && evaluator && !evaluator( retval ) )
- retval = retval.getNext( evaluator );
-
- return retval;
- },
-
- /**
- * See {@link #getFirst}.
- *
- * @param {Function} evaluator Filtering the result node.
- * @returns {CKEDITOR.dom.node}
- */
- getLast: function( evaluator ) {
- var last = this.$.lastChild,
- retval = last && new CKEDITOR.dom.node( last );
- if ( retval && evaluator && !evaluator( retval ) )
- retval = retval.getPrevious( evaluator );
-
- return retval;
- },
-
- /**
- * Gets CSS style value.
- *
- * @param {String} name The CSS property name.
- * @returns {String} Style value.
- */
- getStyle: function( name ) {
- return this.$.style[ CKEDITOR.tools.cssStyleToDomStyle( name ) ];
- },
-
- /**
- * Checks if the element name matches the specified criteria.
- *
- * var element = new CKEDITOR.element( 'span' );
- * alert( element.is( 'span' ) ); // true
- * alert( element.is( 'p', 'span' ) ); // true
- * alert( element.is( 'p' ) ); // false
- * alert( element.is( 'p', 'div' ) ); // false
- * alert( element.is( { p:1,span:1 } ) ); // true
- *
- * @param {String.../Object} name One or more names to be checked, or a {@link CKEDITOR.dtd} object.
- * @returns {Boolean} `true` if the element name matches any of the names.
- */
- is: function() {
- var name = this.getName();
-
- // Check against the specified DTD liternal.
- if ( typeof arguments[ 0 ] == 'object' )
- return !!arguments[ 0 ][ name ];
-
- // Check for tag names
- for ( var i = 0; i < arguments.length; i++ ) {
- if ( arguments[ i ] == name )
- return true;
- }
- return false;
- },
-
- /**
- * Decide whether one element is able to receive cursor.
- *
- * @param {Boolean} [textCursor=true] Only consider element that could receive text child.
- */
- isEditable: function( textCursor ) {
- var name = this.getName();
-
- if ( this.isReadOnly() || this.getComputedStyle( 'display' ) == 'none' ||
- this.getComputedStyle( 'visibility' ) == 'hidden' ||
- CKEDITOR.dtd.$nonEditable[ name ] ||
- CKEDITOR.dtd.$empty[ name ] ||
- ( this.is( 'a' ) &&
- ( this.data( 'cke-saved-name' ) || this.hasAttribute( 'name' ) ) &&
- !this.getChildCount()
- ) )
- {
- return false;
- }
-
- if ( textCursor !== false ) {
- // Get the element DTD (defaults to span for unknown elements).
- var dtd = CKEDITOR.dtd[ name ] || CKEDITOR.dtd.span;
- // In the DTD # == text node.
- return !!( dtd && dtd[ '#' ] );
- }
-
- return true;
- },
-
- /**
- * Compare this element's inner html, tag name, attributes, etc. with other one.
- *
- * See [W3C's DOM Level 3 spec - node#isEqualNode](http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-isEqualNode)
- * for more details.
- *
- * @param {CKEDITOR.dom.element} otherElement Element to compare.
- * @returns {Boolean}
- */
- isIdentical: function( otherElement ) {
- // do shallow clones, but with IDs
- var thisEl = this.clone( 0, 1 ),
- otherEl = otherElement.clone( 0, 1 );
-
- // Remove distractions.
- thisEl.removeAttributes( [ '_moz_dirty', 'data-cke-expando', 'data-cke-saved-href', 'data-cke-saved-name' ] );
- otherEl.removeAttributes( [ '_moz_dirty', 'data-cke-expando', 'data-cke-saved-href', 'data-cke-saved-name' ] );
-
- // Native comparison available.
- if ( thisEl.$.isEqualNode ) {
- // Styles order matters.
- thisEl.$.style.cssText = CKEDITOR.tools.normalizeCssText( thisEl.$.style.cssText );
- otherEl.$.style.cssText = CKEDITOR.tools.normalizeCssText( otherEl.$.style.cssText );
- return thisEl.$.isEqualNode( otherEl.$ );
- } else {
- thisEl = thisEl.getOuterHtml();
- otherEl = otherEl.getOuterHtml();
-
- // Fix tiny difference between link href in older IEs.
- if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 && this.is( 'a' ) ) {
- var parent = this.getParent();
- if ( parent.type == CKEDITOR.NODE_ELEMENT ) {
- var el = parent.clone();
- el.setHtml( thisEl ), thisEl = el.getHtml();
- el.setHtml( otherEl ), otherEl = el.getHtml();
- }
- }
-
- return thisEl == otherEl;
- }
- },
-
- /**
- * Checks if this element is visible. May not work if the element is
- * child of an element with visibility set to `hidden`, but works well
- * on the great majority of cases.
- *
- * @returns {Boolean} True if the element is visible.
- */
- isVisible: function() {
- var isVisible = ( this.$.offsetHeight || this.$.offsetWidth ) && this.getComputedStyle( 'visibility' ) != 'hidden',
- elementWindow, elementWindowFrame;
-
- // Webkit and Opera report non-zero offsetHeight despite that
- // element is inside an invisible iframe. (#4542)
- if ( isVisible && ( CKEDITOR.env.webkit || CKEDITOR.env.opera ) ) {
- elementWindow = this.getWindow();
-
- if ( !elementWindow.equals( CKEDITOR.document.getWindow() ) && ( elementWindowFrame = elementWindow.$.frameElement ) ) {
- isVisible = new CKEDITOR.dom.element( elementWindowFrame ).isVisible();
- }
- }
-
- return !!isVisible;
- },
-
- /**
- * Whether it's an empty inline elements which has no visual impact when removed.
- *
- * @returns {Boolean}
- */
- isEmptyInlineRemoveable: function() {
- if ( !CKEDITOR.dtd.$removeEmpty[ this.getName() ] )
- return false;
-
- var children = this.getChildren();
- for ( var i = 0, count = children.count(); i < count; i++ ) {
- var child = children.getItem( i );
-
- if ( child.type == CKEDITOR.NODE_ELEMENT && child.data( 'cke-bookmark' ) )
- continue;
-
- if ( child.type == CKEDITOR.NODE_ELEMENT && !child.isEmptyInlineRemoveable() || child.type == CKEDITOR.NODE_TEXT && CKEDITOR.tools.trim( child.getText() ) ) {
- return false;
- }
- }
- return true;
- },
-
- /**
- * Checks if the element has any defined attributes.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( 'Example ' );
- * alert( element.hasAttributes() ); // true
- *
- * var element = CKEDITOR.dom.element.createFromHtml( 'Example ' );
- * alert( element.hasAttributes() ); // false
- *
- * @method
- * @returns {Boolean} True if the element has attributes.
- */
- hasAttributes: CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) ?
- function() {
- var attributes = this.$.attributes;
-
- for ( var i = 0; i < attributes.length; i++ ) {
- var attribute = attributes[ i ];
-
- switch ( attribute.nodeName ) {
- case 'class':
- // IE has a strange bug. If calling removeAttribute('className'),
- // the attributes collection will still contain the "class"
- // attribute, which will be marked as "specified", even if the
- // outerHTML of the element is not displaying the class attribute.
- // Note : I was not able to reproduce it outside the editor,
- // but I've faced it while working on the TC of #1391.
- if ( this.getAttribute( 'class' ) )
- return true;
-
- // Attributes to be ignored.
- case 'data-cke-expando':
- continue;
-
- /*jsl:fallthru*/
-
- default:
- if ( attribute.specified )
- return true;
- }
- }
-
- return false;
- } : function() {
- var attrs = this.$.attributes,
- attrsNum = attrs.length;
-
- // The _moz_dirty attribute might get into the element after pasting (#5455)
- var execludeAttrs = { 'data-cke-expando':1,_moz_dirty:1 };
-
- return attrsNum > 0 && ( attrsNum > 2 || !execludeAttrs[ attrs[ 0 ].nodeName ] || ( attrsNum == 2 && !execludeAttrs[ attrs[ 1 ].nodeName ] ) );
- },
-
- /**
- * Checks if the specified attribute is defined for this element.
- *
- * @method
- * @param {String} name The attribute name.
- * @returns {Boolean} `true` if the specified attribute is defined.
- */
- hasAttribute: (function() {
- function standard( name ) {
- var $attr = this.$.attributes.getNamedItem( name );
- return !!( $attr && $attr.specified );
- }
-
- return ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 ) ?
- function( name ) {
- // On IE < 8 the name attribute cannot be retrieved
- // right after the element creation and setting the
- // name with setAttribute.
- if ( name == 'name' )
- return !!this.$.name;
-
- return standard.call( this, name );
- } : standard;
- })(),
-
- /**
- * Hides this element (sets `display: none`).
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.hide();
- */
- hide: function() {
- this.setStyle( 'display', 'none' );
- },
-
- /**
- * Moves this element's children to the target element.
- *
- * @param {CKEDITOR.dom.element} target
- * @param {Boolean} [toStart=false] Insert moved children at the
- * beginning of the target element.
- */
- moveChildren: function( target, toStart ) {
- var $ = this.$;
- target = target.$;
-
- if ( $ == target )
- return;
-
- var child;
-
- if ( toStart ) {
- while ( ( child = $.lastChild ) )
- target.insertBefore( $.removeChild( child ), target.firstChild );
- } else {
- while ( ( child = $.firstChild ) )
- target.appendChild( $.removeChild( child ) );
- }
- },
-
- /**
- * Merges sibling elements that are identical to this one.
- *
- * Identical child elements are also merged. For example:
- *
- * =>
- *
- * @method
- * @param {Boolean} [inlineOnly=true] Allow only inline elements to be merged.
- */
- mergeSiblings: (function() {
- function mergeElements( element, sibling, isNext ) {
- if ( sibling && sibling.type == CKEDITOR.NODE_ELEMENT ) {
- // Jumping over bookmark nodes and empty inline elements, e.g. ,
- // queuing them to be moved later. (#5567)
- var pendingNodes = [];
-
- while ( sibling.data( 'cke-bookmark' ) || sibling.isEmptyInlineRemoveable() ) {
- pendingNodes.push( sibling );
- sibling = isNext ? sibling.getNext() : sibling.getPrevious();
- if ( !sibling || sibling.type != CKEDITOR.NODE_ELEMENT )
- return;
- }
-
- if ( element.isIdentical( sibling ) ) {
- // Save the last child to be checked too, to merge things like
- // =>
- var innerSibling = isNext ? element.getLast() : element.getFirst();
-
- // Move pending nodes first into the target element.
- while ( pendingNodes.length )
- pendingNodes.shift().move( element, !isNext );
-
- sibling.moveChildren( element, !isNext );
- sibling.remove();
-
- // Now check the last inner child (see two comments above).
- if ( innerSibling && innerSibling.type == CKEDITOR.NODE_ELEMENT )
- innerSibling.mergeSiblings();
- }
- }
- }
-
- return function( inlineOnly ) {
- if ( !( inlineOnly === false || CKEDITOR.dtd.$removeEmpty[ this.getName() ] || this.is( 'a' ) ) ) // Merge empty links and anchors also. (#5567)
- {
- return;
- }
-
- mergeElements( this, this.getNext(), true );
- mergeElements( this, this.getPrevious() );
- };
- })(),
-
- /**
- * Shows this element (displays it).
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.show();
- */
- show: function() {
- this.setStyles({
- display: '',
- visibility: ''
- });
- },
-
- /**
- * Sets the value of an element attribute.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.setAttribute( 'class', 'myClass' );
- * element.setAttribute( 'title', 'This is an example' );
- *
- * @method
- * @param {String} name The name of the attribute.
- * @param {String} value The value to be set to the attribute.
- * @returns {CKEDITOR.dom.element} This element instance.
- */
- setAttribute: (function() {
- var standard = function( name, value ) {
- this.$.setAttribute( name, value );
- return this;
- };
-
- if ( CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) ) {
- return function( name, value ) {
- if ( name == 'class' )
- this.$.className = value;
- else if ( name == 'style' )
- this.$.style.cssText = value;
- else if ( name == 'tabindex' ) // Case sensitive.
- this.$.tabIndex = value;
- else if ( name == 'checked' )
- this.$.checked = value;
- else if ( name == 'contenteditable' )
- standard.call( this, 'contentEditable', value );
- else
- standard.apply( this, arguments );
- return this;
- };
- } else if ( CKEDITOR.env.ie8Compat && CKEDITOR.env.secure ) {
- return function( name, value ) {
- // IE8 throws error when setting src attribute to non-ssl value. (#7847)
- if ( name == 'src' && value.match( /^http:\/\// ) )
- try {
- standard.apply( this, arguments );
- } catch ( e ) {} else
- standard.apply( this, arguments );
- return this;
- };
- } else
- return standard;
- })(),
-
- /**
- * Sets the value of several element attributes.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.setAttributes( {
- * 'class': 'myClass',
- * title: 'This is an example'
- * } );
- *
- * @chainable
- * @param {Object} attributesPairs An object containing the names and
- * values of the attributes.
- * @returns {CKEDITOR.dom.element} This element instance.
- */
- setAttributes: function( attributesPairs ) {
- for ( var name in attributesPairs )
- this.setAttribute( name, attributesPairs[ name ] );
- return this;
- },
-
- /**
- * Sets the element value. This function is usually used with form
- * field element.
- *
- * @chainable
- * @param {String} value The element value.
- * @returns {CKEDITOR.dom.element} This element instance.
- */
- setValue: function( value ) {
- this.$.value = value;
- return this;
- },
-
- /**
- * Removes an attribute from the element.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( '' );
- * element.removeAttribute( 'class' );
- *
- * @method
- * @param {String} name The attribute name.
- */
- removeAttribute: (function() {
- var standard = function( name ) {
- this.$.removeAttribute( name );
- };
-
- if ( CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) ) {
- return function( name ) {
- if ( name == 'class' )
- name = 'className';
- else if ( name == 'tabindex' )
- name = 'tabIndex';
- else if ( name == 'contenteditable' )
- name = 'contentEditable';
- standard.call( this, name );
- };
- } else
- return standard;
- })(),
-
- /**
- * Removes all element's attributes or just given ones.
- *
- * @param {Array} [attributes] The array with attributes names.
- */
- removeAttributes: function( attributes ) {
- if ( CKEDITOR.tools.isArray( attributes ) ) {
- for ( var i = 0; i < attributes.length; i++ )
- this.removeAttribute( attributes[ i ] );
- } else {
- for ( var attr in attributes )
- attributes.hasOwnProperty( attr ) && this.removeAttribute( attr );
- }
- },
-
- /**
- * Removes a style from the element.
- *
- * var element = CKEDITOR.dom.element.createFromHtml( '' );
- * element.removeStyle( 'display' );
- *
- * @method
- * @param {String} name The style name.
- */
- removeStyle: function( name ) {
- // Removes the specified property from the current style object.
- var $ = this.$.style;
-
- // "removeProperty" need to be specific on the following styles.
- if ( !$.removeProperty && ( name == 'border' || name == 'margin' || name == 'padding' ) ) {
- var names = expandedRules( name );
- for ( var i = 0 ; i < names.length ; i++ )
- this.removeStyle( names[ i ] );
- return;
- }
-
- $.removeProperty ? $.removeProperty( name ) : $.removeAttribute( CKEDITOR.tools.cssStyleToDomStyle( name ) );
-
- // Eventually remove empty style attribute.
- if ( !this.$.style.cssText )
- this.removeAttribute( 'style' );
- },
-
- /**
- * Sets the value of an element style.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.setStyle( 'background-color', '#ff0000' );
- * element.setStyle( 'margin-top', '10px' );
- * element.setStyle( 'float', 'right' );
- *
- * @param {String} name The name of the style. The CSS naming notation
- * must be used (e.g. `background-color`).
- * @param {String} value The value to be set to the style.
- * @returns {CKEDITOR.dom.element} This element instance.
- */
- setStyle: function( name, value ) {
- this.$.style[ CKEDITOR.tools.cssStyleToDomStyle( name ) ] = value;
- return this;
- },
-
- /**
- * Sets the value of several element styles.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.setStyles( {
- * position: 'absolute',
- * float: 'right'
- * } );
- *
- * @param {Object} stylesPairs An object containing the names and
- * values of the styles.
- * @returns {CKEDITOR.dom.element} This element instance.
- */
- setStyles: function( stylesPairs ) {
- for ( var name in stylesPairs )
- this.setStyle( name, stylesPairs[ name ] );
- return this;
- },
-
- /**
- * Sets the opacity of an element.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.setOpacity( 0.75 );
- *
- * @param {Number} opacity A number within the range `[0.0, 1.0]`.
- */
- setOpacity: function( opacity ) {
- if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
- opacity = Math.round( opacity * 100 );
- this.setStyle( 'filter', opacity >= 100 ? '' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')' );
- } else
- this.setStyle( 'opacity', opacity );
- },
-
- /**
- * Makes the element and its children unselectable.
- *
- * var element = CKEDITOR.document.getById( 'myElement' );
- * element.unselectable();
- *
- * @method
- */
- unselectable: function() {
- // CSS unselectable.
- this.setStyles( CKEDITOR.tools.cssVendorPrefix( 'user-select', 'none' ) );
-
- // For IE/Opera which doesn't support for the above CSS style,
- // the unselectable="on" attribute only specifies the selection
- // process cannot start in the element itself, and it doesn't inherit.
- if ( CKEDITOR.env.ie || CKEDITOR.env.opera ) {
- this.setAttribute( 'unselectable', 'on' );
-
- var element,
- elements = this.getElementsByTag( "*" );
-
- for ( var i = 0, count = elements.count() ; i < count ; i++ ) {
- element = elements.getItem( i );
- element.setAttribute( 'unselectable', 'on' );
- }
- }
- },
-
- /**
- * Gets closest positioned (`position != static`) ancestor.
- *
- * @returns {CKEDITOR.dom.element} Positioned ancestor or `null`.
- */
- getPositionedAncestor: function() {
- var current = this;
- while ( current.getName() != 'html' ) {
- if ( current.getComputedStyle( 'position' ) != 'static' )
- return current;
-
- current = current.getParent();
- }
- return null;
- },
-
- /**
- * Gets this element's position in document.
- *
- * @param {CKEDITOR.dom.document} [refDocument]
- * @returns {Object} Element's position.
- * @returns {Number} return.x
- * @returns {Number} return.y
- * @todo refDocument
- */
- getDocumentPosition: function( refDocument ) {
- var x = 0,
- y = 0,
- doc = this.getDocument(),
- body = doc.getBody(),
- quirks = doc.$.compatMode == 'BackCompat';
-
- if ( document.documentElement[ "getBoundingClientRect" ] ) {
- var box = this.$.getBoundingClientRect(),
- $doc = doc.$,
- $docElem = $doc.documentElement;
-
- var clientTop = $docElem.clientTop || body.$.clientTop || 0,
- clientLeft = $docElem.clientLeft || body.$.clientLeft || 0,
- needAdjustScrollAndBorders = true;
-
- // #3804: getBoundingClientRect() works differently on IE and non-IE
- // browsers, regarding scroll positions.
- //
- // On IE, the top position of the element is always 0, no matter
- // how much you scrolled down.
- //
- // On other browsers, the top position of the element is negative
- // scrollTop.
- if ( CKEDITOR.env.ie ) {
- var inDocElem = doc.getDocumentElement().contains( this ),
- inBody = doc.getBody().contains( this );
-
- needAdjustScrollAndBorders = ( quirks && inBody ) || ( !quirks && inDocElem );
- }
-
- if ( needAdjustScrollAndBorders ) {
- x = box.left + ( !quirks && $docElem.scrollLeft || body.$.scrollLeft );
- x -= clientLeft;
- y = box.top + ( !quirks && $docElem.scrollTop || body.$.scrollTop );
- y -= clientTop;
- }
- } else {
- var current = this,
- previous = null,
- offsetParent;
- while ( current && !( current.getName() == 'body' || current.getName() == 'html' ) ) {
- x += current.$.offsetLeft - current.$.scrollLeft;
- y += current.$.offsetTop - current.$.scrollTop;
-
- // Opera includes clientTop|Left into offsetTop|Left.
- if ( !current.equals( this ) ) {
- x += ( current.$.clientLeft || 0 );
- y += ( current.$.clientTop || 0 );
- }
-
- var scrollElement = previous;
- while ( scrollElement && !scrollElement.equals( current ) ) {
- x -= scrollElement.$.scrollLeft;
- y -= scrollElement.$.scrollTop;
- scrollElement = scrollElement.getParent();
- }
-
- previous = current;
- current = ( offsetParent = current.$.offsetParent ) ? new CKEDITOR.dom.element( offsetParent ) : null;
- }
- }
-
- if ( refDocument ) {
- var currentWindow = this.getWindow(),
- refWindow = refDocument.getWindow();
-
- if ( !currentWindow.equals( refWindow ) && currentWindow.$.frameElement ) {
- var iframePosition = ( new CKEDITOR.dom.element( currentWindow.$.frameElement ) ).getDocumentPosition( refDocument );
-
- x += iframePosition.x;
- y += iframePosition.y;
- }
- }
-
- if ( !document.documentElement[ "getBoundingClientRect" ] ) {
- // In Firefox, we'll endup one pixel before the element positions,
- // so we must add it here.
- if ( CKEDITOR.env.gecko && !quirks ) {
- x += this.$.clientLeft ? 1 : 0;
- y += this.$.clientTop ? 1 : 0;
- }
- }
-
- return { x: x, y: y };
- },
-
- /**
- * Make any page element visible inside the browser viewport.
- *
- * @param {Boolean} [alignToTop=false]
- */
- scrollIntoView: function( alignToTop ) {
- var parent = this.getParent();
- if ( !parent )
- return;
-
- // Scroll the element into parent container from the inner out.
- do {
- // Check ancestors that overflows.
- var overflowed =
- parent.$.clientWidth && parent.$.clientWidth < parent.$.scrollWidth ||
- parent.$.clientHeight && parent.$.clientHeight < parent.$.scrollHeight;
-
- // Skip body element, which will report wrong clientHeight when containing
- // floated content. (#9523)
- if ( overflowed && !parent.is( 'body' ) )
- this.scrollIntoParent( parent, alignToTop, 1 );
-
- // Walk across the frame.
- if ( parent.is( 'html' ) ) {
- var win = parent.getWindow();
-
- // Avoid security error.
- try {
- var iframe = win.$.frameElement;
- iframe && ( parent = new CKEDITOR.dom.element( iframe ) );
- } catch ( er ) {}
- }
- }
- while ( ( parent = parent.getParent() ) );
- },
-
- /**
- * Make any page element visible inside one of the ancestors by scrolling the parent.
- *
- * @param {CKEDITOR.dom.element/CKEDITOR.dom.window} parent The container to scroll into.
- * @param {Boolean} [alignToTop] Align the element's top side with the container's
- * when `true` is specified; align the bottom with viewport bottom when
- * `false` is specified. Otherwise scroll on either side with the minimum
- * amount to show the element.
- * @param {Boolean} [hscroll] Whether horizontal overflow should be considered.
- */
- scrollIntoParent: function( parent, alignToTop, hscroll ) {
- !parent && ( parent = this.getWindow() );
-
- var doc = parent.getDocument();
- var isQuirks = doc.$.compatMode == 'BackCompat';
-
- // On window is scrolled while quirks scrolls .
- if ( parent instanceof CKEDITOR.dom.window )
- parent = isQuirks ? doc.getBody() : doc.getDocumentElement();
-
- // Scroll the parent by the specified amount.
- function scrollBy( x, y ) {
- // Webkit doesn't support "scrollTop/scrollLeft"
- // on documentElement/body element.
- if ( /body|html/.test( parent.getName() ) )
- parent.getWindow().$.scrollBy( x, y );
- else {
- parent.$[ 'scrollLeft' ] += x;
- parent.$[ 'scrollTop' ] += y;
- }
- }
-
- // Figure out the element position relative to the specified window.
- function screenPos( element, refWin ) {
- var pos = { x: 0, y: 0 };
-
- if ( !( element.is( isQuirks ? 'body' : 'html' ) ) ) {
- var box = element.$.getBoundingClientRect();
- pos.x = box.left, pos.y = box.top;
- }
-
- var win = element.getWindow();
- if ( !win.equals( refWin ) ) {
- var outerPos = screenPos( CKEDITOR.dom.element.get( win.$.frameElement ), refWin );
- pos.x += outerPos.x, pos.y += outerPos.y;
- }
-
- return pos;
- }
-
- // calculated margin size.
- function margin( element, side ) {
- return parseInt( element.getComputedStyle( 'margin-' + side ) || 0, 10 ) || 0;
- }
-
- var win = parent.getWindow();
-
- var thisPos = screenPos( this, win ),
- parentPos = screenPos( parent, win ),
- eh = this.$.offsetHeight,
- ew = this.$.offsetWidth,
- ch = parent.$.clientHeight,
- cw = parent.$.clientWidth,
- lt, br;
-
- // Left-top margins.
- lt = {
- x: thisPos.x - margin( this, 'left' ) - parentPos.x || 0,
- y: thisPos.y - margin( this, 'top' ) - parentPos.y || 0
- };
-
- // Bottom-right margins.
- br = {
- x: thisPos.x + ew + margin( this, 'right' ) - ( ( parentPos.x ) + cw ) || 0,
- y: thisPos.y + eh + margin( this, 'bottom' ) - ( ( parentPos.y ) + ch ) || 0
- };
-
- // 1. Do the specified alignment as much as possible;
- // 2. Otherwise be smart to scroll only the minimum amount;
- // 3. Never cut at the top;
- // 4. DO NOT scroll when already visible.
- if ( lt.y < 0 || br.y > 0 ) {
- scrollBy( 0, alignToTop === true ? lt.y : alignToTop === false ? br.y : lt.y < 0 ? lt.y : br.y );
- }
-
- if ( hscroll && ( lt.x < 0 || br.x > 0 ) )
- scrollBy( lt.x < 0 ? lt.x : br.x, 0 );
- },
-
- /**
- * Switch the `class` attribute to reflect one of the triple states of an
- * element in one of {@link CKEDITOR#TRISTATE_ON}, {@link CKEDITOR#TRISTATE_OFF}
- * or {@link CKEDITOR#TRISTATE_DISABLED}.
- *
- * link.setState( CKEDITOR.TRISTATE_ON );
- * // ...
- * link.setState( CKEDITOR.TRISTATE_OFF );
- * // ...
- * link.setState( CKEDITOR.TRISTATE_DISABLED );
- * // ...
- *
- * span.setState( CKEDITOR.TRISTATE_ON, 'cke_button' );
- * //
- *
- * @param {Number} state Indicate the element state. One of {@link CKEDITOR#TRISTATE_ON},
- * {@link CKEDITOR#TRISTATE_OFF}, {@link CKEDITOR#TRISTATE_DISABLED}.
- * @param [base='cke'] The prefix apply to each of the state class name.
- * @param [useAria=true] Whether toggle the ARIA state attributes besides of class name change.
- */
- setState: function( state, base, useAria ) {
- base = base || 'cke';
-
- switch ( state ) {
- case CKEDITOR.TRISTATE_ON:
- this.addClass( base + '_on' );
- this.removeClass( base + '_off' );
- this.removeClass( base + '_disabled' );
- useAria && this.setAttribute( 'aria-pressed', true );
- useAria && this.removeAttribute( 'aria-disabled' );
- break;
-
- case CKEDITOR.TRISTATE_DISABLED:
- this.addClass( base + '_disabled' );
- this.removeClass( base + '_off' );
- this.removeClass( base + '_on' );
- useAria && this.setAttribute( 'aria-disabled', true );
- useAria && this.removeAttribute( 'aria-pressed' );
- break;
-
- default:
- this.addClass( base + '_off' );
- this.removeClass( base + '_on' );
- this.removeClass( base + '_disabled' );
- useAria && this.removeAttribute( 'aria-pressed' );
- useAria && this.removeAttribute( 'aria-disabled' );
- break;
- }
- },
-
- /**
- * Returns the inner document of this ` |