4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
13 * Element class, this enables element blocking in IE. Element blocking is a method to block out select blockes that
14 * gets visible though DIVs on IE 6 it uses a iframe for this blocking. This class also shortens the length of some DOM API calls
15 * since it's bound to an element.
17 * @class tinymce.dom.Element
19 * // Creates an basic element for an existing element
20 * var elm = new tinymce.dom.Element('someid');
22 * elm.setStyle('background-color', 'red');
27 * Constructs a new Element instance. Consult the Wiki for more details on this class.
31 * @param {String} id Element ID to bind/execute methods on.
32 * @param {Object} settings Optional settings name/value collection.
34 tinymce.dom.Element = function(id, settings) {
35 var t = this, dom, el;
37 t.settings = settings = settings || {};
39 t.dom = dom = settings.dom || tinymce.DOM;
41 // Only IE leaks DOM references, this is a lot faster
46 ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
47 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
48 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
49 'isHidden,setHTML,get').split(/,/)
54 for (i = 0; i < arguments.length; i++)
57 a = dom[k].apply(dom, a);
66 * Adds a event handler to the element.
69 * @param {String} n Event name like for example "click".
70 * @param {function} f Function to execute on the specified event.
71 * @param {Object} s Optional scope to execute function on.
72 * @return {function} Event handler function the same as the input function.
74 on : function(n, f, s) {
75 return tinymce.dom.Event.add(t.id, n, f, s);
79 * Returns the absolute X, Y cordinate of the element.
82 * @return {Object} Objext with x, y cordinate fields.
86 x : parseInt(t.getStyle('left')),
87 y : parseInt(t.getStyle('top'))
92 * Returns the size of the element by a object with w and h fields.
95 * @return {Object} Object with element size with a w and h field.
97 getSize : function() {
98 var n = dom.get(t.id);
101 w : parseInt(t.getStyle('width') || n.clientWidth),
102 h : parseInt(t.getStyle('height') || n.clientHeight)
107 * Moves the element to a specific absolute position.
110 * @param {Number} x X cordinate of element position.
111 * @param {Number} y Y cordinate of element position.
113 moveTo : function(x, y) {
114 t.setStyles({left : x, top : y});
118 * Moves the element relative to the current position.
121 * @param {Number} x Relative X cordinate of element position.
122 * @param {Number} y Relative Y cordinate of element position.
124 moveBy : function(x, y) {
127 t.moveTo(p.x + x, p.y + y);
131 * Resizes the element to a specific size.
134 * @param {Number} w New width of element.
135 * @param {Numner} h New height of element.
137 resizeTo : function(w, h) {
138 t.setStyles({width : w, height : h});
142 * Resizes the element relative to the current sizeto a specific size.
145 * @param {Number} w Relative width of element.
146 * @param {Numner} h Relative height of element.
148 resizeBy : function(w, h) {
151 t.resizeTo(s.w + w, s.h + h);
155 * Updates the element blocker in IE6 based on the style information of the element.
158 * @param {String} k Optional function key. Used internally.
160 update : function(k) {
163 if (tinymce.isIE6 && settings.blocker) {
167 if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
170 // Remove blocker on remove
172 dom.remove(t.blocker);
177 t.blocker = dom.uniqueId();
178 b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
179 dom.setStyle(b, 'opacity', 0);
181 b = dom.get(t.blocker);
184 left : t.getStyle('left', 1),
185 top : t.getStyle('top', 1),
186 width : t.getStyle('width', 1),
187 height : t.getStyle('height', 1),
188 display : t.getStyle('display', 1),
189 zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1