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