summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/MochiKit/Style.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/MochiKit/Style.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/MochiKit/Style.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/frontend/gamma/js/MochiKit/Style.js b/frontend/gamma/js/MochiKit/Style.js
index 7f10117..740fd2f 100644
--- a/frontend/gamma/js/MochiKit/Style.js
+++ b/frontend/gamma/js/MochiKit/Style.js
@@ -1,558 +1,561 @@
1/*** 1/***
2 2
3MochiKit.Style 1.5 3MochiKit.Style 1.5
4 4
5See <http://mochikit.com/> for documentation, downloads, license, etc. 5See <http://mochikit.com/> for documentation, downloads, license, etc.
6 6
7(c) 2005-2006 Bob Ippolito, Beau Hartshorne. All rights Reserved. 7(c) 2005-2006 Bob Ippolito, Beau Hartshorne. All rights Reserved.
8 8
9The MochiKit.Style.getElementPosition function is adapted from
10YAHOO.util.Dom.getXY v0.9.0. which is copyrighted by Yahoo! Inc.
11
9***/ 12***/
10 13
11MochiKit.Base._module('Style', '1.5', ['Base', 'DOM']); 14MochiKit.Base.module(MochiKit, 'Style', '1.5', ['Base', 'DOM']);
12 15
13 16
14/** @id MochiKit.Style.Dimensions */ 17/** @id MochiKit.Style.Dimensions */
15MochiKit.Style.Dimensions = function (w, h) { 18MochiKit.Style.Dimensions = function (w, h) {
16 if (!(this instanceof MochiKit.Style.Dimensions)) { 19 if (!(this instanceof MochiKit.Style.Dimensions)) {
17 return new MochiKit.Style.Dimensions(w, h); 20 return new MochiKit.Style.Dimensions(w, h);
18 } 21 }
19 this.w = w; 22 this.w = w;
20 this.h = h; 23 this.h = h;
21}; 24};
22 25
23MochiKit.Style.Dimensions.prototype.__repr__ = function () { 26MochiKit.Style.Dimensions.prototype.__repr__ = function () {
24 var repr = MochiKit.Base.repr; 27 var repr = MochiKit.Base.repr;
25 return '{w: ' + repr(this.w) + ', h: ' + repr(this.h) + '}'; 28 return '{w: ' + repr(this.w) + ', h: ' + repr(this.h) + '}';
26}; 29};
27 30
28MochiKit.Style.Dimensions.prototype.toString = function () { 31MochiKit.Style.Dimensions.prototype.toString = function () {
29 return this.__repr__(); 32 return this.__repr__();
30}; 33};
31 34
32 35
33/** @id MochiKit.Style.Coordinates */ 36/** @id MochiKit.Style.Coordinates */
34MochiKit.Style.Coordinates = function (x, y) { 37MochiKit.Style.Coordinates = function (x, y) {
35 if (!(this instanceof MochiKit.Style.Coordinates)) { 38 if (!(this instanceof MochiKit.Style.Coordinates)) {
36 return new MochiKit.Style.Coordinates(x, y); 39 return new MochiKit.Style.Coordinates(x, y);
37 } 40 }
38 this.x = x; 41 this.x = x;
39 this.y = y; 42 this.y = y;
40}; 43};
41 44
42MochiKit.Style.Coordinates.prototype.__repr__ = function () { 45MochiKit.Style.Coordinates.prototype.__repr__ = function () {
43 var repr = MochiKit.Base.repr; 46 var repr = MochiKit.Base.repr;
44 return '{x: ' + repr(this.x) + ', y: ' + repr(this.y) + '}'; 47 return '{x: ' + repr(this.x) + ', y: ' + repr(this.y) + '}';
45}; 48};
46 49
47MochiKit.Style.Coordinates.prototype.toString = function () { 50MochiKit.Style.Coordinates.prototype.toString = function () {
48 return this.__repr__(); 51 return this.__repr__();
49}; 52};
50 53
51 54
52MochiKit.Base.update(MochiKit.Style, { 55MochiKit.Base.update(MochiKit.Style, {
53 56
54 /** @id MochiKit.Style.getStyle */ 57 /** @id MochiKit.Style.getStyle */
55 getStyle: function (elem, cssProperty) { 58 getStyle: function (elem, cssProperty) {
56 var dom = MochiKit.DOM; 59 var dom = MochiKit.DOM;
57 var d = dom._document; 60 var d = dom._document;
58 61
59 elem = dom.getElement(elem); 62 elem = dom.getElement(elem);
60 cssProperty = MochiKit.Base.camelize(cssProperty); 63 cssProperty = MochiKit.Base.camelize(cssProperty);
61 64
62 if (!elem || elem == d) { 65 if (!elem || elem == d) {
63 return undefined; 66 return undefined;
64 } 67 }
65 if (cssProperty == 'opacity' && typeof(elem.filters) != 'undefined') { 68 if (cssProperty == 'opacity' && typeof(elem.filters) != 'undefined') {
66 var opacity = (MochiKit.Style.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/); 69 var opacity = (MochiKit.Style.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/);
67 if (opacity && opacity[1]) { 70 if (opacity && opacity[1]) {
68 return parseFloat(opacity[1]) / 100; 71 return parseFloat(opacity[1]) / 100;
69 } 72 }
70 return 1.0; 73 return 1.0;
71 } 74 }
72 if (cssProperty == 'float' || cssProperty == 'cssFloat' || cssProperty == 'styleFloat') { 75 if (cssProperty == 'float' || cssProperty == 'cssFloat' || cssProperty == 'styleFloat') {
73 if (elem.style["float"]) { 76 if (elem.style["float"]) {
74 return elem.style["float"]; 77 return elem.style["float"];
75 } else if (elem.style.cssFloat) { 78 } else if (elem.style.cssFloat) {
76 return elem.style.cssFloat; 79 return elem.style.cssFloat;
77 } else if (elem.style.styleFloat) { 80 } else if (elem.style.styleFloat) {
78 return elem.style.styleFloat; 81 return elem.style.styleFloat;
79 } else { 82 } else {
80 return "none"; 83 return "none";
81 } 84 }
82 } 85 }
83 var value = elem.style ? elem.style[cssProperty] : null; 86 var value = elem.style ? elem.style[cssProperty] : null;
84 if (!value) { 87 if (!value) {
85 if (d.defaultView && d.defaultView.getComputedStyle) { 88 if (d.defaultView && d.defaultView.getComputedStyle) {
86 var css = d.defaultView.getComputedStyle(elem, null); 89 var css = d.defaultView.getComputedStyle(elem, null);
87 cssProperty = cssProperty.replace(/([A-Z])/g, '-$1' 90 cssProperty = cssProperty.replace(/([A-Z])/g, '-$1'
88 ).toLowerCase(); // from dojo.style.toSelectorCase 91 ).toLowerCase(); // from dojo.style.toSelectorCase
89 value = css ? css.getPropertyValue(cssProperty) : null; 92 value = css ? css.getPropertyValue(cssProperty) : null;
90 } else if (elem.currentStyle) { 93 } else if (elem.currentStyle) {
91 value = elem.currentStyle[cssProperty]; 94 value = elem.currentStyle[cssProperty];
92 if (/^\d/.test(value) && !/px$/.test(value) && cssProperty != 'fontWeight') { 95 if (/^\d/.test(value) && !/px$/.test(value) && cssProperty != 'fontWeight') {
93 /* Convert to px using an hack from Dean Edwards */ 96 /* Convert to px using an hack from Dean Edwards */
94 var left = elem.style.left; 97 var left = elem.style.left;
95 var rsLeft = elem.runtimeStyle.left; 98 var rsLeft = elem.runtimeStyle.left;
96 elem.runtimeStyle.left = elem.currentStyle.left; 99 elem.runtimeStyle.left = elem.currentStyle.left;
97 elem.style.left = value || 0; 100 elem.style.left = value || 0;
98 value = elem.style.pixelLeft + "px"; 101 value = elem.style.pixelLeft + "px";
99 elem.style.left = left; 102 elem.style.left = left;
100 elem.runtimeStyle.left = rsLeft; 103 elem.runtimeStyle.left = rsLeft;
101 } 104 }
102 } 105 }
103 } 106 }
104 if (cssProperty == 'opacity') { 107 if (cssProperty == 'opacity') {
105 value = parseFloat(value); 108 value = parseFloat(value);
106 } 109 }
107 110
108 if (/Opera/.test(navigator.userAgent) && (MochiKit.Base.findValue(['left', 'top', 'right', 'bottom'], cssProperty) != -1)) { 111 if (/Opera/.test(navigator.userAgent) && (MochiKit.Base.findValue(['left', 'top', 'right', 'bottom'], cssProperty) != -1)) {
109 if (MochiKit.Style.getStyle(elem, 'position') == 'static') { 112 if (MochiKit.Style.getStyle(elem, 'position') == 'static') {
110 value = 'auto'; 113 value = 'auto';
111 } 114 }
112 } 115 }
113 116
114 return value == 'auto' ? null : value; 117 return value == 'auto' ? null : value;
115 }, 118 },
116 119
117 /** @id MochiKit.Style.setStyle */ 120 /** @id MochiKit.Style.setStyle */
118 setStyle: function (elem, style) { 121 setStyle: function (elem, style) {
119 elem = MochiKit.DOM.getElement(elem); 122 elem = MochiKit.DOM.getElement(elem);
120 for (var name in style) { 123 for (var name in style) {
121 switch (name) { 124 switch (name) {
122 case 'opacity': 125 case 'opacity':
123 MochiKit.Style.setOpacity(elem, style[name]); 126 MochiKit.Style.setOpacity(elem, style[name]);
124 break; 127 break;
125 case 'float': 128 case 'float':
126 case 'cssFloat': 129 case 'cssFloat':
127 case 'styleFloat': 130 case 'styleFloat':
128 if (typeof(elem.style["float"]) != "undefined") { 131 if (typeof(elem.style["float"]) != "undefined") {
129 elem.style["float"] = style[name]; 132 elem.style["float"] = style[name];
130 } else if (typeof(elem.style.cssFloat) != "undefined") { 133 } else if (typeof(elem.style.cssFloat) != "undefined") {
131 elem.style.cssFloat = style[name]; 134 elem.style.cssFloat = style[name];
132 } else { 135 } else {
133 elem.style.styleFloat = style[name]; 136 elem.style.styleFloat = style[name];
134 } 137 }
135 break; 138 break;
136 default: 139 default:
137 elem.style[MochiKit.Base.camelize(name)] = style[name]; 140 elem.style[MochiKit.Base.camelize(name)] = style[name];
138 } 141 }
139 } 142 }
140 }, 143 },
141 144
142 /** @id MochiKit.Style.setOpacity */ 145 /** @id MochiKit.Style.setOpacity */
143 setOpacity: function (elem, o) { 146 setOpacity: function (elem, o) {
144 elem = MochiKit.DOM.getElement(elem); 147 elem = MochiKit.DOM.getElement(elem);
145 var self = MochiKit.Style; 148 var self = MochiKit.Style;
146 if (o == 1) { 149 if (o == 1) {
147 var toSet = /Gecko/.test(navigator.userAgent) && !(/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent)); 150 var toSet = /Gecko/.test(navigator.userAgent) && !(/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent));
148 elem.style["opacity"] = toSet ? 0.999999 : 1.0; 151 elem.style["opacity"] = toSet ? 0.999999 : 1.0;
149 if (/MSIE/.test(navigator.userAgent)) { 152 if (/MSIE/.test(navigator.userAgent)) {
150 elem.style['filter'] = 153 elem.style['filter'] =
151 self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, ''); 154 self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '');
152 } 155 }
153 } else { 156 } else {
154 if (o < 0.00001) { 157 if (o < 0.00001) {
155 o = 0; 158 o = 0;
156 } 159 }
157 elem.style["opacity"] = o; 160 elem.style["opacity"] = o;
158 if (/MSIE/.test(navigator.userAgent)) { 161 if (/MSIE/.test(navigator.userAgent)) {
159 elem.style['filter'] = 162 elem.style['filter'] =
160 self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')'; 163 self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')';
161 } 164 }
162 } 165 }
163 }, 166 },
164 167
165 /* 168 /*
166 169
167 getElementPosition is adapted from YAHOO.util.Dom.getXY v0.9.0. 170 getElementPosition is adapted from YAHOO.util.Dom.getXY v0.9.0.
168 Copyright: Copyright (c) 2006, Yahoo! Inc. All rights reserved. 171 Copyright: Copyright (c) 2006, Yahoo! Inc. All rights reserved.
169 License: BSD, http://developer.yahoo.net/yui/license.txt 172 License: BSD, http://developer.yahoo.net/yui/license.txt
170 173
171 */ 174 */
172 175
173 /** @id MochiKit.Style.getElementPosition */ 176 /** @id MochiKit.Style.getElementPosition */
174 getElementPosition: function (elem, /* optional */relativeTo) { 177 getElementPosition: function (elem, /* optional */relativeTo) {
175 var self = MochiKit.Style; 178 var self = MochiKit.Style;
176 var dom = MochiKit.DOM; 179 var dom = MochiKit.DOM;
177 var isCoordinates = function (o) { 180 var isCoordinates = function (o) {
178 return o != null && 181 return o != null &&
179 o.nodeType == null && 182 o.nodeType == null &&
180 typeof(o.x) == "number" && 183 typeof(o.x) == "number" &&
181 typeof(o.y) == "number"; 184 typeof(o.y) == "number";
182 } 185 };
183 186
184 if (typeof(elem) == "string") { 187 if (typeof(elem) == "string") {
185 elem = dom.getElement(elem); 188 elem = dom.getElement(elem);
186 } 189 }
187 if (elem == null || 190 if (elem == null ||
188 (!isCoordinates(elem) && self.getStyle(elem, 'display') == 'none')) { 191 (!isCoordinates(elem) && self.getStyle(elem, 'display') == 'none')) {
189 return undefined; 192 return undefined;
190 } 193 }
191 194
192 var c = new self.Coordinates(0, 0); 195 var c = new self.Coordinates(0, 0);
193 var box = null; 196 var box = null;
194 var parent = null; 197 var parent = null;
195 198
196 var d = MochiKit.DOM._document; 199 var d = MochiKit.DOM._document;
197 var de = d.documentElement; 200 var de = d.documentElement;
198 var b = d.body; 201 var b = d.body;
199 202
200 if (!elem.parentNode && elem.x && elem.y) { 203 if (isCoordinates(elem)) {
201 /* it's just a MochiKit.Style.Coordinates object */ 204 /* it's just a MochiKit.Style.Coordinates object */
202 c.x += elem.x || 0; 205 c.x += elem.x || 0;
203 c.y += elem.y || 0; 206 c.y += elem.y || 0;
204 } else if (elem.getBoundingClientRect) { // IE shortcut 207 } else if (elem.getBoundingClientRect) { // IE shortcut
205 /* 208 /*
206 209
207 The IE shortcut can be off by two. We fix it. See: 210 The IE shortcut can be off by two. We fix it. See:
208 http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getboundingclientrect.asp 211 http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getboundingclientrect.asp
209 212
210 This is similar to the method used in 213 This is similar to the method used in
211 MochiKit.Signal.Event.mouse(). 214 MochiKit.Signal.Event.mouse().
212 215
213 */ 216 */
214 box = elem.getBoundingClientRect(); 217 box = elem.getBoundingClientRect();
215 218
216 c.x += box.left + 219 c.x += box.left +
217 (de.scrollLeft || b.scrollLeft) - 220 (de.scrollLeft || b.scrollLeft) -
218 (de.clientLeft || 0); 221 (de.clientLeft || 0);
219 222
220 c.y += box.top + 223 c.y += box.top +
221 (de.scrollTop || b.scrollTop) - 224 (de.scrollTop || b.scrollTop) -
222 (de.clientTop || 0); 225 (de.clientTop || 0);
223 226
224 } else if (elem.offsetParent) { 227 } else if (elem.offsetParent) {
225 c.x += elem.offsetLeft; 228 c.x += elem.offsetLeft;
226 c.y += elem.offsetTop; 229 c.y += elem.offsetTop;
227 parent = elem.offsetParent; 230 parent = elem.offsetParent;
228 231
229 if (parent != elem) { 232 if (parent != elem) {
230 while (parent) { 233 while (parent) {
231 c.x += parseInt(parent.style.borderLeftWidth) || 0; 234 c.x += parseInt(parent.style.borderLeftWidth, 10) || 0;
232 c.y += parseInt(parent.style.borderTopWidth) || 0; 235 c.y += parseInt(parent.style.borderTopWidth, 10) || 0;
233 c.x += parent.offsetLeft; 236 c.x += parent.offsetLeft;
234 c.y += parent.offsetTop; 237 c.y += parent.offsetTop;
235 parent = parent.offsetParent; 238 parent = parent.offsetParent;
236 } 239 }
237 } 240 }
238 241
239 /* 242 /*
240 243
241 Opera < 9 and old Safari (absolute) incorrectly account for 244 Opera < 9 and old Safari (absolute) incorrectly account for
242 body offsetTop and offsetLeft. 245 body offsetTop and offsetLeft.
243 246
244 */ 247 */
245 var ua = navigator.userAgent.toLowerCase(); 248 var ua = navigator.userAgent.toLowerCase();
246 if ((typeof(opera) != 'undefined' && 249 if ((typeof(opera) != 'undefined' &&
247 parseFloat(opera.version()) < 9) || 250 parseFloat(opera.version()) < 9) ||
248 (ua.indexOf('AppleWebKit') != -1 && 251 (ua.indexOf('AppleWebKit') != -1 &&
249 self.getStyle(elem, 'position') == 'absolute')) { 252 self.getStyle(elem, 'position') == 'absolute')) {
250 253
251 c.x -= b.offsetLeft; 254 c.x -= b.offsetLeft;
252 c.y -= b.offsetTop; 255 c.y -= b.offsetTop;
253 256
254 } 257 }
255 258
256 // Adjust position for strange Opera scroll bug 259 // Adjust position for strange Opera scroll bug
257 if (elem.parentNode) { 260 if (elem.parentNode) {
258 parent = elem.parentNode; 261 parent = elem.parentNode;
259 } else { 262 } else {
260 parent = null; 263 parent = null;
261 } 264 }
262 while (parent) { 265 while (parent) {
263 var tagName = parent.tagName.toUpperCase(); 266 var tagName = parent.tagName.toUpperCase();
264 if (tagName === 'BODY' || tagName === 'HTML') { 267 if (tagName === 'BODY' || tagName === 'HTML') {
265 break; 268 break;
266 } 269 }
267 var disp = self.getStyle(parent, 'display'); 270 var disp = self.getStyle(parent, 'display');
268 // Handle strange Opera bug for some display 271 // Handle strange Opera bug for some display
269 if (disp.search(/^inline|table-row.*$/i)) { 272 if (disp.search(/^inline|table-row.*$/i)) {
270 c.x -= parent.scrollLeft; 273 c.x -= parent.scrollLeft;
271 c.y -= parent.scrollTop; 274 c.y -= parent.scrollTop;
272 } 275 }
273 if (parent.parentNode) { 276 if (parent.parentNode) {
274 parent = parent.parentNode; 277 parent = parent.parentNode;
275 } else { 278 } else {
276 parent = null; 279 parent = null;
277 } 280 }
278 } 281 }
279 } 282 }
280 283
281 if (relativeTo) { 284 if (relativeTo) {
282 relativeTo = arguments.callee(relativeTo); 285 relativeTo = arguments.callee(relativeTo);
283 if (relativeTo) { 286 if (relativeTo) {
284 c.x -= (relativeTo.x || 0); 287 c.x -= (relativeTo.x || 0);
285 c.y -= (relativeTo.y || 0); 288 c.y -= (relativeTo.y || 0);
286 } 289 }
287 } 290 }
288 291
289 return c; 292 return c;
290 }, 293 },
291 294
292 /** @id MochiKit.Style.setElementPosition */ 295 /** @id MochiKit.Style.setElementPosition */
293 setElementPosition: function (elem, newPos/* optional */, units) { 296 setElementPosition: function (elem, newPos/* optional */, units) {
294 elem = MochiKit.DOM.getElement(elem); 297 elem = MochiKit.DOM.getElement(elem);
295 if (typeof(units) == 'undefined') { 298 if (typeof(units) == 'undefined') {
296 units = 'px'; 299 units = 'px';
297 } 300 }
298 var newStyle = {}; 301 var newStyle = {};
299 var isUndefNull = MochiKit.Base.isUndefinedOrNull; 302 var isUndefNull = MochiKit.Base.isUndefinedOrNull;
300 if (!isUndefNull(newPos.x)) { 303 if (!isUndefNull(newPos.x)) {
301 newStyle['left'] = newPos.x + units; 304 newStyle['left'] = newPos.x + units;
302 } 305 }
303 if (!isUndefNull(newPos.y)) { 306 if (!isUndefNull(newPos.y)) {
304 newStyle['top'] = newPos.y + units; 307 newStyle['top'] = newPos.y + units;
305 } 308 }
306 MochiKit.DOM.updateNodeAttributes(elem, {'style': newStyle}); 309 MochiKit.DOM.updateNodeAttributes(elem, {'style': newStyle});
307 }, 310 },
308 311
309 /** @id MochiKit.Style.makePositioned */ 312 /** @id MochiKit.Style.makePositioned */
310 makePositioned: function (element) { 313 makePositioned: function (element) {
311 element = MochiKit.DOM.getElement(element); 314 element = MochiKit.DOM.getElement(element);
312 var pos = MochiKit.Style.getStyle(element, 'position'); 315 var pos = MochiKit.Style.getStyle(element, 'position');
313 if (pos == 'static' || !pos) { 316 if (pos == 'static' || !pos) {
314 element.style.position = 'relative'; 317 element.style.position = 'relative';
315 // Opera returns the offset relative to the positioning context, 318 // Opera returns the offset relative to the positioning context,
316 // when an element is position relative but top and left have 319 // when an element is position relative but top and left have
317 // not been defined 320 // not been defined
318 if (/Opera/.test(navigator.userAgent)) { 321 if (/Opera/.test(navigator.userAgent)) {
319 element.style.top = 0; 322 element.style.top = 0;
320 element.style.left = 0; 323 element.style.left = 0;
321 } 324 }
322 } 325 }
323 }, 326 },
324 327
325 /** @id MochiKit.Style.undoPositioned */ 328 /** @id MochiKit.Style.undoPositioned */
326 undoPositioned: function (element) { 329 undoPositioned: function (element) {
327 element = MochiKit.DOM.getElement(element); 330 element = MochiKit.DOM.getElement(element);
328 if (element.style.position == 'relative') { 331 if (element.style.position == 'relative') {
329 element.style.position = element.style.top = element.style.left = element.style.bottom = element.style.right = ''; 332 element.style.position = element.style.top = element.style.left = element.style.bottom = element.style.right = '';
330 } 333 }
331 }, 334 },
332 335
333 /** @id MochiKit.Style.makeClipping */ 336 /** @id MochiKit.Style.makeClipping */
334 makeClipping: function (element) { 337 makeClipping: function (element) {
335 element = MochiKit.DOM.getElement(element); 338 element = MochiKit.DOM.getElement(element);
336 var s = element.style; 339 var s = element.style;
337 var oldOverflow = { 'overflow': s.overflow, 340 var oldOverflow = { 'overflow': s.overflow,
338 'overflow-x': s.overflowX, 341 'overflow-x': s.overflowX,
339 'overflow-y': s.overflowY }; 342 'overflow-y': s.overflowY };
340 if ((MochiKit.Style.getStyle(element, 'overflow') || 'visible') != 'hidden') { 343 if ((MochiKit.Style.getStyle(element, 'overflow') || 'visible') != 'hidden') {
341 element.style.overflow = 'hidden'; 344 element.style.overflow = 'hidden';
342 element.style.overflowX = 'hidden'; 345 element.style.overflowX = 'hidden';
343 element.style.overflowY = 'hidden'; 346 element.style.overflowY = 'hidden';
344 } 347 }
345 return oldOverflow; 348 return oldOverflow;
346 }, 349 },
347 350
348 /** @id MochiKit.Style.undoClipping */ 351 /** @id MochiKit.Style.undoClipping */
349 undoClipping: function (element, overflow) { 352 undoClipping: function (element, overflow) {
350 element = MochiKit.DOM.getElement(element); 353 element = MochiKit.DOM.getElement(element);
351 if (typeof(overflow) == 'string') { 354 if (typeof(overflow) == 'string') {
352 element.style.overflow = overflow; 355 element.style.overflow = overflow;
353 } else if (overflow != null) { 356 } else if (overflow != null) {
354 element.style.overflow = overflow['overflow']; 357 element.style.overflow = overflow['overflow'];
355 element.style.overflowX = overflow['overflow-x']; 358 element.style.overflowX = overflow['overflow-x'];
356 element.style.overflowY = overflow['overflow-y']; 359 element.style.overflowY = overflow['overflow-y'];
357 } 360 }
358 }, 361 },
359 362
360 /** @id MochiKit.Style.getElementDimensions */ 363 /** @id MochiKit.Style.getElementDimensions */
361 getElementDimensions: function (elem, contentSize/*optional*/) { 364 getElementDimensions: function (elem, contentSize/*optional*/) {
362 var self = MochiKit.Style; 365 var self = MochiKit.Style;
363 var dom = MochiKit.DOM; 366 var dom = MochiKit.DOM;
364 if (typeof(elem.w) == 'number' || typeof(elem.h) == 'number') { 367 if (typeof(elem.w) == 'number' || typeof(elem.h) == 'number') {
365 return new self.Dimensions(elem.w || 0, elem.h || 0); 368 return new self.Dimensions(elem.w || 0, elem.h || 0);
366 } 369 }
367 elem = dom.getElement(elem); 370 elem = dom.getElement(elem);
368 if (!elem) { 371 if (!elem) {
369 return undefined; 372 return undefined;
370 } 373 }
371 var disp = self.getStyle(elem, 'display'); 374 var disp = self.getStyle(elem, 'display');
372 // display can be empty/undefined on WebKit/KHTML 375 // display can be empty/undefined on WebKit/KHTML
373 if (disp == 'none' || disp == '' || typeof(disp) == 'undefined') { 376 if (disp == 'none' || disp == '' || typeof(disp) == 'undefined') {
374 var s = elem.style; 377 var s = elem.style;
375 var originalVisibility = s.visibility; 378 var originalVisibility = s.visibility;
376 var originalPosition = s.position; 379 var originalPosition = s.position;
377 var originalDisplay = s.display; 380 var originalDisplay = s.display;
378 s.visibility = 'hidden'; 381 s.visibility = 'hidden';
379 s.position = 'absolute'; 382 s.position = 'absolute';
380 s.display = self._getDefaultDisplay(elem); 383 s.display = self._getDefaultDisplay(elem);
381 var originalWidth = elem.offsetWidth; 384 var originalWidth = elem.offsetWidth;
382 var originalHeight = elem.offsetHeight; 385 var originalHeight = elem.offsetHeight;
383 s.display = originalDisplay; 386 s.display = originalDisplay;
384 s.position = originalPosition; 387 s.position = originalPosition;
385 s.visibility = originalVisibility; 388 s.visibility = originalVisibility;
386 } else { 389 } else {
387 originalWidth = elem.offsetWidth || 0; 390 originalWidth = elem.offsetWidth || 0;
388 originalHeight = elem.offsetHeight || 0; 391 originalHeight = elem.offsetHeight || 0;
389 } 392 }
390 if (contentSize) { 393 if (contentSize) {
391 var tableCell = 'colSpan' in elem && 'rowSpan' in elem; 394 var tableCell = 'colSpan' in elem && 'rowSpan' in elem;
392 var collapse = (tableCell && elem.parentNode && self.getStyle( 395 var collapse = (tableCell && elem.parentNode && self.getStyle(
393 elem.parentNode, 'borderCollapse') == 'collapse') 396 elem.parentNode, 'borderCollapse') == 'collapse');
394 if (collapse) { 397 if (collapse) {
395 if (/MSIE/.test(navigator.userAgent)) { 398 if (/MSIE/.test(navigator.userAgent)) {
396 var borderLeftQuota = elem.previousSibling? 0.5 : 1; 399 var borderLeftQuota = elem.previousSibling? 0.5 : 1;
397 var borderRightQuota = elem.nextSibling? 0.5 : 1; 400 var borderRightQuota = elem.nextSibling? 0.5 : 1;
398 } 401 }
399 else { 402 else {
400 var borderLeftQuota = 0.5; 403 var borderLeftQuota = 0.5;
401 var borderRightQuota = 0.5; 404 var borderRightQuota = 0.5;
402 } 405 }
403 } else { 406 } else {
404 var borderLeftQuota = 1; 407 var borderLeftQuota = 1;
405 var borderRightQuota = 1; 408 var borderRightQuota = 1;
406 } 409 }
407 originalWidth -= Math.round( 410 originalWidth -= Math.round(
408 (parseFloat(self.getStyle(elem, 'paddingLeft')) || 0) 411 (parseFloat(self.getStyle(elem, 'paddingLeft')) || 0)
409 + (parseFloat(self.getStyle(elem, 'paddingRight')) || 0) 412 + (parseFloat(self.getStyle(elem, 'paddingRight')) || 0)
410 + borderLeftQuota * 413 + borderLeftQuota *
411 (parseFloat(self.getStyle(elem, 'borderLeftWidth')) || 0) 414 (parseFloat(self.getStyle(elem, 'borderLeftWidth')) || 0)
412 + borderRightQuota * 415 + borderRightQuota *
413 (parseFloat(self.getStyle(elem, 'borderRightWidth')) || 0) 416 (parseFloat(self.getStyle(elem, 'borderRightWidth')) || 0)
414 ); 417 );
415 if (tableCell) { 418 if (tableCell) {
416 if (/Gecko|Opera/.test(navigator.userAgent) 419 if (/Gecko|Opera/.test(navigator.userAgent)
417 && !/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent)) { 420 && !/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent)) {
418 var borderHeightQuota = 0; 421 var borderHeightQuota = 0;
419 } else if (/MSIE/.test(navigator.userAgent)) { 422 } else if (/MSIE/.test(navigator.userAgent)) {
420 var borderHeightQuota = 1; 423 var borderHeightQuota = 1;
421 } else { 424 } else {
422 var borderHeightQuota = collapse? 0.5 : 1; 425 var borderHeightQuota = collapse? 0.5 : 1;
423 } 426 }
424 } else { 427 } else {
425 var borderHeightQuota = 1; 428 var borderHeightQuota = 1;
426 } 429 }
427 originalHeight -= Math.round( 430 originalHeight -= Math.round(
428 (parseFloat(self.getStyle(elem, 'paddingTop')) || 0) 431 (parseFloat(self.getStyle(elem, 'paddingTop')) || 0)
429 + (parseFloat(self.getStyle(elem, 'paddingBottom')) || 0) 432 + (parseFloat(self.getStyle(elem, 'paddingBottom')) || 0)
430 + borderHeightQuota * ( 433 + borderHeightQuota * (
431 (parseFloat(self.getStyle(elem, 'borderTopWidth')) || 0) 434 (parseFloat(self.getStyle(elem, 'borderTopWidth')) || 0)
432 + (parseFloat(self.getStyle(elem, 'borderBottomWidth')) || 0)) 435 + (parseFloat(self.getStyle(elem, 'borderBottomWidth')) || 0))
433 ); 436 );
434 } 437 }
435 return new self.Dimensions(originalWidth, originalHeight); 438 return new self.Dimensions(originalWidth, originalHeight);
436 }, 439 },
437 440
438 /** @id MochiKit.Style.setElementDimensions */ 441 /** @id MochiKit.Style.setElementDimensions */
439 setElementDimensions: function (elem, newSize/* optional */, units) { 442 setElementDimensions: function (elem, newSize/* optional */, units) {
440 elem = MochiKit.DOM.getElement(elem); 443 elem = MochiKit.DOM.getElement(elem);
441 if (typeof(units) == 'undefined') { 444 if (typeof(units) == 'undefined') {
442 units = 'px'; 445 units = 'px';
443 } 446 }
444 var newStyle = {}; 447 var newStyle = {};
445 var isUndefNull = MochiKit.Base.isUndefinedOrNull; 448 var isUndefNull = MochiKit.Base.isUndefinedOrNull;
446 if (!isUndefNull(newSize.w)) { 449 if (!isUndefNull(newSize.w)) {
447 newStyle['width'] = newSize.w + units; 450 newStyle['width'] = newSize.w + units;
448 } 451 }
449 if (!isUndefNull(newSize.h)) { 452 if (!isUndefNull(newSize.h)) {
450 newStyle['height'] = newSize.h + units; 453 newStyle['height'] = newSize.h + units;
451 } 454 }
452 MochiKit.DOM.updateNodeAttributes(elem, {'style': newStyle}); 455 MochiKit.DOM.updateNodeAttributes(elem, {'style': newStyle});
453 }, 456 },
454 457
455 _getDefaultDisplay: function (elem) { 458 _getDefaultDisplay: function (elem) {
456 var self = MochiKit.Style; 459 var self = MochiKit.Style;
457 var dom = MochiKit.DOM; 460 var dom = MochiKit.DOM;
458 elem = dom.getElement(elem); 461 elem = dom.getElement(elem);
459 if (!elem) { 462 if (!elem) {
460 return undefined; 463 return undefined;
461 } 464 }
462 var tagName = elem.tagName.toUpperCase(); 465 var tagName = elem.tagName.toUpperCase();
463 return self._defaultDisplay[tagName] || 'block'; 466 return self._defaultDisplay[tagName] || 'block';
464 }, 467 },
465 468
466 /** @id MochiKit.Style.setDisplayForElement */ 469 /** @id MochiKit.Style.setDisplayForElement */
467 setDisplayForElement: function (display, element/*, ...*/) { 470 setDisplayForElement: function (display, element/*, ...*/) {
468 var elements = MochiKit.Base.extend(null, arguments, 1); 471 var elements = MochiKit.Base.extend(null, arguments, 1);
469 var getElement = MochiKit.DOM.getElement; 472 var getElement = MochiKit.DOM.getElement;
470 for (var i = 0; i < elements.length; i++) { 473 for (var i = 0; i < elements.length; i++) {
471 element = getElement(elements[i]); 474 element = getElement(elements[i]);
472 if (element) { 475 if (element) {
473 element.style.display = display; 476 element.style.display = display;
474 } 477 }
475 } 478 }
476 }, 479 },
477 480
478 /** @id MochiKit.Style.getViewportDimensions */ 481 /** @id MochiKit.Style.getViewportDimensions */
479 getViewportDimensions: function () { 482 getViewportDimensions: function () {
480 var d = new MochiKit.Style.Dimensions(); 483 var d = new MochiKit.Style.Dimensions();
481 var w = MochiKit.DOM._window; 484 var w = MochiKit.DOM._window;
482 var b = MochiKit.DOM._document.body; 485 var b = MochiKit.DOM._document.body;
483 if (w.innerWidth) { 486 if (w.innerWidth) {
484 d.w = w.innerWidth; 487 d.w = w.innerWidth;
485 d.h = w.innerHeight; 488 d.h = w.innerHeight;
486 } else if (b && b.parentElement && b.parentElement.clientWidth) { 489 } else if (b && b.parentElement && b.parentElement.clientWidth) {
487 d.w = b.parentElement.clientWidth; 490 d.w = b.parentElement.clientWidth;
488 d.h = b.parentElement.clientHeight; 491 d.h = b.parentElement.clientHeight;
489 } else if (b && b.clientWidth) { 492 } else if (b && b.clientWidth) {
490 d.w = b.clientWidth; 493 d.w = b.clientWidth;
491 d.h = b.clientHeight; 494 d.h = b.clientHeight;
492 } 495 }
493 return d; 496 return d;
494 }, 497 },
495 498
496 /** @id MochiKit.Style.getViewportPosition */ 499 /** @id MochiKit.Style.getViewportPosition */
497 getViewportPosition: function () { 500 getViewportPosition: function () {
498 var c = new MochiKit.Style.Coordinates(0, 0); 501 var c = new MochiKit.Style.Coordinates(0, 0);
499 var d = MochiKit.DOM._document; 502 var d = MochiKit.DOM._document;
500 var de = d.documentElement; 503 var de = d.documentElement;
501 var db = d.body; 504 var db = d.body;
502 if (de && (de.scrollTop || de.scrollLeft)) { 505 if (de && (de.scrollTop || de.scrollLeft)) {
503 c.x = de.scrollLeft; 506 c.x = de.scrollLeft;
504 c.y = de.scrollTop; 507 c.y = de.scrollTop;
505 } else if (db) { 508 } else if (db) {
506 c.x = db.scrollLeft; 509 c.x = db.scrollLeft;
507 c.y = db.scrollTop; 510 c.y = db.scrollTop;
508 } 511 }
509 return c; 512 return c;
510 }, 513 },
511 514
512 __new__: function () { 515 __new__: function () {
513 var m = MochiKit.Base; 516 var m = MochiKit.Base;
514 517
515 var inlines = ['A','ABBR','ACRONYM','B','BASEFONT','BDO','BIG','BR', 518 var inlines = ['A','ABBR','ACRONYM','B','BASEFONT','BDO','BIG','BR',
516 'CITE','CODE','DFN','EM','FONT','I','IMG','KBD','LABEL', 519 'CITE','CODE','DFN','EM','FONT','I','IMG','KBD','LABEL',
517 'Q','S','SAMP','SMALL','SPAN','STRIKE','STRONG','SUB', 520 'Q','S','SAMP','SMALL','SPAN','STRIKE','STRONG','SUB',
518 'SUP','TEXTAREA','TT','U','VAR']; 521 'SUP','TEXTAREA','TT','U','VAR'];
519 this._defaultDisplay = { 'TABLE': 'table', 522 this._defaultDisplay = { 'TABLE': 'table',
520 'THEAD': 'table-header-group', 523 'THEAD': 'table-header-group',
521 'TBODY': 'table-row-group', 524 'TBODY': 'table-row-group',
522 'TFOOT': 'table-footer-group', 525 'TFOOT': 'table-footer-group',
523 'COLGROUP': 'table-column-group', 526 'COLGROUP': 'table-column-group',
524 'COL': 'table-column', 527 'COL': 'table-column',
525 'TR': 'table-row', 528 'TR': 'table-row',
526 'TD': 'table-cell', 529 'TD': 'table-cell',
527 'TH': 'table-cell', 530 'TH': 'table-cell',
528 'CAPTION': 'table-caption', 531 'CAPTION': 'table-caption',
529 'LI': 'list-item', 532 'LI': 'list-item',
530 'INPUT': 'inline-block', 533 'INPUT': 'inline-block',
531 'SELECT': 'inline-block' }; 534 'SELECT': 'inline-block' };
532 // CSS 'display' support in IE6/7 is just broken... 535 // CSS 'display' support in IE6/7 is just broken...
533 if (/MSIE/.test(navigator.userAgent)) { 536 if (/MSIE/.test(navigator.userAgent)) {
534 for (var k in this._defaultDisplay) { 537 for (var k in this._defaultDisplay) {
535 var v = this._defaultDisplay[k]; 538 var v = this._defaultDisplay[k];
536 if (v.indexOf('table') == 0) { 539 if (v.indexOf('table') == 0) {
537 this._defaultDisplay[k] = 'block'; 540 this._defaultDisplay[k] = 'block';
538 } 541 }
539 } 542 }
540 } 543 }
541 for (var i = 0; i < inlines.length; i++) { 544 for (var i = 0; i < inlines.length; i++) {
542 this._defaultDisplay[inlines[i]] = 'inline'; 545 this._defaultDisplay[inlines[i]] = 'inline';
543 } 546 }
544 547
545 // Backwards compatibility aliases 548 // Backwards compatibility aliases
546 m._deprecated(this, 'elementPosition', 'MochiKit.Style.getElementPosition', '1.3'); 549 m._deprecated(this, 'elementPosition', 'MochiKit.Style.getElementPosition', '1.3', true);
547 m._deprecated(this, 'elementDimensions', 'MochiKit.Style.getElementDimensions', '1.3'); 550 m._deprecated(this, 'elementDimensions', 'MochiKit.Style.getElementDimensions', '1.3', true);
548 551
549 this.hideElement = m.partial(this.setDisplayForElement, 'none'); 552 this.hideElement = m.partial(this.setDisplayForElement, 'none');
550 // TODO: showElement could be improved by using getDefaultDisplay. 553 // TODO: showElement could be improved by using getDefaultDisplay.
551 this.showElement = m.partial(this.setDisplayForElement, 'block'); 554 this.showElement = m.partial(this.setDisplayForElement, 'block');
552 555
553 m.nameFunctions(this); 556 m.nameFunctions(this);
554 } 557 }
555}); 558});
556 559
557MochiKit.Style.__new__(); 560MochiKit.Style.__new__();
558MochiKit.Base._exportSymbols(this, MochiKit.Style); 561MochiKit.Base._exportSymbols(this, MochiKit.Style);