testing/mochitest/tests/MochiKit-1.4.2/MochiKit/Style.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial