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