summaryrefslogtreecommitdiff
path: root/frontend/beta/js/MochiKit/Style.js
Unidiff
Diffstat (limited to 'frontend/beta/js/MochiKit/Style.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/MochiKit/Style.js444
1 files changed, 444 insertions, 0 deletions
diff --git a/frontend/beta/js/MochiKit/Style.js b/frontend/beta/js/MochiKit/Style.js
new file mode 100644
index 0000000..6fdfbfb
--- a/dev/null
+++ b/frontend/beta/js/MochiKit/Style.js
@@ -0,0 +1,444 @@
1/***
2
3MochiKit.Style 1.4
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
11if (typeof(dojo) != 'undefined') {
12 dojo.provide('MochiKit.Style');
13 dojo.require('MochiKit.Base');
14 dojo.require('MochiKit.DOM');
15}
16if (typeof(JSAN) != 'undefined') {
17 JSAN.use('MochiKit.Base', []);
18}
19
20try {
21 if (typeof(MochiKit.Base) == 'undefined') {
22 throw '';
23 }
24} catch (e) {
25 throw 'MochiKit.Style depends on MochiKit.Base!';
26}
27
28try {
29 if (typeof(MochiKit.DOM) == 'undefined') {
30 throw '';
31 }
32} catch (e) {
33 throw 'MochiKit.Style depends on MochiKit.DOM!';
34}
35
36
37if (typeof(MochiKit.Style) == 'undefined') {
38 MochiKit.Style = {};
39}
40
41MochiKit.Style.NAME = 'MochiKit.Style';
42MochiKit.Style.VERSION = '1.4';
43MochiKit.Style.__repr__ = function () {
44 return '[' + this.NAME + ' ' + this.VERSION + ']';
45};
46MochiKit.Style.toString = function () {
47 return this.__repr__();
48};
49
50MochiKit.Style.EXPORT_OK = [];
51
52MochiKit.Style.EXPORT = [
53 'setStyle',
54 'setOpacity',
55 'getStyle',
56 'getElementDimensions',
57 'elementDimensions', // deprecated
58 'setElementDimensions',
59 'getElementPosition',
60 'elementPosition', // deprecated
61 'setElementPosition',
62 'setDisplayForElement',
63 'hideElement',
64 'showElement',
65 'getViewportDimensions',
66 'getViewportPosition',
67 'Dimensions',
68 'Coordinates'
69];
70
71
72/*
73
74 Dimensions
75
76*/
77/** @id MochiKit.Style.Dimensions */
78MochiKit.Style.Dimensions = function (w, h) {
79 this.w = w;
80 this.h = h;
81};
82
83MochiKit.Style.Dimensions.prototype.__repr__ = function () {
84 var repr = MochiKit.Base.repr;
85 return '{w: ' + repr(this.w) + ', h: ' + repr(this.h) + '}';
86};
87
88MochiKit.Style.Dimensions.prototype.toString = function () {
89 return this.__repr__();
90};
91
92
93/*
94
95 Coordinates
96
97*/
98/** @id MochiKit.Style.Coordinates */
99MochiKit.Style.Coordinates = function (x, y) {
100 this.x = x;
101 this.y = y;
102};
103
104MochiKit.Style.Coordinates.prototype.__repr__ = function () {
105 var repr = MochiKit.Base.repr;
106 return '{x: ' + repr(this.x) + ', y: ' + repr(this.y) + '}';
107};
108
109MochiKit.Style.Coordinates.prototype.toString = function () {
110 return this.__repr__();
111};
112
113
114MochiKit.Base.update(MochiKit.Style, {
115
116 /** @id MochiKit.Style.getStyle */
117 getStyle: function (elem, cssProperty) {
118 var dom = MochiKit.DOM;
119 var d = dom._document;
120
121 elem = dom.getElement(elem);
122 cssProperty = MochiKit.Base.camelize(cssProperty);
123
124 if (!elem || elem == d) {
125 return undefined;
126 }
127 if (cssProperty == 'opacity' && elem.filters) {
128 var opacity = (MochiKit.Style.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/);
129 if (opacity && opacity[1]) {
130 return parseFloat(opacity[1]) / 100;
131 }
132 return 1.0;
133 }
134 var value = elem.style ? elem.style[cssProperty] : null;
135 if (!value) {
136 if (d.defaultView && d.defaultView.getComputedStyle) {
137 var css = d.defaultView.getComputedStyle(elem, null);
138 cssProperty = cssProperty.replace(/([A-Z])/g, '-$1'
139 ).toLowerCase(); // from dojo.style.toSelectorCase
140 value = css ? css.getPropertyValue(cssProperty) : null;
141 } else if (elem.currentStyle) {
142 value = elem.currentStyle[cssProperty];
143 }
144 }
145 if (cssProperty == 'opacity') {
146 value = parseFloat(value);
147 }
148
149 if (/Opera/.test(navigator.userAgent) && (MochiKit.Base.find(['left', 'top', 'right', 'bottom'], cssProperty) != -1)) {
150 if (MochiKit.Style.getStyle(elem, 'position') == 'static') {
151 value = 'auto';
152 }
153 }
154
155 return value == 'auto' ? null : value;
156 },
157
158 /** @id MochiKit.Style.setStyle */
159 setStyle: function (elem, style) {
160 elem = MochiKit.DOM.getElement(elem);
161 for (name in style) {
162 if (name == 'opacity') {
163 MochiKit.Style.setOpacity(elem, style[name]);
164 } else {
165 elem.style[MochiKit.Base.camelize(name)] = style[name];
166 }
167 }
168 },
169
170 /** @id MochiKit.Style.setOpacity */
171 setOpacity: function (elem, o) {
172 elem = MochiKit.DOM.getElement(elem);
173 var self = MochiKit.Style;
174 if (o == 1) {
175 var toSet = /Gecko/.test(navigator.userAgent) && !(/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent));
176 elem.style["opacity"] = toSet ? 0.999999 : 1.0;
177 if (/MSIE/.test(navigator.userAgent)) {
178 elem.style['filter'] =
179 self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '');
180 }
181 } else {
182 if (o < 0.00001) {
183 o = 0;
184 }
185 elem.style["opacity"] = o;
186 if (/MSIE/.test(navigator.userAgent)) {
187 elem.style['filter'] =
188 self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')';
189 }
190 }
191 },
192
193 /*
194
195 getElementPosition is adapted from YAHOO.util.Dom.getXY v0.9.0.
196 Copyright: Copyright (c) 2006, Yahoo! Inc. All rights reserved.
197 License: BSD, http://developer.yahoo.net/yui/license.txt
198
199 */
200
201 /** @id MochiKit.Style.getElementPosition */
202 getElementPosition: function (elem, /* optional */relativeTo) {
203 var self = MochiKit.Style;
204 var dom = MochiKit.DOM;
205 elem = dom.getElement(elem);
206
207 if (!elem ||
208 (!(elem.x && elem.y) &&
209 (!elem.parentNode === null ||
210 self.getStyle(elem, 'display') == 'none'))) {
211 return undefined;
212 }
213
214 var c = new self.Coordinates(0, 0);
215 var box = null;
216 var parent = null;
217
218 var d = MochiKit.DOM._document;
219 var de = d.documentElement;
220 var b = d.body;
221
222 if (!elem.parentNode && elem.x && elem.y) {
223 /* it's just a MochiKit.Style.Coordinates object */
224 c.x += elem.x || 0;
225 c.y += elem.y || 0;
226 } else if (elem.getBoundingClientRect) { // IE shortcut
227 /*
228
229 The IE shortcut can be off by two. We fix it. See:
230 http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getboundingclientrect.asp
231
232 This is similar to the method used in
233 MochiKit.Signal.Event.mouse().
234
235 */
236 box = elem.getBoundingClientRect();
237
238 c.x += box.left +
239 (de.scrollLeft || b.scrollLeft) -
240 (de.clientLeft || 0);
241
242 c.y += box.top +
243 (de.scrollTop || b.scrollTop) -
244 (de.clientTop || 0);
245
246 } else if (elem.offsetParent) {
247 c.x += elem.offsetLeft;
248 c.y += elem.offsetTop;
249 parent = elem.offsetParent;
250
251 if (parent != elem) {
252 while (parent) {
253 c.x += parent.offsetLeft;
254 c.y += parent.offsetTop;
255 parent = parent.offsetParent;
256 }
257 }
258
259 /*
260
261 Opera < 9 and old Safari (absolute) incorrectly account for
262 body offsetTop and offsetLeft.
263
264 */
265 var ua = navigator.userAgent.toLowerCase();
266 if ((typeof(opera) != 'undefined' &&
267 parseFloat(opera.version()) < 9) ||
268 (ua.indexOf('AppleWebKit') != -1 &&
269 self.getStyle(elem, 'position') == 'absolute')) {
270
271 c.x -= b.offsetLeft;
272 c.y -= b.offsetTop;
273
274 }
275 }
276
277 if (typeof(relativeTo) != 'undefined') {
278 relativeTo = arguments.callee(relativeTo);
279 if (relativeTo) {
280 c.x -= (relativeTo.x || 0);
281 c.y -= (relativeTo.y || 0);
282 }
283 }
284
285 if (elem.parentNode) {
286 parent = elem.parentNode;
287 } else {
288 parent = null;
289 }
290
291 while (parent) {
292 var tagName = parent.tagName.toUpperCase();
293 if (tagName === 'BODY' || tagName === 'HTML') {
294 break;
295 }
296 var disp = self.getStyle(parent, 'display');
297 // Handle strange Opera bug for some display
298 if (disp != 'inline' && disp != 'table-row') {
299 c.x -= parent.scrollLeft;
300 c.y -= parent.scrollTop;
301 }
302 if (parent.parentNode) {
303 parent = parent.parentNode;
304 } else {
305 parent = null;
306 }
307 }
308
309 return c;
310 },
311
312 /** @id MochiKit.Style.setElementPosition */
313 setElementPosition: function (elem, newPos/* optional */, units) {
314 elem = MochiKit.DOM.getElement(elem);
315 if (typeof(units) == 'undefined') {
316 units = 'px';
317 }
318 var newStyle = {};
319 var isUndefNull = MochiKit.Base.isUndefinedOrNull;
320 if (!isUndefNull(newPos.x)) {
321 newStyle['left'] = newPos.x + units;
322 }
323 if (!isUndefNull(newPos.y)) {
324 newStyle['top'] = newPos.y + units;
325 }
326 MochiKit.DOM.updateNodeAttributes(elem, {'style': newStyle});
327 },
328
329 /** @id MochiKit.Style.getElementDimensions */
330 getElementDimensions: function (elem) {
331 var self = MochiKit.Style;
332 var dom = MochiKit.DOM;
333 if (typeof(elem.w) == 'number' || typeof(elem.h) == 'number') {
334 return new self.Dimensions(elem.w || 0, elem.h || 0);
335 }
336 elem = dom.getElement(elem);
337 if (!elem) {
338 return undefined;
339 }
340 var disp = self.getStyle(elem, 'display');
341 // display can be empty/undefined on WebKit/KHTML
342 if (disp != 'none' && disp !== '' && typeof(disp) != 'undefined') {
343 return new self.Dimensions(elem.offsetWidth || 0,
344 elem.offsetHeight || 0);
345 }
346 var s = elem.style;
347 var originalVisibility = s.visibility;
348 var originalPosition = s.position;
349 s.visibility = 'hidden';
350 s.position = 'absolute';
351 s.display = '';
352 var originalWidth = elem.offsetWidth;
353 var originalHeight = elem.offsetHeight;
354 s.display = 'none';
355 s.position = originalPosition;
356 s.visibility = originalVisibility;
357 return new self.Dimensions(originalWidth, originalHeight);
358 },
359
360 /** @id MochiKit.Style.setElementDimensions */
361 setElementDimensions: function (elem, newSize/* optional */, units) {
362 elem = MochiKit.DOM.getElement(elem);
363 if (typeof(units) == 'undefined') {
364 units = 'px';
365 }
366 var newStyle = {};
367 var isUndefNull = MochiKit.Base.isUndefinedOrNull;
368 if (!isUndefNull(newSize.w)) {
369 newStyle['width'] = newSize.w + units;
370 }
371 if (!isUndefNull(newSize.h)) {
372 newStyle['height'] = newSize.h + units;
373 }
374 MochiKit.DOM.updateNodeAttributes(elem, {'style': newStyle});
375 },
376
377 /** @id MochiKit.Style.setDisplayForElement */
378 setDisplayForElement: function (display, element/*, ...*/) {
379 var elements = MochiKit.Base.extend(null, arguments, 1);
380 var getElement = MochiKit.DOM.getElement;
381 for (var i = 0; i < elements.length; i++) {
382 element = getElement(elements[i]);
383 if (element) {
384 element.style.display = display;
385 }
386 }
387 },
388
389 /** @id MochiKit.Style.getViewportDimensions */
390 getViewportDimensions: function () {
391 var d = new MochiKit.Style.Dimensions();
392
393 var w = MochiKit.DOM._window;
394 var b = MochiKit.DOM._document.body;
395
396 if (w.innerWidth) {
397 d.w = w.innerWidth;
398 d.h = w.innerHeight;
399 } else if (b.parentElement.clientWidth) {
400 d.w = b.parentElement.clientWidth;
401 d.h = b.parentElement.clientHeight;
402 } else if (b && b.clientWidth) {
403 d.w = b.clientWidth;
404 d.h = b.clientHeight;
405 }
406 return d;
407 },
408
409 /** @id MochiKit.Style.getViewportPosition */
410 getViewportPosition: function () {
411 var c = new MochiKit.Style.Coordinates(0, 0);
412 var d = MochiKit.DOM._document;
413 var de = d.documentElement;
414 var db = d.body;
415 if (de && (de.scrollTop || de.scrollLeft)) {
416 c.x = de.scrollLeft;
417 c.y = de.scrollTop;
418 } else if (db) {
419 c.x = db.scrollLeft;
420 c.y = db.scrollTop;
421 }
422 return c;
423 },
424
425 __new__: function () {
426 var m = MochiKit.Base;
427
428 this.elementPosition = this.getElementPosition;
429 this.elementDimensions = this.getElementDimensions;
430
431 this.hideElement = m.partial(this.setDisplayForElement, 'none');
432 this.showElement = m.partial(this.setDisplayForElement, 'block');
433
434 this.EXPORT_TAGS = {
435 ':common': this.EXPORT,
436 ':all': m.concat(this.EXPORT, this.EXPORT_OK)
437 };
438
439 m.nameFunctions(this);
440 }
441});
442
443MochiKit.Style.__new__();
444MochiKit.Base._exportSymbols(this, MochiKit.Style);