Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/_bootstrap.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/_bootstrap.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/_bootstrap.js 14 Feb 2012 08:01:31 -0000 1.1 @@ -0,0 +1,87 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview API initialization code. + */ + +(function() +{ + // Disable HC detaction in WebKit. (#5429) + if ( CKEDITOR.env.webkit ) + { + CKEDITOR.env.hc = false; + return; + } + + // Check whether high contrast is active by creating a colored border. + var hcDetect = CKEDITOR.dom.element.createFromHtml( + '
', CKEDITOR.document ); + + hcDetect.appendTo( CKEDITOR.document.getHead() ); + + // Update CKEDITOR.env. + // Catch exception needed sometimes for FF. (#4230) + try + { + CKEDITOR.env.hc = hcDetect.getComputedStyle( 'border-top-color' ) == hcDetect.getComputedStyle( 'border-right-color' ); + } + catch (e) + { + CKEDITOR.env.hc = false; + } + + if ( CKEDITOR.env.hc ) + CKEDITOR.env.cssClass += ' cke_hc'; + + hcDetect.remove(); +})(); + +// Load core plugins. +CKEDITOR.plugins.load( CKEDITOR.config.corePlugins.split( ',' ), function() + { + CKEDITOR.status = 'loaded'; + CKEDITOR.fire( 'loaded' ); + + // Process all instances created by the "basic" implementation. + var pending = CKEDITOR._.pending; + if ( pending ) + { + delete CKEDITOR._.pending; + + for ( var i = 0 ; i < pending.length ; i++ ) + CKEDITOR.add( pending[ i ] ); + } + }); + +// Needed for IE6 to not request image (HTTP 200 or 304) for every CSS background. (#6187) +if ( CKEDITOR.env.ie ) +{ + // Remove IE mouse flickering on IE6 because of background images. + try + { + document.execCommand( 'BackgroundImageCache', false, true ); + } + catch (e) + { + // We have been reported about loading problems caused by the above + // line. For safety, let's just ignore errors. + } +} + +/** + * Indicates that CKEditor is running on a High Contrast environment. + * @name CKEDITOR.env.hc + * @example + * if ( CKEDITOR.env.hc ) + * alert( 'You're running on High Contrast mode. The editor interface will get adapted to provide you a better experience.' ); + */ + +/** + * Fired when a CKEDITOR core object is fully loaded and ready for interaction. + * @name CKEDITOR#loaded + * @event + */ Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/ckeditor.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/ckeditor.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/ckeditor.js 14 Feb 2012 08:01:32 -0000 1.1 @@ -0,0 +1,141 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Contains the third and last part of the {@link CKEDITOR} object + * definition. + */ + +// Remove the CKEDITOR.loadFullCore reference defined on ckeditor_basic. +delete CKEDITOR.loadFullCore; + +/** + * Holds references to all editor instances created. The name of the properties + * in this object correspond to instance names, and their values contains the + * {@link CKEDITOR.editor} object representing them. + * @type {Object} + * @example + * alert( CKEDITOR.instances.editor1.name ); // "editor1" + */ +CKEDITOR.instances = {}; + +/** + * The document of the window holding the CKEDITOR object. + * @type {CKEDITOR.dom.document} + * @example + * alert( CKEDITOR.document.getBody().getName() ); // "body" + */ +CKEDITOR.document = new CKEDITOR.dom.document( document ); + +/** + * Adds an editor instance to the global {@link CKEDITOR} object. This function + * is available for internal use mainly. + * @param {CKEDITOR.editor} editor The editor instance to be added. + * @example + */ +CKEDITOR.add = function( editor ) +{ + CKEDITOR.instances[ editor.name ] = editor; + + editor.on( 'focus', function() + { + if ( CKEDITOR.currentInstance != editor ) + { + CKEDITOR.currentInstance = editor; + CKEDITOR.fire( 'currentInstance' ); + } + }); + + editor.on( 'blur', function() + { + if ( CKEDITOR.currentInstance == editor ) + { + CKEDITOR.currentInstance = null; + CKEDITOR.fire( 'currentInstance' ); + } + }); +}; + +/** + * Removes an editor instance from the global {@link CKEDITOR} object. This function + * is available for internal use only. External code must use {@link CKEDITOR.editor.prototype.destroy} + * to avoid memory leaks. + * @param {CKEDITOR.editor} editor The editor instance to be removed. + * @example + */ +CKEDITOR.remove = function( editor ) +{ + delete CKEDITOR.instances[ editor.name ]; +}; + +/** + * Perform global clean up to free as much memory as possible + * when there are no instances left + */ +CKEDITOR.on( 'instanceDestroyed', function () + { + if ( CKEDITOR.tools.isEmpty( this.instances ) ) + CKEDITOR.fire( 'reset' ); + }); + +// Load the bootstrap script. +CKEDITOR.loader.load( 'core/_bootstrap' ); // @Packager.RemoveLine + +// Tri-state constants. + +/** + * Used to indicate the ON or ACTIVE state. + * @constant + * @example + */ +CKEDITOR.TRISTATE_ON = 1; + +/** + * Used to indicate the OFF or NON ACTIVE state. + * @constant + * @example + */ +CKEDITOR.TRISTATE_OFF = 2; + +/** + * Used to indicate DISABLED state. + * @constant + * @example + */ +CKEDITOR.TRISTATE_DISABLED = 0; + +/** + * The editor which is currently active (have user focus). + * @name CKEDITOR.currentInstance + * @type CKEDITOR.editor + * @see CKEDITOR#currentInstance + * @example + * function showCurrentEditorName() + * { + * if ( CKEDITOR.currentInstance ) + * alert( CKEDITOR.currentInstance.name ); + * else + * alert( 'Please focus an editor first.' ); + * } + */ + +/** + * Fired when the CKEDITOR.currentInstance object reference changes. This may + * happen when setting the focus on different editor instances in the page. + * @name CKEDITOR#currentInstance + * @event + * var editor; // Variable to hold a reference to the current editor. + * CKEDITOR.on( 'currentInstance' , function( e ) + * { + * editor = CKEDITOR.currentInstance; + * }); + */ + +/** + * Fired when the last instance has been destroyed. This event is used to perform + * global memory clean up. + * @name CKEDITOR#reset + * @event + */ Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/ckeditor_base.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/ckeditor_base.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/ckeditor_base.js 14 Feb 2012 08:01:32 -0000 1.1 @@ -0,0 +1,227 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Contains the first and essential part of the {@link CKEDITOR} + * object definition. + */ + +// #### Compressed Code +// Must be updated on changes in the script as well as updated in the +// ckeditor_source.js and ckeditor_basic_source.js files. + +// if(!window.CKEDITOR)window.CKEDITOR=(function(){var a={timestamp:'',version:'3.6.2',rev:'7275',_:{},status:'unloaded',basePath:(function(){var d=window.CKEDITOR_BASEPATH||'';if(!d){var e=document.getElementsByTagName('script');for(var f=0;f=0?'&':'?')+('t=')+this.timestamp;return d;}},b=window.CKEDITOR_GETURL;if(b){var c=a.getUrl;a.getUrl=function(d){return b.call(a,d)||c.call(a,d);};}return a;})(); + +// #### Raw code +// ATTENTION: read the above "Compressed Code" notes when changing this code. + +/* @Packager.RemoveLine +// Avoid having the editor code initialized twice. (#7588) +// Use CKEDITOR.dom to check whether the full ckeditor.js code has been loaded +// or just ckeditor_basic.js. +// Remove these lines when compressing manually. +if ( window.CKEDITOR && window.CKEDITOR.dom ) + return; +@Packager.RemoveLine */ + +if ( !window.CKEDITOR ) +{ + /** + * @name CKEDITOR + * @namespace This is the API entry point. The entire CKEditor code runs under this object. + * @example + */ + window.CKEDITOR = (function() + { + var CKEDITOR = + /** @lends CKEDITOR */ + { + + /** + * A constant string unique for each release of CKEditor. Its value + * is used, by default, to build the URL for all resources loaded + * by the editor code, guaranteeing clean cache results when + * upgrading. + * @type String + * @example + * alert( CKEDITOR.timestamp ); // e.g. '87dm' + */ + // The production implementation contains a fixed timestamp, unique + // for each release and generated by the releaser. + // (Base 36 value of each component of YYMMDDHH - 4 chars total - e.g. 87bm == 08071122) + timestamp : 'B8DJ5M3', + + /** + * Contains the CKEditor version number. + * @type String + * @example + * alert( CKEDITOR.version ); // e.g. 'CKEditor 3.4.1' + */ + version : '3.6.2', + + /** + * Contains the CKEditor revision number. + * The revision number is incremented automatically, following each + * modification to the CKEditor source code. + * @type String + * @example + * alert( CKEDITOR.revision ); // e.g. '3975' + */ + revision : '7275', + + /** + * Private object used to hold core stuff. It should not be used outside of + * the API code as properties defined here may change at any time + * without notice. + * @private + */ + _ : {}, + + /** + * Indicates the API loading status. The following statuses are available: + * + * @type String + * @example + * if ( CKEDITOR.status == 'loaded' ) + * { + * // The API can now be fully used. + * } + */ + status : 'unloaded', + + /** + * Contains the full URL for the CKEditor installation directory. + * It is possible to manually provide the base path by setting a + * global variable named CKEDITOR_BASEPATH. This global variable + * must be set before the editor script loading. + * @type String + * @example + * alert( CKEDITOR.basePath ); // "http://www.example.com/ckeditor/" (e.g.) + */ + basePath : (function() + { + // ATTENTION: fixes to this code must be ported to + // var basePath in "core/loader.js". + + // Find out the editor directory path, based on its ")' ); + } + } + + return $ && new CKEDITOR.dom.document( $.contentWindow.document ); + }, + + /** + * Copy all the attributes from one node to the other, kinda like a clone + * skipAttributes is an object with the attributes that must NOT be copied. + * @param {CKEDITOR.dom.element} dest The destination element. + * @param {Object} skipAttributes A dictionary of attributes to skip. + * @example + */ + copyAttributes : function( dest, skipAttributes ) + { + var attributes = this.$.attributes; + skipAttributes = skipAttributes || {}; + + for ( var n = 0 ; n < attributes.length ; n++ ) + { + var attribute = attributes[n]; + + // Lowercase attribute name hard rule is broken for + // some attribute on IE, e.g. CHECKED. + var attrName = attribute.nodeName.toLowerCase(), + attrValue; + + // We can set the type only once, so do it with the proper value, not copying it. + if ( attrName in skipAttributes ) + continue; + + if ( attrName == 'checked' && ( attrValue = this.getAttribute( attrName ) ) ) + dest.setAttribute( attrName, attrValue ); + // IE BUG: value attribute is never specified even if it exists. + else if ( attribute.specified || + ( CKEDITOR.env.ie && attribute.nodeValue && attrName == 'value' ) ) + { + attrValue = this.getAttribute( attrName ); + if ( attrValue === null ) + attrValue = attribute.nodeValue; + + dest.setAttribute( attrName, attrValue ); + } + } + + // The style: + if ( this.$.style.cssText !== '' ) + dest.$.style.cssText = this.$.style.cssText; + }, + + /** + * Changes the tag name of the current element. + * @param {String} newTag The new tag for the element. + */ + renameNode : function( newTag ) + { + // If it's already correct exit here. + if ( this.getName() == newTag ) + return; + + var doc = this.getDocument(); + + // Create the new node. + var newNode = new CKEDITOR.dom.element( newTag, doc ); + + // Copy all attributes. + this.copyAttributes( newNode ); + + // Move children to the new node. + this.moveChildren( newNode ); + + // Replace the node. + this.getParent() && this.$.parentNode.replaceChild( newNode.$, this.$ ); + newNode.$[ 'data-cke-expando' ] = this.$[ 'data-cke-expando' ]; + this.$ = newNode.$; + }, + + /** + * Gets a DOM tree descendant under the current node. + * @param {Array|Number} indices The child index or array of child indices under the node. + * @returns {CKEDITOR.dom.node} The specified DOM child under the current node. Null if child does not exist. + * @example + * var strong = p.getChild(0); + */ + getChild : function( indices ) + { + var rawNode = this.$; + + if ( !indices.slice ) + rawNode = rawNode.childNodes[ indices ]; + else + { + while ( indices.length > 0 && rawNode ) + rawNode = rawNode.childNodes[ indices.shift() ]; + } + + return rawNode ? new CKEDITOR.dom.node( rawNode ) : null; + }, + + getChildCount : function() + { + return this.$.childNodes.length; + }, + + disableContextMenu : function() + { + this.on( 'contextmenu', function( event ) + { + // Cancel the browser context menu. + if ( !event.data.getTarget().hasClass( 'cke_enable_context_menu' ) ) + event.data.preventDefault(); + } ); + }, + + /** + * Gets element's direction. Supports both CSS 'direction' prop and 'dir' attr. + */ + getDirection : function( useComputed ) + { + return useComputed ? + this.getComputedStyle( 'direction' ) + // Webkit: offline element returns empty direction (#8053). + || this.getDirection() + || this.getDocument().$.dir + || this.getDocument().getBody().getDirection( 1 ) + : this.getStyle( 'direction' ) || this.getAttribute( 'dir' ); + }, + + /** + * Gets, sets and removes custom data to be stored as HTML5 data-* attributes. + * @param {String} name The name of the attribute, excluding the 'data-' part. + * @param {String} [value] The value to set. If set to false, the attribute will be removed. + * @example + * element.data( 'extra-info', 'test' ); // appended the attribute data-extra-info="test" to the element + * alert( element.data( 'extra-info' ) ); // "test" + * element.data( 'extra-info', false ); // remove the data-extra-info attribute from the element + */ + data : function ( name, value ) + { + name = 'data-' + name; + if ( value === undefined ) + return this.getAttribute( name ); + else if ( value === false ) + this.removeAttribute( name ); + else + this.setAttribute( name, value ); + + return null; + } + }); + +( function() +{ + var sides = { + width : [ "border-left-width", "border-right-width","padding-left", "padding-right" ], + height : [ "border-top-width", "border-bottom-width", "padding-top", "padding-bottom" ] + }; + + function marginAndPaddingSize( type ) + { + var adjustment = 0; + for ( var i = 0, len = sides[ type ].length; i < len; i++ ) + adjustment += parseInt( this.getComputedStyle( sides [ type ][ i ] ) || 0, 10 ) || 0; + return adjustment; + } + + /** + * Sets the element size considering the box model. + * @name CKEDITOR.dom.element.prototype.setSize + * @function + * @param {String} type The dimension to set. It accepts "width" and "height". + * @param {Number} size The length unit in px. + * @param {Boolean} isBorderBox Apply the size based on the border box model. + */ + CKEDITOR.dom.element.prototype.setSize = function( type, size, isBorderBox ) + { + if ( typeof size == 'number' ) + { + if ( isBorderBox && !( CKEDITOR.env.ie && CKEDITOR.env.quirks ) ) + size -= marginAndPaddingSize.call( this, type ); + + this.setStyle( type, size + 'px' ); + } + }; + + /** + * Gets the element size, possibly considering the box model. + * @name CKEDITOR.dom.element.prototype.getSize + * @function + * @param {String} type The dimension to get. It accepts "width" and "height". + * @param {Boolean} isBorderBox Get the size based on the border box model. + */ + CKEDITOR.dom.element.prototype.getSize = function( type, isBorderBox ) + { + var size = Math.max( this.$[ 'offset' + CKEDITOR.tools.capitalize( type ) ], + this.$[ 'client' + CKEDITOR.tools.capitalize( type ) ] ) || 0; + + if ( isBorderBox ) + size -= marginAndPaddingSize.call( this, type ); + + return size; + }; +})(); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/elementpath.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/elementpath.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/elementpath.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,119 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + // Elements that may be considered the "Block boundary" in an element path. + var pathBlockElements = { address:1,blockquote:1,dl:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1,li:1,dt:1,dd:1, legend:1,caption:1 }; + + // Elements that may be considered the "Block limit" in an element path. + var pathBlockLimitElements = { body:1,div:1,table:1,tbody:1,tr:1,td:1,th:1,form:1,fieldset:1 }; + + // Check if an element contains any block element. + var checkHasBlock = function( element ) + { + var childNodes = element.getChildren(); + + for ( var i = 0, count = childNodes.count() ; i < count ; i++ ) + { + var child = childNodes.getItem( i ); + + if ( child.type == CKEDITOR.NODE_ELEMENT && CKEDITOR.dtd.$block[ child.getName() ] ) + return true; + } + + return false; + }; + + /** + * @class + */ + CKEDITOR.dom.elementPath = function( lastNode ) + { + var block = null; + var blockLimit = null; + var elements = []; + + var e = lastNode; + + while ( e ) + { + if ( e.type == CKEDITOR.NODE_ELEMENT ) + { + if ( !this.lastElement ) + this.lastElement = e; + + var elementName = e.getName(); + if ( CKEDITOR.env.ie && e.$.scopeName != 'HTML' ) + elementName = e.$.scopeName.toLowerCase() + ':' + elementName; + + if ( !blockLimit ) + { + if ( !block && pathBlockElements[ elementName ] ) + block = e; + + if ( pathBlockLimitElements[ elementName ] ) + { + // DIV is considered the Block, if no block is available (#525) + // and if it doesn't contain other blocks. + if ( !block && elementName == 'div' && !checkHasBlock( e ) ) + block = e; + else + blockLimit = e; + } + } + + elements.push( e ); + + if ( elementName == 'body' ) + break; + } + e = e.getParent(); + } + + this.block = block; + this.blockLimit = blockLimit; + this.elements = elements; + }; +})(); + +CKEDITOR.dom.elementPath.prototype = +{ + /** + * Compares this element path with another one. + * @param {CKEDITOR.dom.elementPath} otherPath The elementPath object to be + * compared with this one. + * @returns {Boolean} "true" if the paths are equal, containing the same + * number of elements and the same elements in the same order. + */ + compare : function( otherPath ) + { + var thisElements = this.elements; + var otherElements = otherPath && otherPath.elements; + + if ( !otherElements || thisElements.length != otherElements.length ) + return false; + + for ( var i = 0 ; i < thisElements.length ; i++ ) + { + if ( !thisElements[ i ].equals( otherElements[ i ] ) ) + return false; + } + + return true; + }, + + contains : function( tagNames ) + { + var elements = this.elements; + for ( var i = 0 ; i < elements.length ; i++ ) + { + if ( elements[ i ].getName() in tagNames ) + return elements[ i ]; + } + + return null; + } +}; Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/event.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/event.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/event.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,145 @@ +/* +Copyright (c) 2003-2011, 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. + * @constructor + * @param {Object} domEvent A native DOM event object. + * @example + */ +CKEDITOR.dom.event = function( domEvent ) +{ + /** + * The native DOM event object represented by this class instance. + * @type Object + * @example + */ + this.$ = domEvent; +}; + +CKEDITOR.dom.event.prototype = +{ + /** + * Gets the key code associated to the event. + * @returns {Number} The key code. + * @example + * alert( event.getKey() ); "65" is "a" has been pressed + */ + 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. + * @returns {Number} The number representing the keys combination. + * @example + * 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 + */ + 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. + * @param {Boolean} [stopPropagation] Stop propagating this event in the + * event chain. + * @example + * 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(); + * }); + */ + preventDefault : function( stopPropagation ) + { + var $ = this.$; + if ( $.preventDefault ) + $.preventDefault(); + else + $.returnValue = false; + + if ( stopPropagation ) + this.stopPropagation(); + }, + + stopPropagation : function() + { + var $ = this.$; + if ( $.stopPropagation ) + $.stopPropagation(); + else + $.cancelBubble = true; + }, + + /** + * Returns the DOM node where the event was targeted to. + * @returns {CKEDITOR.dom.node} The target DOM node. + * @example + * 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' ); + * }); + */ + + getTarget : function() + { + var rawNode = this.$.target || this.$.srcElement; + return rawNode ? new CKEDITOR.dom.node( rawNode ) : null; + } +}; + +// For the followind constants, we need to go over the Unicode boundaries +// (0x10FFFF) to avoid collision. + +/** + * CTRL key (0x110000). + * @constant + * @example + */ +CKEDITOR.CTRL = 0x110000; + +/** + * SHIFT key (0x220000). + * @constant + * @example + */ +CKEDITOR.SHIFT = 0x220000; + +/** + * ALT key (0x440000). + * @constant + * @example + */ +CKEDITOR.ALT = 0x440000; Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/node.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/node.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/node.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,696 @@ +/* +Copyright (c) 2003-2011, 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}. + * @augments CKEDITOR.dom.domObject + * @param {Object} domNode A native DOM node. + * @constructor + * @see CKEDITOR.dom.element + * @see CKEDITOR.dom.text + * @example + */ +CKEDITOR.dom.node = function( domNode ) +{ + if ( domNode ) + { + switch ( domNode.nodeType ) + { + // Safari don't consider document as element node type. (#3389) + case CKEDITOR.NODE_DOCUMENT : + return new CKEDITOR.dom.document( domNode ); + + case CKEDITOR.NODE_ELEMENT : + return new CKEDITOR.dom.element( domNode ); + + case CKEDITOR.NODE_TEXT : + return new CKEDITOR.dom.text( domNode ); + } + + // Call the base constructor. + CKEDITOR.dom.domObject.call( this, domNode ); + } + + return this; +}; + +CKEDITOR.dom.node.prototype = new CKEDITOR.dom.domObject(); + +/** + * Element node type. + * @constant + * @example + */ +CKEDITOR.NODE_ELEMENT = 1; + +/** + * Document node type. + * @constant + * @example + */ +CKEDITOR.NODE_DOCUMENT = 9; + +/** + * Text node type. + * @constant + * @example + */ +CKEDITOR.NODE_TEXT = 3; + +/** + * Comment node type. + * @constant + * @example + */ +CKEDITOR.NODE_COMMENT = 8; + +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, + /** @lends CKEDITOR.dom.node.prototype */ + { + /** + * Makes this node a child of another element. + * @param {CKEDITOR.dom.element} element The target element to which + * this node will be appended. + * @returns {CKEDITOR.dom.element} The target element. + * @example + * var p = new CKEDITOR.dom.element( 'p' ); + * var strong = new CKEDITOR.dom.element( 'strong' ); + * strong.appendTo( p ); + * + * // result: "<p><strong></strong></p>" + */ + appendTo : function( element, toStart ) + { + element.append( this, toStart ); + return element; + }, + + clone : function( includeChildren, cloneId ) + { + var $clone = this.$.cloneNode( includeChildren ); + + var removeIds = function( node ) + { + if ( node.nodeType != CKEDITOR.NODE_ELEMENT ) + return; + + if ( !cloneId ) + node.removeAttribute( 'id', false ); + node.removeAttribute( 'data-cke-expando', 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 ); + }, + + hasPrevious : function() + { + return !!this.$.previousSibling; + }, + + hasNext : function() + { + return !!this.$.nextSibling; + }, + + /** + * Inserts this element after a node. + * @param {CKEDITOR.dom.node} node The node that will precede this element. + * @returns {CKEDITOR.dom.node} The node preceding this one after + * insertion. + * @example + * var em = new CKEDITOR.dom.element( 'em' ); + * var strong = new CKEDITOR.dom.element( 'strong' ); + * strong.insertAfter( em ); + * + * // result: "<em></em><strong></strong>" + */ + insertAfter : function( node ) + { + node.$.parentNode.insertBefore( this.$, node.$.nextSibling ); + return node; + }, + + /** + * Inserts this element before a node. + * @param {CKEDITOR.dom.node} node The node that will succeed this element. + * @returns {CKEDITOR.dom.node} The node being inserted. + * @example + * var em = new CKEDITOR.dom.element( 'em' ); + * var strong = new CKEDITOR.dom.element( 'strong' ); + * strong.insertBefore( em ); + * + * // result: "<strong></strong><em></em>" + */ + insertBefore : function( node ) + { + node.$.parentNode.insertBefore( this.$, node.$ ); + return node; + }, + + 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 <body> is the second child + * of <html> (<head> being the first), + * and we would like to address the third child under the + * fourth child of <body>, 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. + */ + 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. + * @returns {CKEDITOR.dom.document} The document. + * @example + * var element = CKEDITOR.document.getById( 'example' ); + * alert( element.getDocument().equals( CKEDITOR.document ) ); // "true" + */ + getDocument : function() + { + return new CKEDITOR.dom.document( this.$.ownerDocument || this.$.parentNode.ownerDocument ); + }, + + getIndex : function( normalized ) + { + // Attention: getAddress depends on this.$ + + var current = this.$, + index = 0; + + while ( ( current = current.previousSibling ) ) + { + // When normalizing, do not count it if this is an + // empty text node or if it's a text node following another one. + if ( normalized && current.nodeType == 3 && + ( !current.nodeValue.length || + ( current.previousSibling && current.previousSibling.nodeType == 3 ) ) ) + { + continue; + } + + index++; + } + + return index; + }, + + 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; + }, + + 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; + }, + + getPrevious : function( evaluator ) + { + var previous = this.$, retval; + do + { + previous = previous.previousSibling; + retval = previous && 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. + * @param {Function} evaluator Filtering the result node. + * @returns {CKEDITOR.dom.node} The next node or null if not available. + * @example + * var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b> <i>next</i></div>' ); + * var first = element.getFirst().getNext(); + * alert( first.getName() ); // "i" + */ + 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. + * @returns {CKEDITOR.dom.element} The parent element. + * @example + * var node = editor.document.getBody().getFirst(); + * var parent = node.getParent(); + * alert( node.getName() ); // "body" + */ + getParent : function() + { + var parent = this.$.parentNode; + return ( parent && parent.nodeType == 1 ) ? new CKEDITOR.dom.node( parent ) : null; + }, + + getParents : function( closerFirst ) + { + var node = this; + var parents = []; + + do + { + parents[ closerFirst ? 'push' : 'unshift' ]( node ); + } + while ( ( node = node.getParent() ) ) + + return parents; + }, + + 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; + }, + + 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. + * @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. + * @since 3.6.1 + * @example + * // Suppose we have the following HTML structure: + * // <div id="outer"><div id="inner"><p><b>Some text</b></p></div></div> + * // If node == <b> + * ascendant = node.getAscendant( 'div' ); // ascendant == <div id="inner"> + * ascendant = node.getAscendant( 'b' ); // ascendant == null + * ascendant = node.getAscendant( 'b', true ); // ascendant == <b> + * ascendant = node.getAscendant( { div: 1, p: 1} ); // Searches for the first 'div' or 'p': ascendant == <div id="inner"> + */ + 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( $ ); + + $ = $.parentNode; + } + return null; + }, + + hasAscendant : function( name, includeSelf ) + { + var $ = this.$; + + if ( !includeSelf ) + $ = $.parentNode; + + while ( $ ) + { + if ( $.nodeName && $.nodeName.toLowerCase() == name ) + return true; + + $ = $.parentNode; + } + return false; + }, + + move : function( target, toStart ) + { + target.append( this.remove(), toStart ); + }, + + /** + * Removes this node from the document DOM. + * @param {Boolean} [preserveChildren] Indicates that the children + * elements must remain in the document, removing only the outer + * tags. + * @example + * var element = CKEDITOR.dom.element.getById( 'MyElement' ); + * element.remove(); + */ + 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; + }, + + replace : function( nodeToReplace ) + { + this.insertBefore( nodeToReplace ); + nodeToReplace.remove(); + }, + + trim : function() + { + this.ltrim(); + this.rtrim(); + }, + + 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; + } + }, + + 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). + * @returns {Boolean} + * @since 3.5 + * @example + * // For the following HTML: + * // <div contenteditable="false">Some <b>text</b></div> + * + * // If "ele" is the above <div> + * ele.isReadOnly(); // true + */ + 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 + var current = element; + while( current ) + { + if ( current.is( 'body' ) || !!current.data( 'cke-editable' ) ) + break; + + if ( current.getAttribute( 'contentEditable' ) == 'false' ) + return true; + else if ( current.getAttribute( 'contentEditable' ) == 'true' ) + break; + + current = current.getParent(); + } + + return false; + } + } + } +); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/nodelist.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/nodelist.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/nodelist.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,26 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @class + */ +CKEDITOR.dom.nodeList = function( nativeList ) +{ + this.$ = nativeList; +}; + +CKEDITOR.dom.nodeList.prototype = +{ + count : function() + { + return this.$.length; + }, + + getItem : function( index ) + { + var $node = this.$[ index ]; + return $node ? new CKEDITOR.dom.node( $node ) : null; + } +}; Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/range.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/range.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/range.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,2054 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * Creates a CKEDITOR.dom.range instance that can be used inside a specific + * DOM Document. + * @class Represents a delimited piece of content in a DOM Document. + * It is contiguous in the sense that it can be characterized as selecting all + * of the content between a pair of boundary-points.
+ *
+ * This class shares much of the W3C + * Document Object Model Range + * ideas and features, adding several range manipulation tools to it, but it's + * not intended to be compatible with it. + * @param {CKEDITOR.dom.document} document The document into which the range + * features will be available. + * @example + * // Create a range for the entire contents of the editor document body. + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * // Delete the contents. + * range.deleteContents(); + */ +CKEDITOR.dom.range = function( document ) +{ + /** + * Node within which the range begins. + * @type {CKEDITOR.NODE_ELEMENT|CKEDITOR.NODE_TEXT} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.startContainer.getName() ); // "body" + */ + this.startContainer = null; + + /** + * Offset within the starting node of the range. + * @type {Number} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.startOffset ); // "0" + */ + this.startOffset = null; + + /** + * Node within which the range ends. + * @type {CKEDITOR.NODE_ELEMENT|CKEDITOR.NODE_TEXT} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.endContainer.getName() ); // "body" + */ + this.endContainer = null; + + /** + * Offset within the ending node of the range. + * @type {Number} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.endOffset ); // == editor.document.getBody().getChildCount() + */ + this.endOffset = null; + + /** + * Indicates that this is a collapsed range. A collapsed range has it's + * start and end boudaries at the very same point so nothing is contained + * in it. + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.collapsed ); // "false" + * range.collapse(); + * alert( range.collapsed ); // "true" + */ + this.collapsed = true; + + /** + * The document within which the range can be used. + * @type {CKEDITOR.dom.document} + * @example + * // Selects the body contents of the range document. + * range.selectNodeContents( range.document.getBody() ); + */ + this.document = document; +}; + +(function() +{ + // Updates the "collapsed" property for the given range object. + var updateCollapsed = function( range ) + { + range.collapsed = ( + range.startContainer && + range.endContainer && + range.startContainer.equals( range.endContainer ) && + range.startOffset == range.endOffset ); + }; + + // This is a shared function used to delete, extract and clone the range + // contents. + // V2 + var execContentsAction = function( range, action, docFrag, mergeThen ) + { + range.optimizeBookmark(); + + var startNode = range.startContainer; + var endNode = range.endContainer; + + var startOffset = range.startOffset; + var endOffset = range.endOffset; + + var removeStartNode; + var removeEndNode; + + // For text containers, we must simply split the node and point to the + // second part. The removal will be handled by the rest of the code . + if ( endNode.type == CKEDITOR.NODE_TEXT ) + endNode = endNode.split( endOffset ); + else + { + // If the end container has children and the offset is pointing + // to a child, then we should start from it. + if ( endNode.getChildCount() > 0 ) + { + // If the offset points after the last node. + if ( endOffset >= endNode.getChildCount() ) + { + // Let's create a temporary node and mark it for removal. + endNode = endNode.append( range.document.createText( '' ) ); + removeEndNode = true; + } + else + endNode = endNode.getChild( endOffset ); + } + } + + // For text containers, we must simply split the node. The removal will + // be handled by the rest of the code . + if ( startNode.type == CKEDITOR.NODE_TEXT ) + { + startNode.split( startOffset ); + + // In cases the end node is the same as the start node, the above + // splitting will also split the end, so me must move the end to + // the second part of the split. + if ( startNode.equals( endNode ) ) + endNode = startNode.getNext(); + } + else + { + // If the start container has children and the offset is pointing + // to a child, then we should start from its previous sibling. + + // If the offset points to the first node, we don't have a + // sibling, so let's use the first one, but mark it for removal. + if ( !startOffset ) + { + // Let's create a temporary node and mark it for removal. + startNode = startNode.getFirst().insertBeforeMe( range.document.createText( '' ) ); + removeStartNode = true; + } + else if ( startOffset >= startNode.getChildCount() ) + { + // Let's create a temporary node and mark it for removal. + startNode = startNode.append( range.document.createText( '' ) ); + removeStartNode = true; + } + else + startNode = startNode.getChild( startOffset ).getPrevious(); + } + + // Get the parent nodes tree for the start and end boundaries. + var startParents = startNode.getParents(); + var endParents = endNode.getParents(); + + // Compare them, to find the top most siblings. + var i, topStart, topEnd; + + for ( i = 0 ; i < startParents.length ; i++ ) + { + topStart = startParents[ i ]; + topEnd = endParents[ i ]; + + // The compared nodes will match until we find the top most + // siblings (different nodes that have the same parent). + // "i" will hold the index in the parents array for the top + // most element. + if ( !topStart.equals( topEnd ) ) + break; + } + + var clone = docFrag, levelStartNode, levelClone, currentNode, currentSibling; + + // Remove all successive sibling nodes for every node in the + // startParents tree. + for ( var j = i ; j < startParents.length ; j++ ) + { + levelStartNode = startParents[j]; + + // For Extract and Clone, we must clone this level. + if ( clone && !levelStartNode.equals( startNode ) ) // action = 0 = Delete + levelClone = clone.append( levelStartNode.clone() ); + + currentNode = levelStartNode.getNext(); + + while ( currentNode ) + { + // Stop processing when the current node matches a node in the + // endParents tree or if it is the endNode. + if ( currentNode.equals( endParents[ j ] ) || currentNode.equals( endNode ) ) + break; + + // Cache the next sibling. + currentSibling = currentNode.getNext(); + + // If cloning, just clone it. + if ( action == 2 ) // 2 = Clone + clone.append( currentNode.clone( true ) ); + else + { + // Both Delete and Extract will remove the node. + currentNode.remove(); + + // When Extracting, move the removed node to the docFrag. + if ( action == 1 ) // 1 = Extract + clone.append( currentNode ); + } + + currentNode = currentSibling; + } + + if ( clone ) + clone = levelClone; + } + + clone = docFrag; + + // Remove all previous sibling nodes for every node in the + // endParents tree. + for ( var k = i ; k < endParents.length ; k++ ) + { + levelStartNode = endParents[ k ]; + + // For Extract and Clone, we must clone this level. + if ( action > 0 && !levelStartNode.equals( endNode ) ) // action = 0 = Delete + levelClone = clone.append( levelStartNode.clone() ); + + // The processing of siblings may have already been done by the parent. + if ( !startParents[ k ] || levelStartNode.$.parentNode != startParents[ k ].$.parentNode ) + { + currentNode = levelStartNode.getPrevious(); + + while ( currentNode ) + { + // Stop processing when the current node matches a node in the + // startParents tree or if it is the startNode. + if ( currentNode.equals( startParents[ k ] ) || currentNode.equals( startNode ) ) + break; + + // Cache the next sibling. + currentSibling = currentNode.getPrevious(); + + // If cloning, just clone it. + if ( action == 2 ) // 2 = Clone + clone.$.insertBefore( currentNode.$.cloneNode( true ), clone.$.firstChild ) ; + else + { + // Both Delete and Extract will remove the node. + currentNode.remove(); + + // When Extracting, mode the removed node to the docFrag. + if ( action == 1 ) // 1 = Extract + clone.$.insertBefore( currentNode.$, clone.$.firstChild ); + } + + currentNode = currentSibling; + } + } + + if ( clone ) + clone = levelClone; + } + + if ( action == 2 ) // 2 = Clone. + { + // No changes in the DOM should be done, so fix the split text (if any). + + var startTextNode = range.startContainer; + if ( startTextNode.type == CKEDITOR.NODE_TEXT ) + { + startTextNode.$.data += startTextNode.$.nextSibling.data; + startTextNode.$.parentNode.removeChild( startTextNode.$.nextSibling ); + } + + var endTextNode = range.endContainer; + if ( endTextNode.type == CKEDITOR.NODE_TEXT && endTextNode.$.nextSibling ) + { + endTextNode.$.data += endTextNode.$.nextSibling.data; + endTextNode.$.parentNode.removeChild( endTextNode.$.nextSibling ); + } + } + else + { + // Collapse the range. + + // If a node has been partially selected, collapse the range between + // topStart and topEnd. Otherwise, simply collapse it to the start. (W3C specs). + if ( topStart && topEnd && ( startNode.$.parentNode != topStart.$.parentNode || endNode.$.parentNode != topEnd.$.parentNode ) ) + { + var endIndex = topEnd.getIndex(); + + // If the start node is to be removed, we must correct the + // index to reflect the removal. + if ( removeStartNode && topEnd.$.parentNode == startNode.$.parentNode ) + endIndex--; + + // Merge splitted parents. + if ( mergeThen && topStart.type == CKEDITOR.NODE_ELEMENT ) + { + var span = CKEDITOR.dom.element.createFromHtml( ' ', range.document ); + span.insertAfter( topStart ); + topStart.mergeSiblings( false ); + range.moveToBookmark( { startNode : span } ); + } + else + range.setStart( topEnd.getParent(), endIndex ); + } + + // Collapse it to the start. + range.collapse( true ); + } + + // Cleanup any marked node. + if ( removeStartNode ) + startNode.remove(); + + if ( removeEndNode && endNode.$.parentNode ) + endNode.remove(); + }; + + var inlineChildReqElements = { abbr:1,acronym:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,'var':1 }; + + // Creates the appropriate node evaluator for the dom walker used inside + // check(Start|End)OfBlock. + function getCheckStartEndBlockEvalFunction( isStart ) + { + var hadBr = false, bookmarkEvaluator = CKEDITOR.dom.walker.bookmark( true ); + return function( node ) + { + // First ignore bookmark nodes. + if ( bookmarkEvaluator( node ) ) + return true; + + if ( node.type == CKEDITOR.NODE_TEXT ) + { + // If there's any visible text, then we're not at the start. + if ( node.hasAscendant( 'pre' ) || CKEDITOR.tools.trim( node.getText() ).length ) + return false; + } + else if ( node.type == CKEDITOR.NODE_ELEMENT ) + { + // If there are non-empty inline elements (e.g. ), then we're not + // at the start. + if ( !inlineChildReqElements[ node.getName() ] ) + { + // If we're working at the end-of-block, forgive the first
in non-IE + // browsers. + if ( !isStart && !CKEDITOR.env.ie && node.getName() == 'br' && !hadBr ) + hadBr = true; + else + return false; + } + } + return true; + }; + } + + // Evaluator for CKEDITOR.dom.element::checkBoundaryOfElement, reject any + // text node and non-empty elements unless it's being bookmark text. + function elementBoundaryEval( node ) + { + // Reject any text node unless it's being bookmark + // OR it's spaces. (#3883) + return node.type != CKEDITOR.NODE_TEXT + && node.getName() in CKEDITOR.dtd.$removeEmpty + || !CKEDITOR.tools.trim( node.getText() ) + || !!node.getParent().data( 'cke-bookmark' ); + } + + var whitespaceEval = new CKEDITOR.dom.walker.whitespaces(), + bookmarkEval = new CKEDITOR.dom.walker.bookmark(); + + function nonWhitespaceOrBookmarkEval( node ) + { + // Whitespaces and bookmark nodes are to be ignored. + return !whitespaceEval( node ) && !bookmarkEval( node ); + } + + CKEDITOR.dom.range.prototype = + { + clone : function() + { + var clone = new CKEDITOR.dom.range( this.document ); + + clone.startContainer = this.startContainer; + clone.startOffset = this.startOffset; + clone.endContainer = this.endContainer; + clone.endOffset = this.endOffset; + clone.collapsed = this.collapsed; + + return clone; + }, + + collapse : function( toStart ) + { + if ( toStart ) + { + this.endContainer = this.startContainer; + this.endOffset = this.startOffset; + } + else + { + this.startContainer = this.endContainer; + this.startOffset = this.endOffset; + } + + this.collapsed = true; + }, + + /** + * The content nodes of the range are cloned and added to a document fragment, which is returned. + * Note: Text selection may lost after invoking this method. (caused by text node splitting). + */ + cloneContents : function() + { + var docFrag = new CKEDITOR.dom.documentFragment( this.document ); + + if ( !this.collapsed ) + execContentsAction( this, 2, docFrag ); + + return docFrag; + }, + + /** + * Deletes the content nodes of the range permanently from the DOM tree. + * @param {Boolean} [mergeThen] Merge any splitted elements result in DOM true due to partial selection. + */ + deleteContents : function( mergeThen ) + { + if ( this.collapsed ) + return; + + execContentsAction( this, 0, null, mergeThen ); + }, + + /** + * The content nodes of the range are cloned and added to a document fragment, + * meanwhile they're removed permanently from the DOM tree. + * @param {Boolean} [mergeThen] Merge any splitted elements result in DOM true due to partial selection. + */ + extractContents : function( mergeThen ) + { + var docFrag = new CKEDITOR.dom.documentFragment( this.document ); + + if ( !this.collapsed ) + execContentsAction( this, 1, docFrag, mergeThen ); + + return docFrag; + }, + + /** + * Creates a bookmark object, which can be later used to restore the + * range by using the moveToBookmark function. + * This is an "intrusive" way to create a bookmark. It includes tags + * in the range boundaries. The advantage of it is that it is possible to + * handle DOM mutations when moving back to the bookmark. + * Attention: the inclusion of nodes in the DOM is a design choice and + * should not be changed as there are other points in the code that may be + * using those nodes to perform operations. See GetBookmarkNode. + * @param {Boolean} [serializable] Indicates that the bookmark nodes + * must contain ids, which can be used to restore the range even + * when these nodes suffer mutations (like a clonation or innerHTML + * change). + * @returns {Object} And object representing a bookmark. + */ + createBookmark : function( serializable ) + { + var startNode, endNode; + var baseId; + var clone; + var collapsed = this.collapsed; + + startNode = this.document.createElement( 'span' ); + startNode.data( 'cke-bookmark', 1 ); + startNode.setStyle( 'display', 'none' ); + + // For IE, it must have something inside, otherwise it may be + // removed during DOM operations. + startNode.setHtml( ' ' ); + + if ( serializable ) + { + baseId = 'cke_bm_' + CKEDITOR.tools.getNextNumber(); + startNode.setAttribute( 'id', baseId + 'S' ); + } + + // If collapsed, the endNode will not be created. + if ( !collapsed ) + { + endNode = startNode.clone(); + endNode.setHtml( ' ' ); + + if ( serializable ) + endNode.setAttribute( 'id', baseId + 'E' ); + + clone = this.clone(); + clone.collapse(); + clone.insertNode( endNode ); + } + + clone = this.clone(); + clone.collapse( true ); + clone.insertNode( startNode ); + + // Update the range position. + if ( endNode ) + { + this.setStartAfter( startNode ); + this.setEndBefore( endNode ); + } + else + this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END ); + + return { + startNode : serializable ? baseId + 'S' : startNode, + endNode : serializable ? baseId + 'E' : endNode, + serializable : serializable, + collapsed : collapsed + }; + }, + + /** + * Creates a "non intrusive" and "mutation sensible" bookmark. This + * kind of bookmark should be used only when the DOM is supposed to + * remain stable after its creation. + * @param {Boolean} [normalized] Indicates that the bookmark must + * normalized. When normalized, the successive text nodes are + * considered a single node. To sucessful load a normalized + * bookmark, the DOM tree must be also normalized before calling + * moveToBookmark. + * @returns {Object} An object representing the bookmark. + */ + createBookmark2 : function( normalized ) + { + var startContainer = this.startContainer, + endContainer = this.endContainer; + + var startOffset = this.startOffset, + endOffset = this.endOffset; + + var collapsed = this.collapsed; + + var child, previous; + + // If there is no range then get out of here. + // It happens on initial load in Safari #962 and if the editor it's + // hidden also in Firefox + if ( !startContainer || !endContainer ) + return { start : 0, end : 0 }; + + if ( normalized ) + { + // Find out if the start is pointing to a text node that will + // be normalized. + if ( startContainer.type == CKEDITOR.NODE_ELEMENT ) + { + child = startContainer.getChild( startOffset ); + + // In this case, move the start information to that text + // node. + if ( child && child.type == CKEDITOR.NODE_TEXT + && startOffset > 0 && child.getPrevious().type == CKEDITOR.NODE_TEXT ) + { + startContainer = child; + startOffset = 0; + } + + // Get the normalized offset. + if ( child && child.type == CKEDITOR.NODE_ELEMENT ) + startOffset = child.getIndex( 1 ); + } + + // Normalize the start. + while ( startContainer.type == CKEDITOR.NODE_TEXT + && ( previous = startContainer.getPrevious() ) + && previous.type == CKEDITOR.NODE_TEXT ) + { + startContainer = previous; + startOffset += previous.getLength(); + } + + // Process the end only if not normalized. + if ( !collapsed ) + { + // Find out if the start is pointing to a text node that + // will be normalized. + if ( endContainer.type == CKEDITOR.NODE_ELEMENT ) + { + child = endContainer.getChild( endOffset ); + + // In this case, move the start information to that + // text node. + if ( child && child.type == CKEDITOR.NODE_TEXT + && endOffset > 0 && child.getPrevious().type == CKEDITOR.NODE_TEXT ) + { + endContainer = child; + endOffset = 0; + } + + // Get the normalized offset. + if ( child && child.type == CKEDITOR.NODE_ELEMENT ) + endOffset = child.getIndex( 1 ); + } + + // Normalize the end. + while ( endContainer.type == CKEDITOR.NODE_TEXT + && ( previous = endContainer.getPrevious() ) + && previous.type == CKEDITOR.NODE_TEXT ) + { + endContainer = previous; + endOffset += previous.getLength(); + } + } + } + + return { + start : startContainer.getAddress( normalized ), + end : collapsed ? null : endContainer.getAddress( normalized ), + startOffset : startOffset, + endOffset : endOffset, + normalized : normalized, + collapsed : collapsed, + is2 : true // It's a createBookmark2 bookmark. + }; + }, + + moveToBookmark : function( bookmark ) + { + if ( bookmark.is2 ) // Created with createBookmark2(). + { + // Get the start information. + var startContainer = this.document.getByAddress( bookmark.start, bookmark.normalized ), + startOffset = bookmark.startOffset; + + // Get the end information. + var endContainer = bookmark.end && this.document.getByAddress( bookmark.end, bookmark.normalized ), + endOffset = bookmark.endOffset; + + // Set the start boundary. + this.setStart( startContainer, startOffset ); + + // Set the end boundary. If not available, collapse it. + if ( endContainer ) + this.setEnd( endContainer, endOffset ); + else + this.collapse( true ); + } + else // Created with createBookmark(). + { + var serializable = bookmark.serializable, + startNode = serializable ? this.document.getById( bookmark.startNode ) : bookmark.startNode, + endNode = serializable ? this.document.getById( bookmark.endNode ) : bookmark.endNode; + + // Set the range start at the bookmark start node position. + this.setStartBefore( startNode ); + + // Remove it, because it may interfere in the setEndBefore call. + startNode.remove(); + + // Set the range end at the bookmark end node position, or simply + // collapse it if it is not available. + if ( endNode ) + { + this.setEndBefore( endNode ); + endNode.remove(); + } + else + this.collapse( true ); + } + }, + + getBoundaryNodes : function() + { + var startNode = this.startContainer, + endNode = this.endContainer, + startOffset = this.startOffset, + endOffset = this.endOffset, + childCount; + + if ( startNode.type == CKEDITOR.NODE_ELEMENT ) + { + childCount = startNode.getChildCount(); + if ( childCount > startOffset ) + startNode = startNode.getChild( startOffset ); + else if ( childCount < 1 ) + startNode = startNode.getPreviousSourceNode(); + else // startOffset > childCount but childCount is not 0 + { + // Try to take the node just after the current position. + startNode = startNode.$; + while ( startNode.lastChild ) + startNode = startNode.lastChild; + startNode = new CKEDITOR.dom.node( startNode ); + + // Normally we should take the next node in DFS order. But it + // is also possible that we've already reached the end of + // document. + startNode = startNode.getNextSourceNode() || startNode; + } + } + if ( endNode.type == CKEDITOR.NODE_ELEMENT ) + { + childCount = endNode.getChildCount(); + if ( childCount > endOffset ) + endNode = endNode.getChild( endOffset ).getPreviousSourceNode( true ); + else if ( childCount < 1 ) + endNode = endNode.getPreviousSourceNode(); + else // endOffset > childCount but childCount is not 0 + { + // Try to take the node just before the current position. + endNode = endNode.$; + while ( endNode.lastChild ) + endNode = endNode.lastChild; + endNode = new CKEDITOR.dom.node( endNode ); + } + } + + // Sometimes the endNode will come right before startNode for collapsed + // ranges. Fix it. (#3780) + if ( startNode.getPosition( endNode ) & CKEDITOR.POSITION_FOLLOWING ) + startNode = endNode; + + return { startNode : startNode, endNode : endNode }; + }, + + /** + * Find the node which fully contains the range. + * @param includeSelf + * @param {Boolean} ignoreTextNode Whether ignore CKEDITOR.NODE_TEXT type. + */ + getCommonAncestor : function( includeSelf , ignoreTextNode ) + { + var start = this.startContainer, + end = this.endContainer, + ancestor; + + if ( start.equals( end ) ) + { + if ( includeSelf + && start.type == CKEDITOR.NODE_ELEMENT + && this.startOffset == this.endOffset - 1 ) + ancestor = start.getChild( this.startOffset ); + else + ancestor = start; + } + else + ancestor = start.getCommonAncestor( end ); + + return ignoreTextNode && !ancestor.is ? ancestor.getParent() : ancestor; + }, + + /** + * Transforms the startContainer and endContainer properties from text + * nodes to element nodes, whenever possible. This is actually possible + * if either of the boundary containers point to a text node, and its + * offset is set to zero, or after the last char in the node. + */ + optimize : function() + { + var container = this.startContainer; + var offset = this.startOffset; + + if ( container.type != CKEDITOR.NODE_ELEMENT ) + { + if ( !offset ) + this.setStartBefore( container ); + else if ( offset >= container.getLength() ) + this.setStartAfter( container ); + } + + container = this.endContainer; + offset = this.endOffset; + + if ( container.type != CKEDITOR.NODE_ELEMENT ) + { + if ( !offset ) + this.setEndBefore( container ); + else if ( offset >= container.getLength() ) + this.setEndAfter( container ); + } + }, + + /** + * Move the range out of bookmark nodes if they'd been the container. + */ + optimizeBookmark: function() + { + var startNode = this.startContainer, + endNode = this.endContainer; + + if ( startNode.is && startNode.is( 'span' ) + && startNode.data( 'cke-bookmark' ) ) + this.setStartAt( startNode, CKEDITOR.POSITION_BEFORE_START ); + if ( endNode && endNode.is && endNode.is( 'span' ) + && endNode.data( 'cke-bookmark' ) ) + this.setEndAt( endNode, CKEDITOR.POSITION_AFTER_END ); + }, + + trim : function( ignoreStart, ignoreEnd ) + { + var startContainer = this.startContainer, + startOffset = this.startOffset, + collapsed = this.collapsed; + if ( ( !ignoreStart || collapsed ) + && startContainer && startContainer.type == CKEDITOR.NODE_TEXT ) + { + // If the offset is zero, we just insert the new node before + // the start. + if ( !startOffset ) + { + startOffset = startContainer.getIndex(); + startContainer = startContainer.getParent(); + } + // If the offset is at the end, we'll insert it after the text + // node. + else if ( startOffset >= startContainer.getLength() ) + { + startOffset = startContainer.getIndex() + 1; + startContainer = startContainer.getParent(); + } + // In other case, we split the text node and insert the new + // node at the split point. + else + { + var nextText = startContainer.split( startOffset ); + + startOffset = startContainer.getIndex() + 1; + startContainer = startContainer.getParent(); + + // Check all necessity of updating the end boundary. + if ( this.startContainer.equals( this.endContainer ) ) + this.setEnd( nextText, this.endOffset - this.startOffset ); + else if ( startContainer.equals( this.endContainer ) ) + this.endOffset += 1; + } + + this.setStart( startContainer, startOffset ); + + if ( collapsed ) + { + this.collapse( true ); + return; + } + } + + var endContainer = this.endContainer; + var endOffset = this.endOffset; + + if ( !( ignoreEnd || collapsed ) + && endContainer && endContainer.type == CKEDITOR.NODE_TEXT ) + { + // If the offset is zero, we just insert the new node before + // the start. + if ( !endOffset ) + { + endOffset = endContainer.getIndex(); + endContainer = endContainer.getParent(); + } + // If the offset is at the end, we'll insert it after the text + // node. + else if ( endOffset >= endContainer.getLength() ) + { + endOffset = endContainer.getIndex() + 1; + endContainer = endContainer.getParent(); + } + // In other case, we split the text node and insert the new + // node at the split point. + else + { + endContainer.split( endOffset ); + + endOffset = endContainer.getIndex() + 1; + endContainer = endContainer.getParent(); + } + + this.setEnd( endContainer, endOffset ); + } + }, + + /** + * Expands the range so that partial units are completely contained. + * @param unit {Number} The unit type to expand with. + * @param {Boolean} [excludeBrs=false] Whether include line-breaks when expanding. + */ + enlarge : function( unit, excludeBrs ) + { + switch ( unit ) + { + case CKEDITOR.ENLARGE_ELEMENT : + + if ( this.collapsed ) + return; + + // Get the common ancestor. + var commonAncestor = this.getCommonAncestor(); + + var body = this.document.getBody(); + + // For each boundary + // a. Depending on its position, find out the first node to be checked (a sibling) or, if not available, to be enlarge. + // b. Go ahead checking siblings and enlarging the boundary as much as possible until the common ancestor is not reached. After reaching the common ancestor, just save the enlargeable node to be used later. + + var startTop, endTop; + + var enlargeable, sibling, commonReached; + + // Indicates that the node can be added only if whitespace + // is available before it. + var needsWhiteSpace = false; + var isWhiteSpace; + var siblingText; + + // Process the start boundary. + + var container = this.startContainer; + var offset = this.startOffset; + + if ( container.type == CKEDITOR.NODE_TEXT ) + { + if ( offset ) + { + // Check if there is any non-space text before the + // offset. Otherwise, container is null. + container = !CKEDITOR.tools.trim( container.substring( 0, offset ) ).length && container; + + // If we found only whitespace in the node, it + // means that we'll need more whitespace to be able + // to expand. For example, can be expanded in + // "A [B]", but not in "A [B]". + needsWhiteSpace = !!container; + } + + if ( container ) + { + if ( !( sibling = container.getPrevious() ) ) + enlargeable = container.getParent(); + } + } + else + { + // If we have offset, get the node preceeding it as the + // first sibling to be checked. + if ( offset ) + sibling = container.getChild( offset - 1 ) || container.getLast(); + + // If there is no sibling, mark the container to be + // enlarged. + if ( !sibling ) + enlargeable = container; + } + + while ( enlargeable || sibling ) + { + if ( enlargeable && !sibling ) + { + // If we reached the common ancestor, mark the flag + // for it. + if ( !commonReached && enlargeable.equals( commonAncestor ) ) + commonReached = true; + + if ( !body.contains( enlargeable ) ) + break; + + // If we don't need space or this element breaks + // the line, then enlarge it. + if ( !needsWhiteSpace || enlargeable.getComputedStyle( 'display' ) != 'inline' ) + { + needsWhiteSpace = false; + + // If the common ancestor has been reached, + // we'll not enlarge it immediately, but just + // mark it to be enlarged later if the end + // boundary also enlarges it. + if ( commonReached ) + startTop = enlargeable; + else + this.setStartBefore( enlargeable ); + } + + sibling = enlargeable.getPrevious(); + } + + // Check all sibling nodes preceeding the enlargeable + // node. The node wil lbe enlarged only if none of them + // blocks it. + while ( sibling ) + { + // This flag indicates that this node has + // whitespaces at the end. + isWhiteSpace = false; + + if ( sibling.type == CKEDITOR.NODE_TEXT ) + { + siblingText = sibling.getText(); + + if ( /[^\s\ufeff]/.test( siblingText ) ) + sibling = null; + + isWhiteSpace = /[\s\ufeff]$/.test( siblingText ); + } + else + { + // If this is a visible element. + // We need to check for the bookmark attribute because IE insists on + // rendering the display:none nodes we use for bookmarks. (#3363) + // Line-breaks (br) are rendered with zero width, which we don't want to include. (#7041) + if ( ( sibling.$.offsetWidth > 0 || excludeBrs && sibling.is( 'br' ) ) && !sibling.data( 'cke-bookmark' ) ) + { + // We'll accept it only if we need + // whitespace, and this is an inline + // element with whitespace only. + if ( needsWhiteSpace && CKEDITOR.dtd.$removeEmpty[ sibling.getName() ] ) + { + // It must contains spaces and inline elements only. + + siblingText = sibling.getText(); + + if ( (/[^\s\ufeff]/).test( siblingText ) ) // Spaces + Zero Width No-Break Space (U+FEFF) + sibling = null; + else + { + var allChildren = sibling.$.all || sibling.$.getElementsByTagName( '*' ); + for ( var i = 0, child ; child = allChildren[ i++ ] ; ) + { + if ( !CKEDITOR.dtd.$removeEmpty[ child.nodeName.toLowerCase() ] ) + { + sibling = null; + break; + } + } + } + + if ( sibling ) + isWhiteSpace = !!siblingText.length; + } + else + sibling = null; + } + } + + // A node with whitespaces has been found. + if ( isWhiteSpace ) + { + // Enlarge the last enlargeable node, if we + // were waiting for spaces. + if ( needsWhiteSpace ) + { + if ( commonReached ) + startTop = enlargeable; + else if ( enlargeable ) + this.setStartBefore( enlargeable ); + } + else + needsWhiteSpace = true; + } + + if ( sibling ) + { + var next = sibling.getPrevious(); + + if ( !enlargeable && !next ) + { + // Set the sibling as enlargeable, so it's + // parent will be get later outside this while. + enlargeable = sibling; + sibling = null; + break; + } + + sibling = next; + } + else + { + // If sibling has been set to null, then we + // need to stop enlarging. + enlargeable = null; + } + } + + if ( enlargeable ) + enlargeable = enlargeable.getParent(); + } + + // Process the end boundary. This is basically the same + // code used for the start boundary, with small changes to + // make it work in the oposite side (to the right). This + // makes it difficult to reuse the code here. So, fixes to + // the above code are likely to be replicated here. + + container = this.endContainer; + offset = this.endOffset; + + // Reset the common variables. + enlargeable = sibling = null; + commonReached = needsWhiteSpace = false; + + if ( container.type == CKEDITOR.NODE_TEXT ) + { + // Check if there is any non-space text after the + // offset. Otherwise, container is null. + container = !CKEDITOR.tools.trim( container.substring( offset ) ).length && container; + + // If we found only whitespace in the node, it + // means that we'll need more whitespace to be able + // to expand. For example, can be expanded in + // "A [B]", but not in "A [B]". + needsWhiteSpace = !( container && container.getLength() ); + + if ( container ) + { + if ( !( sibling = container.getNext() ) ) + enlargeable = container.getParent(); + } + } + else + { + // Get the node right after the boudary to be checked + // first. + sibling = container.getChild( offset ); + + if ( !sibling ) + enlargeable = container; + } + + while ( enlargeable || sibling ) + { + if ( enlargeable && !sibling ) + { + if ( !commonReached && enlargeable.equals( commonAncestor ) ) + commonReached = true; + + if ( !body.contains( enlargeable ) ) + break; + + if ( !needsWhiteSpace || enlargeable.getComputedStyle( 'display' ) != 'inline' ) + { + needsWhiteSpace = false; + + if ( commonReached ) + endTop = enlargeable; + else if ( enlargeable ) + this.setEndAfter( enlargeable ); + } + + sibling = enlargeable.getNext(); + } + + while ( sibling ) + { + isWhiteSpace = false; + + if ( sibling.type == CKEDITOR.NODE_TEXT ) + { + siblingText = sibling.getText(); + + if ( /[^\s\ufeff]/.test( siblingText ) ) + sibling = null; + + isWhiteSpace = /^[\s\ufeff]/.test( siblingText ); + } + else + { + // If this is a visible element. + // We need to check for the bookmark attribute because IE insists on + // rendering the display:none nodes we use for bookmarks. (#3363) + // Line-breaks (br) are rendered with zero width, which we don't want to include. (#7041) + if ( ( sibling.$.offsetWidth > 0 || excludeBrs && sibling.is( 'br' ) ) && !sibling.data( 'cke-bookmark' ) ) + { + // We'll accept it only if we need + // whitespace, and this is an inline + // element with whitespace only. + if ( needsWhiteSpace && CKEDITOR.dtd.$removeEmpty[ sibling.getName() ] ) + { + // It must contains spaces and inline elements only. + + siblingText = sibling.getText(); + + if ( (/[^\s\ufeff]/).test( siblingText ) ) + sibling = null; + else + { + allChildren = sibling.$.all || sibling.$.getElementsByTagName( '*' ); + for ( i = 0 ; child = allChildren[ i++ ] ; ) + { + if ( !CKEDITOR.dtd.$removeEmpty[ child.nodeName.toLowerCase() ] ) + { + sibling = null; + break; + } + } + } + + if ( sibling ) + isWhiteSpace = !!siblingText.length; + } + else + sibling = null; + } + } + + if ( isWhiteSpace ) + { + if ( needsWhiteSpace ) + { + if ( commonReached ) + endTop = enlargeable; + else + this.setEndAfter( enlargeable ); + } + } + + if ( sibling ) + { + next = sibling.getNext(); + + if ( !enlargeable && !next ) + { + enlargeable = sibling; + sibling = null; + break; + } + + sibling = next; + } + else + { + // If sibling has been set to null, then we + // need to stop enlarging. + enlargeable = null; + } + } + + if ( enlargeable ) + enlargeable = enlargeable.getParent(); + } + + // If the common ancestor can be enlarged by both boundaries, then include it also. + if ( startTop && endTop ) + { + commonAncestor = startTop.contains( endTop ) ? endTop : startTop; + + this.setStartBefore( commonAncestor ); + this.setEndAfter( commonAncestor ); + } + break; + + case CKEDITOR.ENLARGE_BLOCK_CONTENTS: + case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS: + + // Enlarging the start boundary. + var walkerRange = new CKEDITOR.dom.range( this.document ); + + body = this.document.getBody(); + + walkerRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START ); + walkerRange.setEnd( this.startContainer, this.startOffset ); + + var walker = new CKEDITOR.dom.walker( walkerRange ), + blockBoundary, // The node on which the enlarging should stop. + tailBr, // In case BR as block boundary. + notBlockBoundary = CKEDITOR.dom.walker.blockBoundary( + ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? { br : 1 } : null ), + // Record the encountered 'blockBoundary' for later use. + boundaryGuard = function( node ) + { + var retval = notBlockBoundary( node ); + if ( !retval ) + blockBoundary = node; + return retval; + }, + // Record the encounted 'tailBr' for later use. + tailBrGuard = function( node ) + { + var retval = boundaryGuard( node ); + if ( !retval && node.is && node.is( 'br' ) ) + tailBr = node; + return retval; + }; + + walker.guard = boundaryGuard; + + enlargeable = walker.lastBackward(); + + // It's the body which stop the enlarging if no block boundary found. + blockBoundary = blockBoundary || body; + + // Start the range either after the end of found block (

...

[text) + // or at the start of block (

[text...), by comparing the document position + // with 'enlargeable' node. + this.setStartAt( + blockBoundary, + !blockBoundary.is( 'br' ) && + ( !enlargeable && this.checkStartOfBlock() + || enlargeable && blockBoundary.contains( enlargeable ) ) ? + CKEDITOR.POSITION_AFTER_START : + CKEDITOR.POSITION_AFTER_END ); + + // Avoid enlarging the range further when end boundary spans right after the BR. (#7490) + if ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) + { + var theRange = this.clone(); + walker = new CKEDITOR.dom.walker( theRange ); + + var whitespaces = CKEDITOR.dom.walker.whitespaces(), + bookmark = CKEDITOR.dom.walker.bookmark(); + + walker.evaluator = function( node ) { return !whitespaces( node ) && !bookmark( node ); }; + var previous = walker.previous(); + if ( previous && previous.type == CKEDITOR.NODE_ELEMENT && previous.is( 'br' ) ) + return; + } + + + // Enlarging the end boundary. + walkerRange = this.clone(); + walkerRange.collapse(); + walkerRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END ); + walker = new CKEDITOR.dom.walker( walkerRange ); + + // tailBrGuard only used for on range end. + walker.guard = ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? + tailBrGuard : boundaryGuard; + blockBoundary = null; + // End the range right before the block boundary node. + + enlargeable = walker.lastForward(); + + // It's the body which stop the enlarging if no block boundary found. + blockBoundary = blockBoundary || body; + + // Close the range either before the found block start (text]

...

) or at the block end (...text]

) + // by comparing the document position with 'enlargeable' node. + this.setEndAt( + blockBoundary, + ( !enlargeable && this.checkEndOfBlock() + || enlargeable && blockBoundary.contains( enlargeable ) ) ? + CKEDITOR.POSITION_BEFORE_END : + CKEDITOR.POSITION_BEFORE_START ); + // We must include the
at the end of range if there's + // one and we're expanding list item contents + if ( tailBr ) + this.setEndAfter( tailBr ); + } + }, + + /** + * Descrease the range to make sure that boundaries + * always anchor beside text nodes or innermost element. + * @param {Number} mode ( CKEDITOR.SHRINK_ELEMENT | CKEDITOR.SHRINK_TEXT ) The shrinking mode. + *
+ *
CKEDITOR.SHRINK_ELEMENT
+ *
Shrink the range boundaries to the edge of the innermost element.
+ *
CKEDITOR.SHRINK_TEXT
+ *
Shrink the range boudaries to anchor by the side of enclosed text node, range remains if there's no text nodes on boundaries at all.
+ *
+ * @param {Boolean} selectContents Whether result range anchors at the inner OR outer boundary of the node. + */ + shrink : function( mode, selectContents ) + { + // Unable to shrink a collapsed range. + if ( !this.collapsed ) + { + mode = mode || CKEDITOR.SHRINK_TEXT; + + var walkerRange = this.clone(); + + var startContainer = this.startContainer, + endContainer = this.endContainer, + startOffset = this.startOffset, + endOffset = this.endOffset, + collapsed = this.collapsed; + + // Whether the start/end boundary is moveable. + var moveStart = 1, + moveEnd = 1; + + if ( startContainer && startContainer.type == CKEDITOR.NODE_TEXT ) + { + if ( !startOffset ) + walkerRange.setStartBefore( startContainer ); + else if ( startOffset >= startContainer.getLength( ) ) + walkerRange.setStartAfter( startContainer ); + else + { + // Enlarge the range properly to avoid walker making + // DOM changes caused by triming the text nodes later. + walkerRange.setStartBefore( startContainer ); + moveStart = 0; + } + } + + if ( endContainer && endContainer.type == CKEDITOR.NODE_TEXT ) + { + if ( !endOffset ) + walkerRange.setEndBefore( endContainer ); + else if ( endOffset >= endContainer.getLength( ) ) + walkerRange.setEndAfter( endContainer ); + else + { + walkerRange.setEndAfter( endContainer ); + moveEnd = 0; + } + } + + var walker = new CKEDITOR.dom.walker( walkerRange ), + isBookmark = CKEDITOR.dom.walker.bookmark(); + + walker.evaluator = function( node ) + { + return node.type == ( mode == CKEDITOR.SHRINK_ELEMENT ? + CKEDITOR.NODE_ELEMENT : CKEDITOR.NODE_TEXT ); + }; + + var currentElement; + walker.guard = function( node, movingOut ) + { + if ( isBookmark( node ) ) + return true; + + // Stop when we're shrink in element mode while encountering a text node. + if ( mode == CKEDITOR.SHRINK_ELEMENT && node.type == CKEDITOR.NODE_TEXT ) + return false; + + // Stop when we've already walked "through" an element. + if ( movingOut && node.equals( currentElement ) ) + return false; + + if ( !movingOut && node.type == CKEDITOR.NODE_ELEMENT ) + currentElement = node; + + return true; + }; + + if ( moveStart ) + { + var textStart = walker[ mode == CKEDITOR.SHRINK_ELEMENT ? 'lastForward' : 'next'](); + textStart && this.setStartAt( textStart, selectContents ? CKEDITOR.POSITION_AFTER_START : CKEDITOR.POSITION_BEFORE_START ); + } + + if ( moveEnd ) + { + walker.reset(); + var textEnd = walker[ mode == CKEDITOR.SHRINK_ELEMENT ? 'lastBackward' : 'previous'](); + textEnd && this.setEndAt( textEnd, selectContents ? CKEDITOR.POSITION_BEFORE_END : CKEDITOR.POSITION_AFTER_END ); + } + + return !!( moveStart || moveEnd ); + } + }, + + /** + * Inserts a node at the start of the range. The range will be expanded + * the contain the node. + */ + insertNode : function( node ) + { + this.optimizeBookmark(); + this.trim( false, true ); + + var startContainer = this.startContainer; + var startOffset = this.startOffset; + + var nextNode = startContainer.getChild( startOffset ); + + if ( nextNode ) + node.insertBefore( nextNode ); + else + startContainer.append( node ); + + // Check if we need to update the end boundary. + if ( node.getParent().equals( this.endContainer ) ) + this.endOffset++; + + // Expand the range to embrace the new node. + this.setStartBefore( node ); + }, + + moveToPosition : function( node, position ) + { + this.setStartAt( node, position ); + this.collapse( true ); + }, + + selectNodeContents : function( node ) + { + this.setStart( node, 0 ); + this.setEnd( node, node.type == CKEDITOR.NODE_TEXT ? node.getLength() : node.getChildCount() ); + }, + + /** + * Sets the start position of a Range. + * @param {CKEDITOR.dom.node} startNode The node to start the range. + * @param {Number} startOffset An integer greater than or equal to zero + * representing the offset for the start of the range from the start + * of startNode. + */ + setStart : function( startNode, startOffset ) + { + // W3C requires a check for the new position. If it is after the end + // boundary, the range should be collapsed to the new start. It seams + // we will not need this check for our use of this class so we can + // ignore it for now. + + // Fixing invalid range start inside dtd empty elements. + if( startNode.type == CKEDITOR.NODE_ELEMENT + && CKEDITOR.dtd.$empty[ startNode.getName() ] ) + startOffset = startNode.getIndex(), startNode = startNode.getParent(); + + this.startContainer = startNode; + this.startOffset = startOffset; + + if ( !this.endContainer ) + { + this.endContainer = startNode; + this.endOffset = startOffset; + } + + updateCollapsed( this ); + }, + + /** + * Sets the end position of a Range. + * @param {CKEDITOR.dom.node} endNode The node to end the range. + * @param {Number} endOffset An integer greater than or equal to zero + * representing the offset for the end of the range from the start + * of endNode. + */ + setEnd : function( endNode, endOffset ) + { + // W3C requires a check for the new position. If it is before the start + // boundary, the range should be collapsed to the new end. It seams we + // will not need this check for our use of this class so we can ignore + // it for now. + + // Fixing invalid range end inside dtd empty elements. + if( endNode.type == CKEDITOR.NODE_ELEMENT + && CKEDITOR.dtd.$empty[ endNode.getName() ] ) + endOffset = endNode.getIndex() + 1, endNode = endNode.getParent(); + + this.endContainer = endNode; + this.endOffset = endOffset; + + if ( !this.startContainer ) + { + this.startContainer = endNode; + this.startOffset = endOffset; + } + + updateCollapsed( this ); + }, + + setStartAfter : function( node ) + { + this.setStart( node.getParent(), node.getIndex() + 1 ); + }, + + setStartBefore : function( node ) + { + this.setStart( node.getParent(), node.getIndex() ); + }, + + setEndAfter : function( node ) + { + this.setEnd( node.getParent(), node.getIndex() + 1 ); + }, + + setEndBefore : function( node ) + { + this.setEnd( node.getParent(), node.getIndex() ); + }, + + setStartAt : function( node, position ) + { + switch( position ) + { + case CKEDITOR.POSITION_AFTER_START : + this.setStart( node, 0 ); + break; + + case CKEDITOR.POSITION_BEFORE_END : + if ( node.type == CKEDITOR.NODE_TEXT ) + this.setStart( node, node.getLength() ); + else + this.setStart( node, node.getChildCount() ); + break; + + case CKEDITOR.POSITION_BEFORE_START : + this.setStartBefore( node ); + break; + + case CKEDITOR.POSITION_AFTER_END : + this.setStartAfter( node ); + } + + updateCollapsed( this ); + }, + + setEndAt : function( node, position ) + { + switch( position ) + { + case CKEDITOR.POSITION_AFTER_START : + this.setEnd( node, 0 ); + break; + + case CKEDITOR.POSITION_BEFORE_END : + if ( node.type == CKEDITOR.NODE_TEXT ) + this.setEnd( node, node.getLength() ); + else + this.setEnd( node, node.getChildCount() ); + break; + + case CKEDITOR.POSITION_BEFORE_START : + this.setEndBefore( node ); + break; + + case CKEDITOR.POSITION_AFTER_END : + this.setEndAfter( node ); + } + + updateCollapsed( this ); + }, + + fixBlock : function( isStart, blockTag ) + { + var bookmark = this.createBookmark(), + fixedBlock = this.document.createElement( blockTag ); + + this.collapse( isStart ); + + this.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS ); + + this.extractContents().appendTo( fixedBlock ); + fixedBlock.trim(); + + if ( !CKEDITOR.env.ie ) + fixedBlock.appendBogus(); + + this.insertNode( fixedBlock ); + + this.moveToBookmark( bookmark ); + + return fixedBlock; + }, + + splitBlock : function( blockTag ) + { + var startPath = new CKEDITOR.dom.elementPath( this.startContainer ), + endPath = new CKEDITOR.dom.elementPath( this.endContainer ); + + var startBlockLimit = startPath.blockLimit, + endBlockLimit = endPath.blockLimit; + + var startBlock = startPath.block, + endBlock = endPath.block; + + var elementPath = null; + // Do nothing if the boundaries are in different block limits. + if ( !startBlockLimit.equals( endBlockLimit ) ) + return null; + + // Get or fix current blocks. + if ( blockTag != 'br' ) + { + if ( !startBlock ) + { + startBlock = this.fixBlock( true, blockTag ); + endBlock = new CKEDITOR.dom.elementPath( this.endContainer ).block; + } + + if ( !endBlock ) + endBlock = this.fixBlock( false, blockTag ); + } + + // Get the range position. + var isStartOfBlock = startBlock && this.checkStartOfBlock(), + isEndOfBlock = endBlock && this.checkEndOfBlock(); + + // Delete the current contents. + // TODO: Why is 2.x doing CheckIsEmpty()? + this.deleteContents(); + + if ( startBlock && startBlock.equals( endBlock ) ) + { + if ( isEndOfBlock ) + { + elementPath = new CKEDITOR.dom.elementPath( this.startContainer ); + this.moveToPosition( endBlock, CKEDITOR.POSITION_AFTER_END ); + endBlock = null; + } + else if ( isStartOfBlock ) + { + elementPath = new CKEDITOR.dom.elementPath( this.startContainer ); + this.moveToPosition( startBlock, CKEDITOR.POSITION_BEFORE_START ); + startBlock = null; + } + else + { + endBlock = this.splitElement( startBlock ); + + // In Gecko, the last child node must be a bogus
. + // Note: bogus
added under
    or
      would cause + // lists to be incorrectly rendered. + if ( !CKEDITOR.env.ie && !startBlock.is( 'ul', 'ol') ) + startBlock.appendBogus() ; + } + } + + return { + previousBlock : startBlock, + nextBlock : endBlock, + wasStartOfBlock : isStartOfBlock, + wasEndOfBlock : isEndOfBlock, + elementPath : elementPath + }; + }, + + /** + * Branch the specified element from the collapsed range position and + * place the caret between the two result branches. + * Note: The range must be collapsed and been enclosed by this element. + * @param {CKEDITOR.dom.element} element + * @return {CKEDITOR.dom.element} Root element of the new branch after the split. + */ + splitElement : function( toSplit ) + { + if ( !this.collapsed ) + return null; + + // Extract the contents of the block from the selection point to the end + // of its contents. + this.setEndAt( toSplit, CKEDITOR.POSITION_BEFORE_END ); + var documentFragment = this.extractContents(); + + // Duplicate the element after it. + var clone = toSplit.clone( false ); + + // Place the extracted contents into the duplicated element. + documentFragment.appendTo( clone ); + clone.insertAfter( toSplit ); + this.moveToPosition( toSplit, CKEDITOR.POSITION_AFTER_END ); + return clone; + }, + + /** + * Check whether a range boundary is at the inner boundary of a given + * element. + * @param {CKEDITOR.dom.element} element The target element to check. + * @param {Number} checkType The boundary to check for both the range + * and the element. It can be CKEDITOR.START or CKEDITOR.END. + * @returns {Boolean} "true" if the range boundary is at the inner + * boundary of the element. + */ + checkBoundaryOfElement : function( element, checkType ) + { + var checkStart = ( checkType == CKEDITOR.START ); + + // Create a copy of this range, so we can manipulate it for our checks. + var walkerRange = this.clone(); + + // Collapse the range at the proper size. + walkerRange.collapse( checkStart ); + + // Expand the range to element boundary. + walkerRange[ checkStart ? 'setStartAt' : 'setEndAt' ] + ( element, checkStart ? CKEDITOR.POSITION_AFTER_START : CKEDITOR.POSITION_BEFORE_END ); + + // Create the walker, which will check if we have anything useful + // in the range. + var walker = new CKEDITOR.dom.walker( walkerRange ); + walker.evaluator = elementBoundaryEval; + + return walker[ checkStart ? 'checkBackward' : 'checkForward' ](); + }, + + // Calls to this function may produce changes to the DOM. The range may + // be updated to reflect such changes. + checkStartOfBlock : function() + { + var startContainer = this.startContainer, + startOffset = this.startOffset; + + // If the starting node is a text node, and non-empty before the offset, + // then we're surely not at the start of block. + if ( startOffset && startContainer.type == CKEDITOR.NODE_TEXT ) + { + var textBefore = CKEDITOR.tools.ltrim( startContainer.substring( 0, startOffset ) ); + if ( textBefore.length ) + return false; + } + + // Antecipate the trim() call here, so the walker will not make + // changes to the DOM, which would not get reflected into this + // range otherwise. + this.trim(); + + // We need to grab the block element holding the start boundary, so + // let's use an element path for it. + var path = new CKEDITOR.dom.elementPath( this.startContainer ); + + // Creates a range starting at the block start until the range start. + var walkerRange = this.clone(); + walkerRange.collapse( true ); + walkerRange.setStartAt( path.block || path.blockLimit, CKEDITOR.POSITION_AFTER_START ); + + var walker = new CKEDITOR.dom.walker( walkerRange ); + walker.evaluator = getCheckStartEndBlockEvalFunction( true ); + + return walker.checkBackward(); + }, + + checkEndOfBlock : function() + { + var endContainer = this.endContainer, + endOffset = this.endOffset; + + // If the ending node is a text node, and non-empty after the offset, + // then we're surely not at the end of block. + if ( endContainer.type == CKEDITOR.NODE_TEXT ) + { + var textAfter = CKEDITOR.tools.rtrim( endContainer.substring( endOffset ) ); + if ( textAfter.length ) + return false; + } + + // Antecipate the trim() call here, so the walker will not make + // changes to the DOM, which would not get reflected into this + // range otherwise. + this.trim(); + + // We need to grab the block element holding the start boundary, so + // let's use an element path for it. + var path = new CKEDITOR.dom.elementPath( this.endContainer ); + + // Creates a range starting at the block start until the range start. + var walkerRange = this.clone(); + walkerRange.collapse( false ); + walkerRange.setEndAt( path.block || path.blockLimit, CKEDITOR.POSITION_BEFORE_END ); + + var walker = new CKEDITOR.dom.walker( walkerRange ); + walker.evaluator = getCheckStartEndBlockEvalFunction( false ); + + return walker.checkForward(); + }, + + /** + * Check if elements at which the range boundaries anchor are read-only, + * with respect to "contenteditable" attribute. + */ + checkReadOnly : ( function() + { + function checkNodesEditable( node, anotherEnd ) + { + while( node ) + { + if ( node.type == CKEDITOR.NODE_ELEMENT ) + { + if ( node.getAttribute( 'contentEditable' ) == 'false' + && !node.data( 'cke-editable' ) ) + { + return 0; + } + // Range enclosed entirely in an editable element. + else if ( node.is( 'html' ) + || node.getAttribute( 'contentEditable' ) == 'true' + && ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) ) + { + break; + } + } + node = node.getParent(); + } + + return 1; + } + + return function() + { + var startNode = this.startContainer, + endNode = this.endContainer; + + // Check if elements path at both boundaries are editable. + return !( checkNodesEditable( startNode, endNode ) && checkNodesEditable( endNode, startNode ) ); + }; + })(), + + /** + * Moves the range boundaries to the first/end editing point inside an + * element. For example, in an element tree like + * "<p><b><i></i></b> Text</p>", the start editing point is + * "<p><b><i>^</i></b> Text</p>" (inside <i>). + * @param {CKEDITOR.dom.element} el The element into which look for the + * editing spot. + * @param {Boolean} isMoveToEnd Whether move to the end editable position. + */ + moveToElementEditablePosition : function( el, isMoveToEnd ) + { + function nextDFS( node, childOnly ) + { + var next; + + if ( node.type == CKEDITOR.NODE_ELEMENT + && node.isEditable( false ) + && !CKEDITOR.dtd.$nonEditable[ node.getName() ] ) + { + next = node[ isMoveToEnd ? 'getLast' : 'getFirst' ]( nonWhitespaceOrBookmarkEval ); + } + + if ( !childOnly && !next ) + next = node[ isMoveToEnd ? 'getPrevious' : 'getNext' ]( nonWhitespaceOrBookmarkEval ); + + return next; + } + + var found = 0; + + while ( el ) + { + // Stop immediately if we've found a text node. + if ( el.type == CKEDITOR.NODE_TEXT ) + { + this.moveToPosition( el, isMoveToEnd ? + CKEDITOR.POSITION_AFTER_END : + CKEDITOR.POSITION_BEFORE_START ); + found = 1; + break; + } + + // If an editable element is found, move inside it, but not stop the searching. + if ( el.type == CKEDITOR.NODE_ELEMENT ) + { + if ( el.isEditable() ) + { + this.moveToPosition( el, isMoveToEnd ? + CKEDITOR.POSITION_BEFORE_END : + CKEDITOR.POSITION_AFTER_START ); + found = 1; + } + } + + el = nextDFS( el, found ); + } + + return !!found; + }, + + /** + *@see {CKEDITOR.dom.range.moveToElementEditablePosition} + */ + moveToElementEditStart : function( target ) + { + return this.moveToElementEditablePosition( target ); + }, + + /** + *@see {CKEDITOR.dom.range.moveToElementEditablePosition} + */ + moveToElementEditEnd : function( target ) + { + return this.moveToElementEditablePosition( target, true ); + }, + + /** + * Get the single node enclosed within the range if there's one. + */ + getEnclosedNode : function() + { + var walkerRange = this.clone(); + + // Optimize and analyze the range to avoid DOM destructive nature of walker. (#5780) + walkerRange.optimize(); + if ( walkerRange.startContainer.type != CKEDITOR.NODE_ELEMENT + || walkerRange.endContainer.type != CKEDITOR.NODE_ELEMENT ) + return null; + + var walker = new CKEDITOR.dom.walker( walkerRange ), + isNotBookmarks = CKEDITOR.dom.walker.bookmark( true ), + isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ), + evaluator = function( node ) + { + return isNotWhitespaces( node ) && isNotBookmarks( node ); + }; + walkerRange.evaluator = evaluator; + var node = walker.next(); + walker.reset(); + return node && node.equals( walker.previous() ) ? node : null; + }, + + getTouchedStartNode : function() + { + var container = this.startContainer ; + + if ( this.collapsed || container.type != CKEDITOR.NODE_ELEMENT ) + return container ; + + return container.getChild( this.startOffset ) || container ; + }, + + getTouchedEndNode : function() + { + var container = this.endContainer ; + + if ( this.collapsed || container.type != CKEDITOR.NODE_ELEMENT ) + return container ; + + return container.getChild( this.endOffset - 1 ) || container ; + } + }; +})(); + +CKEDITOR.POSITION_AFTER_START = 1; // ^contents "^text" +CKEDITOR.POSITION_BEFORE_END = 2; // contents^ "text^" +CKEDITOR.POSITION_BEFORE_START = 3; // ^contents ^"text" +CKEDITOR.POSITION_AFTER_END = 4; // contents^ "text" + +CKEDITOR.ENLARGE_ELEMENT = 1; +CKEDITOR.ENLARGE_BLOCK_CONTENTS = 2; +CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS = 3; + +// Check boundary types. +// @see CKEDITOR.dom.range.prototype.checkBoundaryOfElement +CKEDITOR.START = 1; +CKEDITOR.END = 2; +CKEDITOR.STARTEND = 3; + +// Shrink range types. +// @see CKEDITOR.dom.range.prototype.shrink +CKEDITOR.SHRINK_ELEMENT = 1; +CKEDITOR.SHRINK_TEXT = 2; Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/rangelist.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/rangelist.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/rangelist.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,213 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + /** + * Represents a list os CKEDITOR.dom.range objects, which can be easily + * iterated sequentially. + * @constructor + * @param {CKEDITOR.dom.range|Array} [ranges] The ranges contained on this list. + * Note that, if an array of ranges is specified, the range sequence + * should match its DOM order. This class will not help to sort them. + */ + CKEDITOR.dom.rangeList = function( ranges ) + { + if ( ranges instanceof CKEDITOR.dom.rangeList ) + return ranges; + + if ( !ranges ) + ranges = []; + else if ( ranges instanceof CKEDITOR.dom.range ) + ranges = [ ranges ]; + + return CKEDITOR.tools.extend( ranges, mixins ); + }; + + var mixins = + /** @lends CKEDITOR.dom.rangeList.prototype */ + { + /** + * Creates an instance of the rangeList iterator, it should be used + * only when the ranges processing could be DOM intrusive, which + * means it may pollute and break other ranges in this list. + * Otherwise, it's enough to just iterate over this array in a for loop. + * @returns {CKEDITOR.dom.rangeListIterator} + */ + createIterator : function() + { + var rangeList = this, + bookmark = CKEDITOR.dom.walker.bookmark(), + guard = function( node ) { return ! ( node.is && node.is( 'tr' ) ); }, + bookmarks = [], + current; + + /** + * @lends CKEDITOR.dom.rangeListIterator.prototype + */ + return { + + /** + * Retrieves the next range in the list. + * @param {Boolean} mergeConsequent Whether join two adjacent ranges into single, e.g. consequent table cells. + */ + getNextRange : function( mergeConsequent ) + { + current = current == undefined ? 0 : current + 1; + + var range = rangeList[ current ]; + + // Multiple ranges might be mangled by each other. + if ( range && rangeList.length > 1 ) + { + // Bookmarking all other ranges on the first iteration, + // the range correctness after it doesn't matter since we'll + // restore them before the next iteration. + if ( !current ) + { + // Make sure bookmark correctness by reverse processing. + for ( var i = rangeList.length - 1; i >= 0; i-- ) + bookmarks.unshift( rangeList[ i ].createBookmark( true ) ); + } + + if ( mergeConsequent ) + { + // Figure out how many ranges should be merged. + var mergeCount = 0; + while ( rangeList[ current + mergeCount + 1 ] ) + { + var doc = range.document, + found = 0, + left = doc.getById( bookmarks[ mergeCount ].endNode ), + right = doc.getById( bookmarks[ mergeCount + 1 ].startNode ), + next; + + // Check subsequent range. + while ( 1 ) + { + next = left.getNextSourceNode( false ); + if ( !right.equals( next ) ) + { + // This could be yet another bookmark or + // walking across block boundaries. + if ( bookmark( next ) || ( next.type == CKEDITOR.NODE_ELEMENT && next.isBlockBoundary() ) ) + { + left = next; + continue; + } + } + else + found = 1; + + break; + } + + if ( !found ) + break; + + mergeCount++; + } + } + + range.moveToBookmark( bookmarks.shift() ); + + // Merge ranges finally after moving to bookmarks. + while( mergeCount-- ) + { + next = rangeList[ ++current ]; + next.moveToBookmark( bookmarks.shift() ); + range.setEnd( next.endContainer, next.endOffset ); + } + } + + return range; + } + }; + }, + + createBookmarks : function( serializable ) + { + var retval = [], bookmark; + for ( var i = 0; i < this.length ; i++ ) + { + retval.push( bookmark = this[ i ].createBookmark( serializable, true) ); + + // Updating the container & offset values for ranges + // that have been touched. + for ( var j = i + 1; j < this.length; j++ ) + { + this[ j ] = updateDirtyRange( bookmark, this[ j ] ); + this[ j ] = updateDirtyRange( bookmark, this[ j ], true ); + } + } + return retval; + }, + + createBookmarks2 : function( normalized ) + { + var bookmarks = []; + + for ( var i = 0 ; i < this.length ; i++ ) + bookmarks.push( this[ i ].createBookmark2( normalized ) ); + + return bookmarks; + }, + + /** + * Move each range in the list to the position specified by a list of bookmarks. + * @param {Array} bookmarks The list of bookmarks, each one matching a range in the list. + */ + moveToBookmarks : function( bookmarks ) + { + for ( var i = 0 ; i < this.length ; i++ ) + this[ i ].moveToBookmark( bookmarks[ i ] ); + } + }; + + // Update the specified range which has been mangled by previous insertion of + // range bookmark nodes.(#3256) + function updateDirtyRange( bookmark, dirtyRange, checkEnd ) + { + var serializable = bookmark.serializable, + container = dirtyRange[ checkEnd ? 'endContainer' : 'startContainer' ], + offset = checkEnd ? 'endOffset' : 'startOffset'; + + var bookmarkStart = serializable ? + dirtyRange.document.getById( bookmark.startNode ) + : bookmark.startNode; + + var bookmarkEnd = serializable ? + dirtyRange.document.getById( bookmark.endNode ) + : bookmark.endNode; + + if ( container.equals( bookmarkStart.getPrevious() ) ) + { + dirtyRange.startOffset = dirtyRange.startOffset + - container.getLength() + - bookmarkEnd.getPrevious().getLength(); + container = bookmarkEnd.getNext(); + } + else if ( container.equals( bookmarkEnd.getPrevious() ) ) + { + dirtyRange.startOffset = dirtyRange.startOffset - container.getLength(); + container = bookmarkEnd.getNext(); + } + + container.equals( bookmarkStart.getParent() ) && dirtyRange[ offset ]++; + container.equals( bookmarkEnd.getParent() ) && dirtyRange[ offset ]++; + + // Update and return this range. + dirtyRange[ checkEnd ? 'endContainer' : 'startContainer' ] = container; + return dirtyRange; + } +})(); + +/** + * (Virtual Class) Do not call this constructor. This class is not really part + * of the API. It just describes the return type of {@link CKEDITOR.dom.rangeList#createIterator}. + * @name CKEDITOR.dom.rangeListIterator + * @constructor + * @example + */ Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/text.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/text.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/text.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,128 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Defines the {@link CKEDITOR.dom.text} class, which represents + * a DOM text node. + */ + +/** + * Represents a DOM text node. + * @constructor + * @augments CKEDITOR.dom.node + * @param {Object|String} text A native DOM text node or a string containing + * the text to use to create a new text node. + * @param {CKEDITOR.dom.document} [ownerDocument] The document that will contain + * the node in case of new node creation. Defaults to the current document. + * @example + * var nativeNode = document.createTextNode( 'Example' ); + * var text = CKEDITOR.dom.text( nativeNode ); + * @example + * var text = CKEDITOR.dom.text( 'Example' ); + */ +CKEDITOR.dom.text = function( text, ownerDocument ) +{ + if ( typeof text == 'string' ) + text = ( ownerDocument ? ownerDocument.$ : document ).createTextNode( text ); + + // Theoretically, we should call the base constructor here + // (not CKEDITOR.dom.node though). But, IE doesn't support expando + // properties on text node, so the features provided by domObject will not + // work for text nodes (which is not a big issue for us). + // + // CKEDITOR.dom.domObject.call( this, element ); + + /** + * The native DOM text node represented by this class instance. + * @type Object + * @example + * var element = new CKEDITOR.dom.text( 'Example' ); + * alert( element.$.nodeType ); // "3" + */ + this.$ = text; +}; + +CKEDITOR.dom.text.prototype = new CKEDITOR.dom.node(); + +CKEDITOR.tools.extend( CKEDITOR.dom.text.prototype, + /** @lends CKEDITOR.dom.text.prototype */ + { + /** + * The node type. This is a constant value set to + * {@link CKEDITOR.NODE_TEXT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_TEXT, + + getLength : function() + { + return this.$.nodeValue.length; + }, + + getText : function() + { + return this.$.nodeValue; + }, + + setText : function( text ) + { + this.$.nodeValue = text; + }, + + /** + * Breaks this text node into two nodes at the specified offset, + * keeping both in the tree as siblings. This node then only contains + * all the content up to the offset point. A new text node, which is + * inserted as the next sibling of this node, contains all the content + * at and after the offset point. When the offset is equal to the + * length of this node, the new node has no data. + * @param {Number} The position at which to split, starting from zero. + * @returns {CKEDITOR.dom.text} The new text node. + */ + split : function( offset ) + { + // If the offset is after the last char, IE creates the text node + // on split, but don't include it into the DOM. So, we have to do + // that manually here. + if ( CKEDITOR.env.ie && offset == this.getLength() ) + { + var next = this.getDocument().createText( '' ); + next.insertAfter( this ); + return next; + } + + var doc = this.getDocument(); + var retval = new CKEDITOR.dom.text( this.$.splitText( offset ), doc ); + + // IE BUG: IE8 does not update the childNodes array in DOM after splitText(), + // we need to make some DOM changes to make it update. (#3436) + if ( CKEDITOR.env.ie8 ) + { + var workaround = new CKEDITOR.dom.text( '', doc ); + workaround.insertAfter( retval ); + workaround.remove(); + } + + return retval; + }, + + /** + * Extracts characters from indexA up to but not including indexB. + * @param {Number} indexA An integer between 0 and one less than the + * length of the text. + * @param {Number} [indexB] An integer between 0 and the length of the + * string. If omitted, extracts characters to the end of the text. + */ + substring : function( indexA, indexB ) + { + // We need the following check due to a Firefox bug + // https://bugzilla.mozilla.org/show_bug.cgi?id=458886 + if ( typeof indexB != 'number' ) + return this.$.nodeValue.substr( indexA ); + else + return this.$.nodeValue.substring( indexA, indexB ); + } + }); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/walker.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/walker.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/walker.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,462 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + // This function is to be called under a "walker" instance scope. + function iterate( rtl, breakOnFalse ) + { + // Return null if we have reached the end. + if ( this._.end ) + return null; + + var node, + range = this.range, + guard, + userGuard = this.guard, + type = this.type, + getSourceNodeFn = ( rtl ? 'getPreviousSourceNode' : 'getNextSourceNode' ); + + // This is the first call. Initialize it. + if ( !this._.start ) + { + this._.start = 1; + + // Trim text nodes and optmize the range boundaries. DOM changes + // may happen at this point. + range.trim(); + + // A collapsed range must return null at first call. + if ( range.collapsed ) + { + this.end(); + return null; + } + } + + // Create the LTR guard function, if necessary. + if ( !rtl && !this._.guardLTR ) + { + // Gets the node that stops the walker when going LTR. + var limitLTR = range.endContainer, + blockerLTR = limitLTR.getChild( range.endOffset ); + + this._.guardLTR = function( node, movingOut ) + { + return ( ( !movingOut || !limitLTR.equals( node ) ) + && ( !blockerLTR || !node.equals( blockerLTR ) ) + && ( node.type != CKEDITOR.NODE_ELEMENT || !movingOut || node.getName() != 'body' ) ); + }; + } + + // Create the RTL guard function, if necessary. + if ( rtl && !this._.guardRTL ) + { + // Gets the node that stops the walker when going LTR. + var limitRTL = range.startContainer, + blockerRTL = ( range.startOffset > 0 ) && limitRTL.getChild( range.startOffset - 1 ); + + this._.guardRTL = function( node, movingOut ) + { + return ( ( !movingOut || !limitRTL.equals( node ) ) + && ( !blockerRTL || !node.equals( blockerRTL ) ) + && ( node.type != CKEDITOR.NODE_ELEMENT || !movingOut || node.getName() != 'body' ) ); + }; + } + + // Define which guard function to use. + var stopGuard = rtl ? this._.guardRTL : this._.guardLTR; + + // Make the user defined guard function participate in the process, + // otherwise simply use the boundary guard. + if ( userGuard ) + { + guard = function( node, movingOut ) + { + if ( stopGuard( node, movingOut ) === false ) + return false; + + return userGuard( node, movingOut ); + }; + } + else + guard = stopGuard; + + if ( this.current ) + node = this.current[ getSourceNodeFn ]( false, type, guard ); + else + { + // Get the first node to be returned. + + if ( rtl ) + { + node = range.endContainer; + + if ( range.endOffset > 0 ) + { + node = node.getChild( range.endOffset - 1 ); + if ( guard( node ) === false ) + node = null; + } + else + node = ( guard ( node, true ) === false ) ? + null : node.getPreviousSourceNode( true, type, guard ); + } + else + { + node = range.startContainer; + node = node.getChild( range.startOffset ); + + if ( node ) + { + if ( guard( node ) === false ) + node = null; + } + else + node = ( guard ( range.startContainer, true ) === false ) ? + null : range.startContainer.getNextSourceNode( true, type, guard ) ; + } + } + + while ( node && !this._.end ) + { + this.current = node; + + if ( !this.evaluator || this.evaluator( node ) !== false ) + { + if ( !breakOnFalse ) + return node; + } + else if ( breakOnFalse && this.evaluator ) + return false; + + node = node[ getSourceNodeFn ]( false, type, guard ); + } + + this.end(); + return this.current = null; + } + + function iterateToLast( rtl ) + { + var node, last = null; + + while ( ( node = iterate.call( this, rtl ) ) ) + last = node; + + return last; + } + + CKEDITOR.dom.walker = CKEDITOR.tools.createClass( + { + /** + * Utility class to "walk" the DOM inside a range boundaries. If + * necessary, partially included nodes (text nodes) are broken to + * reflect the boundaries limits, so DOM and range changes may happen. + * Outside changes to the range may break the walker. + * + * The walker may return nodes that are not totaly included into the + * range boundaires. Let's take the following range representation, + * where the square brackets indicate the boundaries: + * + * [<p>Some <b>sample] text</b> + * + * While walking forward into the above range, the following nodes are + * returned: <p>, "Some ", <b> and "sample". Going + * backwards instead we have: "sample" and "Some ". So note that the + * walker always returns nodes when "entering" them, but not when + * "leaving" them. The guard function is instead called both when + * entering and leaving nodes. + * + * @constructor + * @param {CKEDITOR.dom.range} range The range within which walk. + */ + $ : function( range ) + { + this.range = range; + + /** + * A function executed for every matched node, to check whether + * it's to be considered into the walk or not. If not provided, all + * matched nodes are considered good. + * If the function returns "false" the node is ignored. + * @name CKEDITOR.dom.walker.prototype.evaluator + * @property + * @type Function + */ + // this.evaluator = null; + + /** + * A function executed for every node the walk pass by to check + * whether the walk is to be finished. It's called when both + * entering and exiting nodes, as well as for the matched nodes. + * If this function returns "false", the walking ends and no more + * nodes are evaluated. + * @name CKEDITOR.dom.walker.prototype.guard + * @property + * @type Function + */ + // this.guard = null; + + /** @private */ + this._ = {}; + }, + +// statics : +// { +// /* Creates a CKEDITOR.dom.walker instance to walk inside DOM boundaries set by nodes. +// * @param {CKEDITOR.dom.node} startNode The node from wich the walk +// * will start. +// * @param {CKEDITOR.dom.node} [endNode] The last node to be considered +// * in the walk. No more nodes are retrieved after touching or +// * passing it. If not provided, the walker stops at the +// * <body> closing boundary. +// * @returns {CKEDITOR.dom.walker} A DOM walker for the nodes between the +// * provided nodes. +// */ +// createOnNodes : function( startNode, endNode, startInclusive, endInclusive ) +// { +// var range = new CKEDITOR.dom.range(); +// if ( startNode ) +// range.setStartAt( startNode, startInclusive ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_END ) ; +// else +// range.setStartAt( startNode.getDocument().getBody(), CKEDITOR.POSITION_AFTER_START ) ; +// +// if ( endNode ) +// range.setEndAt( endNode, endInclusive ? CKEDITOR.POSITION_AFTER_END : CKEDITOR.POSITION_BEFORE_START ) ; +// else +// range.setEndAt( startNode.getDocument().getBody(), CKEDITOR.POSITION_BEFORE_END ) ; +// +// return new CKEDITOR.dom.walker( range ); +// } +// }, +// + proto : + { + /** + * Stop walking. No more nodes are retrieved if this function gets + * called. + */ + end : function() + { + this._.end = 1; + }, + + /** + * Retrieves the next node (at right). + * @returns {CKEDITOR.dom.node} The next node or null if no more + * nodes are available. + */ + next : function() + { + return iterate.call( this ); + }, + + /** + * Retrieves the previous node (at left). + * @returns {CKEDITOR.dom.node} The previous node or null if no more + * nodes are available. + */ + previous : function() + { + return iterate.call( this, 1 ); + }, + + /** + * Check all nodes at right, executing the evaluation fuction. + * @returns {Boolean} "false" if the evaluator function returned + * "false" for any of the matched nodes. Otherwise "true". + */ + checkForward : function() + { + return iterate.call( this, 0, 1 ) !== false; + }, + + /** + * Check all nodes at left, executing the evaluation fuction. + * @returns {Boolean} "false" if the evaluator function returned + * "false" for any of the matched nodes. Otherwise "true". + */ + checkBackward : function() + { + return iterate.call( this, 1, 1 ) !== false; + }, + + /** + * Executes a full walk forward (to the right), until no more nodes + * are available, returning the last valid node. + * @returns {CKEDITOR.dom.node} The last node at the right or null + * if no valid nodes are available. + */ + lastForward : function() + { + return iterateToLast.call( this ); + }, + + /** + * Executes a full walk backwards (to the left), until no more nodes + * are available, returning the last valid node. + * @returns {CKEDITOR.dom.node} The last node at the left or null + * if no valid nodes are available. + */ + lastBackward : function() + { + return iterateToLast.call( this, 1 ); + }, + + reset : function() + { + delete this.current; + this._ = {}; + } + + } + }); + + /* + * Anything whose display computed style is block, list-item, table, + * table-row-group, table-header-group, table-footer-group, table-row, + * table-column-group, table-column, table-cell, table-caption, or whose node + * name is hr, br (when enterMode is br only) is a block boundary. + */ + var blockBoundaryDisplayMatch = + { + block : 1, + 'list-item' : 1, + table : 1, + 'table-row-group' : 1, + 'table-header-group' : 1, + 'table-footer-group' : 1, + 'table-row' : 1, + 'table-column-group' : 1, + 'table-column' : 1, + 'table-cell' : 1, + 'table-caption' : 1 + }; + + CKEDITOR.dom.element.prototype.isBlockBoundary = function( customNodeNames ) + { + var nodeNameMatches = customNodeNames ? + CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$block, customNodeNames || {} ) : + CKEDITOR.dtd.$block; + + // Don't consider floated formatting as block boundary, fall back to dtd check in that case. (#6297) + return this.getComputedStyle( 'float' ) == 'none' && blockBoundaryDisplayMatch[ this.getComputedStyle( 'display' ) ] + || nodeNameMatches[ this.getName() ]; + }; + + CKEDITOR.dom.walker.blockBoundary = function( customNodeNames ) + { + return function( node , type ) + { + return ! ( node.type == CKEDITOR.NODE_ELEMENT + && node.isBlockBoundary( customNodeNames ) ); + }; + }; + + CKEDITOR.dom.walker.listItemBoundary = function() + { + return this.blockBoundary( { br : 1 } ); + }; + + /** + * Whether the to-be-evaluated node is a bookmark node OR bookmark node + * inner contents. + * @param {Boolean} contentOnly Whether only test againt the text content of + * bookmark node instead of the element itself(default). + * @param {Boolean} isReject Whether should return 'false' for the bookmark + * node instead of 'true'(default). + */ + CKEDITOR.dom.walker.bookmark = function( contentOnly, isReject ) + { + function isBookmarkNode( node ) + { + return ( node && node.getName + && node.getName() == 'span' + && node.data( 'cke-bookmark' ) ); + } + + return function( node ) + { + var isBookmark, parent; + // Is bookmark inner text node? + isBookmark = ( node && !node.getName && ( parent = node.getParent() ) + && isBookmarkNode( parent ) ); + // Is bookmark node? + isBookmark = contentOnly ? isBookmark : isBookmark || isBookmarkNode( node ); + return !! ( isReject ^ isBookmark ); + }; + }; + + /** + * Whether the node is a text node containing only whitespaces characters. + * @param isReject + */ + CKEDITOR.dom.walker.whitespaces = function( isReject ) + { + return function( node ) + { + var isWhitespace = node && ( node.type == CKEDITOR.NODE_TEXT ) + && !CKEDITOR.tools.trim( node.getText() ); + return !! ( isReject ^ isWhitespace ); + }; + }; + + /** + * Whether the node is invisible in wysiwyg mode. + * @param isReject + */ + CKEDITOR.dom.walker.invisible = function( isReject ) + { + var whitespace = CKEDITOR.dom.walker.whitespaces(); + return function( node ) + { + // Nodes that take no spaces in wysiwyg: + // 1. White-spaces but not including NBSP; + // 2. Empty inline elements, e.g. we're checking here + // 'offsetHeight' instead of 'offsetWidth' for properly excluding + // all sorts of empty paragraph, e.g.
      . + var isInvisible = whitespace( node ) || node.is && !node.$.offsetHeight; + return !! ( isReject ^ isInvisible ); + }; + }; + + CKEDITOR.dom.walker.nodeType = function( type, isReject ) + { + return function( node ) + { + return !! ( isReject ^ ( node.type == type ) ); + }; + }; + + var tailNbspRegex = /^[\t\r\n ]*(?: |\xa0)$/, + isWhitespaces = CKEDITOR.dom.walker.whitespaces(), + isBookmark = CKEDITOR.dom.walker.bookmark(), + toSkip = function( node ) + { + return isBookmark( node ) + || isWhitespaces( node ) + || node.type == CKEDITOR.NODE_ELEMENT + && node.getName() in CKEDITOR.dtd.$inline + && !( node.getName() in CKEDITOR.dtd.$empty ); + }; + + // Check if there's a filler node at the end of an element, and return it. + CKEDITOR.dom.element.prototype.getBogus = function() + { + // Bogus are not always at the end, e.g.

      text

      (#7070). + var tail = this; + do { tail = tail.getPreviousSourceNode(); } + while ( toSkip( tail ) ) + + if ( tail && ( !CKEDITOR.env.ie ? tail.is && tail.is( 'br' ) + : tail.getText && tailNbspRegex.test( tail.getText() ) ) ) + { + return tail; + } + return false; + }; + +})(); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/window.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/window.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/dom/window.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,96 @@ +/* +Copyright (c) 2003-2011, 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. + * @constructor + * @augments CKEDITOR.dom.domObject + * @param {Object} domWindow A native DOM window. + * @example + * var document = new CKEDITOR.dom.window( 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, + /** @lends CKEDITOR.dom.window.prototype */ + { + /** + * Moves the selection focus to this window. + * @function + * @example + * var win = new CKEDITOR.dom.window( window ); + * win.focus(); + */ + focus : function() + { + // Webkit is sometimes failed to focus iframe, blur it first(#3835). + if ( CKEDITOR.env.webkit && this.$.parent ) + this.$.parent.focus(); + this.$.focus(); + }, + + /** + * Gets the width and height of this window's viewable area. + * @function + * @returns {Object} An object with the "width" and "height" + * properties containing the size. + * @example + * var win = new CKEDITOR.dom.window( window ); + * var size = win.getViewPaneSize(); + * alert( size.width ); + * alert( size.height ); + */ + 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. + * @function + * @returns {Object} An object with the "x" and "y" properties + * containing the scroll position. + * @example + * var win = new CKEDITOR.dom.window( window ); + * var pos = win.getScrollPosition(); + * alert( pos.x ); + * alert( pos.y ); + */ + 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 + }; + } + } + }); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/basicwriter.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/basicwriter.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/basicwriter.js 14 Feb 2012 08:01:34 -0000 1.1 @@ -0,0 +1,145 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass( +{ + $ : function() + { + this._ = + { + output : [] + }; + }, + + proto : + { + /** + * Writes the tag opening part for a opener tag. + * @param {String} tagName The element name for this tag. + * @param {Object} attributes The attributes defined for this tag. The + * attributes could be used to inspect the tag. + * @example + * // Writes "<p". + * writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } ); + */ + openTag : function( tagName, attributes ) + { + this._.output.push( '<', tagName ); + }, + + /** + * Writes the tag closing part for a opener tag. + * @param {String} tagName The element name for this tag. + * @param {Boolean} isSelfClose Indicates that this is a self-closing tag, + * like "br" or "img". + * @example + * // Writes ">". + * writer.openTagClose( 'p', false ); + * @example + * // Writes " />". + * writer.openTagClose( 'br', true ); + */ + openTagClose : function( tagName, isSelfClose ) + { + if ( isSelfClose ) + this._.output.push( ' />' ); + else + this._.output.push( '>' ); + }, + + /** + * Writes an attribute. This function should be called after opening the + * tag with {@link #openTagClose}. + * @param {String} attName The attribute name. + * @param {String} attValue The attribute value. + * @example + * // Writes ' class="MyClass"'. + * writer.attribute( 'class', 'MyClass' ); + */ + attribute : function( attName, attValue ) + { + // Browsers don't always escape special character in attribute values. (#4683, #4719). + if ( typeof attValue == 'string' ) + attValue = CKEDITOR.tools.htmlEncodeAttr( attValue ); + + this._.output.push( ' ', attName, '="', attValue, '"' ); + }, + + /** + * Writes a closer tag. + * @param {String} tagName The element name for this tag. + * @example + * // Writes "</p>". + * writer.closeTag( 'p' ); + */ + closeTag : function( tagName ) + { + this._.output.push( '' ); + }, + + /** + * Writes text. + * @param {String} text The text value + * @example + * // Writes "Hello Word". + * writer.text( 'Hello Word' ); + */ + text : function( text ) + { + this._.output.push( text ); + }, + + /** + * Writes a comment. + * @param {String} comment The comment text. + * @example + * // Writes "<!-- My comment -->". + * writer.comment( ' My comment ' ); + */ + comment : function( comment ) + { + this._.output.push( '' ); + }, + + /** + * Writes any kind of data to the ouput. + * @example + * writer.write( 'This is an <b>example</b>.' ); + */ + write : function( data ) + { + this._.output.push( data ); + }, + + /** + * Empties the current output buffer. + * @example + * writer.reset(); + */ + reset : function() + { + this._.output = []; + this._.indent = false; + }, + + /** + * Empties the current output buffer. + * @param {Boolean} reset Indicates that the {@link reset} function is to + * be automatically called after retrieving the HTML. + * @returns {String} The HTML written to the writer so far. + * @example + * var html = writer.getHtml(); + */ + getHtml : function( reset ) + { + var html = this._.output.join( '' ); + + if ( reset ) + this.reset(); + + return html; + } + } +}); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/cdata.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/cdata.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/cdata.js 14 Feb 2012 08:01:35 -0000 1.1 @@ -0,0 +1,43 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + + /** + * A lightweight representation of HTML text. + * @constructor + * @example + */ + CKEDITOR.htmlParser.cdata = function( value ) + { + /** + * The CDATA value. + * @type String + * @example + */ + this.value = value; + }; + + CKEDITOR.htmlParser.cdata.prototype = + { + /** + * CDATA has the same type as {@link CKEDITOR.htmlParser.text} This is + * a constant value set to {@link CKEDITOR.NODE_TEXT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_TEXT, + + /** + * Writes write the CDATA with no special manipulations. + * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML. + */ + writeHtml : function( writer ) + { + writer.write( this.value ); + } + }; +})(); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/comment.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/comment.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/comment.js 14 Feb 2012 08:01:35 -0000 1.1 @@ -0,0 +1,60 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * A lightweight representation of an HTML comment. + * @constructor + * @example + */ +CKEDITOR.htmlParser.comment = function( value ) +{ + /** + * The comment text. + * @type String + * @example + */ + this.value = value; + + /** @private */ + this._ = + { + isBlockLike : false + }; +}; + +CKEDITOR.htmlParser.comment.prototype = +{ + /** + * The node type. This is a constant value set to {@link CKEDITOR.NODE_COMMENT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_COMMENT, + + /** + * Writes the HTML representation of this comment to a CKEDITOR.htmlWriter. + * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML. + * @example + */ + writeHtml : function( writer, filter ) + { + var comment = this.value; + + if ( filter ) + { + if ( !( comment = filter.onComment( comment, this ) ) ) + return; + + if ( typeof comment != 'string' ) + { + comment.parent = this.parent; + comment.writeHtml( writer, filter ); + return; + } + } + + writer.comment( comment ); + } +}; Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/element.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/element.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/element.js 14 Feb 2012 08:01:35 -0000 1.1 @@ -0,0 +1,308 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * A lightweight representation of an HTML element. + * @param {String} name The element name. + * @param {Object} attributes And object holding all attributes defined for + * this element. + * @constructor + * @example + */ +CKEDITOR.htmlParser.element = function( name, attributes ) +{ + /** + * The element name. + * @type String + * @example + */ + this.name = name; + + /** + * Holds the attributes defined for this element. + * @type Object + * @example + */ + this.attributes = attributes || ( attributes = {} ); + + /** + * The nodes that are direct children of this element. + * @type Array + * @example + */ + this.children = []; + + var tagName = attributes[ 'data-cke-real-element-type' ] || name || ''; + + // Reveal the real semantic of our internal custom tag name (#6639). + var internalTag = tagName.match( /^cke:(.*)/ ); + internalTag && ( tagName = internalTag[ 1 ] ); + + var dtd = CKEDITOR.dtd, + isBlockLike = !!( dtd.$nonBodyContent[ tagName ] + || dtd.$block[ tagName ] + || dtd.$listItem[ tagName ] + || dtd.$tableContent[ tagName ] + || dtd.$nonEditable[ tagName ] + || tagName == 'br' ), + isEmpty = !!dtd.$empty[ name ]; + + this.isEmpty = isEmpty; + this.isUnknown = !dtd[ name ]; + + /** @private */ + this._ = + { + isBlockLike : isBlockLike, + hasInlineStarted : isEmpty || !isBlockLike + }; +}; + +/** + * Object presentation of CSS style declaration text. + * @param {CKEDITOR.htmlParser.element|String} elementOrStyleText A html parser element or the inline style text. + */ +CKEDITOR.htmlParser.cssStyle = function() +{ + var styleText, + arg = arguments[ 0 ], + rules = {}; + + styleText = arg instanceof CKEDITOR.htmlParser.element ? arg.attributes.style : arg; + + // html-encoded quote might be introduced by 'font-family' + // from MS-Word which confused the following regexp. e.g. + //'font-family: "Lucida, Console"' + ( styleText || '' ) + .replace( /"/g, '"' ) + .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, + function( match, name, value ) + { + name == 'font-family' && ( value = value.replace( /["']/g, '' ) ); + rules[ name.toLowerCase() ] = value; + }); + + return { + + rules : rules, + + /** + * Apply the styles onto the specified element or object. + * @param {CKEDITOR.htmlParser.element|CKEDITOR.dom.element|Object} obj + */ + populate : function( obj ) + { + var style = this.toString(); + if ( style ) + { + obj instanceof CKEDITOR.dom.element ? + obj.setAttribute( 'style', style ) : + obj instanceof CKEDITOR.htmlParser.element ? + obj.attributes.style = style : + obj.style = style; + } + }, + + toString : function() + { + var output = []; + for ( var i in rules ) + rules[ i ] && output.push( i, ':', rules[ i ], ';' ); + return output.join( '' ); + } + }; +}; + +(function() +{ + // Used to sort attribute entries in an array, where the first element of + // each object is the attribute name. + var sortAttribs = function( a, b ) + { + a = a[0]; + b = b[0]; + return a < b ? -1 : a > b ? 1 : 0; + }; + + CKEDITOR.htmlParser.element.prototype = + { + /** + * The node type. This is a constant value set to {@link CKEDITOR.NODE_ELEMENT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_ELEMENT, + + /** + * Adds a node to the element children list. + * @param {Object} node The node to be added. It can be any of of the + * following types: {@link CKEDITOR.htmlParser.element}, + * {@link CKEDITOR.htmlParser.text} and + * {@link CKEDITOR.htmlParser.comment}. + * @function + * @example + */ + add : CKEDITOR.htmlParser.fragment.prototype.add, + + /** + * Clone this element. + * @returns {CKEDITOR.htmlParser.element} The element clone. + * @example + */ + clone : function() + { + return new CKEDITOR.htmlParser.element( this.name, this.attributes ); + }, + + /** + * Writes the element HTML to a CKEDITOR.htmlWriter. + * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML. + * @example + */ + writeHtml : function( writer, filter ) + { + var attributes = this.attributes; + + // Ignore cke: prefixes when writing HTML. + var element = this, + writeName = element.name, + a, newAttrName, value; + + var isChildrenFiltered; + + /** + * Providing an option for bottom-up filtering order ( element + * children to be pre-filtered before the element itself ). + */ + element.filterChildren = function() + { + if ( !isChildrenFiltered ) + { + var writer = new CKEDITOR.htmlParser.basicWriter(); + CKEDITOR.htmlParser.fragment.prototype.writeChildrenHtml.call( element, writer, filter ); + element.children = new CKEDITOR.htmlParser.fragment.fromHtml( writer.getHtml(), 0, element.clone() ).children; + isChildrenFiltered = 1; + } + }; + + if ( filter ) + { + while ( true ) + { + if ( !( writeName = filter.onElementName( writeName ) ) ) + return; + + element.name = writeName; + + if ( !( element = filter.onElement( element ) ) ) + return; + + element.parent = this.parent; + + if ( element.name == writeName ) + break; + + // If the element has been replaced with something of a + // different type, then make the replacement write itself. + if ( element.type != CKEDITOR.NODE_ELEMENT ) + { + element.writeHtml( writer, filter ); + return; + } + + writeName = element.name; + + // This indicate that the element has been dropped by + // filter but not the children. + if ( !writeName ) + { + // Fix broken parent refs. + for ( var c = 0, length = this.children.length ; c < length ; c++ ) + this.children[ c ].parent = element.parent; + + this.writeChildrenHtml.call( element, writer, isChildrenFiltered ? null : filter ); + return; + } + } + + // The element may have been changed, so update the local + // references. + attributes = element.attributes; + } + + // Open element tag. + writer.openTag( writeName, attributes ); + + // Copy all attributes to an array. + var attribsArray = []; + // Iterate over the attributes twice since filters may alter + // other attributes. + for ( var i = 0 ; i < 2; i++ ) + { + for ( a in attributes ) + { + newAttrName = a; + value = attributes[ a ]; + if ( i == 1 ) + attribsArray.push( [ a, value ] ); + else if ( filter ) + { + while ( true ) + { + if ( !( newAttrName = filter.onAttributeName( a ) ) ) + { + delete attributes[ a ]; + break; + } + else if ( newAttrName != a ) + { + delete attributes[ a ]; + a = newAttrName; + continue; + } + else + break; + } + if ( newAttrName ) + { + if ( ( value = filter.onAttribute( element, newAttrName, value ) ) === false ) + delete attributes[ newAttrName ]; + else + attributes [ newAttrName ] = value; + } + } + } + } + // Sort the attributes by name. + if ( writer.sortAttributes ) + attribsArray.sort( sortAttribs ); + + // Send the attributes. + var len = attribsArray.length; + for ( i = 0 ; i < len ; i++ ) + { + var attrib = attribsArray[ i ]; + writer.attribute( attrib[0], attrib[1] ); + } + + // Close the tag. + writer.openTagClose( writeName, element.isEmpty ); + + if ( !element.isEmpty ) + { + this.writeChildrenHtml.call( element, writer, isChildrenFiltered ? null : filter ); + // Close the element. + writer.closeTag( writeName ); + } + }, + + writeChildrenHtml : function( writer, filter ) + { + // Send children. + CKEDITOR.htmlParser.fragment.prototype.writeChildrenHtml.apply( this, arguments ); + + } + }; +})(); Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/filter.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/filter.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/filter.js 14 Feb 2012 08:01:35 -0000 1.1 @@ -0,0 +1,288 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + CKEDITOR.htmlParser.filter = CKEDITOR.tools.createClass( + { + $ : function( rules ) + { + this._ = + { + elementNames : [], + attributeNames : [], + elements : { $length : 0 }, + attributes : { $length : 0 } + }; + + if ( rules ) + this.addRules( rules, 10 ); + }, + + proto : + { + addRules : function( rules, priority ) + { + if ( typeof priority != 'number' ) + priority = 10; + + // Add the elementNames. + addItemsToList( this._.elementNames, rules.elementNames, priority ); + + // Add the attributeNames. + addItemsToList( this._.attributeNames, rules.attributeNames, priority ); + + // Add the elements. + addNamedItems( this._.elements, rules.elements, priority ); + + // Add the attributes. + addNamedItems( this._.attributes, rules.attributes, priority ); + + // Add the text. + this._.text = transformNamedItem( this._.text, rules.text, priority ) || this._.text; + + // Add the comment. + this._.comment = transformNamedItem( this._.comment, rules.comment, priority ) || this._.comment; + + // Add root fragment. + this._.root = transformNamedItem( this._.root, rules.root, priority ) || this._.root; + }, + + onElementName : function( name ) + { + return filterName( name, this._.elementNames ); + }, + + onAttributeName : function( name ) + { + return filterName( name, this._.attributeNames ); + }, + + onText : function( text ) + { + var textFilter = this._.text; + return textFilter ? textFilter.filter( text ) : text; + }, + + onComment : function( commentText, comment ) + { + var textFilter = this._.comment; + return textFilter ? textFilter.filter( commentText, comment ) : commentText; + }, + + onFragment : function( element ) + { + var rootFilter = this._.root; + return rootFilter ? rootFilter.filter( element ) : element; + }, + + onElement : function( element ) + { + // We must apply filters set to the specific element name as + // well as those set to the generic $ name. So, add both to an + // array and process them in a small loop. + var filters = [ this._.elements[ '^' ], this._.elements[ element.name ], this._.elements.$ ], + filter, ret; + + for ( var i = 0 ; i < 3 ; i++ ) + { + filter = filters[ i ]; + if ( filter ) + { + ret = filter.filter( element, this ); + + if ( ret === false ) + return null; + + if ( ret && ret != element ) + return this.onNode( ret ); + + // The non-root element has been dismissed by one of the filters. + if ( element.parent && !element.name ) + break; + } + } + + return element; + }, + + onNode : function( node ) + { + var type = node.type; + + return type == CKEDITOR.NODE_ELEMENT ? this.onElement( node ) : + type == CKEDITOR.NODE_TEXT ? new CKEDITOR.htmlParser.text( this.onText( node.value ) ) : + type == CKEDITOR.NODE_COMMENT ? new CKEDITOR.htmlParser.comment( this.onComment( node.value ) ): + null; + }, + + onAttribute : function( element, name, value ) + { + var filter = this._.attributes[ name ]; + + if ( filter ) + { + var ret = filter.filter( value, element, this ); + + if ( ret === false ) + return false; + + if ( typeof ret != 'undefined' ) + return ret; + } + + return value; + } + } + }); + + function filterName( name, filters ) + { + for ( var i = 0 ; name && i < filters.length ; i++ ) + { + var filter = filters[ i ]; + name = name.replace( filter[ 0 ], filter[ 1 ] ); + } + return name; + } + + function addItemsToList( list, items, priority ) + { + if ( typeof items == 'function' ) + items = [ items ]; + + var i, j, + listLength = list.length, + itemsLength = items && items.length; + + if ( itemsLength ) + { + // Find the index to insert the items at. + for ( i = 0 ; i < listLength && list[ i ].pri < priority ; i++ ) + { /*jsl:pass*/ } + + // Add all new items to the list at the specific index. + for ( j = itemsLength - 1 ; j >= 0 ; j-- ) + { + var item = items[ j ]; + if ( item ) + { + item.pri = priority; + list.splice( i, 0, item ); + } + } + } + } + + function addNamedItems( hashTable, items, priority ) + { + if ( items ) + { + for ( var name in items ) + { + var current = hashTable[ name ]; + + hashTable[ name ] = + transformNamedItem( + current, + items[ name ], + priority ); + + if ( !current ) + hashTable.$length++; + } + } + } + + function transformNamedItem( current, item, priority ) + { + if ( item ) + { + item.pri = priority; + + if ( current ) + { + // If the current item is not an Array, transform it. + if ( !current.splice ) + { + if ( current.pri > priority ) + current = [ item, current ]; + else + current = [ current, item ]; + + current.filter = callItems; + } + else + addItemsToList( current, item, priority ); + + return current; + } + else + { + item.filter = item; + return item; + } + } + } + + // Invoke filters sequentially on the array, break the iteration + // when it doesn't make sense to continue anymore. + function callItems( currentEntry ) + { + var isNode = currentEntry.type + || currentEntry instanceof CKEDITOR.htmlParser.fragment; + + for ( var i = 0 ; i < this.length ; i++ ) + { + // Backup the node info before filtering. + if ( isNode ) + { + var orgType = currentEntry.type, + orgName = currentEntry.name; + } + + var item = this[ i ], + ret = item.apply( window, arguments ); + + if ( ret === false ) + return ret; + + // We're filtering node (element/fragment). + if ( isNode ) + { + // No further filtering if it's not anymore + // fitable for the subsequent filters. + if ( ret && ( ret.name != orgName + || ret.type != orgType ) ) + { + return ret; + } + } + // Filtering value (nodeName/textValue/attrValue). + else + { + // No further filtering if it's not + // any more values. + if ( typeof ret != 'string' ) + return ret; + } + + ret != undefined && ( currentEntry = ret ); + } + + return currentEntry; + } +})(); + +// "entities" plugin +/* +{ + text : function( text ) + { + // TODO : Process entities. + return text.toUpperCase(); + } +}; +*/ Index: openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/fragment.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/fragment.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/resources/ckeditor/_source/core/htmlparser/fragment.js 14 Feb 2012 08:01:35 -0000 1.1 @@ -0,0 +1,518 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * A lightweight representation of an HTML DOM structure. + * @constructor + * @example + */ +CKEDITOR.htmlParser.fragment = function() +{ + /** + * The nodes contained in the root of this fragment. + * @type Array + * @example + * var fragment = CKEDITOR.htmlParser.fragment.fromHtml( 'Sample Text' ); + * alert( fragment.children.length ); "2" + */ + this.children = []; + + /** + * Get the fragment parent. Should always be null. + * @type Object + * @default null + * @example + */ + this.parent = null; + + /** @private */ + this._ = + { + isBlockLike : true, + hasInlineStarted : false + }; +}; + +(function() +{ + // Block-level elements whose internal structure should be respected during + // parser fixing. + var nonBreakingBlocks = CKEDITOR.tools.extend( { table:1,ul:1,ol:1,dl:1 }, CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl ); + + // IE < 8 don't output the close tag on definition list items. (#6975) + var optionalCloseTags = CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? { dd : 1, dt :1 } : {}; + + var listBlocks = { ol:1, ul:1 }; + + // Dtd of the fragment element, basically it accept anything except for intermediate structure, e.g. orphan
    1. . + var rootDtd = CKEDITOR.tools.extend( {}, { html: 1 }, CKEDITOR.dtd.html, CKEDITOR.dtd.body, CKEDITOR.dtd.head, { style:1,script:1 } ); + + function isRemoveEmpty( node ) + { + // Empty link is to be removed when empty but not anchor. (#7894) + return node.name == 'a' && node.attributes.href + || CKEDITOR.dtd.$removeEmpty[ node.name ]; + } + + /** + * Creates a {@link CKEDITOR.htmlParser.fragment} from an HTML string. + * @param {String} fragmentHtml The HTML to be parsed, filling the fragment. + * @param {Number} [fixForBody=false] Wrap body with specified element if needed. + * @param {CKEDITOR.htmlParser.element} contextNode Parse the html as the content of this element. + * @returns CKEDITOR.htmlParser.fragment The fragment created. + * @example + * var fragment = CKEDITOR.htmlParser.fragment.fromHtml( 'Sample Text' ); + * alert( fragment.children[0].name ); "b" + * alert( fragment.children[1].value ); " Text" + */ + CKEDITOR.htmlParser.fragment.fromHtml = function( fragmentHtml, fixForBody, contextNode ) + { + var parser = new CKEDITOR.htmlParser(), + fragment = contextNode || new CKEDITOR.htmlParser.fragment(), + pendingInline = [], + pendingBRs = [], + currentNode = fragment, + // Indicate we're inside a