JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2
[ckeditor.git] / _source / core / dom / element.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @fileOverview Defines the {@link CKEDITOR.dom.element} class, which\r
8  *              represents a DOM element.\r
9  */\r
10 \r
11 /**\r
12  * Represents a DOM element.\r
13  * @constructor\r
14  * @augments CKEDITOR.dom.node\r
15  * @param {Object|String} element A native DOM element or the element name for\r
16  *              new elements.\r
17  * @param {CKEDITOR.dom.document} [ownerDocument] The document that will contain\r
18  *              the element in case of element creation.\r
19  * @example\r
20  * // Create a new <span> element.\r
21  * var element = new CKEDITOR.dom.element( 'span' );\r
22  * @example\r
23  * // Create an element based on a native DOM element.\r
24  * var element = new CKEDITOR.dom.element( document.getElementById( 'myId' ) );\r
25  */\r
26 CKEDITOR.dom.element = function( element, ownerDocument )\r
27 {\r
28         if ( typeof element == 'string' )\r
29                 element = ( ownerDocument ? ownerDocument.$ : document ).createElement( element );\r
30 \r
31         // Call the base constructor (we must not call CKEDITOR.dom.node).\r
32         CKEDITOR.dom.domObject.call( this, element );\r
33 };\r
34 \r
35 // PACKAGER_RENAME( CKEDITOR.dom.element )\r
36 \r
37 /**\r
38  * The the {@link CKEDITOR.dom.element} representing and element. If the\r
39  * element is a native DOM element, it will be transformed into a valid\r
40  * CKEDITOR.dom.element object.\r
41  * @returns {CKEDITOR.dom.element} The transformed element.\r
42  * @example\r
43  * var element = new CKEDITOR.dom.element( 'span' );\r
44  * alert( element == <b>CKEDITOR.dom.element.get( element )</b> );  "true"\r
45  * @example\r
46  * var element = document.getElementById( 'myElement' );\r
47  * alert( <b>CKEDITOR.dom.element.get( element )</b>.getName() );  e.g. "p"\r
48  */\r
49 CKEDITOR.dom.element.get = function( element )\r
50 {\r
51         return element && ( element.$ ? element : new CKEDITOR.dom.element( element ) );\r
52 };\r
53 \r
54 CKEDITOR.dom.element.prototype = new CKEDITOR.dom.node();\r
55 \r
56 /**\r
57  * Creates an instance of the {@link CKEDITOR.dom.element} class based on the\r
58  * HTML representation of an element.\r
59  * @param {String} html The element HTML. It should define only one element in\r
60  *              the "root" level. The "root" element can have child nodes, but not\r
61  *              siblings.\r
62  * @returns {CKEDITOR.dom.element} The element instance.\r
63  * @example\r
64  * var element = <b>CKEDITOR.dom.element.createFromHtml( '&lt;strong class="anyclass"&gt;My element&lt;/strong&gt;' )</b>;\r
65  * alert( element.getName() );  // "strong"\r
66  */\r
67 CKEDITOR.dom.element.createFromHtml = function( html, ownerDocument )\r
68 {\r
69         var temp = new CKEDITOR.dom.element( 'div', ownerDocument );\r
70         temp.setHtml( html );\r
71 \r
72         // When returning the node, remove it from its parent to detach it.\r
73         return temp.getFirst().remove();\r
74 };\r
75 \r
76 CKEDITOR.dom.element.setMarker = function( database, element, name, value )\r
77 {\r
78         var id = element.getCustomData( 'list_marker_id' ) ||\r
79                         ( element.setCustomData( 'list_marker_id', CKEDITOR.tools.getNextNumber() ).getCustomData( 'list_marker_id' ) ),\r
80                 markerNames = element.getCustomData( 'list_marker_names' ) ||\r
81                         ( element.setCustomData( 'list_marker_names', {} ).getCustomData( 'list_marker_names' ) );\r
82         database[id] = element;\r
83         markerNames[name] = 1;\r
84 \r
85         return element.setCustomData( name, value );\r
86 };\r
87 \r
88 CKEDITOR.dom.element.clearAllMarkers = function( database )\r
89 {\r
90         for ( var i in database )\r
91                 CKEDITOR.dom.element.clearMarkers( database, database[i], true );\r
92 };\r
93 \r
94 CKEDITOR.dom.element.clearMarkers = function( database, element, removeFromDatabase )\r
95 {\r
96         var names = element.getCustomData( 'list_marker_names' ),\r
97                 id = element.getCustomData( 'list_marker_id' );\r
98         for ( var i in names )\r
99                 element.removeCustomData( i );\r
100         element.removeCustomData( 'list_marker_names' );\r
101         if ( removeFromDatabase )\r
102         {\r
103                 element.removeCustomData( 'list_marker_id' );\r
104                 delete database[id];\r
105         }\r
106 };\r
107 \r
108 CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,\r
109         /** @lends CKEDITOR.dom.element.prototype */\r
110         {\r
111                 /**\r
112                  * The node type. This is a constant value set to\r
113                  * {@link CKEDITOR.NODE_ELEMENT}.\r
114                  * @type Number\r
115                  * @example\r
116                  */\r
117                 type : CKEDITOR.NODE_ELEMENT,\r
118 \r
119                 /**\r
120                  * Adds a CSS class to the element. It appends the class to the\r
121                  * already existing names.\r
122                  * @param {String} className The name of the class to be added.\r
123                  * @example\r
124                  * var element = new CKEDITOR.dom.element( 'div' );\r
125                  * element.addClass( 'classA' );  // &lt;div class="classA"&gt;\r
126                  * element.addClass( 'classB' );  // &lt;div class="classA classB"&gt;\r
127                  * element.addClass( 'classA' );  // &lt;div class="classA classB"&gt;\r
128                  */\r
129                 addClass : function( className )\r
130                 {\r
131                         var c = this.$.className;\r
132                         if ( c )\r
133                         {\r
134                                 var regex = new RegExp( '(?:^|\\s)' + className + '(?:\\s|$)', '' );\r
135                                 if ( !regex.test( c ) )\r
136                                         c += ' ' + className;\r
137                         }\r
138                         this.$.className = c || className;\r
139                 },\r
140 \r
141                 /**\r
142                  * Removes a CSS class name from the elements classes. Other classes\r
143                  * remain untouched.\r
144                  * @param {String} className The name of the class to remove.\r
145                  * @example\r
146                  * var element = new CKEDITOR.dom.element( 'div' );\r
147                  * element.addClass( 'classA' );  // &lt;div class="classA"&gt;\r
148                  * element.addClass( 'classB' );  // &lt;div class="classA classB"&gt;\r
149                  * element.removeClass( 'classA' );  // &lt;div class="classB"&gt;\r
150                  * element.removeClass( 'classB' );  // &lt;div&gt;\r
151                  */\r
152                 removeClass : function( className )\r
153                 {\r
154                         var c = this.getAttribute( 'class' );\r
155                         if ( c )\r
156                         {\r
157                                 var regex = new RegExp( '(?:^|\\s+)' + className + '(?=\\s|$)', 'i' );\r
158                                 if ( regex.test( c ) )\r
159                                 {\r
160                                         c = c.replace( regex, '' ).replace( /^\s+/, '' );\r
161 \r
162                                         if ( c )\r
163                                                 this.setAttribute( 'class', c );\r
164                                         else\r
165                                                 this.removeAttribute( 'class' );\r
166                                 }\r
167                         }\r
168                 },\r
169 \r
170                 hasClass : function( className )\r
171                 {\r
172                         var regex = new RegExp( '(?:^|\\s+)' + className + '(?=\\s|$)', '' );\r
173                         return regex.test( this.getAttribute('class') );\r
174                 },\r
175 \r
176                 /**\r
177                  * Append a node as a child of this element.\r
178                  * @param {CKEDITOR.dom.node|String} node The node or element name to be\r
179                  *              appended.\r
180                  * @param {Boolean} [toStart] Indicates that the element is to be\r
181                  *              appended at the start.\r
182                  * @returns {CKEDITOR.dom.node} The appended node.\r
183                  * @example\r
184                  * var p = new CKEDITOR.dom.element( 'p' );\r
185                  *\r
186                  * var strong = new CKEDITOR.dom.element( 'strong' );\r
187                  * <b>p.append( strong );</b>\r
188                  *\r
189                  * var em = <b>p.append( 'em' );</b>\r
190                  *\r
191                  * // result: "&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;"\r
192                  */\r
193                 append : function( node, toStart )\r
194                 {\r
195                         if ( typeof node == 'string' )\r
196                                 node = this.getDocument().createElement( node );\r
197 \r
198                         if ( toStart )\r
199                                 this.$.insertBefore( node.$, this.$.firstChild );\r
200                         else\r
201                                 this.$.appendChild( node.$ );\r
202 \r
203                         return node;\r
204                 },\r
205 \r
206                 appendHtml : function( html )\r
207                 {\r
208                         if ( !this.$.childNodes.length )\r
209                                 this.setHtml( html );\r
210                         else\r
211                         {\r
212                                 var temp = new CKEDITOR.dom.element( 'div', this.getDocument() );\r
213                                 temp.setHtml( html );\r
214                                 temp.moveChildren( this );\r
215                         }\r
216                 },\r
217 \r
218                 /**\r
219                  * Append text to this element.\r
220                  * @param {String} text The text to be appended.\r
221                  * @returns {CKEDITOR.dom.node} The appended node.\r
222                  * @example\r
223                  * var p = new CKEDITOR.dom.element( 'p' );\r
224                  * p.appendText( 'This is' );\r
225                  * p.appendText( ' some text' );\r
226                  *\r
227                  * // result: "&lt;p&gt;This is some text&lt;/p&gt;"\r
228                  */\r
229                 appendText : function( text )\r
230                 {\r
231                         if ( this.$.text != undefined )\r
232                                 this.$.text += text;\r
233                         else\r
234                                 this.append( new CKEDITOR.dom.text( text ) );\r
235                 },\r
236 \r
237                 appendBogus : function()\r
238                 {\r
239                         var lastChild = this.getLast() ;\r
240 \r
241                         // Ignore empty/spaces text.\r
242                         while ( lastChild && lastChild.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.rtrim( lastChild.getText() ) )\r
243                                 lastChild = lastChild.getPrevious();\r
244                         if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) )\r
245                         {\r
246                                 var bogus = CKEDITOR.env.opera ?\r
247                                                 this.getDocument().createText('') :\r
248                                                 this.getDocument().createElement( 'br' );\r
249 \r
250                                 CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' );\r
251 \r
252                                 this.append( bogus );\r
253                         }\r
254                 },\r
255 \r
256                 /**\r
257                  * Breaks one of the ancestor element in the element position, moving\r
258                  * this element between the broken parts.\r
259                  * @param {CKEDITOR.dom.element} parent The anscestor element to get broken.\r
260                  * @example\r
261                  * // Before breaking:\r
262                  * //     &lt;b&gt;This &lt;i&gt;is some&lt;span /&gt; sample&lt;/i&gt; test text&lt;/b&gt;\r
263                  * // If "element" is &lt;span /&gt; and "parent" is &lt;i&gt;:\r
264                  * //     &lt;b&gt;This &lt;i&gt;is some&lt;/i&gt;&lt;span /&gt;&lt;i&gt; sample&lt;/i&gt; test text&lt;/b&gt;\r
265                  * element.breakParent( parent );\r
266                  * @example\r
267                  * // Before breaking:\r
268                  * //     &lt;b&gt;This &lt;i&gt;is some&lt;span /&gt; sample&lt;/i&gt; test text&lt;/b&gt;\r
269                  * // If "element" is &lt;span /&gt; and "parent" is &lt;b&gt;:\r
270                  * //     &lt;b&gt;This &lt;i&gt;is some&lt;/i&gt;&lt;/b&gt;&lt;span /&gt;&lt;b&gt;&lt;i&gt; sample&lt;/i&gt; test text&lt;/b&gt;\r
271                  * element.breakParent( parent );\r
272                  */\r
273                 breakParent : function( parent )\r
274                 {\r
275                         var range = new CKEDITOR.dom.range( this.getDocument() );\r
276 \r
277                         // We'll be extracting part of this element, so let's use our\r
278                         // range to get the correct piece.\r
279                         range.setStartAfter( this );\r
280                         range.setEndAfter( parent );\r
281 \r
282                         // Extract it.\r
283                         var docFrag = range.extractContents();\r
284 \r
285                         // Move the element outside the broken element.\r
286                         range.insertNode( this.remove() );\r
287 \r
288                         // Re-insert the extracted piece after the element.\r
289                         docFrag.insertAfterNode( this );\r
290                 },\r
291 \r
292                 contains :\r
293                         CKEDITOR.env.ie || CKEDITOR.env.webkit ?\r
294                                 function( node )\r
295                                 {\r
296                                         var $ = this.$;\r
297 \r
298                                         return node.type != CKEDITOR.NODE_ELEMENT ?\r
299                                                 $.contains( node.getParent().$ ) :\r
300                                                 $ != node.$ && $.contains( node.$ );\r
301                                 }\r
302                         :\r
303                                 function( node )\r
304                                 {\r
305                                         return !!( this.$.compareDocumentPosition( node.$ ) & 16 );\r
306                                 },\r
307 \r
308                 /**\r
309                  * Moves the selection focus to this element.\r
310                  * @example\r
311                  * var element = CKEDITOR.document.getById( 'myTextarea' );\r
312                  * <b>element.focus()</b>;\r
313                  */\r
314                 focus : function()\r
315                 {\r
316                         // IE throws error if the element is not visible.\r
317                         try\r
318                         {\r
319                                 this.$.focus();\r
320                         }\r
321                         catch (e)\r
322                         {}\r
323                 },\r
324 \r
325                 /**\r
326                  * Gets the inner HTML of this element.\r
327                  * @returns {String} The inner HTML of this element.\r
328                  * @example\r
329                  * var element = CKEDITOR.dom.element.createFromHtml( '&lt;div&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/div&gt;' );\r
330                  * alert( <b>p.getHtml()</b> );  // "&lt;b&gt;Example&lt;/b&gt;"\r
331                  */\r
332                 getHtml : function()\r
333                 {\r
334                         var retval = this.$.innerHTML;\r
335                         // Strip <?xml:namespace> tags in IE. (#3341).\r
336                         return CKEDITOR.env.ie ? retval.replace( /<\?[^>]*>/g, '' ) : retval;\r
337                 },\r
338 \r
339                 getOuterHtml : function()\r
340                 {\r
341                         if ( this.$.outerHTML )\r
342                         {\r
343                                 // IE includes the <?xml:namespace> tag in the outerHTML of\r
344                                 // namespaced element. So, we must strip it here. (#3341)\r
345                                 return this.$.outerHTML.replace( /<\?[^>]*>/, '' );\r
346                         }\r
347 \r
348                         var tmpDiv = this.$.ownerDocument.createElement( 'div' );\r
349                         tmpDiv.appendChild( this.$.cloneNode( true ) );\r
350                         return tmpDiv.innerHTML;\r
351                 },\r
352 \r
353                 /**\r
354                  * Sets the inner HTML of this element.\r
355                  * @param {String} html The HTML to be set for this element.\r
356                  * @returns {String} The inserted HTML.\r
357                  * @example\r
358                  * var p = new CKEDITOR.dom.element( 'p' );\r
359                  * <b>p.setHtml( '&lt;b&gt;Inner&lt;/b&gt; HTML' );</b>\r
360                  *\r
361                  * // result: "&lt;p&gt;&lt;b&gt;Inner&lt;/b&gt; HTML&lt;/p&gt;"\r
362                  */\r
363                 setHtml : function( html )\r
364                 {\r
365                         return ( this.$.innerHTML = html );\r
366                 },\r
367 \r
368                 /**\r
369                  * Sets the element contents as plain text.\r
370                  * @param {String} text The text to be set.\r
371                  * @returns {String} The inserted text.\r
372                  * @example\r
373                  * var element = new CKEDITOR.dom.element( 'div' );\r
374                  * element.setText( 'A > B & C < D' );\r
375                  * alert( element.innerHTML );  // "A &amp;gt; B &amp;amp; C &amp;lt; D"\r
376                  */\r
377                 setText : function( text )\r
378                 {\r
379                         CKEDITOR.dom.element.prototype.setText = ( this.$.innerText != undefined ) ?\r
380                                 function ( text )\r
381                                 {\r
382                                         return this.$.innerText = text;\r
383                                 } :\r
384                                 function ( text )\r
385                                 {\r
386                                         return this.$.textContent = text;\r
387                                 };\r
388 \r
389                         return this.setText( text );\r
390                 },\r
391 \r
392                 /**\r
393                  * Gets the value of an element attribute.\r
394                  * @function\r
395                  * @param {String} name The attribute name.\r
396                  * @returns {String} The attribute value or null if not defined.\r
397                  * @example\r
398                  * var element = CKEDITOR.dom.element.createFromHtml( '&lt;input type="text" /&gt;' );\r
399                  * alert( <b>element.getAttribute( 'type' )</b> );  // "text"\r
400                  */\r
401                 getAttribute : (function()\r
402                 {\r
403                         var standard = function( name )\r
404                         {\r
405                                 return this.$.getAttribute( name, 2 );\r
406                         };\r
407 \r
408                         if ( CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) )\r
409                         {\r
410                                 return function( name )\r
411                                 {\r
412                                         switch ( name )\r
413                                         {\r
414                                                 case 'class':\r
415                                                         name = 'className';\r
416                                                         break;\r
417 \r
418                                                 case 'tabindex':\r
419                                                         var tabIndex = standard.call( this, name );\r
420 \r
421                                                         // IE returns tabIndex=0 by default for all\r
422                                                         // elements. For those elements,\r
423                                                         // getAtrribute( 'tabindex', 2 ) returns 32768\r
424                                                         // instead. So, we must make this check to give a\r
425                                                         // uniform result among all browsers.\r
426                                                         if ( tabIndex !== 0 && this.$.tabIndex === 0 )\r
427                                                                 tabIndex = null;\r
428 \r
429                                                         return tabIndex;\r
430                                                         break;\r
431 \r
432                                                 case 'checked':\r
433                                                 {\r
434                                                         var attr = this.$.attributes.getNamedItem( name ),\r
435                                                                 attrValue = attr.specified ? attr.nodeValue     // For value given by parser.\r
436                                                                                                                          : this.$.checked;  // For value created via DOM interface.\r
437 \r
438                                                         return attrValue ? 'checked' : null;\r
439                                                 }\r
440 \r
441                                                 case 'hspace':\r
442                                                         return this.$.hspace;\r
443 \r
444                                                 case 'style':\r
445                                                         // IE does not return inline styles via getAttribute(). See #2947.\r
446                                                         return this.$.style.cssText;\r
447                                         }\r
448 \r
449                                         return standard.call( this, name );\r
450                                 };\r
451                         }\r
452                         else\r
453                                 return standard;\r
454                 })(),\r
455 \r
456                 getChildren : function()\r
457                 {\r
458                         return new CKEDITOR.dom.nodeList( this.$.childNodes );\r
459                 },\r
460 \r
461                 /**\r
462                  * Gets the current computed value of one of the element CSS style\r
463                  * properties.\r
464                  * @function\r
465                  * @param {String} propertyName The style property name.\r
466                  * @returns {String} The property value.\r
467                  * @example\r
468                  * var element = new CKEDITOR.dom.element( 'span' );\r
469                  * alert( <b>element.getComputedStyle( 'display' )</b> );  // "inline"\r
470                  */\r
471                 getComputedStyle :\r
472                         CKEDITOR.env.ie ?\r
473                                 function( propertyName )\r
474                                 {\r
475                                         return this.$.currentStyle[ CKEDITOR.tools.cssStyleToDomStyle( propertyName ) ];\r
476                                 }\r
477                         :\r
478                                 function( propertyName )\r
479                                 {\r
480                                         return this.getWindow().$.getComputedStyle( this.$, '' ).getPropertyValue( propertyName );\r
481                                 },\r
482 \r
483                 /**\r
484                  * Gets the DTD entries for this element.\r
485                  * @returns {Object} An object containing the list of elements accepted\r
486                  *              by this element.\r
487                  */\r
488                 getDtd : function()\r
489                 {\r
490                         var dtd = CKEDITOR.dtd[ this.getName() ];\r
491 \r
492                         this.getDtd = function()\r
493                         {\r
494                                 return dtd;\r
495                         };\r
496 \r
497                         return dtd;\r
498                 },\r
499 \r
500                 getElementsByTag : CKEDITOR.dom.document.prototype.getElementsByTag,\r
501 \r
502                 /**\r
503                  * Gets the computed tabindex for this element.\r
504                  * @function\r
505                  * @returns {Number} The tabindex value.\r
506                  * @example\r
507                  * var element = CKEDITOR.document.getById( 'myDiv' );\r
508                  * alert( <b>element.getTabIndex()</b> );  // e.g. "-1"\r
509                  */\r
510                 getTabIndex :\r
511                         CKEDITOR.env.ie ?\r
512                                 function()\r
513                                 {\r
514                                         var tabIndex = this.$.tabIndex;\r
515 \r
516                                         // IE returns tabIndex=0 by default for all elements. In\r
517                                         // those cases we must check that the element really has\r
518                                         // the tabindex attribute set to zero, or it is one of\r
519                                         // those element that should have zero by default.\r
520                                         if ( tabIndex === 0 && !CKEDITOR.dtd.$tabIndex[ this.getName() ] && parseInt( this.getAttribute( 'tabindex' ), 10 ) !== 0 )\r
521                                                 tabIndex = -1;\r
522 \r
523                                                 return tabIndex;\r
524                                 }\r
525                         : CKEDITOR.env.webkit ?\r
526                                 function()\r
527                                 {\r
528                                         var tabIndex = this.$.tabIndex;\r
529 \r
530                                         // Safari returns "undefined" for elements that should not\r
531                                         // have tabindex (like a div). So, we must try to get it\r
532                                         // from the attribute.\r
533                                         // https://bugs.webkit.org/show_bug.cgi?id=20596\r
534                                         if ( tabIndex == undefined )\r
535                                         {\r
536                                                 tabIndex = parseInt( this.getAttribute( 'tabindex' ), 10 );\r
537 \r
538                                                 // If the element don't have the tabindex attribute,\r
539                                                 // then we should return -1.\r
540                                                 if ( isNaN( tabIndex ) )\r
541                                                         tabIndex = -1;\r
542                                         }\r
543 \r
544                                         return tabIndex;\r
545                                 }\r
546                         :\r
547                                 function()\r
548                                 {\r
549                                         return this.$.tabIndex;\r
550                                 },\r
551 \r
552                 /**\r
553                  * Gets the text value of this element.\r
554                  *\r
555                  * Only in IE (which uses innerText), &lt;br&gt; will cause linebreaks,\r
556                  * and sucessive whitespaces (including line breaks) will be reduced to\r
557                  * a single space. This behavior is ok for us, for now. It may change\r
558                  * in the future.\r
559                  * @returns {String} The text value.\r
560                  * @example\r
561                  * var element = CKEDITOR.dom.element.createFromHtml( '&lt;div&gt;Same &lt;i&gt;text&lt;/i&gt;.&lt;/div&gt;' );\r
562                  * alert( <b>element.getText()</b> );  // "Sample text."\r
563                  */\r
564                 getText : function()\r
565                 {\r
566                         return this.$.textContent || this.$.innerText || '';\r
567                 },\r
568 \r
569                 /**\r
570                  * Gets the window object that contains this element.\r
571                  * @returns {CKEDITOR.dom.window} The window object.\r
572                  * @example\r
573                  */\r
574                 getWindow : function()\r
575                 {\r
576                         return this.getDocument().getWindow();\r
577                 },\r
578 \r
579                 /**\r
580                  * Gets the value of the "id" attribute of this element.\r
581                  * @returns {String} The element id, or null if not available.\r
582                  * @example\r
583                  * var element = CKEDITOR.dom.element.createFromHtml( '&lt;p id="myId"&gt;&lt;/p&gt;' );\r
584                  * alert( <b>element.getId()</b> );  // "myId"\r
585                  */\r
586                 getId : function()\r
587                 {\r
588                         return this.$.id || null;\r
589                 },\r
590 \r
591                 /**\r
592                  * Gets the value of the "name" attribute of this element.\r
593                  * @returns {String} The element name, or null if not available.\r
594                  * @example\r
595                  * var element = CKEDITOR.dom.element.createFromHtml( '&lt;input name="myName"&gt;&lt;/input&gt;' );\r
596                  * alert( <b>element.getNameAtt()</b> );  // "myName"\r
597                  */\r
598                 getNameAtt : function()\r
599                 {\r
600                         return this.$.name || null;\r
601                 },\r
602 \r
603                 /**\r
604                  * Gets the element name (tag name). The returned name is guaranteed to\r
605                  * be always full lowercased.\r
606                  * @returns {String} The element name.\r
607                  * @example\r
608                  * var element = new CKEDITOR.dom.element( 'span' );\r
609                  * alert( <b>element.getName()</b> );  // "span"\r
610                  */\r
611                 getName : function()\r
612                 {\r
613                         // Cache the lowercased name inside a closure.\r
614                         var nodeName = this.$.nodeName.toLowerCase();\r
615 \r
616                         if ( CKEDITOR.env.ie )\r
617                         {\r
618                                 var scopeName = this.$.scopeName;\r
619                                 if ( scopeName != 'HTML' )\r
620                                         nodeName = scopeName.toLowerCase() + ':' + nodeName;\r
621                         }\r
622 \r
623                         return (\r
624                         this.getName = function()\r
625                                 {\r
626                                         return nodeName;\r
627                                 })();\r
628                 },\r
629 \r
630                 /**\r
631                  * Gets the value set to this element. This value is usually available\r
632                  * for form field elements.\r
633                  * @returns {String} The element value.\r
634                  */\r
635                 getValue : function()\r
636                 {\r
637                         return this.$.value;\r
638                 },\r
639 \r
640                 /**\r
641                  * Gets the first child node of this element.\r
642                  * @param {Function} evaluator Filtering the result node.\r
643                  * @returns {CKEDITOR.dom.node} The first child node or null if not\r
644                  *              available.\r
645                  * @example\r
646                  * var element = CKEDITOR.dom.element.createFromHtml( '&lt;div&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/div&gt;' );\r
647                  * var first = <b>element.getFirst()</b>;\r
648                  * alert( first.getName() );  // "b"\r
649                  */\r
650                 getFirst : function( evaluator )\r
651                 {\r
652                         var first = this.$.firstChild,\r
653                                 retval = first && new CKEDITOR.dom.node( first );\r
654                         if ( retval && evaluator && !evaluator( retval ) )\r
655                                 retval = retval.getNext( evaluator );\r
656 \r
657                         return retval;\r
658                 },\r
659 \r
660                 /**\r
661                  * @param {Function} evaluator Filtering the result node.\r
662                  */\r
663                 getLast : function( evaluator )\r
664                 {\r
665                         var last = this.$.lastChild,\r
666                                 retval = last && new CKEDITOR.dom.node( last );\r
667                         if ( retval && evaluator && !evaluator( retval ) )\r
668                                 retval = retval.getPrevious( evaluator );\r
669 \r
670                         return retval;\r
671                 },\r
672 \r
673                 getStyle : function( name )\r
674                 {\r
675                         return this.$.style[ CKEDITOR.tools.cssStyleToDomStyle( name ) ];\r
676                 },\r
677 \r
678                 /**\r
679                  * Checks if the element name matches one or more names.\r
680                  * @param {String} name[,name[,...]] One or more names to be checked.\r
681                  * @returns {Boolean} true if the element name matches any of the names.\r
682                  * @example\r
683                  * var element = new CKEDITOR.element( 'span' );\r
684                  * alert( <b>element.is( 'span' )</b> );  "true"\r
685                  * alert( <b>element.is( 'p', 'span' )</b> );  "true"\r
686                  * alert( <b>element.is( 'p' )</b> );  "false"\r
687                  * alert( <b>element.is( 'p', 'div' )</b> );  "false"\r
688                  */\r
689                 is : function()\r
690                 {\r
691                         var name = this.getName();\r
692                         for ( var i = 0 ; i < arguments.length ; i++ )\r
693                         {\r
694                                 if ( arguments[ i ] == name )\r
695                                         return true;\r
696                         }\r
697                         return false;\r
698                 },\r
699 \r
700                 isEditable : function()\r
701                 {\r
702                         // Get the element name.\r
703                         var name = this.getName();\r
704 \r
705                         // Get the element DTD (defaults to span for unknown elements).\r
706                         var dtd = !CKEDITOR.dtd.$nonEditable[ name ]\r
707                                                 && ( CKEDITOR.dtd[ name ] || CKEDITOR.dtd.span );\r
708 \r
709                         // In the DTD # == text node.\r
710                         return ( dtd && dtd['#'] );\r
711                 },\r
712 \r
713                 isIdentical : function( otherElement )\r
714                 {\r
715                         if ( this.getName() != otherElement.getName() )\r
716                                 return false;\r
717 \r
718                         var thisAttribs = this.$.attributes,\r
719                                 otherAttribs = otherElement.$.attributes;\r
720 \r
721                         var thisLength = thisAttribs.length,\r
722                                 otherLength = otherAttribs.length;\r
723 \r
724                         if ( !CKEDITOR.env.ie && thisLength != otherLength )\r
725                                 return false;\r
726 \r
727                         for ( var i = 0 ; i < thisLength ; i++ )\r
728                         {\r
729                                 var attribute = thisAttribs[ i ];\r
730 \r
731                                 if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != '_cke_expando' ) ) && attribute.nodeValue != otherElement.getAttribute( attribute.nodeName ) )\r
732                                         return false;\r
733                         }\r
734 \r
735                         // For IE, we have to for both elements, because it's difficult to\r
736                         // know how the atttibutes collection is organized in its DOM.\r
737                         if ( CKEDITOR.env.ie )\r
738                         {\r
739                                 for ( i = 0 ; i < otherLength ; i++ )\r
740                                 {\r
741                                         attribute = otherAttribs[ i ];\r
742                                         if ( attribute.specified && attribute.nodeName != '_cke_expando'\r
743                                                         && attribute.nodeValue != this.getAttribute( attribute.nodeName ) )\r
744                                                 return false;\r
745                                 }\r
746                         }\r
747 \r
748                         return true;\r
749                 },\r
750 \r
751                 /**\r
752                  * Checks if this element is visible. May not work if the element is\r
753                  * child of an element with visibility set to "hidden", but works well\r
754                  * on the great majority of cases.\r
755                  * @return {Boolean} True if the element is visible.\r
756                  */\r
757                 isVisible : function()\r
758                 {\r
759                         var isVisible = !!this.$.offsetHeight && this.getComputedStyle( 'visibility' ) != 'hidden',\r
760                                 elementWindow,\r
761                                 elementWindowFrame;\r
762 \r
763                         // Webkit and Opera report non-zero offsetHeight despite that\r
764                         // element is inside an invisible iframe. (#4542)\r
765                         if ( isVisible && ( CKEDITOR.env.webkit || CKEDITOR.env.opera ) )\r
766                         {\r
767                                 elementWindow = this.getWindow();\r
768 \r
769                                 if ( !elementWindow.equals( CKEDITOR.document.getWindow() )\r
770                                                 && ( elementWindowFrame = elementWindow.$.frameElement ) )\r
771                                 {\r
772                                         isVisible = new CKEDITOR.dom.element( elementWindowFrame ).isVisible();\r
773                                 }\r
774                         }\r
775 \r
776                         return isVisible;\r
777                 },\r
778 \r
779                 /**\r
780                  * Indicates that the element has defined attributes.\r
781                  * @returns {Boolean} True if the element has attributes.\r
782                  * @example\r
783                  * var element = CKEDITOR.dom.element.createFromHtml( '<div title="Test">Example</div>' );\r
784                  * alert( <b>element.hasAttributes()</b> );  "true"\r
785                  * @example\r
786                  * var element = CKEDITOR.dom.element.createFromHtml( '<div>Example</div>' );\r
787                  * alert( <b>element.hasAttributes()</b> );  "false"\r
788                  */\r
789                 hasAttributes :\r
790                         CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) ?\r
791                                 function()\r
792                                 {\r
793                                         var attributes = this.$.attributes;\r
794 \r
795                                         for ( var i = 0 ; i < attributes.length ; i++ )\r
796                                         {\r
797                                                 var attribute = attributes[i];\r
798 \r
799                                                 switch ( attribute.nodeName )\r
800                                                 {\r
801                                                         case 'class' :\r
802                                                                 // IE has a strange bug. If calling removeAttribute('className'),\r
803                                                                 // the attributes collection will still contain the "class"\r
804                                                                 // attribute, which will be marked as "specified", even if the\r
805                                                                 // outerHTML of the element is not displaying the class attribute.\r
806                                                                 // Note : I was not able to reproduce it outside the editor,\r
807                                                                 // but I've faced it while working on the TC of #1391.\r
808                                                                 if ( this.getAttribute( 'class' ) )\r
809                                                                         return true;\r
810 \r
811                                                         // Attributes to be ignored.\r
812                                                         case '_cke_expando' :\r
813                                                                 continue;\r
814 \r
815                                                         /*jsl:fallthru*/\r
816 \r
817                                                         default :\r
818                                                                 if ( attribute.specified )\r
819                                                                         return true;\r
820                                                 }\r
821                                         }\r
822 \r
823                                         return false;\r
824                                 }\r
825                         :\r
826                                 function()\r
827                                 {\r
828                                         var attributes = this.$.attributes;\r
829                                         return ( attributes.length > 1 || ( attributes.length == 1 && attributes[0].nodeName != '_cke_expando' ) );\r
830                                 },\r
831 \r
832                 /**\r
833                  * Indicates whether a specified attribute is defined for this element.\r
834                  * @returns {Boolean} True if the specified attribute is defined.\r
835                  * @param (String) name The attribute name.\r
836                  * @example\r
837                  */\r
838                 hasAttribute : function( name )\r
839                 {\r
840                         var $attr = this.$.attributes.getNamedItem( name );\r
841                         return !!( $attr && $attr.specified );\r
842                 },\r
843 \r
844                 /**\r
845                  * Hides this element (display:none).\r
846                  * @example\r
847                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
848                  * <b>element.hide()</b>;\r
849                  */\r
850                 hide : function()\r
851                 {\r
852                         this.setStyle( 'display', 'none' );\r
853                 },\r
854 \r
855                 moveChildren : function( target, toStart )\r
856                 {\r
857                         var $ = this.$;\r
858                         target = target.$;\r
859 \r
860                         if ( $ == target )\r
861                                 return;\r
862 \r
863                         var child;\r
864 \r
865                         if ( toStart )\r
866                         {\r
867                                 while ( ( child = $.lastChild ) )\r
868                                         target.insertBefore( $.removeChild( child ), target.firstChild );\r
869                         }\r
870                         else\r
871                         {\r
872                                 while ( ( child = $.firstChild ) )\r
873                                         target.appendChild( $.removeChild( child ) );\r
874                         }\r
875                 },\r
876 \r
877                 /**\r
878                  * Shows this element (display it).\r
879                  * @example\r
880                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
881                  * <b>element.show()</b>;\r
882                  */\r
883                 show : function()\r
884                 {\r
885                         this.setStyles(\r
886                                 {\r
887                                         display : '',\r
888                                         visibility : ''\r
889                                 });\r
890                 },\r
891 \r
892                 /**\r
893                  * Sets the value of an element attribute.\r
894                  * @param {String} name The name of the attribute.\r
895                  * @param {String} value The value to be set to the attribute.\r
896                  * @function\r
897                  * @returns {CKEDITOR.dom.element} This element instance.\r
898                  * @example\r
899                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
900                  * <b>element.setAttribute( 'class', 'myClass' )</b>;\r
901                  * <b>element.setAttribute( 'title', 'This is an example' )</b>;\r
902                  */\r
903                 setAttribute : (function()\r
904                 {\r
905                         var standard = function( name, value )\r
906                         {\r
907                                 this.$.setAttribute( name, value );\r
908                                 return this;\r
909                         };\r
910 \r
911                         if ( CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) )\r
912                         {\r
913                                 return function( name, value )\r
914                                 {\r
915                                         if ( name == 'class' )\r
916                                                 this.$.className = value;\r
917                                         else if ( name == 'style' )\r
918                                                 this.$.style.cssText = value;\r
919                                         else if ( name == 'tabindex' )  // Case sensitive.\r
920                                                 this.$.tabIndex = value;\r
921                                         else if ( name == 'checked' )\r
922                                                 this.$.checked = value;\r
923                                         else\r
924                                                 standard.apply( this, arguments );\r
925                                         return this;\r
926                                 };\r
927                         }\r
928                         else\r
929                                 return standard;\r
930                 })(),\r
931 \r
932                 /**\r
933                  * Sets the value of several element attributes.\r
934                  * @param {Object} attributesPairs An object containing the names and\r
935                  *              values of the attributes.\r
936                  * @returns {CKEDITOR.dom.element} This element instance.\r
937                  * @example\r
938                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
939                  * <b>element.setAttributes({\r
940                  *     'class' : 'myClass',\r
941                  *     'title' : 'This is an example' })</b>;\r
942                  */\r
943                 setAttributes : function( attributesPairs )\r
944                 {\r
945                         for ( var name in attributesPairs )\r
946                                 this.setAttribute( name, attributesPairs[ name ] );\r
947                         return this;\r
948                 },\r
949 \r
950                 /**\r
951                  * Sets the element value. This function is usually used with form\r
952                  * field element.\r
953                  * @param {String} value The element value.\r
954                  * @returns {CKEDITOR.dom.element} This element instance.\r
955                  */\r
956                 setValue : function( value )\r
957                 {\r
958                         this.$.value = value;\r
959                         return this;\r
960                 },\r
961 \r
962                 /**\r
963                  * Removes an attribute from the element.\r
964                  * @param {String} name The attribute name.\r
965                  * @function\r
966                  * @example\r
967                  * var element = CKEDITOR.dom.element.createFromHtml( '<div class="classA"></div>' );\r
968                  * element.removeAttribute( 'class' );\r
969                  */\r
970                 removeAttribute : (function()\r
971                 {\r
972                         var standard = function( name )\r
973                         {\r
974                                 this.$.removeAttribute( name );\r
975                         };\r
976 \r
977                         if ( CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) )\r
978                         {\r
979                                 return function( name )\r
980                                 {\r
981                                         if ( name == 'class' )\r
982                                                 name = 'className';\r
983                                         else if ( name == 'tabindex' )\r
984                                                 name = 'tabIndex';\r
985                                         standard.call( this, name );\r
986                                 };\r
987                         }\r
988                         else\r
989                                 return standard;\r
990                 })(),\r
991 \r
992                 removeAttributes : function ( attributes )\r
993                 {\r
994                         if ( CKEDITOR.tools.isArray( attributes ) )\r
995                         {\r
996                                 for ( var i = 0 ; i < attributes.length ; i++ )\r
997                                         this.removeAttribute( attributes[ i ] );\r
998                         }\r
999                         else\r
1000                         {\r
1001                                 for ( var attr in attributes )\r
1002                                         attributes.hasOwnProperty( attr ) && this.removeAttribute( attr );\r
1003                         }\r
1004                 },\r
1005 \r
1006                 /**\r
1007                  * Removes a style from the element.\r
1008                  * @param {String} name The style name.\r
1009                  * @function\r
1010                  * @example\r
1011                  * var element = CKEDITOR.dom.element.createFromHtml( '<div style="display:none"></div>' );\r
1012                  * element.removeStyle( 'display' );\r
1013                  */\r
1014                 removeStyle : function( name )\r
1015                 {\r
1016                         this.setStyle( name, '' );\r
1017                         if ( this.$.style.removeAttribute )\r
1018                                 this.$.style.removeAttribute( CKEDITOR.tools.cssStyleToDomStyle( name ) );\r
1019 \r
1020                         if ( !this.$.style.cssText )\r
1021                                 this.removeAttribute( 'style' );\r
1022                 },\r
1023 \r
1024                 /**\r
1025                  * Sets the value of an element style.\r
1026                  * @param {String} name The name of the style. The CSS naming notation\r
1027                  *              must be used (e.g. "background-color").\r
1028                  * @param {String} value The value to be set to the style.\r
1029                  * @returns {CKEDITOR.dom.element} This element instance.\r
1030                  * @example\r
1031                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
1032                  * <b>element.setStyle( 'background-color', '#ff0000' )</b>;\r
1033                  * <b>element.setStyle( 'margin-top', '10px' )</b>;\r
1034                  * <b>element.setStyle( 'float', 'right' )</b>;\r
1035                  */\r
1036                 setStyle : function( name, value )\r
1037                 {\r
1038                         this.$.style[ CKEDITOR.tools.cssStyleToDomStyle( name ) ] = value;\r
1039                         return this;\r
1040                 },\r
1041 \r
1042                 /**\r
1043                  * Sets the value of several element styles.\r
1044                  * @param {Object} stylesPairs An object containing the names and\r
1045                  *              values of the styles.\r
1046                  * @returns {CKEDITOR.dom.element} This element instance.\r
1047                  * @example\r
1048                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
1049                  * <b>element.setStyles({\r
1050                  *     'position' : 'absolute',\r
1051                  *     'float' : 'right' })</b>;\r
1052                  */\r
1053                 setStyles : function( stylesPairs )\r
1054                 {\r
1055                         for ( var name in stylesPairs )\r
1056                                 this.setStyle( name, stylesPairs[ name ] );\r
1057                         return this;\r
1058                 },\r
1059 \r
1060                 /**\r
1061                  * Sets the opacity of an element.\r
1062                  * @param {Number} opacity A number within the range [0.0, 1.0].\r
1063                  * @example\r
1064                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
1065                  * <b>element.setOpacity( 0.75 )</b>;\r
1066                  */\r
1067                 setOpacity : function( opacity )\r
1068                 {\r
1069                         if ( CKEDITOR.env.ie )\r
1070                         {\r
1071                                 opacity = Math.round( opacity * 100 );\r
1072                                 this.setStyle( 'filter', opacity >= 100 ? '' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')' );\r
1073                         }\r
1074                         else\r
1075                                 this.setStyle( 'opacity', opacity );\r
1076                 },\r
1077 \r
1078                 /**\r
1079                  * Makes the element and its children unselectable.\r
1080                  * @function\r
1081                  * @example\r
1082                  * var element = CKEDITOR.dom.element.getById( 'myElement' );\r
1083                  * element.unselectable();\r
1084                  */\r
1085                 unselectable :\r
1086                         CKEDITOR.env.gecko ?\r
1087                                 function()\r
1088                                 {\r
1089                                         this.$.style.MozUserSelect = 'none';\r
1090                                 }\r
1091                         : CKEDITOR.env.webkit ?\r
1092                                 function()\r
1093                                 {\r
1094                                         this.$.style.KhtmlUserSelect = 'none';\r
1095                                 }\r
1096                         :\r
1097                                 function()\r
1098                                 {\r
1099                                         if ( CKEDITOR.env.ie || CKEDITOR.env.opera )\r
1100                                         {\r
1101                                                 var element = this.$,\r
1102                                                         e,\r
1103                                                         i = 0;\r
1104 \r
1105                                                 element.unselectable = 'on';\r
1106 \r
1107                                                 while ( ( e = element.all[ i++ ] ) )\r
1108                                                 {\r
1109                                                         switch ( e.tagName.toLowerCase() )\r
1110                                                         {\r
1111                                                                 case 'iframe' :\r
1112                                                                 case 'textarea' :\r
1113                                                                 case 'input' :\r
1114                                                                 case 'select' :\r
1115                                                                         /* Ignore the above tags */\r
1116                                                                         break;\r
1117                                                                 default :\r
1118                                                                         e.unselectable = 'on';\r
1119                                                         }\r
1120                                                 }\r
1121                                         }\r
1122                                 },\r
1123 \r
1124                 getPositionedAncestor : function()\r
1125                 {\r
1126                         var current = this;\r
1127                         while ( current.getName() != 'html' )\r
1128                         {\r
1129                                 if ( current.getComputedStyle( 'position' ) != 'static' )\r
1130                                         return current;\r
1131 \r
1132                                 current = current.getParent();\r
1133                         }\r
1134                         return null;\r
1135                 },\r
1136 \r
1137                 getDocumentPosition : function( refDocument )\r
1138                 {\r
1139                         var x = 0, y = 0,\r
1140                                 body = this.getDocument().getBody(),\r
1141                                 quirks = this.getDocument().$.compatMode == 'BackCompat';\r
1142 \r
1143                         var doc = this.getDocument();\r
1144 \r
1145                         if ( document.documentElement[ "getBoundingClientRect" ] )\r
1146                         {\r
1147                                 var box  = this.$.getBoundingClientRect(),\r
1148                                         $doc = doc.$,\r
1149                                         $docElem = $doc.documentElement;\r
1150 \r
1151                                 var clientTop = $docElem.clientTop || body.$.clientTop || 0,\r
1152                                         clientLeft = $docElem.clientLeft || body.$.clientLeft || 0,\r
1153                                         needAdjustScrollAndBorders = true;\r
1154 \r
1155                                 /*\r
1156                                  * #3804: getBoundingClientRect() works differently on IE and non-IE\r
1157                                  * browsers, regarding scroll positions.\r
1158                                  *\r
1159                                  * On IE, the top position of the <html> element is always 0, no matter\r
1160                                  * how much you scrolled down.\r
1161                                  *\r
1162                                  * On other browsers, the top position of the <html> element is negative\r
1163                                  * scrollTop.\r
1164                                  */\r
1165                                 if ( CKEDITOR.env.ie )\r
1166                                 {\r
1167                                         var inDocElem = doc.getDocumentElement().contains( this ),\r
1168                                                 inBody = doc.getBody().contains( this );\r
1169 \r
1170                                         needAdjustScrollAndBorders = ( quirks && inBody ) || ( !quirks && inDocElem );\r
1171                                 }\r
1172 \r
1173                                 if ( needAdjustScrollAndBorders )\r
1174                                 {\r
1175                                         x = box.left + ( !quirks && $docElem.scrollLeft || body.$.scrollLeft );\r
1176                                         x -= clientLeft;\r
1177                                         y = box.top  + ( !quirks && $docElem.scrollTop || body.$.scrollTop );\r
1178                                         y -= clientTop;\r
1179                                 }\r
1180                         }\r
1181                         else\r
1182                         {\r
1183                                 var current = this, previous = null, offsetParent;\r
1184                                 while ( current && !( current.getName() == 'body' || current.getName() == 'html' ) )\r
1185                                 {\r
1186                                         x += current.$.offsetLeft - current.$.scrollLeft;\r
1187                                         y += current.$.offsetTop - current.$.scrollTop;\r
1188 \r
1189                                         // Opera includes clientTop|Left into offsetTop|Left.\r
1190                                         if ( !current.equals( this ) )\r
1191                                         {\r
1192                                                 x += ( current.$.clientLeft || 0 );\r
1193                                                 y += ( current.$.clientTop || 0 );\r
1194                                         }\r
1195 \r
1196                                         var scrollElement = previous;\r
1197                                         while ( scrollElement && !scrollElement.equals( current ) )\r
1198                                         {\r
1199                                                 x -= scrollElement.$.scrollLeft;\r
1200                                                 y -= scrollElement.$.scrollTop;\r
1201                                                 scrollElement = scrollElement.getParent();\r
1202                                         }\r
1203 \r
1204                                         previous = current;\r
1205                                         current = ( offsetParent = current.$.offsetParent ) ?\r
1206                                                   new CKEDITOR.dom.element( offsetParent ) : null;\r
1207                                 }\r
1208                         }\r
1209 \r
1210                         if ( refDocument )\r
1211                         {\r
1212                                 var currentWindow = this.getWindow(),\r
1213                                         refWindow = refDocument.getWindow();\r
1214 \r
1215                                 if ( !currentWindow.equals( refWindow ) && currentWindow.$.frameElement )\r
1216                                 {\r
1217                                         var iframePosition = ( new CKEDITOR.dom.element( currentWindow.$.frameElement ) ).getDocumentPosition( refDocument );\r
1218 \r
1219                                         x += iframePosition.x;\r
1220                                         y += iframePosition.y;\r
1221                                 }\r
1222                         }\r
1223 \r
1224                         if ( !document.documentElement[ "getBoundingClientRect" ] )\r
1225                         {\r
1226                                 // In Firefox, we'll endup one pixel before the element positions,\r
1227                                 // so we must add it here.\r
1228                                 if ( CKEDITOR.env.gecko && !quirks )\r
1229                                 {\r
1230                                         x += this.$.clientLeft ? 1 : 0;\r
1231                                         y += this.$.clientTop ? 1 : 0;\r
1232                                 }\r
1233                         }\r
1234 \r
1235                         return { x : x, y : y };\r
1236                 },\r
1237 \r
1238                 scrollIntoView : function( alignTop )\r
1239                 {\r
1240                         // Get the element window.\r
1241                         var win = this.getWindow(),\r
1242                                 winHeight = win.getViewPaneSize().height;\r
1243 \r
1244                         // Starts from the offset that will be scrolled with the negative value of\r
1245                         // the visible window height.\r
1246                         var offset = winHeight * -1;\r
1247 \r
1248                         // Append the view pane's height if align to top.\r
1249                         // Append element height if we are aligning to the bottom.\r
1250                         if ( alignTop )\r
1251                                 offset += winHeight;\r
1252                         else\r
1253                         {\r
1254                                 offset += this.$.offsetHeight || 0;\r
1255 \r
1256                                 // Consider the margin in the scroll, which is ok for our current needs, but\r
1257                                 // needs investigation if we will be using this function in other places.\r
1258                                 offset += parseInt( this.getComputedStyle( 'marginBottom' ) || 0, 10 ) || 0;\r
1259                         }\r
1260 \r
1261                         // Append the offsets for the entire element hierarchy.\r
1262                         var elementPosition = this.getDocumentPosition();\r
1263                         offset += elementPosition.y;\r
1264 \r
1265                         // offset value might be out of range(nagative), fix it(#3692).\r
1266                         offset = offset < 0 ? 0 : offset;\r
1267 \r
1268                         // Scroll the window to the desired position, if not already visible(#3795).\r
1269                         var currentScroll = win.getScrollPosition().y;\r
1270                         if ( offset > currentScroll || offset < currentScroll - winHeight )\r
1271                                 win.$.scrollTo( 0, offset );\r
1272                 },\r
1273 \r
1274                 setState : function( state )\r
1275                 {\r
1276                         switch ( state )\r
1277                         {\r
1278                                 case CKEDITOR.TRISTATE_ON :\r
1279                                         this.addClass( 'cke_on' );\r
1280                                         this.removeClass( 'cke_off' );\r
1281                                         this.removeClass( 'cke_disabled' );\r
1282                                         break;\r
1283                                 case CKEDITOR.TRISTATE_DISABLED :\r
1284                                         this.addClass( 'cke_disabled' );\r
1285                                         this.removeClass( 'cke_off' );\r
1286                                         this.removeClass( 'cke_on' );\r
1287                                         break;\r
1288                                 default :\r
1289                                         this.addClass( 'cke_off' );\r
1290                                         this.removeClass( 'cke_on' );\r
1291                                         this.removeClass( 'cke_disabled' );\r
1292                                         break;\r
1293                         }\r
1294                 },\r
1295 \r
1296                 /**\r
1297                  * Returns the inner document of this IFRAME element.\r
1298                  * @returns {CKEDITOR.dom.document} The inner document.\r
1299                  */\r
1300                 getFrameDocument : function()\r
1301                 {\r
1302                         var $ = this.$;\r
1303 \r
1304                         try\r
1305                         {\r
1306                                 // In IE, with custom document.domain, it may happen that\r
1307                                 // the iframe is not yet available, resulting in "Access\r
1308                                 // Denied" for the following property access.\r
1309                                 $.contentWindow.document;\r
1310                         }\r
1311                         catch ( e )\r
1312                         {\r
1313                                 // Trick to solve this issue, forcing the iframe to get ready\r
1314                                 // by simply setting its "src" property.\r
1315                                 $.src = $.src;\r
1316 \r
1317                                 // In IE6 though, the above is not enough, so we must pause the\r
1318                                 // execution for a while, giving it time to think.\r
1319                                 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )\r
1320                                 {\r
1321                                         window.showModalDialog(\r
1322                                                 'javascript:document.write("' +\r
1323                                                         '<script>' +\r
1324                                                                 'window.setTimeout(' +\r
1325                                                                         'function(){window.close();}' +\r
1326                                                                         ',50);' +\r
1327                                                         '</script>")' );\r
1328                                 }\r
1329                         }\r
1330 \r
1331                         return $ && new CKEDITOR.dom.document( $.contentWindow.document );\r
1332                 },\r
1333 \r
1334                 /**\r
1335                  * Copy all the attributes from one node to the other, kinda like a clone\r
1336                  * skipAttributes is an object with the attributes that must NOT be copied.\r
1337                  * @param {CKEDITOR.dom.element} dest The destination element.\r
1338                  * @param {Object} skipAttributes A dictionary of attributes to skip.\r
1339                  * @example\r
1340                  */\r
1341                 copyAttributes : function( dest, skipAttributes )\r
1342                 {\r
1343                         var attributes = this.$.attributes;\r
1344                         skipAttributes = skipAttributes || {};\r
1345 \r
1346                         for ( var n = 0 ; n < attributes.length ; n++ )\r
1347                         {\r
1348                                 var attribute = attributes[n];\r
1349 \r
1350                                 // Lowercase attribute name hard rule is broken for\r
1351                                 // some attribute on IE, e.g. CHECKED.\r
1352                                 var attrName = attribute.nodeName.toLowerCase(),\r
1353                                         attrValue;\r
1354 \r
1355                                 // We can set the type only once, so do it with the proper value, not copying it.\r
1356                                 if ( attrName in skipAttributes )\r
1357                                         continue;\r
1358 \r
1359                                 if ( attrName == 'checked' && ( attrValue = this.getAttribute( attrName ) ) )\r
1360                                         dest.setAttribute( attrName, attrValue );\r
1361                                 // IE BUG: value attribute is never specified even if it exists.\r
1362                                 else if ( attribute.specified ||\r
1363                                   ( CKEDITOR.env.ie && attribute.nodeValue && attrName == 'value' ) )\r
1364                                 {\r
1365                                         attrValue = this.getAttribute( attrName );\r
1366                                         if ( attrValue === null )\r
1367                                                 attrValue = attribute.nodeValue;\r
1368 \r
1369                                         dest.setAttribute( attrName, attrValue );\r
1370                                 }\r
1371                         }\r
1372 \r
1373                         // The style:\r
1374                         if ( this.$.style.cssText !== '' )\r
1375                                 dest.$.style.cssText = this.$.style.cssText;\r
1376                 },\r
1377 \r
1378                 /**\r
1379                  * Changes the tag name of the current element.\r
1380                  * @param {String} newTag The new tag for the element.\r
1381                  */\r
1382                 renameNode : function( newTag )\r
1383                 {\r
1384                         // If it's already correct exit here.\r
1385                         if ( this.getName() == newTag )\r
1386                                 return;\r
1387 \r
1388                         var doc = this.getDocument();\r
1389 \r
1390                         // Create the new node.\r
1391                         var newNode = new CKEDITOR.dom.element( newTag, doc );\r
1392 \r
1393                         // Copy all attributes.\r
1394                         this.copyAttributes( newNode );\r
1395 \r
1396                         // Move children to the new node.\r
1397                         this.moveChildren( newNode );\r
1398 \r
1399                         // Replace the node.\r
1400                         this.$.parentNode.replaceChild( newNode.$, this.$ );\r
1401                         newNode.$._cke_expando = this.$._cke_expando;\r
1402                         this.$ = newNode.$;\r
1403                 },\r
1404 \r
1405                 /**\r
1406                  * Gets a DOM tree descendant under the current node.\r
1407                  * @param {Array|Number} indices The child index or array of child indices under the node.\r
1408                  * @returns {CKEDITOR.dom.node} The specified DOM child under the current node. Null if child does not exist.\r
1409                  * @example\r
1410                  * var strong = p.getChild(0);\r
1411                  */\r
1412                 getChild : function( indices )\r
1413                 {\r
1414                         var rawNode = this.$;\r
1415 \r
1416                         if ( !indices.slice )\r
1417                                 rawNode = rawNode.childNodes[ indices ];\r
1418                         else\r
1419                         {\r
1420                                 while ( indices.length > 0 && rawNode )\r
1421                                         rawNode = rawNode.childNodes[ indices.shift() ];\r
1422                         }\r
1423 \r
1424                         return rawNode ? new CKEDITOR.dom.node( rawNode ) : null;\r
1425                 },\r
1426 \r
1427                 getChildCount : function()\r
1428                 {\r
1429                         return this.$.childNodes.length;\r
1430                 },\r
1431 \r
1432                 disableContextMenu : function()\r
1433                 {\r
1434                         this.on( 'contextmenu', function( event )\r
1435                                 {\r
1436                                         // Cancel the browser context menu.\r
1437                                         if ( !event.data.getTarget().hasClass( 'cke_enable_context_menu' ) )\r
1438                                                 event.data.preventDefault();\r
1439                                 } );\r
1440                 }\r
1441         });\r