1 /* 2 * CKEditor - The text editor for Internet - http://ckeditor.com 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 */ 21 22 /** 23 * @fileOverview Defines the {@link CKEDITOR.dom.node} class, which is the base 24 * class for classes that represent DOM nodes. 25 */ 26 27 /** 28 * Base class for classes representing DOM nodes. 29 * @constructor 30 * @see CKEDITOR.dom.element 31 * @example 32 */ 33 CKEDITOR.dom.node = function() 34 {}; 35 36 CKEDITOR.dom.node.prototype = 37 { 38 /** 39 * Makes this node child of another element. 40 * @param {CKEDITOR.dom.element} element The target element to which append 41 * this node. 42 * @returns {CKEDITOR.dom.element} The target element. 43 * @example 44 * var p = new CKEDITOR.dom.element( 'p' ); 45 * var strong = new CKEDITOR.dom.element( 'strong' ); 46 * strong.appendTo( p ); 47 * 48 * // result: "<p><strong></strong></p>" 49 */ 50 appendTo : function( element ) 51 { 52 element.append( this ); 53 return element; 54 }, 55 56 /** 57 * Inserts this element after a node. 58 * @param {CKEDITOR.dom.node} node The that will preceed this element. 59 * @returns {CKEDITOR.dom.node} The node preceeding this one after 60 * insertion. 61 * @example 62 * var em = new CKEDITOR.dom.element( 'em' ); 63 * var strong = new CKEDITOR.dom.element( 'strong' ); 64 * strong.insertAfter( em ); 65 * 66 * // result: "<em></em><strong></strong>" 67 */ 68 insertAfter : function( node ) 69 { 70 node.$.parentNode.insertBefore( this.$, node.$.nextSibling ); 71 return node; 72 }, 73 74 /** 75 * Inserts this element before a node. 76 * @param {CKEDITOR.dom.node} node The that will be after this element. 77 * @returns {CKEDITOR.dom.node} The node after this one after insertion. 78 * @example 79 * var em = new CKEDITOR.dom.element( 'em' ); 80 * var strong = new CKEDITOR.dom.element( 'strong' ); 81 * strong.insertBefore( em ); 82 * 83 * // result: "<strong></strong><em></em>" 84 */ 85 insertBefore : function( node ) 86 { 87 node.$.parentNode.insertBefore( this.$, node.$ ); 88 } 89 }; 90