Commit 4497885029291bf1f1d9eddf8ebedccabfa8aad0
1 parent
fc28454f
KTS-3831
"Upgrade ExtJS to 2.2" Adding Source Folder Committed By: Tohir Solomons Reviewed By: Megan Watson git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9759 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
13 changed files
with
12028 additions
and
0 deletions
thirdpartyjs/extjs/source/adapter/ext-base.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +(function() { | |
| 10 | + var libFlyweight; | |
| 11 | + | |
| 12 | + Ext.lib.Dom = { | |
| 13 | + getViewWidth : function(full) { | |
| 14 | + return full ? this.getDocumentWidth() : this.getViewportWidth(); | |
| 15 | + }, | |
| 16 | + | |
| 17 | + getViewHeight : function(full) { | |
| 18 | + return full ? this.getDocumentHeight() : this.getViewportHeight(); | |
| 19 | + }, | |
| 20 | + | |
| 21 | + getDocumentHeight: function() { | |
| 22 | + var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight; | |
| 23 | + return Math.max(scrollHeight, this.getViewportHeight()); | |
| 24 | + }, | |
| 25 | + | |
| 26 | + getDocumentWidth: function() { | |
| 27 | + var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth; | |
| 28 | + return Math.max(scrollWidth, this.getViewportWidth()); | |
| 29 | + }, | |
| 30 | + | |
| 31 | + getViewportHeight: function(){ | |
| 32 | + if(Ext.isIE){ | |
| 33 | + return Ext.isStrict ? document.documentElement.clientHeight : | |
| 34 | + document.body.clientHeight; | |
| 35 | + }else{ | |
| 36 | + return self.innerHeight; | |
| 37 | + } | |
| 38 | + }, | |
| 39 | + | |
| 40 | + getViewportWidth: function() { | |
| 41 | + if(Ext.isIE){ | |
| 42 | + return Ext.isStrict ? document.documentElement.clientWidth : | |
| 43 | + document.body.clientWidth; | |
| 44 | + }else{ | |
| 45 | + return self.innerWidth; | |
| 46 | + } | |
| 47 | + }, | |
| 48 | + | |
| 49 | + isAncestor : function(p, c) { | |
| 50 | + p = Ext.getDom(p); | |
| 51 | + c = Ext.getDom(c); | |
| 52 | + if (!p || !c) { | |
| 53 | + return false; | |
| 54 | + } | |
| 55 | + | |
| 56 | + if (p.contains && !Ext.isSafari) { | |
| 57 | + return p.contains(c); | |
| 58 | + } else if (p.compareDocumentPosition) { | |
| 59 | + return !!(p.compareDocumentPosition(c) & 16); | |
| 60 | + } else { | |
| 61 | + var parent = c.parentNode; | |
| 62 | + while (parent) { | |
| 63 | + if (parent == p) { | |
| 64 | + return true; | |
| 65 | + } | |
| 66 | + else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") { | |
| 67 | + return false; | |
| 68 | + } | |
| 69 | + parent = parent.parentNode; | |
| 70 | + } | |
| 71 | + return false; | |
| 72 | + } | |
| 73 | + }, | |
| 74 | + | |
| 75 | + getRegion : function(el) { | |
| 76 | + return Ext.lib.Region.getRegion(el); | |
| 77 | + }, | |
| 78 | + | |
| 79 | + getY : function(el) { | |
| 80 | + return this.getXY(el)[1]; | |
| 81 | + }, | |
| 82 | + | |
| 83 | + getX : function(el) { | |
| 84 | + return this.getXY(el)[0]; | |
| 85 | + }, | |
| 86 | + | |
| 87 | + | |
| 88 | + getXY : function(el) { | |
| 89 | + var p, pe, b, scroll, bd = (document.body || document.documentElement); | |
| 90 | + el = Ext.getDom(el); | |
| 91 | + | |
| 92 | + if(el == bd){ | |
| 93 | + return [0, 0]; | |
| 94 | + } | |
| 95 | + | |
| 96 | + if (el.getBoundingClientRect) { | |
| 97 | + b = el.getBoundingClientRect(); | |
| 98 | + scroll = fly(document).getScroll(); | |
| 99 | + return [b.left + scroll.left, b.top + scroll.top]; | |
| 100 | + } | |
| 101 | + var x = 0, y = 0; | |
| 102 | + | |
| 103 | + p = el; | |
| 104 | + | |
| 105 | + var hasAbsolute = fly(el).getStyle("position") == "absolute"; | |
| 106 | + | |
| 107 | + while (p) { | |
| 108 | + | |
| 109 | + x += p.offsetLeft; | |
| 110 | + y += p.offsetTop; | |
| 111 | + | |
| 112 | + if (!hasAbsolute && fly(p).getStyle("position") == "absolute") { | |
| 113 | + hasAbsolute = true; | |
| 114 | + } | |
| 115 | + | |
| 116 | + if (Ext.isGecko) { | |
| 117 | + pe = fly(p); | |
| 118 | + | |
| 119 | + var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0; | |
| 120 | + var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0; | |
| 121 | + | |
| 122 | + | |
| 123 | + x += bl; | |
| 124 | + y += bt; | |
| 125 | + | |
| 126 | + | |
| 127 | + if (p != el && pe.getStyle('overflow') != 'visible') { | |
| 128 | + x += bl; | |
| 129 | + y += bt; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + p = p.offsetParent; | |
| 133 | + } | |
| 134 | + | |
| 135 | + if (Ext.isSafari && hasAbsolute) { | |
| 136 | + x -= bd.offsetLeft; | |
| 137 | + y -= bd.offsetTop; | |
| 138 | + } | |
| 139 | + | |
| 140 | + if (Ext.isGecko && !hasAbsolute) { | |
| 141 | + var dbd = fly(bd); | |
| 142 | + x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0; | |
| 143 | + y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0; | |
| 144 | + } | |
| 145 | + | |
| 146 | + p = el.parentNode; | |
| 147 | + while (p && p != bd) { | |
| 148 | + if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) { | |
| 149 | + x -= p.scrollLeft; | |
| 150 | + y -= p.scrollTop; | |
| 151 | + } | |
| 152 | + p = p.parentNode; | |
| 153 | + } | |
| 154 | + return [x, y]; | |
| 155 | + }, | |
| 156 | + | |
| 157 | + setXY : function(el, xy) { | |
| 158 | + el = Ext.fly(el, '_setXY'); | |
| 159 | + el.position(); | |
| 160 | + var pts = el.translatePoints(xy); | |
| 161 | + if (xy[0] !== false) { | |
| 162 | + el.dom.style.left = pts.left + "px"; | |
| 163 | + } | |
| 164 | + if (xy[1] !== false) { | |
| 165 | + el.dom.style.top = pts.top + "px"; | |
| 166 | + } | |
| 167 | + }, | |
| 168 | + | |
| 169 | + setX : function(el, x) { | |
| 170 | + this.setXY(el, [x, false]); | |
| 171 | + }, | |
| 172 | + | |
| 173 | + setY : function(el, y) { | |
| 174 | + this.setXY(el, [false, y]); | |
| 175 | + } | |
| 176 | + }; | |
| 177 | + | |
| 178 | +/* | |
| 179 | + * Portions of this file are based on pieces of Yahoo User Interface Library | |
| 180 | + * Copyright (c) 2007, Yahoo! Inc. All rights reserved. | |
| 181 | + * YUI licensed under the BSD License: | |
| 182 | + * http://developer.yahoo.net/yui/license.txt | |
| 183 | + */ | |
| 184 | + Ext.lib.Event = function() { | |
| 185 | + var loadComplete = false; | |
| 186 | + var listeners = []; | |
| 187 | + var unloadListeners = []; | |
| 188 | + var retryCount = 0; | |
| 189 | + var onAvailStack = []; | |
| 190 | + var counter = 0; | |
| 191 | + var lastError = null; | |
| 192 | + | |
| 193 | + return { | |
| 194 | + POLL_RETRYS: 200, | |
| 195 | + POLL_INTERVAL: 20, | |
| 196 | + EL: 0, | |
| 197 | + TYPE: 1, | |
| 198 | + FN: 2, | |
| 199 | + WFN: 3, | |
| 200 | + OBJ: 3, | |
| 201 | + ADJ_SCOPE: 4, | |
| 202 | + _interval: null, | |
| 203 | + | |
| 204 | + startInterval: function() { | |
| 205 | + if (!this._interval) { | |
| 206 | + var self = this; | |
| 207 | + var callback = function() { | |
| 208 | + self._tryPreloadAttach(); | |
| 209 | + }; | |
| 210 | + this._interval = setInterval(callback, this.POLL_INTERVAL); | |
| 211 | + | |
| 212 | + } | |
| 213 | + }, | |
| 214 | + | |
| 215 | + onAvailable: function(p_id, p_fn, p_obj, p_override) { | |
| 216 | + onAvailStack.push({ id: p_id, | |
| 217 | + fn: p_fn, | |
| 218 | + obj: p_obj, | |
| 219 | + override: p_override, | |
| 220 | + checkReady: false }); | |
| 221 | + | |
| 222 | + retryCount = this.POLL_RETRYS; | |
| 223 | + this.startInterval(); | |
| 224 | + }, | |
| 225 | + | |
| 226 | + | |
| 227 | + addListener: function(el, eventName, fn) { | |
| 228 | + el = Ext.getDom(el); | |
| 229 | + if (!el || !fn) { | |
| 230 | + return false; | |
| 231 | + } | |
| 232 | + | |
| 233 | + if ("unload" == eventName) { | |
| 234 | + unloadListeners[unloadListeners.length] = | |
| 235 | + [el, eventName, fn]; | |
| 236 | + return true; | |
| 237 | + } | |
| 238 | + | |
| 239 | + // prevent unload errors with simple check | |
| 240 | + var wrappedFn = function(e) { | |
| 241 | + return typeof Ext != 'undefined' ? fn(Ext.lib.Event.getEvent(e)) : false; | |
| 242 | + }; | |
| 243 | + | |
| 244 | + var li = [el, eventName, fn, wrappedFn]; | |
| 245 | + | |
| 246 | + var index = listeners.length; | |
| 247 | + listeners[index] = li; | |
| 248 | + | |
| 249 | + this.doAdd(el, eventName, wrappedFn, false); | |
| 250 | + return true; | |
| 251 | + | |
| 252 | + }, | |
| 253 | + | |
| 254 | + | |
| 255 | + removeListener: function(el, eventName, fn) { | |
| 256 | + var i, len; | |
| 257 | + | |
| 258 | + el = Ext.getDom(el); | |
| 259 | + | |
| 260 | + if(!fn) { | |
| 261 | + return this.purgeElement(el, false, eventName); | |
| 262 | + } | |
| 263 | + | |
| 264 | + | |
| 265 | + if ("unload" == eventName) { | |
| 266 | + | |
| 267 | + for (i = 0,len = unloadListeners.length; i < len; i++) { | |
| 268 | + var li = unloadListeners[i]; | |
| 269 | + if (li && | |
| 270 | + li[0] == el && | |
| 271 | + li[1] == eventName && | |
| 272 | + li[2] == fn) { | |
| 273 | + unloadListeners.splice(i, 1); | |
| 274 | + return true; | |
| 275 | + } | |
| 276 | + } | |
| 277 | + | |
| 278 | + return false; | |
| 279 | + } | |
| 280 | + | |
| 281 | + var cacheItem = null; | |
| 282 | + | |
| 283 | + | |
| 284 | + var index = arguments[3]; | |
| 285 | + | |
| 286 | + if ("undefined" == typeof index) { | |
| 287 | + index = this._getCacheIndex(el, eventName, fn); | |
| 288 | + } | |
| 289 | + | |
| 290 | + if (index >= 0) { | |
| 291 | + cacheItem = listeners[index]; | |
| 292 | + } | |
| 293 | + | |
| 294 | + if (!el || !cacheItem) { | |
| 295 | + return false; | |
| 296 | + } | |
| 297 | + | |
| 298 | + this.doRemove(el, eventName, cacheItem[this.WFN], false); | |
| 299 | + | |
| 300 | + delete listeners[index][this.WFN]; | |
| 301 | + delete listeners[index][this.FN]; | |
| 302 | + listeners.splice(index, 1); | |
| 303 | + | |
| 304 | + return true; | |
| 305 | + | |
| 306 | + }, | |
| 307 | + | |
| 308 | + | |
| 309 | + getTarget: function(ev, resolveTextNode) { | |
| 310 | + ev = ev.browserEvent || ev; | |
| 311 | + var t = ev.target || ev.srcElement; | |
| 312 | + return this.resolveTextNode(t); | |
| 313 | + }, | |
| 314 | + | |
| 315 | + | |
| 316 | + resolveTextNode: function(node) { | |
| 317 | + if (Ext.isSafari && node && 3 == node.nodeType) { | |
| 318 | + return node.parentNode; | |
| 319 | + } else { | |
| 320 | + return node; | |
| 321 | + } | |
| 322 | + }, | |
| 323 | + | |
| 324 | + | |
| 325 | + getPageX: function(ev) { | |
| 326 | + ev = ev.browserEvent || ev; | |
| 327 | + var x = ev.pageX; | |
| 328 | + if (!x && 0 !== x) { | |
| 329 | + x = ev.clientX || 0; | |
| 330 | + | |
| 331 | + if (Ext.isIE) { | |
| 332 | + x += this.getScroll()[1]; | |
| 333 | + } | |
| 334 | + } | |
| 335 | + | |
| 336 | + return x; | |
| 337 | + }, | |
| 338 | + | |
| 339 | + | |
| 340 | + getPageY: function(ev) { | |
| 341 | + ev = ev.browserEvent || ev; | |
| 342 | + var y = ev.pageY; | |
| 343 | + if (!y && 0 !== y) { | |
| 344 | + y = ev.clientY || 0; | |
| 345 | + | |
| 346 | + if (Ext.isIE) { | |
| 347 | + y += this.getScroll()[0]; | |
| 348 | + } | |
| 349 | + } | |
| 350 | + | |
| 351 | + | |
| 352 | + return y; | |
| 353 | + }, | |
| 354 | + | |
| 355 | + | |
| 356 | + getXY: function(ev) { | |
| 357 | + ev = ev.browserEvent || ev; | |
| 358 | + return [this.getPageX(ev), this.getPageY(ev)]; | |
| 359 | + }, | |
| 360 | + | |
| 361 | + | |
| 362 | + getRelatedTarget: function(ev) { | |
| 363 | + ev = ev.browserEvent || ev; | |
| 364 | + var t = ev.relatedTarget; | |
| 365 | + if (!t) { | |
| 366 | + if (ev.type == "mouseout") { | |
| 367 | + t = ev.toElement; | |
| 368 | + } else if (ev.type == "mouseover") { | |
| 369 | + t = ev.fromElement; | |
| 370 | + } | |
| 371 | + } | |
| 372 | + | |
| 373 | + return this.resolveTextNode(t); | |
| 374 | + }, | |
| 375 | + | |
| 376 | + | |
| 377 | + getTime: function(ev) { | |
| 378 | + ev = ev.browserEvent || ev; | |
| 379 | + if (!ev.time) { | |
| 380 | + var t = new Date().getTime(); | |
| 381 | + try { | |
| 382 | + ev.time = t; | |
| 383 | + } catch(ex) { | |
| 384 | + this.lastError = ex; | |
| 385 | + return t; | |
| 386 | + } | |
| 387 | + } | |
| 388 | + | |
| 389 | + return ev.time; | |
| 390 | + }, | |
| 391 | + | |
| 392 | + | |
| 393 | + stopEvent: function(ev) { | |
| 394 | + this.stopPropagation(ev); | |
| 395 | + this.preventDefault(ev); | |
| 396 | + }, | |
| 397 | + | |
| 398 | + | |
| 399 | + stopPropagation: function(ev) { | |
| 400 | + ev = ev.browserEvent || ev; | |
| 401 | + if (ev.stopPropagation) { | |
| 402 | + ev.stopPropagation(); | |
| 403 | + } else { | |
| 404 | + ev.cancelBubble = true; | |
| 405 | + } | |
| 406 | + }, | |
| 407 | + | |
| 408 | + | |
| 409 | + preventDefault: function(ev) { | |
| 410 | + ev = ev.browserEvent || ev; | |
| 411 | + if(ev.preventDefault) { | |
| 412 | + ev.preventDefault(); | |
| 413 | + } else { | |
| 414 | + ev.returnValue = false; | |
| 415 | + } | |
| 416 | + }, | |
| 417 | + | |
| 418 | + | |
| 419 | + getEvent: function(e) { | |
| 420 | + var ev = e || window.event; | |
| 421 | + if (!ev) { | |
| 422 | + var c = this.getEvent.caller; | |
| 423 | + while (c) { | |
| 424 | + ev = c.arguments[0]; | |
| 425 | + if (ev && Event == ev.constructor) { | |
| 426 | + break; | |
| 427 | + } | |
| 428 | + c = c.caller; | |
| 429 | + } | |
| 430 | + } | |
| 431 | + return ev; | |
| 432 | + }, | |
| 433 | + | |
| 434 | + | |
| 435 | + getCharCode: function(ev) { | |
| 436 | + ev = ev.browserEvent || ev; | |
| 437 | + return ev.charCode || ev.keyCode || 0; | |
| 438 | + }, | |
| 439 | + | |
| 440 | + | |
| 441 | + _getCacheIndex: function(el, eventName, fn) { | |
| 442 | + for (var i = 0,len = listeners.length; i < len; ++i) { | |
| 443 | + var li = listeners[i]; | |
| 444 | + if (li && | |
| 445 | + li[this.FN] == fn && | |
| 446 | + li[this.EL] == el && | |
| 447 | + li[this.TYPE] == eventName) { | |
| 448 | + return i; | |
| 449 | + } | |
| 450 | + } | |
| 451 | + | |
| 452 | + return -1; | |
| 453 | + }, | |
| 454 | + | |
| 455 | + | |
| 456 | + elCache: {}, | |
| 457 | + | |
| 458 | + | |
| 459 | + getEl: function(id) { | |
| 460 | + return document.getElementById(id); | |
| 461 | + }, | |
| 462 | + | |
| 463 | + | |
| 464 | + clearCache: function() { | |
| 465 | + }, | |
| 466 | + | |
| 467 | + | |
| 468 | + _load: function(e) { | |
| 469 | + loadComplete = true; | |
| 470 | + var EU = Ext.lib.Event; | |
| 471 | + | |
| 472 | + | |
| 473 | + if (Ext.isIE) { | |
| 474 | + EU.doRemove(window, "load", EU._load); | |
| 475 | + } | |
| 476 | + }, | |
| 477 | + | |
| 478 | + | |
| 479 | + _tryPreloadAttach: function() { | |
| 480 | + | |
| 481 | + if (this.locked) { | |
| 482 | + return false; | |
| 483 | + } | |
| 484 | + | |
| 485 | + this.locked = true; | |
| 486 | + | |
| 487 | + | |
| 488 | + var tryAgain = !loadComplete; | |
| 489 | + if (!tryAgain) { | |
| 490 | + tryAgain = (retryCount > 0); | |
| 491 | + } | |
| 492 | + | |
| 493 | + | |
| 494 | + var notAvail = []; | |
| 495 | + for (var i = 0,len = onAvailStack.length; i < len; ++i) { | |
| 496 | + var item = onAvailStack[i]; | |
| 497 | + if (item) { | |
| 498 | + var el = this.getEl(item.id); | |
| 499 | + | |
| 500 | + if (el) { | |
| 501 | + if (!item.checkReady || | |
| 502 | + loadComplete || | |
| 503 | + el.nextSibling || | |
| 504 | + (document && document.body)) { | |
| 505 | + | |
| 506 | + var scope = el; | |
| 507 | + if (item.override) { | |
| 508 | + if (item.override === true) { | |
| 509 | + scope = item.obj; | |
| 510 | + } else { | |
| 511 | + scope = item.override; | |
| 512 | + } | |
| 513 | + } | |
| 514 | + item.fn.call(scope, item.obj); | |
| 515 | + onAvailStack[i] = null; | |
| 516 | + } | |
| 517 | + } else { | |
| 518 | + notAvail.push(item); | |
| 519 | + } | |
| 520 | + } | |
| 521 | + } | |
| 522 | + | |
| 523 | + retryCount = (notAvail.length === 0) ? 0 : retryCount - 1; | |
| 524 | + | |
| 525 | + if (tryAgain) { | |
| 526 | + | |
| 527 | + this.startInterval(); | |
| 528 | + } else { | |
| 529 | + clearInterval(this._interval); | |
| 530 | + this._interval = null; | |
| 531 | + } | |
| 532 | + | |
| 533 | + this.locked = false; | |
| 534 | + | |
| 535 | + return true; | |
| 536 | + | |
| 537 | + }, | |
| 538 | + | |
| 539 | + | |
| 540 | + purgeElement: function(el, recurse, eventName) { | |
| 541 | + var elListeners = this.getListeners(el, eventName); | |
| 542 | + if (elListeners) { | |
| 543 | + for (var i = 0,len = elListeners.length; i < len; ++i) { | |
| 544 | + var l = elListeners[i]; | |
| 545 | + this.removeListener(el, l.type, l.fn); | |
| 546 | + } | |
| 547 | + } | |
| 548 | + | |
| 549 | + if (recurse && el && el.childNodes) { | |
| 550 | + for (i = 0,len = el.childNodes.length; i < len; ++i) { | |
| 551 | + this.purgeElement(el.childNodes[i], recurse, eventName); | |
| 552 | + } | |
| 553 | + } | |
| 554 | + }, | |
| 555 | + | |
| 556 | + | |
| 557 | + getListeners: function(el, eventName) { | |
| 558 | + var results = [], searchLists; | |
| 559 | + if (!eventName) { | |
| 560 | + searchLists = [listeners, unloadListeners]; | |
| 561 | + } else if (eventName == "unload") { | |
| 562 | + searchLists = [unloadListeners]; | |
| 563 | + } else { | |
| 564 | + searchLists = [listeners]; | |
| 565 | + } | |
| 566 | + | |
| 567 | + for (var j = 0; j < searchLists.length; ++j) { | |
| 568 | + var searchList = searchLists[j]; | |
| 569 | + if (searchList && searchList.length > 0) { | |
| 570 | + for (var i = 0,len = searchList.length; i < len; ++i) { | |
| 571 | + var l = searchList[i]; | |
| 572 | + if (l && l[this.EL] === el && | |
| 573 | + (!eventName || eventName === l[this.TYPE])) { | |
| 574 | + results.push({ | |
| 575 | + type: l[this.TYPE], | |
| 576 | + fn: l[this.FN], | |
| 577 | + obj: l[this.OBJ], | |
| 578 | + adjust: l[this.ADJ_SCOPE], | |
| 579 | + index: i | |
| 580 | + }); | |
| 581 | + } | |
| 582 | + } | |
| 583 | + } | |
| 584 | + } | |
| 585 | + | |
| 586 | + return (results.length) ? results : null; | |
| 587 | + }, | |
| 588 | + | |
| 589 | + | |
| 590 | + _unload: function(e) { | |
| 591 | + | |
| 592 | + var EU = Ext.lib.Event, i, j, l, len, index; | |
| 593 | + | |
| 594 | + for (i = 0,len = unloadListeners.length; i < len; ++i) { | |
| 595 | + l = unloadListeners[i]; | |
| 596 | + if (l) { | |
| 597 | + var scope = window; | |
| 598 | + if (l[EU.ADJ_SCOPE]) { | |
| 599 | + if (l[EU.ADJ_SCOPE] === true) { | |
| 600 | + scope = l[EU.OBJ]; | |
| 601 | + } else { | |
| 602 | + scope = l[EU.ADJ_SCOPE]; | |
| 603 | + } | |
| 604 | + } | |
| 605 | + l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]); | |
| 606 | + unloadListeners[i] = null; | |
| 607 | + l = null; | |
| 608 | + scope = null; | |
| 609 | + } | |
| 610 | + } | |
| 611 | + | |
| 612 | + unloadListeners = null; | |
| 613 | + | |
| 614 | + if (listeners && listeners.length > 0) { | |
| 615 | + j = listeners.length; | |
| 616 | + while (j) { | |
| 617 | + index = j - 1; | |
| 618 | + l = listeners[index]; | |
| 619 | + if (l) { | |
| 620 | + EU.removeListener(l[EU.EL], l[EU.TYPE], | |
| 621 | + l[EU.FN], index); | |
| 622 | + } | |
| 623 | + j = j - 1; | |
| 624 | + } | |
| 625 | + l = null; | |
| 626 | + | |
| 627 | + EU.clearCache(); | |
| 628 | + } | |
| 629 | + | |
| 630 | + EU.doRemove(window, "unload", EU._unload); | |
| 631 | + | |
| 632 | + }, | |
| 633 | + | |
| 634 | + | |
| 635 | + getScroll: function() { | |
| 636 | + var dd = document.documentElement, db = document.body; | |
| 637 | + if (dd && (dd.scrollTop || dd.scrollLeft)) { | |
| 638 | + return [dd.scrollTop, dd.scrollLeft]; | |
| 639 | + } else if (db) { | |
| 640 | + return [db.scrollTop, db.scrollLeft]; | |
| 641 | + } else { | |
| 642 | + return [0, 0]; | |
| 643 | + } | |
| 644 | + }, | |
| 645 | + | |
| 646 | + | |
| 647 | + doAdd: function () { | |
| 648 | + if (window.addEventListener) { | |
| 649 | + return function(el, eventName, fn, capture) { | |
| 650 | + el.addEventListener(eventName, fn, (capture)); | |
| 651 | + }; | |
| 652 | + } else if (window.attachEvent) { | |
| 653 | + return function(el, eventName, fn, capture) { | |
| 654 | + el.attachEvent("on" + eventName, fn); | |
| 655 | + }; | |
| 656 | + } else { | |
| 657 | + return function() { | |
| 658 | + }; | |
| 659 | + } | |
| 660 | + }(), | |
| 661 | + | |
| 662 | + | |
| 663 | + doRemove: function() { | |
| 664 | + if (window.removeEventListener) { | |
| 665 | + return function (el, eventName, fn, capture) { | |
| 666 | + el.removeEventListener(eventName, fn, (capture)); | |
| 667 | + }; | |
| 668 | + } else if (window.detachEvent) { | |
| 669 | + return function (el, eventName, fn) { | |
| 670 | + el.detachEvent("on" + eventName, fn); | |
| 671 | + }; | |
| 672 | + } else { | |
| 673 | + return function() { | |
| 674 | + }; | |
| 675 | + } | |
| 676 | + }() | |
| 677 | + }; | |
| 678 | + | |
| 679 | + }(); | |
| 680 | + | |
| 681 | + var E = Ext.lib.Event; | |
| 682 | + E.on = E.addListener; | |
| 683 | + E.un = E.removeListener; | |
| 684 | + if(document && document.body) { | |
| 685 | + E._load(); | |
| 686 | + } else { | |
| 687 | + E.doAdd(window, "load", E._load); | |
| 688 | + } | |
| 689 | + E.doAdd(window, "unload", E._unload); | |
| 690 | + E._tryPreloadAttach(); | |
| 691 | + | |
| 692 | + Ext.lib.Ajax = { | |
| 693 | + request : function(method, uri, cb, data, options) { | |
| 694 | + if(options){ | |
| 695 | + var hs = options.headers; | |
| 696 | + if(hs){ | |
| 697 | + for(var h in hs){ | |
| 698 | + if(hs.hasOwnProperty(h)){ | |
| 699 | + this.initHeader(h, hs[h], false); | |
| 700 | + } | |
| 701 | + } | |
| 702 | + } | |
| 703 | + if(options.xmlData){ | |
| 704 | + if (!hs || !hs['Content-Type']){ | |
| 705 | + this.initHeader('Content-Type', 'text/xml', false); | |
| 706 | + } | |
| 707 | + method = (method ? method : (options.method ? options.method : 'POST')); | |
| 708 | + data = options.xmlData; | |
| 709 | + }else if(options.jsonData){ | |
| 710 | + if (!hs || !hs['Content-Type']){ | |
| 711 | + this.initHeader('Content-Type', 'application/json', false); | |
| 712 | + } | |
| 713 | + method = (method ? method : (options.method ? options.method : 'POST')); | |
| 714 | + data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData; | |
| 715 | + } | |
| 716 | + } | |
| 717 | + | |
| 718 | + return this.asyncRequest(method, uri, cb, data); | |
| 719 | + }, | |
| 720 | + | |
| 721 | + serializeForm : function(form) { | |
| 722 | + if(typeof form == 'string') { | |
| 723 | + form = (document.getElementById(form) || document.forms[form]); | |
| 724 | + } | |
| 725 | + | |
| 726 | + var el, name, val, disabled, data = '', hasSubmit = false; | |
| 727 | + for (var i = 0; i < form.elements.length; i++) { | |
| 728 | + el = form.elements[i]; | |
| 729 | + disabled = form.elements[i].disabled; | |
| 730 | + name = form.elements[i].name; | |
| 731 | + val = form.elements[i].value; | |
| 732 | + | |
| 733 | + if (!disabled && name){ | |
| 734 | + switch (el.type) | |
| 735 | + { | |
| 736 | + case 'select-one': | |
| 737 | + case 'select-multiple': | |
| 738 | + for (var j = 0; j < el.options.length; j++) { | |
| 739 | + if (el.options[j].selected) { | |
| 740 | + if (Ext.isIE) { | |
| 741 | + data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&'; | |
| 742 | + } | |
| 743 | + else { | |
| 744 | + data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&'; | |
| 745 | + } | |
| 746 | + } | |
| 747 | + } | |
| 748 | + break; | |
| 749 | + case 'radio': | |
| 750 | + case 'checkbox': | |
| 751 | + if (el.checked) { | |
| 752 | + data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&'; | |
| 753 | + } | |
| 754 | + break; | |
| 755 | + case 'file': | |
| 756 | + | |
| 757 | + case undefined: | |
| 758 | + | |
| 759 | + case 'reset': | |
| 760 | + | |
| 761 | + case 'button': | |
| 762 | + | |
| 763 | + break; | |
| 764 | + case 'submit': | |
| 765 | + if(hasSubmit == false) { | |
| 766 | + data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&'; | |
| 767 | + hasSubmit = true; | |
| 768 | + } | |
| 769 | + break; | |
| 770 | + default: | |
| 771 | + data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&'; | |
| 772 | + break; | |
| 773 | + } | |
| 774 | + } | |
| 775 | + } | |
| 776 | + data = data.substr(0, data.length - 1); | |
| 777 | + return data; | |
| 778 | + }, | |
| 779 | + | |
| 780 | + headers:{}, | |
| 781 | + | |
| 782 | + hasHeaders:false, | |
| 783 | + | |
| 784 | + useDefaultHeader:true, | |
| 785 | + | |
| 786 | + defaultPostHeader:'application/x-www-form-urlencoded; charset=UTF-8', | |
| 787 | + | |
| 788 | + useDefaultXhrHeader:true, | |
| 789 | + | |
| 790 | + defaultXhrHeader:'XMLHttpRequest', | |
| 791 | + | |
| 792 | + hasDefaultHeaders:true, | |
| 793 | + | |
| 794 | + defaultHeaders:{}, | |
| 795 | + | |
| 796 | + poll:{}, | |
| 797 | + | |
| 798 | + timeout:{}, | |
| 799 | + | |
| 800 | + pollInterval:50, | |
| 801 | + | |
| 802 | + transactionId:0, | |
| 803 | + | |
| 804 | + setProgId:function(id) | |
| 805 | + { | |
| 806 | + this.activeX.unshift(id); | |
| 807 | + }, | |
| 808 | + | |
| 809 | + setDefaultPostHeader:function(b) | |
| 810 | + { | |
| 811 | + this.useDefaultHeader = b; | |
| 812 | + }, | |
| 813 | + | |
| 814 | + setDefaultXhrHeader:function(b) | |
| 815 | + { | |
| 816 | + this.useDefaultXhrHeader = b; | |
| 817 | + }, | |
| 818 | + | |
| 819 | + setPollingInterval:function(i) | |
| 820 | + { | |
| 821 | + if (typeof i == 'number' && isFinite(i)) { | |
| 822 | + this.pollInterval = i; | |
| 823 | + } | |
| 824 | + }, | |
| 825 | + | |
| 826 | + createXhrObject:function(transactionId) | |
| 827 | + { | |
| 828 | + var obj,http; | |
| 829 | + try | |
| 830 | + { | |
| 831 | + | |
| 832 | + http = new XMLHttpRequest(); | |
| 833 | + | |
| 834 | + obj = { conn:http, tId:transactionId }; | |
| 835 | + } | |
| 836 | + catch(e) | |
| 837 | + { | |
| 838 | + for (var i = 0; i < this.activeX.length; ++i) { | |
| 839 | + try | |
| 840 | + { | |
| 841 | + | |
| 842 | + http = new ActiveXObject(this.activeX[i]); | |
| 843 | + | |
| 844 | + obj = { conn:http, tId:transactionId }; | |
| 845 | + break; | |
| 846 | + } | |
| 847 | + catch(e) { | |
| 848 | + } | |
| 849 | + } | |
| 850 | + } | |
| 851 | + finally | |
| 852 | + { | |
| 853 | + return obj; | |
| 854 | + } | |
| 855 | + }, | |
| 856 | + | |
| 857 | + getConnectionObject:function() | |
| 858 | + { | |
| 859 | + var o; | |
| 860 | + var tId = this.transactionId; | |
| 861 | + | |
| 862 | + try | |
| 863 | + { | |
| 864 | + o = this.createXhrObject(tId); | |
| 865 | + if (o) { | |
| 866 | + this.transactionId++; | |
| 867 | + } | |
| 868 | + } | |
| 869 | + catch(e) { | |
| 870 | + } | |
| 871 | + finally | |
| 872 | + { | |
| 873 | + return o; | |
| 874 | + } | |
| 875 | + }, | |
| 876 | + | |
| 877 | + asyncRequest:function(method, uri, callback, postData) | |
| 878 | + { | |
| 879 | + var o = this.getConnectionObject(); | |
| 880 | + | |
| 881 | + if (!o) { | |
| 882 | + return null; | |
| 883 | + } | |
| 884 | + else { | |
| 885 | + o.conn.open(method, uri, true); | |
| 886 | + | |
| 887 | + if (this.useDefaultXhrHeader) { | |
| 888 | + if (!this.defaultHeaders['X-Requested-With']) { | |
| 889 | + this.initHeader('X-Requested-With', this.defaultXhrHeader, true); | |
| 890 | + } | |
| 891 | + } | |
| 892 | + | |
| 893 | + if(postData && this.useDefaultHeader && (!this.hasHeaders || !this.headers['Content-Type'])){ | |
| 894 | + this.initHeader('Content-Type', this.defaultPostHeader); | |
| 895 | + } | |
| 896 | + | |
| 897 | + if (this.hasDefaultHeaders || this.hasHeaders) { | |
| 898 | + this.setHeader(o); | |
| 899 | + } | |
| 900 | + | |
| 901 | + this.handleReadyState(o, callback); | |
| 902 | + o.conn.send(postData || null); | |
| 903 | + | |
| 904 | + return o; | |
| 905 | + } | |
| 906 | + }, | |
| 907 | + | |
| 908 | + handleReadyState:function(o, callback) | |
| 909 | + { | |
| 910 | + var oConn = this; | |
| 911 | + | |
| 912 | + if (callback && callback.timeout) { | |
| 913 | + this.timeout[o.tId] = window.setTimeout(function() { | |
| 914 | + oConn.abort(o, callback, true); | |
| 915 | + }, callback.timeout); | |
| 916 | + } | |
| 917 | + | |
| 918 | + this.poll[o.tId] = window.setInterval( | |
| 919 | + function() { | |
| 920 | + if (o.conn && o.conn.readyState == 4) { | |
| 921 | + window.clearInterval(oConn.poll[o.tId]); | |
| 922 | + delete oConn.poll[o.tId]; | |
| 923 | + | |
| 924 | + if (callback && callback.timeout) { | |
| 925 | + window.clearTimeout(oConn.timeout[o.tId]); | |
| 926 | + delete oConn.timeout[o.tId]; | |
| 927 | + } | |
| 928 | + | |
| 929 | + oConn.handleTransactionResponse(o, callback); | |
| 930 | + } | |
| 931 | + } | |
| 932 | + , this.pollInterval); | |
| 933 | + }, | |
| 934 | + | |
| 935 | + handleTransactionResponse:function(o, callback, isAbort) | |
| 936 | + { | |
| 937 | + | |
| 938 | + if (!callback) { | |
| 939 | + this.releaseObject(o); | |
| 940 | + return; | |
| 941 | + } | |
| 942 | + | |
| 943 | + var httpStatus, responseObject; | |
| 944 | + | |
| 945 | + try | |
| 946 | + { | |
| 947 | + if (o.conn.status !== undefined && o.conn.status != 0) { | |
| 948 | + httpStatus = o.conn.status; | |
| 949 | + } | |
| 950 | + else { | |
| 951 | + httpStatus = 13030; | |
| 952 | + } | |
| 953 | + } | |
| 954 | + catch(e) { | |
| 955 | + | |
| 956 | + | |
| 957 | + httpStatus = 13030; | |
| 958 | + } | |
| 959 | + | |
| 960 | + if (httpStatus >= 200 && httpStatus < 300) { | |
| 961 | + responseObject = this.createResponseObject(o, callback.argument); | |
| 962 | + if (callback.success) { | |
| 963 | + if (!callback.scope) { | |
| 964 | + callback.success(responseObject); | |
| 965 | + } | |
| 966 | + else { | |
| 967 | + | |
| 968 | + | |
| 969 | + callback.success.apply(callback.scope, [responseObject]); | |
| 970 | + } | |
| 971 | + } | |
| 972 | + } | |
| 973 | + else { | |
| 974 | + switch (httpStatus) { | |
| 975 | + | |
| 976 | + case 12002: | |
| 977 | + case 12029: | |
| 978 | + case 12030: | |
| 979 | + case 12031: | |
| 980 | + case 12152: | |
| 981 | + case 13030: | |
| 982 | + responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false)); | |
| 983 | + if (callback.failure) { | |
| 984 | + if (!callback.scope) { | |
| 985 | + callback.failure(responseObject); | |
| 986 | + } | |
| 987 | + else { | |
| 988 | + callback.failure.apply(callback.scope, [responseObject]); | |
| 989 | + } | |
| 990 | + } | |
| 991 | + break; | |
| 992 | + default: | |
| 993 | + responseObject = this.createResponseObject(o, callback.argument); | |
| 994 | + if (callback.failure) { | |
| 995 | + if (!callback.scope) { | |
| 996 | + callback.failure(responseObject); | |
| 997 | + } | |
| 998 | + else { | |
| 999 | + callback.failure.apply(callback.scope, [responseObject]); | |
| 1000 | + } | |
| 1001 | + } | |
| 1002 | + } | |
| 1003 | + } | |
| 1004 | + | |
| 1005 | + this.releaseObject(o); | |
| 1006 | + responseObject = null; | |
| 1007 | + }, | |
| 1008 | + | |
| 1009 | + createResponseObject:function(o, callbackArg) | |
| 1010 | + { | |
| 1011 | + var obj = {}; | |
| 1012 | + var headerObj = {}; | |
| 1013 | + | |
| 1014 | + try | |
| 1015 | + { | |
| 1016 | + var headerStr = o.conn.getAllResponseHeaders(); | |
| 1017 | + var header = headerStr.split('\n'); | |
| 1018 | + for (var i = 0; i < header.length; i++) { | |
| 1019 | + var delimitPos = header[i].indexOf(':'); | |
| 1020 | + if (delimitPos != -1) { | |
| 1021 | + headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2); | |
| 1022 | + } | |
| 1023 | + } | |
| 1024 | + } | |
| 1025 | + catch(e) { | |
| 1026 | + } | |
| 1027 | + | |
| 1028 | + obj.tId = o.tId; | |
| 1029 | + obj.status = o.conn.status; | |
| 1030 | + obj.statusText = o.conn.statusText; | |
| 1031 | + obj.getResponseHeader = headerObj; | |
| 1032 | + obj.getAllResponseHeaders = headerStr; | |
| 1033 | + obj.responseText = o.conn.responseText; | |
| 1034 | + obj.responseXML = o.conn.responseXML; | |
| 1035 | + | |
| 1036 | + if (typeof callbackArg !== undefined) { | |
| 1037 | + obj.argument = callbackArg; | |
| 1038 | + } | |
| 1039 | + | |
| 1040 | + return obj; | |
| 1041 | + }, | |
| 1042 | + | |
| 1043 | + createExceptionObject:function(tId, callbackArg, isAbort) | |
| 1044 | + { | |
| 1045 | + var COMM_CODE = 0; | |
| 1046 | + var COMM_ERROR = 'communication failure'; | |
| 1047 | + var ABORT_CODE = -1; | |
| 1048 | + var ABORT_ERROR = 'transaction aborted'; | |
| 1049 | + | |
| 1050 | + var obj = {}; | |
| 1051 | + | |
| 1052 | + obj.tId = tId; | |
| 1053 | + if (isAbort) { | |
| 1054 | + obj.status = ABORT_CODE; | |
| 1055 | + obj.statusText = ABORT_ERROR; | |
| 1056 | + } | |
| 1057 | + else { | |
| 1058 | + obj.status = COMM_CODE; | |
| 1059 | + obj.statusText = COMM_ERROR; | |
| 1060 | + } | |
| 1061 | + | |
| 1062 | + if (callbackArg) { | |
| 1063 | + obj.argument = callbackArg; | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + return obj; | |
| 1067 | + }, | |
| 1068 | + | |
| 1069 | + initHeader:function(label, value, isDefault) | |
| 1070 | + { | |
| 1071 | + var headerObj = (isDefault) ? this.defaultHeaders : this.headers; | |
| 1072 | + | |
| 1073 | + if (headerObj[label] === undefined) { | |
| 1074 | + headerObj[label] = value; | |
| 1075 | + } | |
| 1076 | + else { | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + headerObj[label] = value + "," + headerObj[label]; | |
| 1080 | + } | |
| 1081 | + | |
| 1082 | + if (isDefault) { | |
| 1083 | + this.hasDefaultHeaders = true; | |
| 1084 | + } | |
| 1085 | + else { | |
| 1086 | + this.hasHeaders = true; | |
| 1087 | + } | |
| 1088 | + }, | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + setHeader:function(o) | |
| 1092 | + { | |
| 1093 | + if (this.hasDefaultHeaders) { | |
| 1094 | + for (var prop in this.defaultHeaders) { | |
| 1095 | + if (this.defaultHeaders.hasOwnProperty(prop)) { | |
| 1096 | + o.conn.setRequestHeader(prop, this.defaultHeaders[prop]); | |
| 1097 | + } | |
| 1098 | + } | |
| 1099 | + } | |
| 1100 | + | |
| 1101 | + if (this.hasHeaders) { | |
| 1102 | + for (var prop in this.headers) { | |
| 1103 | + if (this.headers.hasOwnProperty(prop)) { | |
| 1104 | + o.conn.setRequestHeader(prop, this.headers[prop]); | |
| 1105 | + } | |
| 1106 | + } | |
| 1107 | + this.headers = {}; | |
| 1108 | + this.hasHeaders = false; | |
| 1109 | + } | |
| 1110 | + }, | |
| 1111 | + | |
| 1112 | + resetDefaultHeaders:function() { | |
| 1113 | + delete this.defaultHeaders; | |
| 1114 | + this.defaultHeaders = {}; | |
| 1115 | + this.hasDefaultHeaders = false; | |
| 1116 | + }, | |
| 1117 | + | |
| 1118 | + abort:function(o, callback, isTimeout) | |
| 1119 | + { | |
| 1120 | + if (this.isCallInProgress(o)) { | |
| 1121 | + o.conn.abort(); | |
| 1122 | + window.clearInterval(this.poll[o.tId]); | |
| 1123 | + delete this.poll[o.tId]; | |
| 1124 | + if (isTimeout) { | |
| 1125 | + delete this.timeout[o.tId]; | |
| 1126 | + } | |
| 1127 | + | |
| 1128 | + this.handleTransactionResponse(o, callback, true); | |
| 1129 | + | |
| 1130 | + return true; | |
| 1131 | + } | |
| 1132 | + else { | |
| 1133 | + return false; | |
| 1134 | + } | |
| 1135 | + }, | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + isCallInProgress:function(o) | |
| 1139 | + { | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + if (o.conn) { | |
| 1143 | + return o.conn.readyState != 4 && o.conn.readyState != 0; | |
| 1144 | + } | |
| 1145 | + else { | |
| 1146 | + | |
| 1147 | + return false; | |
| 1148 | + } | |
| 1149 | + }, | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + releaseObject:function(o) | |
| 1153 | + { | |
| 1154 | + | |
| 1155 | + o.conn = null; | |
| 1156 | + | |
| 1157 | + o = null; | |
| 1158 | + }, | |
| 1159 | + | |
| 1160 | + activeX:[ | |
| 1161 | + 'MSXML2.XMLHTTP.3.0', | |
| 1162 | + 'MSXML2.XMLHTTP', | |
| 1163 | + 'Microsoft.XMLHTTP' | |
| 1164 | + ] | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + }; | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + Ext.lib.Region = function(t, r, b, l) { | |
| 1171 | + this.top = t; | |
| 1172 | + this[1] = t; | |
| 1173 | + this.right = r; | |
| 1174 | + this.bottom = b; | |
| 1175 | + this.left = l; | |
| 1176 | + this[0] = l; | |
| 1177 | + }; | |
| 1178 | + | |
| 1179 | + Ext.lib.Region.prototype = { | |
| 1180 | + contains : function(region) { | |
| 1181 | + return ( region.left >= this.left && | |
| 1182 | + region.right <= this.right && | |
| 1183 | + region.top >= this.top && | |
| 1184 | + region.bottom <= this.bottom ); | |
| 1185 | + | |
| 1186 | + }, | |
| 1187 | + | |
| 1188 | + getArea : function() { | |
| 1189 | + return ( (this.bottom - this.top) * (this.right - this.left) ); | |
| 1190 | + }, | |
| 1191 | + | |
| 1192 | + intersect : function(region) { | |
| 1193 | + var t = Math.max(this.top, region.top); | |
| 1194 | + var r = Math.min(this.right, region.right); | |
| 1195 | + var b = Math.min(this.bottom, region.bottom); | |
| 1196 | + var l = Math.max(this.left, region.left); | |
| 1197 | + | |
| 1198 | + if (b >= t && r >= l) { | |
| 1199 | + return new Ext.lib.Region(t, r, b, l); | |
| 1200 | + } else { | |
| 1201 | + return null; | |
| 1202 | + } | |
| 1203 | + }, | |
| 1204 | + union : function(region) { | |
| 1205 | + var t = Math.min(this.top, region.top); | |
| 1206 | + var r = Math.max(this.right, region.right); | |
| 1207 | + var b = Math.max(this.bottom, region.bottom); | |
| 1208 | + var l = Math.min(this.left, region.left); | |
| 1209 | + | |
| 1210 | + return new Ext.lib.Region(t, r, b, l); | |
| 1211 | + }, | |
| 1212 | + | |
| 1213 | + constrainTo : function(r) { | |
| 1214 | + this.top = this.top.constrain(r.top, r.bottom); | |
| 1215 | + this.bottom = this.bottom.constrain(r.top, r.bottom); | |
| 1216 | + this.left = this.left.constrain(r.left, r.right); | |
| 1217 | + this.right = this.right.constrain(r.left, r.right); | |
| 1218 | + return this; | |
| 1219 | + }, | |
| 1220 | + | |
| 1221 | + adjust : function(t, l, b, r) { | |
| 1222 | + this.top += t; | |
| 1223 | + this.left += l; | |
| 1224 | + this.right += r; | |
| 1225 | + this.bottom += b; | |
| 1226 | + return this; | |
| 1227 | + } | |
| 1228 | + }; | |
| 1229 | + | |
| 1230 | + Ext.lib.Region.getRegion = function(el) { | |
| 1231 | + var p = Ext.lib.Dom.getXY(el); | |
| 1232 | + | |
| 1233 | + var t = p[1]; | |
| 1234 | + var r = p[0] + el.offsetWidth; | |
| 1235 | + var b = p[1] + el.offsetHeight; | |
| 1236 | + var l = p[0]; | |
| 1237 | + | |
| 1238 | + return new Ext.lib.Region(t, r, b, l); | |
| 1239 | + }; | |
| 1240 | + | |
| 1241 | + Ext.lib.Point = function(x, y) { | |
| 1242 | + if (Ext.isArray(x)) { | |
| 1243 | + y = x[1]; | |
| 1244 | + x = x[0]; | |
| 1245 | + } | |
| 1246 | + this.x = this.right = this.left = this[0] = x; | |
| 1247 | + this.y = this.top = this.bottom = this[1] = y; | |
| 1248 | + }; | |
| 1249 | + | |
| 1250 | + Ext.lib.Point.prototype = new Ext.lib.Region(); | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + Ext.lib.Anim = { | |
| 1254 | + scroll : function(el, args, duration, easing, cb, scope) { | |
| 1255 | + return this.run(el, args, duration, easing, cb, scope, Ext.lib.Scroll); | |
| 1256 | + }, | |
| 1257 | + | |
| 1258 | + motion : function(el, args, duration, easing, cb, scope) { | |
| 1259 | + return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion); | |
| 1260 | + }, | |
| 1261 | + | |
| 1262 | + color : function(el, args, duration, easing, cb, scope) { | |
| 1263 | + return this.run(el, args, duration, easing, cb, scope, Ext.lib.ColorAnim); | |
| 1264 | + }, | |
| 1265 | + | |
| 1266 | + run : function(el, args, duration, easing, cb, scope, type) { | |
| 1267 | + type = type || Ext.lib.AnimBase; | |
| 1268 | + if (typeof easing == "string") { | |
| 1269 | + easing = Ext.lib.Easing[easing]; | |
| 1270 | + } | |
| 1271 | + var anim = new type(el, args, duration, easing); | |
| 1272 | + anim.animateX(function() { | |
| 1273 | + Ext.callback(cb, scope); | |
| 1274 | + }); | |
| 1275 | + return anim; | |
| 1276 | + } | |
| 1277 | + }; | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + function fly(el) { | |
| 1281 | + if (!libFlyweight) { | |
| 1282 | + libFlyweight = new Ext.Element.Flyweight(); | |
| 1283 | + } | |
| 1284 | + libFlyweight.dom = el; | |
| 1285 | + return libFlyweight; | |
| 1286 | + } | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + if(Ext.isIE) { | |
| 1290 | + function fnCleanUp() { | |
| 1291 | + var p = Function.prototype; | |
| 1292 | + delete p.createSequence; | |
| 1293 | + delete p.defer; | |
| 1294 | + delete p.createDelegate; | |
| 1295 | + delete p.createCallback; | |
| 1296 | + delete p.createInterceptor; | |
| 1297 | + | |
| 1298 | + window.detachEvent("onunload", fnCleanUp); | |
| 1299 | + } | |
| 1300 | + window.attachEvent("onunload", fnCleanUp); | |
| 1301 | + } | |
| 1302 | + | |
| 1303 | + Ext.lib.AnimBase = function(el, attributes, duration, method) { | |
| 1304 | + if (el) { | |
| 1305 | + this.init(el, attributes, duration, method); | |
| 1306 | + } | |
| 1307 | + }; | |
| 1308 | + | |
| 1309 | + Ext.lib.AnimBase.prototype = { | |
| 1310 | + | |
| 1311 | + toString: function() { | |
| 1312 | + var el = this.getEl(); | |
| 1313 | + var id = el.id || el.tagName; | |
| 1314 | + return ("Anim " + id); | |
| 1315 | + }, | |
| 1316 | + | |
| 1317 | + patterns: { | |
| 1318 | + noNegatives: /width|height|opacity|padding/i, | |
| 1319 | + offsetAttribute: /^((width|height)|(top|left))$/, | |
| 1320 | + defaultUnit: /width|height|top$|bottom$|left$|right$/i, | |
| 1321 | + offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i | |
| 1322 | + }, | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + doMethod: function(attr, start, end) { | |
| 1326 | + return this.method(this.currentFrame, start, end - start, this.totalFrames); | |
| 1327 | + }, | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + setAttribute: function(attr, val, unit) { | |
| 1331 | + if (this.patterns.noNegatives.test(attr)) { | |
| 1332 | + val = (val > 0) ? val : 0; | |
| 1333 | + } | |
| 1334 | + | |
| 1335 | + Ext.fly(this.getEl(), '_anim').setStyle(attr, val + unit); | |
| 1336 | + }, | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + getAttribute: function(attr) { | |
| 1340 | + var el = this.getEl(); | |
| 1341 | + var val = fly(el).getStyle(attr); | |
| 1342 | + | |
| 1343 | + if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) { | |
| 1344 | + return parseFloat(val); | |
| 1345 | + } | |
| 1346 | + | |
| 1347 | + var a = this.patterns.offsetAttribute.exec(attr) || []; | |
| 1348 | + var pos = !!( a[3] ); | |
| 1349 | + var box = !!( a[2] ); | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + if (box || (fly(el).getStyle('position') == 'absolute' && pos)) { | |
| 1353 | + val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)]; | |
| 1354 | + } else { | |
| 1355 | + val = 0; | |
| 1356 | + } | |
| 1357 | + | |
| 1358 | + return val; | |
| 1359 | + }, | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + getDefaultUnit: function(attr) { | |
| 1363 | + if (this.patterns.defaultUnit.test(attr)) { | |
| 1364 | + return 'px'; | |
| 1365 | + } | |
| 1366 | + | |
| 1367 | + return ''; | |
| 1368 | + }, | |
| 1369 | + | |
| 1370 | + animateX : function(callback, scope) { | |
| 1371 | + var f = function() { | |
| 1372 | + this.onComplete.removeListener(f); | |
| 1373 | + if (typeof callback == "function") { | |
| 1374 | + callback.call(scope || this, this); | |
| 1375 | + } | |
| 1376 | + }; | |
| 1377 | + this.onComplete.addListener(f, this); | |
| 1378 | + this.animate(); | |
| 1379 | + }, | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + setRuntimeAttribute: function(attr) { | |
| 1383 | + var start; | |
| 1384 | + var end; | |
| 1385 | + var attributes = this.attributes; | |
| 1386 | + | |
| 1387 | + this.runtimeAttributes[attr] = {}; | |
| 1388 | + | |
| 1389 | + var isset = function(prop) { | |
| 1390 | + return (typeof prop !== 'undefined'); | |
| 1391 | + }; | |
| 1392 | + | |
| 1393 | + if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) { | |
| 1394 | + return false; | |
| 1395 | + } | |
| 1396 | + | |
| 1397 | + start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr); | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + if (isset(attributes[attr]['to'])) { | |
| 1401 | + end = attributes[attr]['to']; | |
| 1402 | + } else if (isset(attributes[attr]['by'])) { | |
| 1403 | + if (start.constructor == Array) { | |
| 1404 | + end = []; | |
| 1405 | + for (var i = 0, len = start.length; i < len; ++i) { | |
| 1406 | + end[i] = start[i] + attributes[attr]['by'][i]; | |
| 1407 | + } | |
| 1408 | + } else { | |
| 1409 | + end = start + attributes[attr]['by']; | |
| 1410 | + } | |
| 1411 | + } | |
| 1412 | + | |
| 1413 | + this.runtimeAttributes[attr].start = start; | |
| 1414 | + this.runtimeAttributes[attr].end = end; | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr); | |
| 1418 | + }, | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + init: function(el, attributes, duration, method) { | |
| 1422 | + | |
| 1423 | + var isAnimated = false; | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + var startTime = null; | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + var actualFrames = 0; | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + el = Ext.getDom(el); | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + this.attributes = attributes || {}; | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + this.duration = duration || 1; | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + this.method = method || Ext.lib.Easing.easeNone; | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + this.useSeconds = true; | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + this.currentFrame = 0; | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + this.totalFrames = Ext.lib.AnimMgr.fps; | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + this.getEl = function() { | |
| 1454 | + return el; | |
| 1455 | + }; | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + this.isAnimated = function() { | |
| 1459 | + return isAnimated; | |
| 1460 | + }; | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + this.getStartTime = function() { | |
| 1464 | + return startTime; | |
| 1465 | + }; | |
| 1466 | + | |
| 1467 | + this.runtimeAttributes = {}; | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + this.animate = function() { | |
| 1471 | + if (this.isAnimated()) { | |
| 1472 | + return false; | |
| 1473 | + } | |
| 1474 | + | |
| 1475 | + this.currentFrame = 0; | |
| 1476 | + | |
| 1477 | + this.totalFrames = ( this.useSeconds ) ? Math.ceil(Ext.lib.AnimMgr.fps * this.duration) : this.duration; | |
| 1478 | + | |
| 1479 | + Ext.lib.AnimMgr.registerElement(this); | |
| 1480 | + }; | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + this.stop = function(finish) { | |
| 1484 | + if (finish) { | |
| 1485 | + this.currentFrame = this.totalFrames; | |
| 1486 | + this._onTween.fire(); | |
| 1487 | + } | |
| 1488 | + Ext.lib.AnimMgr.stop(this); | |
| 1489 | + }; | |
| 1490 | + | |
| 1491 | + var onStart = function() { | |
| 1492 | + this.onStart.fire(); | |
| 1493 | + | |
| 1494 | + this.runtimeAttributes = {}; | |
| 1495 | + for (var attr in this.attributes) { | |
| 1496 | + this.setRuntimeAttribute(attr); | |
| 1497 | + } | |
| 1498 | + | |
| 1499 | + isAnimated = true; | |
| 1500 | + actualFrames = 0; | |
| 1501 | + startTime = new Date(); | |
| 1502 | + }; | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + var onTween = function() { | |
| 1506 | + var data = { | |
| 1507 | + duration: new Date() - this.getStartTime(), | |
| 1508 | + currentFrame: this.currentFrame | |
| 1509 | + }; | |
| 1510 | + | |
| 1511 | + data.toString = function() { | |
| 1512 | + return ( | |
| 1513 | + 'duration: ' + data.duration + | |
| 1514 | + ', currentFrame: ' + data.currentFrame | |
| 1515 | + ); | |
| 1516 | + }; | |
| 1517 | + | |
| 1518 | + this.onTween.fire(data); | |
| 1519 | + | |
| 1520 | + var runtimeAttributes = this.runtimeAttributes; | |
| 1521 | + | |
| 1522 | + for (var attr in runtimeAttributes) { | |
| 1523 | + this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit); | |
| 1524 | + } | |
| 1525 | + | |
| 1526 | + actualFrames += 1; | |
| 1527 | + }; | |
| 1528 | + | |
| 1529 | + var onComplete = function() { | |
| 1530 | + var actual_duration = (new Date() - startTime) / 1000 ; | |
| 1531 | + | |
| 1532 | + var data = { | |
| 1533 | + duration: actual_duration, | |
| 1534 | + frames: actualFrames, | |
| 1535 | + fps: actualFrames / actual_duration | |
| 1536 | + }; | |
| 1537 | + | |
| 1538 | + data.toString = function() { | |
| 1539 | + return ( | |
| 1540 | + 'duration: ' + data.duration + | |
| 1541 | + ', frames: ' + data.frames + | |
| 1542 | + ', fps: ' + data.fps | |
| 1543 | + ); | |
| 1544 | + }; | |
| 1545 | + | |
| 1546 | + isAnimated = false; | |
| 1547 | + actualFrames = 0; | |
| 1548 | + this.onComplete.fire(data); | |
| 1549 | + }; | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + this._onStart = new Ext.util.Event(this); | |
| 1553 | + this.onStart = new Ext.util.Event(this); | |
| 1554 | + this.onTween = new Ext.util.Event(this); | |
| 1555 | + this._onTween = new Ext.util.Event(this); | |
| 1556 | + this.onComplete = new Ext.util.Event(this); | |
| 1557 | + this._onComplete = new Ext.util.Event(this); | |
| 1558 | + this._onStart.addListener(onStart); | |
| 1559 | + this._onTween.addListener(onTween); | |
| 1560 | + this._onComplete.addListener(onComplete); | |
| 1561 | + } | |
| 1562 | + }; | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + Ext.lib.AnimMgr = new function() { | |
| 1566 | + | |
| 1567 | + var thread = null; | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + var queue = []; | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + var tweenCount = 0; | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + this.fps = 1000; | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + this.delay = 1; | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + this.registerElement = function(tween) { | |
| 1583 | + queue[queue.length] = tween; | |
| 1584 | + tweenCount += 1; | |
| 1585 | + tween._onStart.fire(); | |
| 1586 | + this.start(); | |
| 1587 | + }; | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + this.unRegister = function(tween, index) { | |
| 1591 | + tween._onComplete.fire(); | |
| 1592 | + index = index || getIndex(tween); | |
| 1593 | + if (index != -1) { | |
| 1594 | + queue.splice(index, 1); | |
| 1595 | + } | |
| 1596 | + | |
| 1597 | + tweenCount -= 1; | |
| 1598 | + if (tweenCount <= 0) { | |
| 1599 | + this.stop(); | |
| 1600 | + } | |
| 1601 | + }; | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + this.start = function() { | |
| 1605 | + if (thread === null) { | |
| 1606 | + thread = setInterval(this.run, this.delay); | |
| 1607 | + } | |
| 1608 | + }; | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + this.stop = function(tween) { | |
| 1612 | + if (!tween) { | |
| 1613 | + clearInterval(thread); | |
| 1614 | + | |
| 1615 | + for (var i = 0, len = queue.length; i < len; ++i) { | |
| 1616 | + if (queue[0].isAnimated()) { | |
| 1617 | + this.unRegister(queue[0], 0); | |
| 1618 | + } | |
| 1619 | + } | |
| 1620 | + | |
| 1621 | + queue = []; | |
| 1622 | + thread = null; | |
| 1623 | + tweenCount = 0; | |
| 1624 | + } | |
| 1625 | + else { | |
| 1626 | + this.unRegister(tween); | |
| 1627 | + } | |
| 1628 | + }; | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + this.run = function() { | |
| 1632 | + for (var i = 0, len = queue.length; i < len; ++i) { | |
| 1633 | + var tween = queue[i]; | |
| 1634 | + if (!tween || !tween.isAnimated()) { | |
| 1635 | + continue; | |
| 1636 | + } | |
| 1637 | + | |
| 1638 | + if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null) | |
| 1639 | + { | |
| 1640 | + tween.currentFrame += 1; | |
| 1641 | + | |
| 1642 | + if (tween.useSeconds) { | |
| 1643 | + correctFrame(tween); | |
| 1644 | + } | |
| 1645 | + tween._onTween.fire(); | |
| 1646 | + } | |
| 1647 | + else { | |
| 1648 | + Ext.lib.AnimMgr.stop(tween, i); | |
| 1649 | + } | |
| 1650 | + } | |
| 1651 | + }; | |
| 1652 | + | |
| 1653 | + var getIndex = function(anim) { | |
| 1654 | + for (var i = 0, len = queue.length; i < len; ++i) { | |
| 1655 | + if (queue[i] == anim) { | |
| 1656 | + return i; | |
| 1657 | + } | |
| 1658 | + } | |
| 1659 | + return -1; | |
| 1660 | + }; | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + var correctFrame = function(tween) { | |
| 1664 | + var frames = tween.totalFrames; | |
| 1665 | + var frame = tween.currentFrame; | |
| 1666 | + var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames); | |
| 1667 | + var elapsed = (new Date() - tween.getStartTime()); | |
| 1668 | + var tweak = 0; | |
| 1669 | + | |
| 1670 | + if (elapsed < tween.duration * 1000) { | |
| 1671 | + tweak = Math.round((elapsed / expected - 1) * tween.currentFrame); | |
| 1672 | + } else { | |
| 1673 | + tweak = frames - (frame + 1); | |
| 1674 | + } | |
| 1675 | + if (tweak > 0 && isFinite(tweak)) { | |
| 1676 | + if (tween.currentFrame + tweak >= frames) { | |
| 1677 | + tweak = frames - (frame + 1); | |
| 1678 | + } | |
| 1679 | + | |
| 1680 | + tween.currentFrame += tweak; | |
| 1681 | + } | |
| 1682 | + }; | |
| 1683 | + }; | |
| 1684 | + | |
| 1685 | + Ext.lib.Bezier = new function() { | |
| 1686 | + | |
| 1687 | + this.getPosition = function(points, t) { | |
| 1688 | + var n = points.length; | |
| 1689 | + var tmp = []; | |
| 1690 | + | |
| 1691 | + for (var i = 0; i < n; ++i) { | |
| 1692 | + tmp[i] = [points[i][0], points[i][1]]; | |
| 1693 | + } | |
| 1694 | + | |
| 1695 | + for (var j = 1; j < n; ++j) { | |
| 1696 | + for (i = 0; i < n - j; ++i) { | |
| 1697 | + tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; | |
| 1698 | + tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; | |
| 1699 | + } | |
| 1700 | + } | |
| 1701 | + | |
| 1702 | + return [ tmp[0][0], tmp[0][1] ]; | |
| 1703 | + | |
| 1704 | + }; | |
| 1705 | + }; | |
| 1706 | + (function() { | |
| 1707 | + | |
| 1708 | + Ext.lib.ColorAnim = function(el, attributes, duration, method) { | |
| 1709 | + Ext.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method); | |
| 1710 | + }; | |
| 1711 | + | |
| 1712 | + Ext.extend(Ext.lib.ColorAnim, Ext.lib.AnimBase); | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + var Y = Ext.lib; | |
| 1716 | + var superclass = Y.ColorAnim.superclass; | |
| 1717 | + var proto = Y.ColorAnim.prototype; | |
| 1718 | + | |
| 1719 | + proto.toString = function() { | |
| 1720 | + var el = this.getEl(); | |
| 1721 | + var id = el.id || el.tagName; | |
| 1722 | + return ("ColorAnim " + id); | |
| 1723 | + }; | |
| 1724 | + | |
| 1725 | + proto.patterns.color = /color$/i; | |
| 1726 | + proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i; | |
| 1727 | + proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i; | |
| 1728 | + proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i; | |
| 1729 | + proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/; | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + proto.parseColor = function(s) { | |
| 1733 | + if (s.length == 3) { | |
| 1734 | + return s; | |
| 1735 | + } | |
| 1736 | + | |
| 1737 | + var c = this.patterns.hex.exec(s); | |
| 1738 | + if (c && c.length == 4) { | |
| 1739 | + return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ]; | |
| 1740 | + } | |
| 1741 | + | |
| 1742 | + c = this.patterns.rgb.exec(s); | |
| 1743 | + if (c && c.length == 4) { | |
| 1744 | + return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ]; | |
| 1745 | + } | |
| 1746 | + | |
| 1747 | + c = this.patterns.hex3.exec(s); | |
| 1748 | + if (c && c.length == 4) { | |
| 1749 | + return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ]; | |
| 1750 | + } | |
| 1751 | + | |
| 1752 | + return null; | |
| 1753 | + }; | |
| 1754 | + | |
| 1755 | + proto.getAttribute = function(attr) { | |
| 1756 | + var el = this.getEl(); | |
| 1757 | + if (this.patterns.color.test(attr)) { | |
| 1758 | + var val = fly(el).getStyle(attr); | |
| 1759 | + | |
| 1760 | + if (this.patterns.transparent.test(val)) { | |
| 1761 | + var parent = el.parentNode; | |
| 1762 | + val = fly(parent).getStyle(attr); | |
| 1763 | + | |
| 1764 | + while (parent && this.patterns.transparent.test(val)) { | |
| 1765 | + parent = parent.parentNode; | |
| 1766 | + val = fly(parent).getStyle(attr); | |
| 1767 | + if (parent.tagName.toUpperCase() == 'HTML') { | |
| 1768 | + val = '#fff'; | |
| 1769 | + } | |
| 1770 | + } | |
| 1771 | + } | |
| 1772 | + } else { | |
| 1773 | + val = superclass.getAttribute.call(this, attr); | |
| 1774 | + } | |
| 1775 | + | |
| 1776 | + return val; | |
| 1777 | + }; | |
| 1778 | + | |
| 1779 | + proto.doMethod = function(attr, start, end) { | |
| 1780 | + var val; | |
| 1781 | + | |
| 1782 | + if (this.patterns.color.test(attr)) { | |
| 1783 | + val = []; | |
| 1784 | + for (var i = 0, len = start.length; i < len; ++i) { | |
| 1785 | + val[i] = superclass.doMethod.call(this, attr, start[i], end[i]); | |
| 1786 | + } | |
| 1787 | + | |
| 1788 | + val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')'; | |
| 1789 | + } | |
| 1790 | + else { | |
| 1791 | + val = superclass.doMethod.call(this, attr, start, end); | |
| 1792 | + } | |
| 1793 | + | |
| 1794 | + return val; | |
| 1795 | + }; | |
| 1796 | + | |
| 1797 | + proto.setRuntimeAttribute = function(attr) { | |
| 1798 | + superclass.setRuntimeAttribute.call(this, attr); | |
| 1799 | + | |
| 1800 | + if (this.patterns.color.test(attr)) { | |
| 1801 | + var attributes = this.attributes; | |
| 1802 | + var start = this.parseColor(this.runtimeAttributes[attr].start); | |
| 1803 | + var end = this.parseColor(this.runtimeAttributes[attr].end); | |
| 1804 | + | |
| 1805 | + if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') { | |
| 1806 | + end = this.parseColor(attributes[attr].by); | |
| 1807 | + | |
| 1808 | + for (var i = 0, len = start.length; i < len; ++i) { | |
| 1809 | + end[i] = start[i] + end[i]; | |
| 1810 | + } | |
| 1811 | + } | |
| 1812 | + | |
| 1813 | + this.runtimeAttributes[attr].start = start; | |
| 1814 | + this.runtimeAttributes[attr].end = end; | |
| 1815 | + } | |
| 1816 | + }; | |
| 1817 | + })(); | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + Ext.lib.Easing = { | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + easeNone: function (t, b, c, d) { | |
| 1824 | + return c * t / d + b; | |
| 1825 | + }, | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + easeIn: function (t, b, c, d) { | |
| 1829 | + return c * (t /= d) * t + b; | |
| 1830 | + }, | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + easeOut: function (t, b, c, d) { | |
| 1834 | + return -c * (t /= d) * (t - 2) + b; | |
| 1835 | + }, | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + easeBoth: function (t, b, c, d) { | |
| 1839 | + if ((t /= d / 2) < 1) { | |
| 1840 | + return c / 2 * t * t + b; | |
| 1841 | + } | |
| 1842 | + | |
| 1843 | + return -c / 2 * ((--t) * (t - 2) - 1) + b; | |
| 1844 | + }, | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + easeInStrong: function (t, b, c, d) { | |
| 1848 | + return c * (t /= d) * t * t * t + b; | |
| 1849 | + }, | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + easeOutStrong: function (t, b, c, d) { | |
| 1853 | + return -c * ((t = t / d - 1) * t * t * t - 1) + b; | |
| 1854 | + }, | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + easeBothStrong: function (t, b, c, d) { | |
| 1858 | + if ((t /= d / 2) < 1) { | |
| 1859 | + return c / 2 * t * t * t * t + b; | |
| 1860 | + } | |
| 1861 | + | |
| 1862 | + return -c / 2 * ((t -= 2) * t * t * t - 2) + b; | |
| 1863 | + }, | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + elasticIn: function (t, b, c, d, a, p) { | |
| 1868 | + if (t == 0) { | |
| 1869 | + return b; | |
| 1870 | + } | |
| 1871 | + if ((t /= d) == 1) { | |
| 1872 | + return b + c; | |
| 1873 | + } | |
| 1874 | + if (!p) { | |
| 1875 | + p = d * .3; | |
| 1876 | + } | |
| 1877 | + | |
| 1878 | + if (!a || a < Math.abs(c)) { | |
| 1879 | + a = c; | |
| 1880 | + var s = p / 4; | |
| 1881 | + } | |
| 1882 | + else { | |
| 1883 | + var s = p / (2 * Math.PI) * Math.asin(c / a); | |
| 1884 | + } | |
| 1885 | + | |
| 1886 | + return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; | |
| 1887 | + }, | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + elasticOut: function (t, b, c, d, a, p) { | |
| 1891 | + if (t == 0) { | |
| 1892 | + return b; | |
| 1893 | + } | |
| 1894 | + if ((t /= d) == 1) { | |
| 1895 | + return b + c; | |
| 1896 | + } | |
| 1897 | + if (!p) { | |
| 1898 | + p = d * .3; | |
| 1899 | + } | |
| 1900 | + | |
| 1901 | + if (!a || a < Math.abs(c)) { | |
| 1902 | + a = c; | |
| 1903 | + var s = p / 4; | |
| 1904 | + } | |
| 1905 | + else { | |
| 1906 | + var s = p / (2 * Math.PI) * Math.asin(c / a); | |
| 1907 | + } | |
| 1908 | + | |
| 1909 | + return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b; | |
| 1910 | + }, | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + elasticBoth: function (t, b, c, d, a, p) { | |
| 1914 | + if (t == 0) { | |
| 1915 | + return b; | |
| 1916 | + } | |
| 1917 | + | |
| 1918 | + if ((t /= d / 2) == 2) { | |
| 1919 | + return b + c; | |
| 1920 | + } | |
| 1921 | + | |
| 1922 | + if (!p) { | |
| 1923 | + p = d * (.3 * 1.5); | |
| 1924 | + } | |
| 1925 | + | |
| 1926 | + if (!a || a < Math.abs(c)) { | |
| 1927 | + a = c; | |
| 1928 | + var s = p / 4; | |
| 1929 | + } | |
| 1930 | + else { | |
| 1931 | + var s = p / (2 * Math.PI) * Math.asin(c / a); | |
| 1932 | + } | |
| 1933 | + | |
| 1934 | + if (t < 1) { | |
| 1935 | + return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * | |
| 1936 | + Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; | |
| 1937 | + } | |
| 1938 | + return a * Math.pow(2, -10 * (t -= 1)) * | |
| 1939 | + Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b; | |
| 1940 | + }, | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + backIn: function (t, b, c, d, s) { | |
| 1945 | + if (typeof s == 'undefined') { | |
| 1946 | + s = 1.70158; | |
| 1947 | + } | |
| 1948 | + return c * (t /= d) * t * ((s + 1) * t - s) + b; | |
| 1949 | + }, | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + backOut: function (t, b, c, d, s) { | |
| 1953 | + if (typeof s == 'undefined') { | |
| 1954 | + s = 1.70158; | |
| 1955 | + } | |
| 1956 | + return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; | |
| 1957 | + }, | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + backBoth: function (t, b, c, d, s) { | |
| 1961 | + if (typeof s == 'undefined') { | |
| 1962 | + s = 1.70158; | |
| 1963 | + } | |
| 1964 | + | |
| 1965 | + if ((t /= d / 2 ) < 1) { | |
| 1966 | + return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; | |
| 1967 | + } | |
| 1968 | + return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; | |
| 1969 | + }, | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + bounceIn: function (t, b, c, d) { | |
| 1973 | + return c - Ext.lib.Easing.bounceOut(d - t, 0, c, d) + b; | |
| 1974 | + }, | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + bounceOut: function (t, b, c, d) { | |
| 1978 | + if ((t /= d) < (1 / 2.75)) { | |
| 1979 | + return c * (7.5625 * t * t) + b; | |
| 1980 | + } else if (t < (2 / 2.75)) { | |
| 1981 | + return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; | |
| 1982 | + } else if (t < (2.5 / 2.75)) { | |
| 1983 | + return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; | |
| 1984 | + } | |
| 1985 | + return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; | |
| 1986 | + }, | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + bounceBoth: function (t, b, c, d) { | |
| 1990 | + if (t < d / 2) { | |
| 1991 | + return Ext.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b; | |
| 1992 | + } | |
| 1993 | + return Ext.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b; | |
| 1994 | + } | |
| 1995 | + }; | |
| 1996 | + | |
| 1997 | + (function() { | |
| 1998 | + Ext.lib.Motion = function(el, attributes, duration, method) { | |
| 1999 | + if (el) { | |
| 2000 | + Ext.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method); | |
| 2001 | + } | |
| 2002 | + }; | |
| 2003 | + | |
| 2004 | + Ext.extend(Ext.lib.Motion, Ext.lib.ColorAnim); | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + var Y = Ext.lib; | |
| 2008 | + var superclass = Y.Motion.superclass; | |
| 2009 | + var proto = Y.Motion.prototype; | |
| 2010 | + | |
| 2011 | + proto.toString = function() { | |
| 2012 | + var el = this.getEl(); | |
| 2013 | + var id = el.id || el.tagName; | |
| 2014 | + return ("Motion " + id); | |
| 2015 | + }; | |
| 2016 | + | |
| 2017 | + proto.patterns.points = /^points$/i; | |
| 2018 | + | |
| 2019 | + proto.setAttribute = function(attr, val, unit) { | |
| 2020 | + if (this.patterns.points.test(attr)) { | |
| 2021 | + unit = unit || 'px'; | |
| 2022 | + superclass.setAttribute.call(this, 'left', val[0], unit); | |
| 2023 | + superclass.setAttribute.call(this, 'top', val[1], unit); | |
| 2024 | + } else { | |
| 2025 | + superclass.setAttribute.call(this, attr, val, unit); | |
| 2026 | + } | |
| 2027 | + }; | |
| 2028 | + | |
| 2029 | + proto.getAttribute = function(attr) { | |
| 2030 | + if (this.patterns.points.test(attr)) { | |
| 2031 | + var val = [ | |
| 2032 | + superclass.getAttribute.call(this, 'left'), | |
| 2033 | + superclass.getAttribute.call(this, 'top') | |
| 2034 | + ]; | |
| 2035 | + } else { | |
| 2036 | + val = superclass.getAttribute.call(this, attr); | |
| 2037 | + } | |
| 2038 | + | |
| 2039 | + return val; | |
| 2040 | + }; | |
| 2041 | + | |
| 2042 | + proto.doMethod = function(attr, start, end) { | |
| 2043 | + var val = null; | |
| 2044 | + | |
| 2045 | + if (this.patterns.points.test(attr)) { | |
| 2046 | + var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100; | |
| 2047 | + val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t); | |
| 2048 | + } else { | |
| 2049 | + val = superclass.doMethod.call(this, attr, start, end); | |
| 2050 | + } | |
| 2051 | + return val; | |
| 2052 | + }; | |
| 2053 | + | |
| 2054 | + proto.setRuntimeAttribute = function(attr) { | |
| 2055 | + if (this.patterns.points.test(attr)) { | |
| 2056 | + var el = this.getEl(); | |
| 2057 | + var attributes = this.attributes; | |
| 2058 | + var start; | |
| 2059 | + var control = attributes['points']['control'] || []; | |
| 2060 | + var end; | |
| 2061 | + var i, len; | |
| 2062 | + | |
| 2063 | + if (control.length > 0 && !Ext.isArray(control[0])) { | |
| 2064 | + control = [control]; | |
| 2065 | + } else { | |
| 2066 | + var tmp = []; | |
| 2067 | + for (i = 0,len = control.length; i < len; ++i) { | |
| 2068 | + tmp[i] = control[i]; | |
| 2069 | + } | |
| 2070 | + control = tmp; | |
| 2071 | + } | |
| 2072 | + | |
| 2073 | + Ext.fly(el, '_anim').position(); | |
| 2074 | + | |
| 2075 | + if (isset(attributes['points']['from'])) { | |
| 2076 | + Ext.lib.Dom.setXY(el, attributes['points']['from']); | |
| 2077 | + } | |
| 2078 | + else { | |
| 2079 | + Ext.lib.Dom.setXY(el, Ext.lib.Dom.getXY(el)); | |
| 2080 | + } | |
| 2081 | + | |
| 2082 | + start = this.getAttribute('points'); | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + if (isset(attributes['points']['to'])) { | |
| 2086 | + end = translateValues.call(this, attributes['points']['to'], start); | |
| 2087 | + | |
| 2088 | + var pageXY = Ext.lib.Dom.getXY(this.getEl()); | |
| 2089 | + for (i = 0,len = control.length; i < len; ++i) { | |
| 2090 | + control[i] = translateValues.call(this, control[i], start); | |
| 2091 | + } | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + } else if (isset(attributes['points']['by'])) { | |
| 2095 | + end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ]; | |
| 2096 | + | |
| 2097 | + for (i = 0,len = control.length; i < len; ++i) { | |
| 2098 | + control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ]; | |
| 2099 | + } | |
| 2100 | + } | |
| 2101 | + | |
| 2102 | + this.runtimeAttributes[attr] = [start]; | |
| 2103 | + | |
| 2104 | + if (control.length > 0) { | |
| 2105 | + this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control); | |
| 2106 | + } | |
| 2107 | + | |
| 2108 | + this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end; | |
| 2109 | + } | |
| 2110 | + else { | |
| 2111 | + superclass.setRuntimeAttribute.call(this, attr); | |
| 2112 | + } | |
| 2113 | + }; | |
| 2114 | + | |
| 2115 | + var translateValues = function(val, start) { | |
| 2116 | + var pageXY = Ext.lib.Dom.getXY(this.getEl()); | |
| 2117 | + val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ]; | |
| 2118 | + | |
| 2119 | + return val; | |
| 2120 | + }; | |
| 2121 | + | |
| 2122 | + var isset = function(prop) { | |
| 2123 | + return (typeof prop !== 'undefined'); | |
| 2124 | + }; | |
| 2125 | + })(); | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + (function() { | |
| 2129 | + Ext.lib.Scroll = function(el, attributes, duration, method) { | |
| 2130 | + if (el) { | |
| 2131 | + Ext.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method); | |
| 2132 | + } | |
| 2133 | + }; | |
| 2134 | + | |
| 2135 | + Ext.extend(Ext.lib.Scroll, Ext.lib.ColorAnim); | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + var Y = Ext.lib; | |
| 2139 | + var superclass = Y.Scroll.superclass; | |
| 2140 | + var proto = Y.Scroll.prototype; | |
| 2141 | + | |
| 2142 | + proto.toString = function() { | |
| 2143 | + var el = this.getEl(); | |
| 2144 | + var id = el.id || el.tagName; | |
| 2145 | + return ("Scroll " + id); | |
| 2146 | + }; | |
| 2147 | + | |
| 2148 | + proto.doMethod = function(attr, start, end) { | |
| 2149 | + var val = null; | |
| 2150 | + | |
| 2151 | + if (attr == 'scroll') { | |
| 2152 | + val = [ | |
| 2153 | + this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames), | |
| 2154 | + this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames) | |
| 2155 | + ]; | |
| 2156 | + | |
| 2157 | + } else { | |
| 2158 | + val = superclass.doMethod.call(this, attr, start, end); | |
| 2159 | + } | |
| 2160 | + return val; | |
| 2161 | + }; | |
| 2162 | + | |
| 2163 | + proto.getAttribute = function(attr) { | |
| 2164 | + var val = null; | |
| 2165 | + var el = this.getEl(); | |
| 2166 | + | |
| 2167 | + if (attr == 'scroll') { | |
| 2168 | + val = [ el.scrollLeft, el.scrollTop ]; | |
| 2169 | + } else { | |
| 2170 | + val = superclass.getAttribute.call(this, attr); | |
| 2171 | + } | |
| 2172 | + | |
| 2173 | + return val; | |
| 2174 | + }; | |
| 2175 | + | |
| 2176 | + proto.setAttribute = function(attr, val, unit) { | |
| 2177 | + var el = this.getEl(); | |
| 2178 | + | |
| 2179 | + if (attr == 'scroll') { | |
| 2180 | + el.scrollLeft = val[0]; | |
| 2181 | + el.scrollTop = val[1]; | |
| 2182 | + } else { | |
| 2183 | + superclass.setAttribute.call(this, attr, val, unit); | |
| 2184 | + } | |
| 2185 | + }; | |
| 2186 | + })(); | |
| 2187 | + | |
| 2188 | + | |
| 2189 | +})(); | |
| 0 | 2190 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/adapter/jquery-bridge.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +if(typeof jQuery == "undefined"){ | |
| 10 | + throw "Unable to load Ext, jQuery not found."; | |
| 11 | +} | |
| 12 | + | |
| 13 | +(function(){ | |
| 14 | +var libFlyweight; | |
| 15 | + | |
| 16 | +Ext.lib.Dom = { | |
| 17 | + getViewWidth : function(full){ | |
| 18 | + // jQuery doesn't report full window size on document query, so max both | |
| 19 | + return full ? Math.max(jQuery(document).width(),jQuery(window).width()) : jQuery(window).width(); | |
| 20 | + }, | |
| 21 | + | |
| 22 | + getViewHeight : function(full){ | |
| 23 | + // jQuery doesn't report full window size on document query, so max both | |
| 24 | + return full ? Math.max(jQuery(document).height(),jQuery(window).height()) : jQuery(window).height(); | |
| 25 | + }, | |
| 26 | + | |
| 27 | + isAncestor : function(p, c){ | |
| 28 | + p = Ext.getDom(p); | |
| 29 | + c = Ext.getDom(c); | |
| 30 | + if (!p || !c) {return false;} | |
| 31 | + | |
| 32 | + if(p.contains && !Ext.isSafari) { | |
| 33 | + return p.contains(c); | |
| 34 | + }else if(p.compareDocumentPosition) { | |
| 35 | + return !!(p.compareDocumentPosition(c) & 16); | |
| 36 | + }else{ | |
| 37 | + var parent = c.parentNode; | |
| 38 | + while (parent) { | |
| 39 | + if (parent == p) { | |
| 40 | + return true; | |
| 41 | + } | |
| 42 | + else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") { | |
| 43 | + return false; | |
| 44 | + } | |
| 45 | + parent = parent.parentNode; | |
| 46 | + } | |
| 47 | + return false; | |
| 48 | + } | |
| 49 | + }, | |
| 50 | + | |
| 51 | + getRegion : function(el){ | |
| 52 | + return Ext.lib.Region.getRegion(el); | |
| 53 | + }, | |
| 54 | + | |
| 55 | + ////////////////////////////////////////////////////////////////////////////////////// | |
| 56 | + // Use of jQuery.offset() removed to promote consistent behavior across libs. | |
| 57 | + // JVS 05/23/07 | |
| 58 | + ////////////////////////////////////////////////////////////////////////////////////// | |
| 59 | + | |
| 60 | + getY : function(el){ | |
| 61 | + return this.getXY(el)[1]; | |
| 62 | + }, | |
| 63 | + | |
| 64 | + getX : function(el){ | |
| 65 | + return this.getXY(el)[0]; | |
| 66 | + }, | |
| 67 | + | |
| 68 | + getXY : function(el) { | |
| 69 | + var p, pe, b, scroll, bd = (document.body || document.documentElement); | |
| 70 | + el = Ext.getDom(el); | |
| 71 | + | |
| 72 | + if(el == bd){ | |
| 73 | + return [0, 0]; | |
| 74 | + } | |
| 75 | + | |
| 76 | + if (el.getBoundingClientRect) { | |
| 77 | + b = el.getBoundingClientRect(); | |
| 78 | + scroll = fly(document).getScroll(); | |
| 79 | + return [b.left + scroll.left, b.top + scroll.top]; | |
| 80 | + } | |
| 81 | + var x = 0, y = 0; | |
| 82 | + | |
| 83 | + p = el; | |
| 84 | + | |
| 85 | + var hasAbsolute = fly(el).getStyle("position") == "absolute"; | |
| 86 | + | |
| 87 | + while (p) { | |
| 88 | + | |
| 89 | + x += p.offsetLeft; | |
| 90 | + y += p.offsetTop; | |
| 91 | + | |
| 92 | + if (!hasAbsolute && fly(p).getStyle("position") == "absolute") { | |
| 93 | + hasAbsolute = true; | |
| 94 | + } | |
| 95 | + | |
| 96 | + if (Ext.isGecko) { | |
| 97 | + pe = fly(p); | |
| 98 | + | |
| 99 | + var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0; | |
| 100 | + var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0; | |
| 101 | + | |
| 102 | + | |
| 103 | + x += bl; | |
| 104 | + y += bt; | |
| 105 | + | |
| 106 | + | |
| 107 | + if (p != el && pe.getStyle('overflow') != 'visible') { | |
| 108 | + x += bl; | |
| 109 | + y += bt; | |
| 110 | + } | |
| 111 | + } | |
| 112 | + p = p.offsetParent; | |
| 113 | + } | |
| 114 | + | |
| 115 | + if (Ext.isSafari && hasAbsolute) { | |
| 116 | + x -= bd.offsetLeft; | |
| 117 | + y -= bd.offsetTop; | |
| 118 | + } | |
| 119 | + | |
| 120 | + if (Ext.isGecko && !hasAbsolute) { | |
| 121 | + var dbd = fly(bd); | |
| 122 | + x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0; | |
| 123 | + y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0; | |
| 124 | + } | |
| 125 | + | |
| 126 | + p = el.parentNode; | |
| 127 | + while (p && p != bd) { | |
| 128 | + if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) { | |
| 129 | + x -= p.scrollLeft; | |
| 130 | + y -= p.scrollTop; | |
| 131 | + } | |
| 132 | + p = p.parentNode; | |
| 133 | + } | |
| 134 | + return [x, y]; | |
| 135 | + }, | |
| 136 | + | |
| 137 | + setXY : function(el, xy){ | |
| 138 | + el = Ext.fly(el, '_setXY'); | |
| 139 | + el.position(); | |
| 140 | + var pts = el.translatePoints(xy); | |
| 141 | + if(xy[0] !== false){ | |
| 142 | + el.dom.style.left = pts.left + "px"; | |
| 143 | + } | |
| 144 | + if(xy[1] !== false){ | |
| 145 | + el.dom.style.top = pts.top + "px"; | |
| 146 | + } | |
| 147 | + }, | |
| 148 | + | |
| 149 | + setX : function(el, x){ | |
| 150 | + this.setXY(el, [x, false]); | |
| 151 | + }, | |
| 152 | + | |
| 153 | + setY : function(el, y){ | |
| 154 | + this.setXY(el, [false, y]); | |
| 155 | + } | |
| 156 | +}; | |
| 157 | + | |
| 158 | +// all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights | |
| 159 | +function fly(el){ | |
| 160 | + if(!libFlyweight){ | |
| 161 | + libFlyweight = new Ext.Element.Flyweight(); | |
| 162 | + } | |
| 163 | + libFlyweight.dom = el; | |
| 164 | + return libFlyweight; | |
| 165 | +} | |
| 166 | +Ext.lib.Event = { | |
| 167 | + getPageX : function(e){ | |
| 168 | + e = e.browserEvent || e; | |
| 169 | + return e.pageX; | |
| 170 | + }, | |
| 171 | + | |
| 172 | + getPageY : function(e){ | |
| 173 | + e = e.browserEvent || e; | |
| 174 | + return e.pageY; | |
| 175 | + }, | |
| 176 | + | |
| 177 | + getXY : function(e){ | |
| 178 | + e = e.browserEvent || e; | |
| 179 | + return [e.pageX, e.pageY]; | |
| 180 | + }, | |
| 181 | + | |
| 182 | + getTarget : function(e){ | |
| 183 | + return e.target; | |
| 184 | + }, | |
| 185 | + | |
| 186 | + // all Ext events will go through event manager which provides scoping | |
| 187 | + on : function(el, eventName, fn, scope, override){ | |
| 188 | + jQuery(el).bind(eventName, fn); | |
| 189 | + }, | |
| 190 | + | |
| 191 | + un : function(el, eventName, fn){ | |
| 192 | + jQuery(el).unbind(eventName, fn); | |
| 193 | + }, | |
| 194 | + | |
| 195 | + purgeElement : function(el){ | |
| 196 | + jQuery(el).unbind(); | |
| 197 | + }, | |
| 198 | + | |
| 199 | + preventDefault : function(e){ | |
| 200 | + e = e.browserEvent || e; | |
| 201 | + if(e.preventDefault){ | |
| 202 | + e.preventDefault(); | |
| 203 | + }else{ | |
| 204 | + e.returnValue = false; | |
| 205 | + } | |
| 206 | + }, | |
| 207 | + | |
| 208 | + stopPropagation : function(e){ | |
| 209 | + e = e.browserEvent || e; | |
| 210 | + if(e.stopPropagation){ | |
| 211 | + e.stopPropagation(); | |
| 212 | + }else{ | |
| 213 | + e.cancelBubble = true; | |
| 214 | + } | |
| 215 | + }, | |
| 216 | + | |
| 217 | + stopEvent : function(e){ | |
| 218 | + this.preventDefault(e); | |
| 219 | + this.stopPropagation(e); | |
| 220 | + }, | |
| 221 | + | |
| 222 | + onAvailable : function(id, fn, scope){ | |
| 223 | + var start = new Date(); | |
| 224 | + var f = function(){ | |
| 225 | + if(start.getElapsed() > 10000){ | |
| 226 | + clearInterval(iid); | |
| 227 | + } | |
| 228 | + var el = document.getElementById(id); | |
| 229 | + if(el){ | |
| 230 | + clearInterval(iid); | |
| 231 | + fn.call(scope||window, el); | |
| 232 | + } | |
| 233 | + }; | |
| 234 | + var iid = setInterval(f, 50); | |
| 235 | + }, | |
| 236 | + | |
| 237 | + resolveTextNode: function(node) { | |
| 238 | + if (node && 3 == node.nodeType) { | |
| 239 | + return node.parentNode; | |
| 240 | + } else { | |
| 241 | + return node; | |
| 242 | + } | |
| 243 | + }, | |
| 244 | + | |
| 245 | + getRelatedTarget: function(ev) { | |
| 246 | + ev = ev.browserEvent || ev; | |
| 247 | + var t = ev.relatedTarget; | |
| 248 | + if (!t) { | |
| 249 | + if (ev.type == "mouseout") { | |
| 250 | + t = ev.toElement; | |
| 251 | + } else if (ev.type == "mouseover") { | |
| 252 | + t = ev.fromElement; | |
| 253 | + } | |
| 254 | + } | |
| 255 | + | |
| 256 | + return this.resolveTextNode(t); | |
| 257 | + } | |
| 258 | +}; | |
| 259 | + | |
| 260 | +Ext.lib.Ajax = function(){ | |
| 261 | + var createComplete = function(cb){ | |
| 262 | + return function(xhr, status){ | |
| 263 | + if((status == 'error' || status == 'timeout') && cb.failure){ | |
| 264 | + cb.failure.call(cb.scope||window, { | |
| 265 | + responseText: xhr.responseText, | |
| 266 | + responseXML : xhr.responseXML, | |
| 267 | + argument: cb.argument | |
| 268 | + }); | |
| 269 | + }else if(cb.success){ | |
| 270 | + cb.success.call(cb.scope||window, { | |
| 271 | + responseText: xhr.responseText, | |
| 272 | + responseXML : xhr.responseXML, | |
| 273 | + argument: cb.argument | |
| 274 | + }); | |
| 275 | + } | |
| 276 | + }; | |
| 277 | + }; | |
| 278 | + return { | |
| 279 | + request : function(method, uri, cb, data, options){ | |
| 280 | + var o = { | |
| 281 | + type: method, | |
| 282 | + url: uri, | |
| 283 | + data: data, | |
| 284 | + timeout: cb.timeout, | |
| 285 | + complete: createComplete(cb) | |
| 286 | + }; | |
| 287 | + | |
| 288 | + if(options){ | |
| 289 | + var hs = options.headers; | |
| 290 | + if(options.xmlData){ | |
| 291 | + o.data = options.xmlData; | |
| 292 | + o.processData = false; | |
| 293 | + o.type = (method ? method : (options.method ? options.method : 'POST')); | |
| 294 | + if (!hs || !hs['Content-Type']){ | |
| 295 | + o.contentType = 'text/xml'; | |
| 296 | + } | |
| 297 | + }else if(options.jsonData){ | |
| 298 | + o.data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData; | |
| 299 | + o.processData = false; | |
| 300 | + o.type = (method ? method : (options.method ? options.method : 'POST')); | |
| 301 | + if (!hs || !hs['Content-Type']){ | |
| 302 | + o.contentType = 'application/json'; | |
| 303 | + } | |
| 304 | + } | |
| 305 | + if(hs){ | |
| 306 | + o.beforeSend = function(xhr){ | |
| 307 | + for(var h in hs){ | |
| 308 | + if(hs.hasOwnProperty(h)){ | |
| 309 | + xhr.setRequestHeader(h, hs[h]); | |
| 310 | + } | |
| 311 | + } | |
| 312 | + } | |
| 313 | + } | |
| 314 | + } | |
| 315 | + jQuery.ajax(o); | |
| 316 | + }, | |
| 317 | + | |
| 318 | + formRequest : function(form, uri, cb, data, isUpload, sslUri){ | |
| 319 | + jQuery.ajax({ | |
| 320 | + type: Ext.getDom(form).method ||'POST', | |
| 321 | + url: uri, | |
| 322 | + data: jQuery(form).serialize()+(data?'&'+data:''), | |
| 323 | + timeout: cb.timeout, | |
| 324 | + complete: createComplete(cb) | |
| 325 | + }); | |
| 326 | + }, | |
| 327 | + | |
| 328 | + isCallInProgress : function(trans){ | |
| 329 | + return false; | |
| 330 | + }, | |
| 331 | + | |
| 332 | + abort : function(trans){ | |
| 333 | + return false; | |
| 334 | + }, | |
| 335 | + | |
| 336 | + serializeForm : function(form){ | |
| 337 | + return jQuery(form.dom||form).serialize(); | |
| 338 | + } | |
| 339 | + }; | |
| 340 | +}(); | |
| 341 | + | |
| 342 | +Ext.lib.Anim = function(){ | |
| 343 | + var createAnim = function(cb, scope){ | |
| 344 | + var animated = true; | |
| 345 | + return { | |
| 346 | + stop : function(skipToLast){ | |
| 347 | + // do nothing | |
| 348 | + }, | |
| 349 | + | |
| 350 | + isAnimated : function(){ | |
| 351 | + return animated; | |
| 352 | + }, | |
| 353 | + | |
| 354 | + proxyCallback : function(){ | |
| 355 | + animated = false; | |
| 356 | + Ext.callback(cb, scope); | |
| 357 | + } | |
| 358 | + }; | |
| 359 | + }; | |
| 360 | + return { | |
| 361 | + scroll : function(el, args, duration, easing, cb, scope){ | |
| 362 | + // scroll anim not supported so just scroll immediately | |
| 363 | + var anim = createAnim(cb, scope); | |
| 364 | + el = Ext.getDom(el); | |
| 365 | + if(typeof args.scroll.to[0] == 'number'){ | |
| 366 | + el.scrollLeft = args.scroll.to[0]; | |
| 367 | + } | |
| 368 | + if(typeof args.scroll.to[1] == 'number'){ | |
| 369 | + el.scrollTop = args.scroll.to[1]; | |
| 370 | + } | |
| 371 | + anim.proxyCallback(); | |
| 372 | + return anim; | |
| 373 | + }, | |
| 374 | + | |
| 375 | + motion : function(el, args, duration, easing, cb, scope){ | |
| 376 | + return this.run(el, args, duration, easing, cb, scope); | |
| 377 | + }, | |
| 378 | + | |
| 379 | + color : function(el, args, duration, easing, cb, scope){ | |
| 380 | + // color anim not supported, so execute callback immediately | |
| 381 | + var anim = createAnim(cb, scope); | |
| 382 | + anim.proxyCallback(); | |
| 383 | + return anim; | |
| 384 | + }, | |
| 385 | + | |
| 386 | + run : function(el, args, duration, easing, cb, scope, type){ | |
| 387 | + var anim = createAnim(cb, scope), e = Ext.fly(el, '_animrun'); | |
| 388 | + var o = {}; | |
| 389 | + for(var k in args){ | |
| 390 | + if(args[k].from){ | |
| 391 | + if(k != 'points'){ | |
| 392 | + e.setStyle(k, args[k].from); | |
| 393 | + } | |
| 394 | + } | |
| 395 | + switch(k){ // jquery doesn't support, so convert | |
| 396 | + case 'points': | |
| 397 | + var by, pts; | |
| 398 | + e.position(); | |
| 399 | + if(by = args.points.by){ | |
| 400 | + var xy = e.getXY(); | |
| 401 | + pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]); | |
| 402 | + }else{ | |
| 403 | + pts = e.translatePoints(args.points.to); | |
| 404 | + } | |
| 405 | + o.left = pts.left; | |
| 406 | + o.top = pts.top; | |
| 407 | + if(!parseInt(e.getStyle('left'), 10)){ // auto bug | |
| 408 | + e.setLeft(0); | |
| 409 | + } | |
| 410 | + if(!parseInt(e.getStyle('top'), 10)){ | |
| 411 | + e.setTop(0); | |
| 412 | + } | |
| 413 | + if(args.points.from){ | |
| 414 | + e.setXY(args.points.from); | |
| 415 | + } | |
| 416 | + break; | |
| 417 | + case 'width': | |
| 418 | + o.width = args.width.to; | |
| 419 | + break; | |
| 420 | + case 'height': | |
| 421 | + o.height = args.height.to; | |
| 422 | + break; | |
| 423 | + case 'opacity': | |
| 424 | + o.opacity = args.opacity.to; | |
| 425 | + break; | |
| 426 | + case 'left': | |
| 427 | + o.left = args.left.to; | |
| 428 | + break; | |
| 429 | + case 'top': | |
| 430 | + o.top = args.top.to; | |
| 431 | + break; | |
| 432 | + default: | |
| 433 | + o[k] = args[k].to; | |
| 434 | + break; | |
| 435 | + } | |
| 436 | + } | |
| 437 | + // TODO: find out about easing plug in? | |
| 438 | + jQuery(el).animate(o, duration*1000, undefined, anim.proxyCallback); | |
| 439 | + return anim; | |
| 440 | + } | |
| 441 | + }; | |
| 442 | +}(); | |
| 443 | + | |
| 444 | + | |
| 445 | +Ext.lib.Region = function(t, r, b, l) { | |
| 446 | + this.top = t; | |
| 447 | + this[1] = t; | |
| 448 | + this.right = r; | |
| 449 | + this.bottom = b; | |
| 450 | + this.left = l; | |
| 451 | + this[0] = l; | |
| 452 | +}; | |
| 453 | + | |
| 454 | +Ext.lib.Region.prototype = { | |
| 455 | + contains : function(region) { | |
| 456 | + return ( region.left >= this.left && | |
| 457 | + region.right <= this.right && | |
| 458 | + region.top >= this.top && | |
| 459 | + region.bottom <= this.bottom ); | |
| 460 | + | |
| 461 | + }, | |
| 462 | + | |
| 463 | + getArea : function() { | |
| 464 | + return ( (this.bottom - this.top) * (this.right - this.left) ); | |
| 465 | + }, | |
| 466 | + | |
| 467 | + intersect : function(region) { | |
| 468 | + var t = Math.max( this.top, region.top ); | |
| 469 | + var r = Math.min( this.right, region.right ); | |
| 470 | + var b = Math.min( this.bottom, region.bottom ); | |
| 471 | + var l = Math.max( this.left, region.left ); | |
| 472 | + | |
| 473 | + if (b >= t && r >= l) { | |
| 474 | + return new Ext.lib.Region(t, r, b, l); | |
| 475 | + } else { | |
| 476 | + return null; | |
| 477 | + } | |
| 478 | + }, | |
| 479 | + union : function(region) { | |
| 480 | + var t = Math.min( this.top, region.top ); | |
| 481 | + var r = Math.max( this.right, region.right ); | |
| 482 | + var b = Math.max( this.bottom, region.bottom ); | |
| 483 | + var l = Math.min( this.left, region.left ); | |
| 484 | + | |
| 485 | + return new Ext.lib.Region(t, r, b, l); | |
| 486 | + }, | |
| 487 | + | |
| 488 | + constrainTo : function(r) { | |
| 489 | + this.top = this.top.constrain(r.top, r.bottom); | |
| 490 | + this.bottom = this.bottom.constrain(r.top, r.bottom); | |
| 491 | + this.left = this.left.constrain(r.left, r.right); | |
| 492 | + this.right = this.right.constrain(r.left, r.right); | |
| 493 | + return this; | |
| 494 | + }, | |
| 495 | + | |
| 496 | + adjust : function(t, l, b, r){ | |
| 497 | + this.top += t; | |
| 498 | + this.left += l; | |
| 499 | + this.right += r; | |
| 500 | + this.bottom += b; | |
| 501 | + return this; | |
| 502 | + } | |
| 503 | +}; | |
| 504 | + | |
| 505 | +Ext.lib.Region.getRegion = function(el) { | |
| 506 | + var p = Ext.lib.Dom.getXY(el); | |
| 507 | + | |
| 508 | + var t = p[1]; | |
| 509 | + var r = p[0] + el.offsetWidth; | |
| 510 | + var b = p[1] + el.offsetHeight; | |
| 511 | + var l = p[0]; | |
| 512 | + | |
| 513 | + return new Ext.lib.Region(t, r, b, l); | |
| 514 | +}; | |
| 515 | + | |
| 516 | +Ext.lib.Point = function(x, y) { | |
| 517 | + if (Ext.isArray(x)) { | |
| 518 | + y = x[1]; | |
| 519 | + x = x[0]; | |
| 520 | + } | |
| 521 | + this.x = this.right = this.left = this[0] = x; | |
| 522 | + this.y = this.top = this.bottom = this[1] = y; | |
| 523 | +}; | |
| 524 | + | |
| 525 | +Ext.lib.Point.prototype = new Ext.lib.Region(); | |
| 526 | + | |
| 527 | +// prevent IE leaks | |
| 528 | +if(Ext.isIE) { | |
| 529 | + function fnCleanUp() { | |
| 530 | + var p = Function.prototype; | |
| 531 | + delete p.createSequence; | |
| 532 | + delete p.defer; | |
| 533 | + delete p.createDelegate; | |
| 534 | + delete p.createCallback; | |
| 535 | + delete p.createInterceptor; | |
| 536 | + | |
| 537 | + window.detachEvent("onunload", fnCleanUp); | |
| 538 | + } | |
| 539 | + window.attachEvent("onunload", fnCleanUp); | |
| 540 | +} | |
| 541 | +})(); | |
| 0 | 542 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/adapter/prototype-bridge.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +(function(){ | |
| 10 | + | |
| 11 | +var libFlyweight; | |
| 12 | + | |
| 13 | +Ext.lib.Dom = { | |
| 14 | + getViewWidth : function(full){ | |
| 15 | + return full ? this.getDocumentWidth() : this.getViewportWidth(); | |
| 16 | + }, | |
| 17 | + | |
| 18 | + getViewHeight : function(full){ | |
| 19 | + return full ? this.getDocumentHeight() : this.getViewportHeight(); | |
| 20 | + }, | |
| 21 | + | |
| 22 | + getDocumentHeight: function() { // missing from prototype? | |
| 23 | + var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight; | |
| 24 | + return Math.max(scrollHeight, this.getViewportHeight()); | |
| 25 | + }, | |
| 26 | + | |
| 27 | + getDocumentWidth: function() { // missing from prototype? | |
| 28 | + var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth; | |
| 29 | + return Math.max(scrollWidth, this.getViewportWidth()); | |
| 30 | + }, | |
| 31 | + | |
| 32 | + getViewportHeight: function() { // missing from prototype? | |
| 33 | + var height = self.innerHeight; | |
| 34 | + var mode = document.compatMode; | |
| 35 | + | |
| 36 | + if ( (mode || Ext.isIE) && !Ext.isOpera ) { | |
| 37 | + height = (mode == "CSS1Compat") ? | |
| 38 | + document.documentElement.clientHeight : // Standards | |
| 39 | + document.body.clientHeight; // Quirks | |
| 40 | + } | |
| 41 | + | |
| 42 | + return height; | |
| 43 | + }, | |
| 44 | + | |
| 45 | + getViewportWidth: function() { // missing from prototype? | |
| 46 | + var width = self.innerWidth; // Safari | |
| 47 | + var mode = document.compatMode; | |
| 48 | + | |
| 49 | + if (mode || Ext.isIE) { // IE, Gecko, Opera | |
| 50 | + width = (mode == "CSS1Compat") ? | |
| 51 | + document.documentElement.clientWidth : // Standards | |
| 52 | + document.body.clientWidth; // Quirks | |
| 53 | + } | |
| 54 | + return width; | |
| 55 | + }, | |
| 56 | + | |
| 57 | + isAncestor : function(p, c){ // missing from prototype? | |
| 58 | + p = Ext.getDom(p); | |
| 59 | + c = Ext.getDom(c); | |
| 60 | + if (!p || !c) {return false;} | |
| 61 | + | |
| 62 | + if(p.contains && !Ext.isSafari) { | |
| 63 | + return p.contains(c); | |
| 64 | + }else if(p.compareDocumentPosition) { | |
| 65 | + return !!(p.compareDocumentPosition(c) & 16); | |
| 66 | + }else{ | |
| 67 | + var parent = c.parentNode; | |
| 68 | + while (parent) { | |
| 69 | + if (parent == p) { | |
| 70 | + return true; | |
| 71 | + } | |
| 72 | + else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") { | |
| 73 | + return false; | |
| 74 | + } | |
| 75 | + parent = parent.parentNode; | |
| 76 | + } | |
| 77 | + return false; | |
| 78 | + } | |
| 79 | + }, | |
| 80 | + | |
| 81 | + getRegion : function(el){ | |
| 82 | + return Ext.lib.Region.getRegion(el); | |
| 83 | + }, | |
| 84 | + | |
| 85 | + getY : function(el){ | |
| 86 | + return this.getXY(el)[1]; | |
| 87 | + }, | |
| 88 | + | |
| 89 | + getX : function(el){ | |
| 90 | + return this.getXY(el)[0]; | |
| 91 | + }, | |
| 92 | + | |
| 93 | + getXY : function(el){ // this initially used Position.cumulativeOffset but it is not accurate enough | |
| 94 | + var p, pe, b, scroll, bd = (document.body || document.documentElement); | |
| 95 | + el = Ext.getDom(el); | |
| 96 | + | |
| 97 | + if(el == bd){ | |
| 98 | + return [0, 0]; | |
| 99 | + } | |
| 100 | + | |
| 101 | + if (el.getBoundingClientRect) { | |
| 102 | + b = el.getBoundingClientRect(); | |
| 103 | + scroll = fly(document).getScroll(); | |
| 104 | + return [b.left + scroll.left, b.top + scroll.top]; | |
| 105 | + } | |
| 106 | + var x = 0, y = 0; | |
| 107 | + | |
| 108 | + p = el; | |
| 109 | + | |
| 110 | + var hasAbsolute = fly(el).getStyle("position") == "absolute"; | |
| 111 | + | |
| 112 | + while (p) { | |
| 113 | + | |
| 114 | + x += p.offsetLeft; | |
| 115 | + y += p.offsetTop; | |
| 116 | + | |
| 117 | + if (!hasAbsolute && fly(p).getStyle("position") == "absolute") { | |
| 118 | + hasAbsolute = true; | |
| 119 | + } | |
| 120 | + | |
| 121 | + if (Ext.isGecko) { | |
| 122 | + pe = fly(p); | |
| 123 | + | |
| 124 | + var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0; | |
| 125 | + var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0; | |
| 126 | + | |
| 127 | + | |
| 128 | + x += bl; | |
| 129 | + y += bt; | |
| 130 | + | |
| 131 | + | |
| 132 | + if (p != el && pe.getStyle('overflow') != 'visible') { | |
| 133 | + x += bl; | |
| 134 | + y += bt; | |
| 135 | + } | |
| 136 | + } | |
| 137 | + p = p.offsetParent; | |
| 138 | + } | |
| 139 | + | |
| 140 | + if (Ext.isSafari && hasAbsolute) { | |
| 141 | + x -= bd.offsetLeft; | |
| 142 | + y -= bd.offsetTop; | |
| 143 | + } | |
| 144 | + | |
| 145 | + if (Ext.isGecko && !hasAbsolute) { | |
| 146 | + var dbd = fly(bd); | |
| 147 | + x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0; | |
| 148 | + y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0; | |
| 149 | + } | |
| 150 | + | |
| 151 | + p = el.parentNode; | |
| 152 | + while (p && p != bd) { | |
| 153 | + if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) { | |
| 154 | + x -= p.scrollLeft; | |
| 155 | + y -= p.scrollTop; | |
| 156 | + } | |
| 157 | + p = p.parentNode; | |
| 158 | + } | |
| 159 | + return [x, y]; | |
| 160 | + }, | |
| 161 | + | |
| 162 | + setXY : function(el, xy){ // this initially used Position.cumulativeOffset but it is not accurate enough | |
| 163 | + el = Ext.fly(el, '_setXY'); | |
| 164 | + el.position(); | |
| 165 | + var pts = el.translatePoints(xy); | |
| 166 | + if(xy[0] !== false){ | |
| 167 | + el.dom.style.left = pts.left + "px"; | |
| 168 | + } | |
| 169 | + if(xy[1] !== false){ | |
| 170 | + el.dom.style.top = pts.top + "px"; | |
| 171 | + } | |
| 172 | + }, | |
| 173 | + | |
| 174 | + setX : function(el, x){ | |
| 175 | + this.setXY(el, [x, false]); | |
| 176 | + }, | |
| 177 | + | |
| 178 | + setY : function(el, y){ | |
| 179 | + this.setXY(el, [false, y]); | |
| 180 | + } | |
| 181 | +}; | |
| 182 | + | |
| 183 | +Ext.lib.Event = { | |
| 184 | + getPageX : function(e){ | |
| 185 | + return Event.pointerX(e.browserEvent || e); | |
| 186 | + }, | |
| 187 | + | |
| 188 | + getPageY : function(e){ | |
| 189 | + return Event.pointerY(e.browserEvent || e); | |
| 190 | + }, | |
| 191 | + | |
| 192 | + getXY : function(e){ | |
| 193 | + e = e.browserEvent || e; | |
| 194 | + return [Event.pointerX(e), Event.pointerY(e)]; | |
| 195 | + }, | |
| 196 | + | |
| 197 | + getTarget : function(e){ | |
| 198 | + return Event.element(e.browserEvent || e); | |
| 199 | + }, | |
| 200 | + | |
| 201 | + resolveTextNode: function(node) { | |
| 202 | + if (node && 3 == node.nodeType) { | |
| 203 | + return node.parentNode; | |
| 204 | + } else { | |
| 205 | + return node; | |
| 206 | + } | |
| 207 | + }, | |
| 208 | + | |
| 209 | + getRelatedTarget: function(ev) { // missing from prototype? | |
| 210 | + ev = ev.browserEvent || ev; | |
| 211 | + var t = ev.relatedTarget; | |
| 212 | + if (!t) { | |
| 213 | + if (ev.type == "mouseout") { | |
| 214 | + t = ev.toElement; | |
| 215 | + } else if (ev.type == "mouseover") { | |
| 216 | + t = ev.fromElement; | |
| 217 | + } | |
| 218 | + } | |
| 219 | + | |
| 220 | + return this.resolveTextNode(t); | |
| 221 | + }, | |
| 222 | + | |
| 223 | + on : function(el, eventName, fn){ | |
| 224 | + Event.observe(el, eventName, fn, false); | |
| 225 | + }, | |
| 226 | + | |
| 227 | + un : function(el, eventName, fn){ | |
| 228 | + Event.stopObserving(el, eventName, fn, false); | |
| 229 | + }, | |
| 230 | + | |
| 231 | + purgeElement : function(el){ | |
| 232 | + // no equiv? | |
| 233 | + }, | |
| 234 | + | |
| 235 | + preventDefault : function(e){ // missing from prototype? | |
| 236 | + e = e.browserEvent || e; | |
| 237 | + if(e.preventDefault) { | |
| 238 | + e.preventDefault(); | |
| 239 | + } else { | |
| 240 | + e.returnValue = false; | |
| 241 | + } | |
| 242 | + }, | |
| 243 | + | |
| 244 | + stopPropagation : function(e){ // missing from prototype? | |
| 245 | + e = e.browserEvent || e; | |
| 246 | + if(e.stopPropagation) { | |
| 247 | + e.stopPropagation(); | |
| 248 | + } else { | |
| 249 | + e.cancelBubble = true; | |
| 250 | + } | |
| 251 | + }, | |
| 252 | + | |
| 253 | + stopEvent : function(e){ | |
| 254 | + Event.stop(e.browserEvent || e); | |
| 255 | + }, | |
| 256 | + | |
| 257 | + onAvailable : function(id, fn, scope){ // no equiv | |
| 258 | + var start = new Date(), iid; | |
| 259 | + var f = function(){ | |
| 260 | + if(start.getElapsed() > 10000){ | |
| 261 | + clearInterval(iid); | |
| 262 | + } | |
| 263 | + var el = document.getElementById(id); | |
| 264 | + if(el){ | |
| 265 | + clearInterval(iid); | |
| 266 | + fn.call(scope||window, el); | |
| 267 | + } | |
| 268 | + }; | |
| 269 | + iid = setInterval(f, 50); | |
| 270 | + } | |
| 271 | +}; | |
| 272 | + | |
| 273 | +Ext.lib.Ajax = function(){ | |
| 274 | + var createSuccess = function(cb){ | |
| 275 | + return cb.success ? function(xhr){ | |
| 276 | + cb.success.call(cb.scope||window, { | |
| 277 | + responseText: xhr.responseText, | |
| 278 | + responseXML : xhr.responseXML, | |
| 279 | + argument: cb.argument | |
| 280 | + }); | |
| 281 | + } : Ext.emptyFn; | |
| 282 | + }; | |
| 283 | + var createFailure = function(cb){ | |
| 284 | + return cb.failure ? function(xhr){ | |
| 285 | + cb.failure.call(cb.scope||window, { | |
| 286 | + responseText: xhr.responseText, | |
| 287 | + responseXML : xhr.responseXML, | |
| 288 | + argument: cb.argument | |
| 289 | + }); | |
| 290 | + } : Ext.emptyFn; | |
| 291 | + }; | |
| 292 | + return { | |
| 293 | + request : function(method, uri, cb, data, options){ | |
| 294 | + var o = { | |
| 295 | + method: method, | |
| 296 | + parameters: data || '', | |
| 297 | + timeout: cb.timeout, | |
| 298 | + onSuccess: createSuccess(cb), | |
| 299 | + onFailure: createFailure(cb) | |
| 300 | + }; | |
| 301 | + if(options){ | |
| 302 | + var hs = options.headers; | |
| 303 | + if(hs){ | |
| 304 | + o.requestHeaders = hs; | |
| 305 | + } | |
| 306 | + if(options.xmlData){ | |
| 307 | + method = (method ? method : (options.method ? options.method : 'POST')); | |
| 308 | + if (!hs || !hs['Content-Type']){ | |
| 309 | + o.contentType = 'text/xml'; | |
| 310 | + } | |
| 311 | + o.postBody = options.xmlData; | |
| 312 | + delete o.parameters; | |
| 313 | + } | |
| 314 | + if(options.jsonData){ | |
| 315 | + method = (method ? method : (options.method ? options.method : 'POST')); | |
| 316 | + if (!hs || !hs['Content-Type']){ | |
| 317 | + o.contentType = 'application/json'; | |
| 318 | + } | |
| 319 | + o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData; | |
| 320 | + delete o.parameters; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + new Ajax.Request(uri, o); | |
| 324 | + }, | |
| 325 | + | |
| 326 | + formRequest : function(form, uri, cb, data, isUpload, sslUri){ | |
| 327 | + new Ajax.Request(uri, { | |
| 328 | + method: Ext.getDom(form).method ||'POST', | |
| 329 | + parameters: Form.serialize(form)+(data?'&'+data:''), | |
| 330 | + timeout: cb.timeout, | |
| 331 | + onSuccess: createSuccess(cb), | |
| 332 | + onFailure: createFailure(cb) | |
| 333 | + }); | |
| 334 | + }, | |
| 335 | + | |
| 336 | + isCallInProgress : function(trans){ | |
| 337 | + return false; | |
| 338 | + }, | |
| 339 | + | |
| 340 | + abort : function(trans){ | |
| 341 | + return false; | |
| 342 | + }, | |
| 343 | + | |
| 344 | + serializeForm : function(form){ | |
| 345 | + return Form.serialize(form.dom||form); | |
| 346 | + } | |
| 347 | + }; | |
| 348 | +}(); | |
| 349 | + | |
| 350 | + | |
| 351 | +Ext.lib.Anim = function(){ | |
| 352 | + | |
| 353 | + var easings = { | |
| 354 | + easeOut: function(pos) { | |
| 355 | + return 1-Math.pow(1-pos,2); | |
| 356 | + }, | |
| 357 | + easeIn: function(pos) { | |
| 358 | + return 1-Math.pow(1-pos,2); | |
| 359 | + } | |
| 360 | + }; | |
| 361 | + var createAnim = function(cb, scope){ | |
| 362 | + return { | |
| 363 | + stop : function(skipToLast){ | |
| 364 | + this.effect.cancel(); | |
| 365 | + }, | |
| 366 | + | |
| 367 | + isAnimated : function(){ | |
| 368 | + return this.effect.state == 'running'; | |
| 369 | + }, | |
| 370 | + | |
| 371 | + proxyCallback : function(){ | |
| 372 | + Ext.callback(cb, scope); | |
| 373 | + } | |
| 374 | + }; | |
| 375 | + }; | |
| 376 | + return { | |
| 377 | + scroll : function(el, args, duration, easing, cb, scope){ | |
| 378 | + // not supported so scroll immediately? | |
| 379 | + var anim = createAnim(cb, scope); | |
| 380 | + el = Ext.getDom(el); | |
| 381 | + if(typeof args.scroll.to[0] == 'number'){ | |
| 382 | + el.scrollLeft = args.scroll.to[0]; | |
| 383 | + } | |
| 384 | + if(typeof args.scroll.to[1] == 'number'){ | |
| 385 | + el.scrollTop = args.scroll.to[1]; | |
| 386 | + } | |
| 387 | + anim.proxyCallback(); | |
| 388 | + return anim; | |
| 389 | + }, | |
| 390 | + | |
| 391 | + motion : function(el, args, duration, easing, cb, scope){ | |
| 392 | + return this.run(el, args, duration, easing, cb, scope); | |
| 393 | + }, | |
| 394 | + | |
| 395 | + color : function(el, args, duration, easing, cb, scope){ | |
| 396 | + return this.run(el, args, duration, easing, cb, scope); | |
| 397 | + }, | |
| 398 | + | |
| 399 | + run : function(el, args, duration, easing, cb, scope, type){ | |
| 400 | + var o = {}; | |
| 401 | + for(var k in args){ | |
| 402 | + switch(k){ // scriptaculous doesn't support, so convert these | |
| 403 | + case 'points': | |
| 404 | + var by, pts, e = Ext.fly(el, '_animrun'); | |
| 405 | + e.position(); | |
| 406 | + if(by = args.points.by){ | |
| 407 | + var xy = e.getXY(); | |
| 408 | + pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]); | |
| 409 | + }else{ | |
| 410 | + pts = e.translatePoints(args.points.to); | |
| 411 | + } | |
| 412 | + o.left = pts.left+'px'; | |
| 413 | + o.top = pts.top+'px'; | |
| 414 | + break; | |
| 415 | + case 'width': | |
| 416 | + o.width = args.width.to+'px'; | |
| 417 | + break; | |
| 418 | + case 'height': | |
| 419 | + o.height = args.height.to+'px'; | |
| 420 | + break; | |
| 421 | + case 'opacity': | |
| 422 | + o.opacity = String(args.opacity.to); | |
| 423 | + break; | |
| 424 | + default: | |
| 425 | + o[k] = String(args[k].to); | |
| 426 | + break; | |
| 427 | + } | |
| 428 | + } | |
| 429 | + var anim = createAnim(cb, scope); | |
| 430 | + anim.effect = new Effect.Morph(Ext.id(el), { | |
| 431 | + duration: duration, | |
| 432 | + afterFinish: anim.proxyCallback, | |
| 433 | + transition: easings[easing] || Effect.Transitions.linear, | |
| 434 | + style: o | |
| 435 | + }); | |
| 436 | + return anim; | |
| 437 | + } | |
| 438 | + }; | |
| 439 | +}(); | |
| 440 | + | |
| 441 | + | |
| 442 | +// all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights | |
| 443 | +function fly(el){ | |
| 444 | + if(!libFlyweight){ | |
| 445 | + libFlyweight = new Ext.Element.Flyweight(); | |
| 446 | + } | |
| 447 | + libFlyweight.dom = el; | |
| 448 | + return libFlyweight; | |
| 449 | +} | |
| 450 | + | |
| 451 | +Ext.lib.Region = function(t, r, b, l) { | |
| 452 | + this.top = t; | |
| 453 | + this[1] = t; | |
| 454 | + this.right = r; | |
| 455 | + this.bottom = b; | |
| 456 | + this.left = l; | |
| 457 | + this[0] = l; | |
| 458 | +}; | |
| 459 | + | |
| 460 | +Ext.lib.Region.prototype = { | |
| 461 | + contains : function(region) { | |
| 462 | + return ( region.left >= this.left && | |
| 463 | + region.right <= this.right && | |
| 464 | + region.top >= this.top && | |
| 465 | + region.bottom <= this.bottom ); | |
| 466 | + | |
| 467 | + }, | |
| 468 | + | |
| 469 | + getArea : function() { | |
| 470 | + return ( (this.bottom - this.top) * (this.right - this.left) ); | |
| 471 | + }, | |
| 472 | + | |
| 473 | + intersect : function(region) { | |
| 474 | + var t = Math.max( this.top, region.top ); | |
| 475 | + var r = Math.min( this.right, region.right ); | |
| 476 | + var b = Math.min( this.bottom, region.bottom ); | |
| 477 | + var l = Math.max( this.left, region.left ); | |
| 478 | + | |
| 479 | + if (b >= t && r >= l) { | |
| 480 | + return new Ext.lib.Region(t, r, b, l); | |
| 481 | + } else { | |
| 482 | + return null; | |
| 483 | + } | |
| 484 | + }, | |
| 485 | + union : function(region) { | |
| 486 | + var t = Math.min( this.top, region.top ); | |
| 487 | + var r = Math.max( this.right, region.right ); | |
| 488 | + var b = Math.max( this.bottom, region.bottom ); | |
| 489 | + var l = Math.min( this.left, region.left ); | |
| 490 | + | |
| 491 | + return new Ext.lib.Region(t, r, b, l); | |
| 492 | + }, | |
| 493 | + | |
| 494 | + constrainTo : function(r) { | |
| 495 | + this.top = this.top.constrain(r.top, r.bottom); | |
| 496 | + this.bottom = this.bottom.constrain(r.top, r.bottom); | |
| 497 | + this.left = this.left.constrain(r.left, r.right); | |
| 498 | + this.right = this.right.constrain(r.left, r.right); | |
| 499 | + return this; | |
| 500 | + }, | |
| 501 | + | |
| 502 | + adjust : function(t, l, b, r){ | |
| 503 | + this.top += t; | |
| 504 | + this.left += l; | |
| 505 | + this.right += r; | |
| 506 | + this.bottom += b; | |
| 507 | + return this; | |
| 508 | + } | |
| 509 | +}; | |
| 510 | + | |
| 511 | +Ext.lib.Region.getRegion = function(el) { | |
| 512 | + var p = Ext.lib.Dom.getXY(el); | |
| 513 | + | |
| 514 | + var t = p[1]; | |
| 515 | + var r = p[0] + el.offsetWidth; | |
| 516 | + var b = p[1] + el.offsetHeight; | |
| 517 | + var l = p[0]; | |
| 518 | + | |
| 519 | + return new Ext.lib.Region(t, r, b, l); | |
| 520 | +}; | |
| 521 | + | |
| 522 | +Ext.lib.Point = function(x, y) { | |
| 523 | + if (Ext.isArray(x)) { | |
| 524 | + y = x[1]; | |
| 525 | + x = x[0]; | |
| 526 | + } | |
| 527 | + this.x = this.right = this.left = this[0] = x; | |
| 528 | + this.y = this.top = this.bottom = this[1] = y; | |
| 529 | +}; | |
| 530 | + | |
| 531 | +Ext.lib.Point.prototype = new Ext.lib.Region(); | |
| 532 | + | |
| 533 | + | |
| 534 | +// prevent IE leaks | |
| 535 | +if(Ext.isIE) { | |
| 536 | + function fnCleanUp() { | |
| 537 | + var p = Function.prototype; | |
| 538 | + delete p.createSequence; | |
| 539 | + delete p.defer; | |
| 540 | + delete p.createDelegate; | |
| 541 | + delete p.createCallback; | |
| 542 | + delete p.createInterceptor; | |
| 543 | + | |
| 544 | + window.detachEvent("onunload", fnCleanUp); | |
| 545 | + } | |
| 546 | + window.attachEvent("onunload", fnCleanUp); | |
| 547 | +} | |
| 548 | +})(); | |
| 0 | 549 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/adapter/yui-bridge.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +if(typeof YAHOO == "undefined"){ | |
| 10 | + throw "Unable to load Ext, core YUI utilities (yahoo, dom, event) not found."; | |
| 11 | +} | |
| 12 | + | |
| 13 | +(function(){ | |
| 14 | +var E = YAHOO.util.Event; | |
| 15 | +var D = YAHOO.util.Dom; | |
| 16 | +var CN = YAHOO.util.Connect; | |
| 17 | + | |
| 18 | +var ES = YAHOO.util.Easing; | |
| 19 | +var A = YAHOO.util.Anim; | |
| 20 | +var libFlyweight; | |
| 21 | + | |
| 22 | +Ext.lib.Dom = { | |
| 23 | + getViewWidth : function(full){ | |
| 24 | + return full ? D.getDocumentWidth() : D.getViewportWidth(); | |
| 25 | + }, | |
| 26 | + | |
| 27 | + getViewHeight : function(full){ | |
| 28 | + return full ? D.getDocumentHeight() : D.getViewportHeight(); | |
| 29 | + }, | |
| 30 | + | |
| 31 | + isAncestor : function(haystack, needle){ | |
| 32 | + return D.isAncestor(haystack, needle); | |
| 33 | + }, | |
| 34 | + | |
| 35 | + getRegion : function(el){ | |
| 36 | + return D.getRegion(el); | |
| 37 | + }, | |
| 38 | + | |
| 39 | + getY : function(el){ | |
| 40 | + return this.getXY(el)[1]; | |
| 41 | + }, | |
| 42 | + | |
| 43 | + getX : function(el){ | |
| 44 | + return this.getXY(el)[0]; | |
| 45 | + }, | |
| 46 | + | |
| 47 | + // original version based on YahooUI getXY | |
| 48 | + // this version fixes several issues in Safari and FF | |
| 49 | + // and boosts performance by removing the batch overhead, repetitive dom lookups and array index calls | |
| 50 | + getXY : function(el){ | |
| 51 | + var p, pe, b, scroll, bd = (document.body || document.documentElement); | |
| 52 | + el = Ext.getDom(el); | |
| 53 | + | |
| 54 | + if(el == bd){ | |
| 55 | + return [0, 0]; | |
| 56 | + } | |
| 57 | + | |
| 58 | + if (el.getBoundingClientRect) { | |
| 59 | + b = el.getBoundingClientRect(); | |
| 60 | + scroll = fly(document).getScroll(); | |
| 61 | + return [b.left + scroll.left, b.top + scroll.top]; | |
| 62 | + } | |
| 63 | + var x = 0, y = 0; | |
| 64 | + | |
| 65 | + p = el; | |
| 66 | + | |
| 67 | + var hasAbsolute = fly(el).getStyle("position") == "absolute"; | |
| 68 | + | |
| 69 | + while (p) { | |
| 70 | + | |
| 71 | + x += p.offsetLeft; | |
| 72 | + y += p.offsetTop; | |
| 73 | + | |
| 74 | + if (!hasAbsolute && fly(p).getStyle("position") == "absolute") { | |
| 75 | + hasAbsolute = true; | |
| 76 | + } | |
| 77 | + | |
| 78 | + if (Ext.isGecko) { | |
| 79 | + pe = fly(p); | |
| 80 | + | |
| 81 | + var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0; | |
| 82 | + var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0; | |
| 83 | + | |
| 84 | + | |
| 85 | + x += bl; | |
| 86 | + y += bt; | |
| 87 | + | |
| 88 | + | |
| 89 | + if (p != el && pe.getStyle('overflow') != 'visible') { | |
| 90 | + x += bl; | |
| 91 | + y += bt; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + p = p.offsetParent; | |
| 95 | + } | |
| 96 | + | |
| 97 | + if (Ext.isSafari && hasAbsolute) { | |
| 98 | + x -= bd.offsetLeft; | |
| 99 | + y -= bd.offsetTop; | |
| 100 | + } | |
| 101 | + | |
| 102 | + if (Ext.isGecko && !hasAbsolute) { | |
| 103 | + var dbd = fly(bd); | |
| 104 | + x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0; | |
| 105 | + y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0; | |
| 106 | + } | |
| 107 | + | |
| 108 | + p = el.parentNode; | |
| 109 | + while (p && p != bd) { | |
| 110 | + if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) { | |
| 111 | + x -= p.scrollLeft; | |
| 112 | + y -= p.scrollTop; | |
| 113 | + } | |
| 114 | + p = p.parentNode; | |
| 115 | + } | |
| 116 | + return [x, y]; | |
| 117 | + }, | |
| 118 | + | |
| 119 | + setXY : function(el, xy){ | |
| 120 | + el = Ext.fly(el, '_setXY'); | |
| 121 | + el.position(); | |
| 122 | + var pts = el.translatePoints(xy); | |
| 123 | + if(xy[0] !== false){ | |
| 124 | + el.dom.style.left = pts.left + "px"; | |
| 125 | + } | |
| 126 | + if(xy[1] !== false){ | |
| 127 | + el.dom.style.top = pts.top + "px"; | |
| 128 | + } | |
| 129 | + }, | |
| 130 | + | |
| 131 | + setX : function(el, x){ | |
| 132 | + this.setXY(el, [x, false]); | |
| 133 | + }, | |
| 134 | + | |
| 135 | + setY : function(el, y){ | |
| 136 | + this.setXY(el, [false, y]); | |
| 137 | + } | |
| 138 | +}; | |
| 139 | + | |
| 140 | +Ext.lib.Event = { | |
| 141 | + getPageX : function(e){ | |
| 142 | + return E.getPageX(e.browserEvent || e); | |
| 143 | + }, | |
| 144 | + | |
| 145 | + getPageY : function(e){ | |
| 146 | + return E.getPageY(e.browserEvent || e); | |
| 147 | + }, | |
| 148 | + | |
| 149 | + getXY : function(e){ | |
| 150 | + return E.getXY(e.browserEvent || e); | |
| 151 | + }, | |
| 152 | + | |
| 153 | + getTarget : function(e){ | |
| 154 | + return E.getTarget(e.browserEvent || e); | |
| 155 | + }, | |
| 156 | + | |
| 157 | + getRelatedTarget : function(e){ | |
| 158 | + return E.getRelatedTarget(e.browserEvent || e); | |
| 159 | + }, | |
| 160 | + | |
| 161 | + on : function(el, eventName, fn, scope, override){ | |
| 162 | + E.on(el, eventName, fn, scope, override); | |
| 163 | + }, | |
| 164 | + | |
| 165 | + un : function(el, eventName, fn){ | |
| 166 | + E.removeListener(el, eventName, fn); | |
| 167 | + }, | |
| 168 | + | |
| 169 | + purgeElement : function(el){ | |
| 170 | + E.purgeElement(el); | |
| 171 | + }, | |
| 172 | + | |
| 173 | + preventDefault : function(e){ | |
| 174 | + E.preventDefault(e.browserEvent || e); | |
| 175 | + }, | |
| 176 | + | |
| 177 | + stopPropagation : function(e){ | |
| 178 | + E.stopPropagation(e.browserEvent || e); | |
| 179 | + }, | |
| 180 | + | |
| 181 | + stopEvent : function(e){ | |
| 182 | + E.stopEvent(e.browserEvent || e); | |
| 183 | + }, | |
| 184 | + | |
| 185 | + onAvailable : function(el, fn, scope, override){ | |
| 186 | + return E.onAvailable(el, fn, scope, override); | |
| 187 | + } | |
| 188 | +}; | |
| 189 | + | |
| 190 | +Ext.lib.Ajax = { | |
| 191 | + request : function(method, uri, cb, data, options){ | |
| 192 | + if(options){ | |
| 193 | + var hs = options.headers; | |
| 194 | + if(hs){ | |
| 195 | + for(var h in hs){ | |
| 196 | + if(hs.hasOwnProperty(h)){ | |
| 197 | + CN.initHeader(h, hs[h], false); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + } | |
| 201 | + if(options.xmlData){ | |
| 202 | + if (!hs || !hs['Content-Type']){ | |
| 203 | + CN.initHeader('Content-Type', 'text/xml', false); | |
| 204 | + } | |
| 205 | + method = (method ? method : (options.method ? options.method : 'POST')); | |
| 206 | + data = options.xmlData; | |
| 207 | + }else if(options.jsonData){ | |
| 208 | + if (!hs || !hs['Content-Type']){ | |
| 209 | + CN.initHeader('Content-Type', 'application/json', false); | |
| 210 | + } | |
| 211 | + method = (method ? method : (options.method ? options.method : 'POST')); | |
| 212 | + data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData; | |
| 213 | + } | |
| 214 | + } | |
| 215 | + return CN.asyncRequest(method, uri, cb, data); | |
| 216 | + }, | |
| 217 | + | |
| 218 | + formRequest : function(form, uri, cb, data, isUpload, sslUri){ | |
| 219 | + CN.setForm(form, isUpload, sslUri); | |
| 220 | + return CN.asyncRequest(Ext.getDom(form).method ||'POST', uri, cb, data); | |
| 221 | + }, | |
| 222 | + | |
| 223 | + isCallInProgress : function(trans){ | |
| 224 | + return CN.isCallInProgress(trans); | |
| 225 | + }, | |
| 226 | + | |
| 227 | + abort : function(trans){ | |
| 228 | + return CN.abort(trans); | |
| 229 | + }, | |
| 230 | + | |
| 231 | + serializeForm : function(form){ | |
| 232 | + var d = CN.setForm(form.dom || form); | |
| 233 | + CN.resetFormState(); | |
| 234 | + return d; | |
| 235 | + } | |
| 236 | +}; | |
| 237 | + | |
| 238 | +Ext.lib.Region = YAHOO.util.Region; | |
| 239 | +Ext.lib.Point = YAHOO.util.Point; | |
| 240 | + | |
| 241 | + | |
| 242 | +Ext.lib.Anim = { | |
| 243 | + scroll : function(el, args, duration, easing, cb, scope){ | |
| 244 | + this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll); | |
| 245 | + }, | |
| 246 | + | |
| 247 | + motion : function(el, args, duration, easing, cb, scope){ | |
| 248 | + this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion); | |
| 249 | + }, | |
| 250 | + | |
| 251 | + color : function(el, args, duration, easing, cb, scope){ | |
| 252 | + this.run(el, args, duration, easing, cb, scope, YAHOO.util.ColorAnim); | |
| 253 | + }, | |
| 254 | + | |
| 255 | + run : function(el, args, duration, easing, cb, scope, type){ | |
| 256 | + type = type || YAHOO.util.Anim; | |
| 257 | + if(typeof easing == "string"){ | |
| 258 | + easing = YAHOO.util.Easing[easing]; | |
| 259 | + } | |
| 260 | + var anim = new type(el, args, duration, easing); | |
| 261 | + anim.animateX(function(){ | |
| 262 | + Ext.callback(cb, scope); | |
| 263 | + }); | |
| 264 | + return anim; | |
| 265 | + } | |
| 266 | +}; | |
| 267 | + | |
| 268 | +// all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights | |
| 269 | +function fly(el){ | |
| 270 | + if(!libFlyweight){ | |
| 271 | + libFlyweight = new Ext.Element.Flyweight(); | |
| 272 | + } | |
| 273 | + libFlyweight.dom = el; | |
| 274 | + return libFlyweight; | |
| 275 | +} | |
| 276 | + | |
| 277 | +// prevent IE leaks | |
| 278 | +if(Ext.isIE) { | |
| 279 | + function fnCleanUp() { | |
| 280 | + var p = Function.prototype; | |
| 281 | + delete p.createSequence; | |
| 282 | + delete p.defer; | |
| 283 | + delete p.createDelegate; | |
| 284 | + delete p.createCallback; | |
| 285 | + delete p.createInterceptor; | |
| 286 | + | |
| 287 | + window.detachEvent("onunload", fnCleanUp); | |
| 288 | + } | |
| 289 | + window.attachEvent("onunload", fnCleanUp); | |
| 290 | +} | |
| 291 | +// various overrides | |
| 292 | + | |
| 293 | +// add ability for callbacks with animations | |
| 294 | +if(YAHOO.util.Anim){ | |
| 295 | + YAHOO.util.Anim.prototype.animateX = function(callback, scope){ | |
| 296 | + var f = function(){ | |
| 297 | + this.onComplete.unsubscribe(f); | |
| 298 | + if(typeof callback == "function"){ | |
| 299 | + callback.call(scope || this, this); | |
| 300 | + } | |
| 301 | + }; | |
| 302 | + this.onComplete.subscribe(f, this, true); | |
| 303 | + this.animate(); | |
| 304 | + }; | |
| 305 | +} | |
| 306 | + | |
| 307 | +if(YAHOO.util.DragDrop && Ext.dd.DragDrop){ | |
| 308 | + YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding; | |
| 309 | + YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo; | |
| 310 | +} | |
| 311 | + | |
| 312 | +YAHOO.util.Dom.getXY = function(el) { | |
| 313 | + var f = function(el) { | |
| 314 | + return Ext.lib.Dom.getXY(el); | |
| 315 | + }; | |
| 316 | + return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true); | |
| 317 | +}; | |
| 318 | + | |
| 319 | + | |
| 320 | +// workaround for Safari anim duration speed problems | |
| 321 | +if(YAHOO.util.AnimMgr){ | |
| 322 | + YAHOO.util.AnimMgr.fps = 1000; | |
| 323 | +} | |
| 324 | + | |
| 325 | +YAHOO.util.Region.prototype.adjust = function(t, l, b, r){ | |
| 326 | + this.top += t; | |
| 327 | + this.left += l; | |
| 328 | + this.right += r; | |
| 329 | + this.bottom += b; | |
| 330 | + return this; | |
| 331 | +}; | |
| 332 | + | |
| 333 | +YAHOO.util.Region.prototype.constrainTo = function(r) { | |
| 334 | + this.top = this.top.constrain(r.top, r.bottom); | |
| 335 | + this.bottom = this.bottom.constrain(r.top, r.bottom); | |
| 336 | + this.left = this.left.constrain(r.left, r.right); | |
| 337 | + this.right = this.right.constrain(r.left, r.right); | |
| 338 | + return this; | |
| 339 | +}; | |
| 340 | + | |
| 341 | + | |
| 342 | +})(); | |
| 0 | 343 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/core/CompositeElement.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * @class Ext.CompositeElement | |
| 11 | + * Standard composite class. Creates a Ext.Element for every element in the collection. | |
| 12 | + * <br><br> | |
| 13 | + * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Ext.Element. All Ext.Element | |
| 14 | + * actions will be performed on all the elements in this collection.</b> | |
| 15 | + * <br><br> | |
| 16 | + * All methods return <i>this</i> and can be chained. | |
| 17 | + <pre><code> | |
| 18 | + var els = Ext.select("#some-el div.some-class", true); | |
| 19 | + // or select directly from an existing element | |
| 20 | + var el = Ext.get('some-el'); | |
| 21 | + el.select('div.some-class', true); | |
| 22 | + | |
| 23 | + els.setWidth(100); // all elements become 100 width | |
| 24 | + els.hide(true); // all elements fade out and hide | |
| 25 | + // or | |
| 26 | + els.setWidth(100).hide(true); | |
| 27 | + </code></pre> | |
| 28 | + */ | |
| 29 | +Ext.CompositeElement = function(els){ | |
| 30 | + this.elements = []; | |
| 31 | + this.addElements(els); | |
| 32 | +}; | |
| 33 | +Ext.CompositeElement.prototype = { | |
| 34 | + isComposite: true, | |
| 35 | + addElements : function(els){ | |
| 36 | + if(!els) return this; | |
| 37 | + if(typeof els == "string"){ | |
| 38 | + els = Ext.Element.selectorFunction(els); | |
| 39 | + } | |
| 40 | + var yels = this.elements; | |
| 41 | + var index = yels.length-1; | |
| 42 | + for(var i = 0, len = els.length; i < len; i++) { | |
| 43 | + yels[++index] = Ext.get(els[i]); | |
| 44 | + } | |
| 45 | + return this; | |
| 46 | + }, | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Clears this composite and adds the elements returned by the passed selector. | |
| 50 | + * @param {String/Array} els A string CSS selector, an array of elements or an element | |
| 51 | + * @return {CompositeElement} this | |
| 52 | + */ | |
| 53 | + fill : function(els){ | |
| 54 | + this.elements = []; | |
| 55 | + this.add(els); | |
| 56 | + return this; | |
| 57 | + }, | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Filters this composite to only elements that match the passed selector. | |
| 61 | + * @param {String} selector A string CSS selector | |
| 62 | + * @return {CompositeElement} this | |
| 63 | + */ | |
| 64 | + filter : function(selector){ | |
| 65 | + var els = []; | |
| 66 | + this.each(function(el){ | |
| 67 | + if(el.is(selector)){ | |
| 68 | + els[els.length] = el.dom; | |
| 69 | + } | |
| 70 | + }); | |
| 71 | + this.fill(els); | |
| 72 | + return this; | |
| 73 | + }, | |
| 74 | + | |
| 75 | + invoke : function(fn, args){ | |
| 76 | + var els = this.elements; | |
| 77 | + for(var i = 0, len = els.length; i < len; i++) { | |
| 78 | + Ext.Element.prototype[fn].apply(els[i], args); | |
| 79 | + } | |
| 80 | + return this; | |
| 81 | + }, | |
| 82 | + /** | |
| 83 | + * Adds elements to this composite. | |
| 84 | + * @param {String/Array} els A string CSS selector, an array of elements or an element | |
| 85 | + * @return {CompositeElement} this | |
| 86 | + */ | |
| 87 | + add : function(els){ | |
| 88 | + if(typeof els == "string"){ | |
| 89 | + this.addElements(Ext.Element.selectorFunction(els)); | |
| 90 | + }else if(els.length !== undefined){ | |
| 91 | + this.addElements(els); | |
| 92 | + }else{ | |
| 93 | + this.addElements([els]); | |
| 94 | + } | |
| 95 | + return this; | |
| 96 | + }, | |
| 97 | + /** | |
| 98 | + * Calls the passed function passing (el, this, index) for each element in this composite. | |
| 99 | + * @param {Function} fn The function to call | |
| 100 | + * @param {Object} scope (optional) The <i>this</i> object (defaults to the element) | |
| 101 | + * @return {CompositeElement} this | |
| 102 | + */ | |
| 103 | + each : function(fn, scope){ | |
| 104 | + var els = this.elements; | |
| 105 | + for(var i = 0, len = els.length; i < len; i++){ | |
| 106 | + if(fn.call(scope || els[i], els[i], this, i) === false) { | |
| 107 | + break; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + return this; | |
| 111 | + }, | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Returns the Element object at the specified index | |
| 115 | + * @param {Number} index | |
| 116 | + * @return {Ext.Element} | |
| 117 | + */ | |
| 118 | + item : function(index){ | |
| 119 | + return this.elements[index] || null; | |
| 120 | + }, | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Returns the first Element | |
| 124 | + * @return {Ext.Element} | |
| 125 | + */ | |
| 126 | + first : function(){ | |
| 127 | + return this.item(0); | |
| 128 | + }, | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * Returns the last Element | |
| 132 | + * @return {Ext.Element} | |
| 133 | + */ | |
| 134 | + last : function(){ | |
| 135 | + return this.item(this.elements.length-1); | |
| 136 | + }, | |
| 137 | + | |
| 138 | + /** | |
| 139 | + * Returns the number of elements in this composite | |
| 140 | + * @return Number | |
| 141 | + */ | |
| 142 | + getCount : function(){ | |
| 143 | + return this.elements.length; | |
| 144 | + }, | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Returns true if this composite contains the passed element | |
| 148 | + * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection. | |
| 149 | + * @return Boolean | |
| 150 | + */ | |
| 151 | + contains : function(el){ | |
| 152 | + return this.indexOf(el) !== -1; | |
| 153 | + }, | |
| 154 | + | |
| 155 | + /** | |
| 156 | + * Find the index of the passed element within the composite collection. | |
| 157 | + * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection. | |
| 158 | + * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found. | |
| 159 | + */ | |
| 160 | + indexOf : function(el){ | |
| 161 | + return this.elements.indexOf(Ext.get(el)); | |
| 162 | + }, | |
| 163 | + | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * Removes the specified element(s). | |
| 167 | + * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite | |
| 168 | + * or an array of any of those. | |
| 169 | + * @param {Boolean} removeDom (optional) True to also remove the element from the document | |
| 170 | + * @return {CompositeElement} this | |
| 171 | + */ | |
| 172 | + removeElement : function(el, removeDom){ | |
| 173 | + if(Ext.isArray(el)){ | |
| 174 | + for(var i = 0, len = el.length; i < len; i++){ | |
| 175 | + this.removeElement(el[i]); | |
| 176 | + } | |
| 177 | + return this; | |
| 178 | + } | |
| 179 | + var index = typeof el == 'number' ? el : this.indexOf(el); | |
| 180 | + if(index !== -1 && this.elements[index]){ | |
| 181 | + if(removeDom){ | |
| 182 | + var d = this.elements[index]; | |
| 183 | + if(d.dom){ | |
| 184 | + d.remove(); | |
| 185 | + }else{ | |
| 186 | + Ext.removeNode(d); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + this.elements.splice(index, 1); | |
| 190 | + } | |
| 191 | + return this; | |
| 192 | + }, | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Replaces the specified element with the passed element. | |
| 196 | + * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite | |
| 197 | + * to replace. | |
| 198 | + * @param {Mixed} replacement The id of an element or the Element itself. | |
| 199 | + * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too. | |
| 200 | + * @return {CompositeElement} this | |
| 201 | + */ | |
| 202 | + replaceElement : function(el, replacement, domReplace){ | |
| 203 | + var index = typeof el == 'number' ? el : this.indexOf(el); | |
| 204 | + if(index !== -1){ | |
| 205 | + if(domReplace){ | |
| 206 | + this.elements[index].replaceWith(replacement); | |
| 207 | + }else{ | |
| 208 | + this.elements.splice(index, 1, Ext.get(replacement)) | |
| 209 | + } | |
| 210 | + } | |
| 211 | + return this; | |
| 212 | + }, | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * Removes all elements. | |
| 216 | + */ | |
| 217 | + clear : function(){ | |
| 218 | + this.elements = []; | |
| 219 | + } | |
| 220 | +}; | |
| 221 | +(function(){ | |
| 222 | +Ext.CompositeElement.createCall = function(proto, fnName){ | |
| 223 | + if(!proto[fnName]){ | |
| 224 | + proto[fnName] = function(){ | |
| 225 | + return this.invoke(fnName, arguments); | |
| 226 | + }; | |
| 227 | + } | |
| 228 | +}; | |
| 229 | +for(var fnName in Ext.Element.prototype){ | |
| 230 | + if(typeof Ext.Element.prototype[fnName] == "function"){ | |
| 231 | + Ext.CompositeElement.createCall(Ext.CompositeElement.prototype, fnName); | |
| 232 | + } | |
| 233 | +}; | |
| 234 | +})(); | |
| 235 | + | |
| 236 | +/** | |
| 237 | + * @class Ext.CompositeElementLite | |
| 238 | + * @extends Ext.CompositeElement | |
| 239 | + * Flyweight composite class. Reuses the same Ext.Element for element operations. | |
| 240 | + <pre><code> | |
| 241 | + var els = Ext.select("#some-el div.some-class"); | |
| 242 | + // or select directly from an existing element | |
| 243 | + var el = Ext.get('some-el'); | |
| 244 | + el.select('div.some-class'); | |
| 245 | + | |
| 246 | + els.setWidth(100); // all elements become 100 width | |
| 247 | + els.hide(true); // all elements fade out and hide | |
| 248 | + // or | |
| 249 | + els.setWidth(100).hide(true); | |
| 250 | + </code></pre><br><br> | |
| 251 | + * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Ext.Element. All Ext.Element | |
| 252 | + * actions will be performed on all the elements in this collection.</b> | |
| 253 | + */ | |
| 254 | +Ext.CompositeElementLite = function(els){ | |
| 255 | + Ext.CompositeElementLite.superclass.constructor.call(this, els); | |
| 256 | + this.el = new Ext.Element.Flyweight(); | |
| 257 | +}; | |
| 258 | +Ext.extend(Ext.CompositeElementLite, Ext.CompositeElement, { | |
| 259 | + addElements : function(els){ | |
| 260 | + if(els){ | |
| 261 | + if(Ext.isArray(els)){ | |
| 262 | + this.elements = this.elements.concat(els); | |
| 263 | + }else{ | |
| 264 | + var yels = this.elements; | |
| 265 | + var index = yels.length-1; | |
| 266 | + for(var i = 0, len = els.length; i < len; i++) { | |
| 267 | + yels[++index] = els[i]; | |
| 268 | + } | |
| 269 | + } | |
| 270 | + } | |
| 271 | + return this; | |
| 272 | + }, | |
| 273 | + invoke : function(fn, args){ | |
| 274 | + var els = this.elements; | |
| 275 | + var el = this.el; | |
| 276 | + for(var i = 0, len = els.length; i < len; i++) { | |
| 277 | + el.dom = els[i]; | |
| 278 | + Ext.Element.prototype[fn].apply(el, args); | |
| 279 | + } | |
| 280 | + return this; | |
| 281 | + }, | |
| 282 | + /** | |
| 283 | + * Returns a flyweight Element of the dom element object at the specified index | |
| 284 | + * @param {Number} index | |
| 285 | + * @return {Ext.Element} | |
| 286 | + */ | |
| 287 | + item : function(index){ | |
| 288 | + if(!this.elements[index]){ | |
| 289 | + return null; | |
| 290 | + } | |
| 291 | + this.el.dom = this.elements[index]; | |
| 292 | + return this.el; | |
| 293 | + }, | |
| 294 | + | |
| 295 | + // fixes scope with flyweight | |
| 296 | + addListener : function(eventName, handler, scope, opt){ | |
| 297 | + var els = this.elements; | |
| 298 | + for(var i = 0, len = els.length; i < len; i++) { | |
| 299 | + Ext.EventManager.on(els[i], eventName, handler, scope || els[i], opt); | |
| 300 | + } | |
| 301 | + return this; | |
| 302 | + }, | |
| 303 | + | |
| 304 | + /** | |
| 305 | + * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element | |
| 306 | + * passed is the flyweight (shared) Ext.Element instance, so if you require a | |
| 307 | + * a reference to the dom node, use el.dom.</b> | |
| 308 | + * @param {Function} fn The function to call | |
| 309 | + * @param {Object} scope (optional) The <i>this</i> object (defaults to the element) | |
| 310 | + * @return {CompositeElement} this | |
| 311 | + */ | |
| 312 | + each : function(fn, scope){ | |
| 313 | + var els = this.elements; | |
| 314 | + var el = this.el; | |
| 315 | + for(var i = 0, len = els.length; i < len; i++){ | |
| 316 | + el.dom = els[i]; | |
| 317 | + if(fn.call(scope || el, el, this, i) === false){ | |
| 318 | + break; | |
| 319 | + } | |
| 320 | + } | |
| 321 | + return this; | |
| 322 | + }, | |
| 323 | + | |
| 324 | + indexOf : function(el){ | |
| 325 | + return this.elements.indexOf(Ext.getDom(el)); | |
| 326 | + }, | |
| 327 | + | |
| 328 | + replaceElement : function(el, replacement, domReplace){ | |
| 329 | + var index = typeof el == 'number' ? el : this.indexOf(el); | |
| 330 | + if(index !== -1){ | |
| 331 | + replacement = Ext.getDom(replacement); | |
| 332 | + if(domReplace){ | |
| 333 | + var d = this.elements[index]; | |
| 334 | + d.parentNode.insertBefore(replacement, d); | |
| 335 | + Ext.removeNode(d); | |
| 336 | + } | |
| 337 | + this.elements.splice(index, 1, replacement); | |
| 338 | + } | |
| 339 | + return this; | |
| 340 | + } | |
| 341 | +}); | |
| 342 | +Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener; | |
| 343 | +if(Ext.DomQuery){ | |
| 344 | + Ext.Element.selectorFunction = Ext.DomQuery.select; | |
| 345 | +} | |
| 346 | + | |
| 347 | +Ext.Element.select = function(selector, unique, root){ | |
| 348 | + var els; | |
| 349 | + if(typeof selector == "string"){ | |
| 350 | + els = Ext.Element.selectorFunction(selector, root); | |
| 351 | + }else if(selector.length !== undefined){ | |
| 352 | + els = selector; | |
| 353 | + }else{ | |
| 354 | + throw "Invalid selector"; | |
| 355 | + } | |
| 356 | + if(unique === true){ | |
| 357 | + return new Ext.CompositeElement(els); | |
| 358 | + }else{ | |
| 359 | + return new Ext.CompositeElementLite(els); | |
| 360 | + } | |
| 361 | +}; | |
| 362 | +/** | |
| 363 | + * Selects elements based on the passed CSS selector to enable working on them as 1. | |
| 364 | + * @param {String/Array} selector The CSS selector or an array of elements | |
| 365 | + * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object) | |
| 366 | + * @param {HTMLElement/String} root (optional) The root element of the query or id of the root | |
| 367 | + * @return {CompositeElementLite/CompositeElement} | |
| 368 | + * @member Ext | |
| 369 | + * @method select | |
| 370 | + */ | |
| 371 | +Ext.select = Ext.Element.select; | |
| 0 | 372 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/core/DomHelper.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * @class Ext.DomHelper | |
| 11 | + * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.<br> | |
| 12 | + * This is an example, where an unordered list with 5 children items is appended to an existing element with id 'my-div':<br> | |
| 13 | + <pre><code> | |
| 14 | +var dh = Ext.DomHelper; | |
| 15 | +var list = dh.append('my-div', { | |
| 16 | + id: 'my-ul', tag: 'ul', cls: 'my-list', children: [ | |
| 17 | + {tag: 'li', id: 'item0', html: 'List Item 0'}, | |
| 18 | + {tag: 'li', id: 'item1', html: 'List Item 1'}, | |
| 19 | + {tag: 'li', id: 'item2', html: 'List Item 2'}, | |
| 20 | + {tag: 'li', id: 'item3', html: 'List Item 3'}, | |
| 21 | + {tag: 'li', id: 'item4', html: 'List Item 4'} | |
| 22 | + ] | |
| 23 | +}); | |
| 24 | + </code></pre> | |
| 25 | + * <p>Element creation specification parameters in this class may also be passed as an Array of | |
| 26 | + * specification objects. This can be used to insert multiple sibling nodes into an existing | |
| 27 | + * container very efficiently. For example, to add more list items to the example above:<pre><code> | |
| 28 | +dh.append('my-ul', [ | |
| 29 | + {tag: 'li', id: 'item5', html: 'List Item 5'}, | |
| 30 | + {tag: 'li', id: 'item6', html: 'List Item 6'} ]); | |
| 31 | +</code></pre></p> | |
| 32 | + * <p>Element creation specification parameters may also be strings. If {@link useDom} is false, then the string is used | |
| 33 | + * as innerHTML. If {@link useDom} is true, a string specification results in the creation of a text node.</p> | |
| 34 | + * For more information and examples, see <a href="http://www.jackslocum.com/blog/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">the original blog post</a>. | |
| 35 | + * @singleton | |
| 36 | + */ | |
| 37 | +Ext.DomHelper = function(){ | |
| 38 | + var tempTableEl = null; | |
| 39 | + var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i; | |
| 40 | + var tableRe = /^table|tbody|tr|td$/i; | |
| 41 | + | |
| 42 | + // build as innerHTML where available | |
| 43 | + var createHtml = function(o){ | |
| 44 | + if(typeof o == 'string'){ | |
| 45 | + return o; | |
| 46 | + } | |
| 47 | + var b = ""; | |
| 48 | + if (Ext.isArray(o)) { | |
| 49 | + for (var i = 0, l = o.length; i < l; i++) { | |
| 50 | + b += createHtml(o[i]); | |
| 51 | + } | |
| 52 | + return b; | |
| 53 | + } | |
| 54 | + if(!o.tag){ | |
| 55 | + o.tag = "div"; | |
| 56 | + } | |
| 57 | + b += "<" + o.tag; | |
| 58 | + for(var attr in o){ | |
| 59 | + if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue; | |
| 60 | + if(attr == "style"){ | |
| 61 | + var s = o["style"]; | |
| 62 | + if(typeof s == "function"){ | |
| 63 | + s = s.call(); | |
| 64 | + } | |
| 65 | + if(typeof s == "string"){ | |
| 66 | + b += ' style="' + s + '"'; | |
| 67 | + }else if(typeof s == "object"){ | |
| 68 | + b += ' style="'; | |
| 69 | + for(var key in s){ | |
| 70 | + if(typeof s[key] != "function"){ | |
| 71 | + b += key + ":" + s[key] + ";"; | |
| 72 | + } | |
| 73 | + } | |
| 74 | + b += '"'; | |
| 75 | + } | |
| 76 | + }else{ | |
| 77 | + if(attr == "cls"){ | |
| 78 | + b += ' class="' + o["cls"] + '"'; | |
| 79 | + }else if(attr == "htmlFor"){ | |
| 80 | + b += ' for="' + o["htmlFor"] + '"'; | |
| 81 | + }else{ | |
| 82 | + b += " " + attr + '="' + o[attr] + '"'; | |
| 83 | + } | |
| 84 | + } | |
| 85 | + } | |
| 86 | + if(emptyTags.test(o.tag)){ | |
| 87 | + b += "/>"; | |
| 88 | + }else{ | |
| 89 | + b += ">"; | |
| 90 | + var cn = o.children || o.cn; | |
| 91 | + if(cn){ | |
| 92 | + b += createHtml(cn); | |
| 93 | + } else if(o.html){ | |
| 94 | + b += o.html; | |
| 95 | + } | |
| 96 | + b += "</" + o.tag + ">"; | |
| 97 | + } | |
| 98 | + return b; | |
| 99 | + }; | |
| 100 | + | |
| 101 | + // build as dom | |
| 102 | + /** @ignore */ | |
| 103 | + var createDom = function(o, parentNode){ | |
| 104 | + var el; | |
| 105 | + if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted | |
| 106 | + el = document.createDocumentFragment(); // in one shot using a DocumentFragment | |
| 107 | + for(var i = 0, l = o.length; i < l; i++) { | |
| 108 | + createDom(o[i], el); | |
| 109 | + } | |
| 110 | + } else if (typeof o == "string") { // Allow a string as a child spec. | |
| 111 | + el = document.createTextNode(o); | |
| 112 | + } else { | |
| 113 | + el = document.createElement(o.tag||'div'); | |
| 114 | + var useSet = !!el.setAttribute; // In IE some elements don't have setAttribute | |
| 115 | + for(var attr in o){ | |
| 116 | + if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || attr == "style" || typeof o[attr] == "function") continue; | |
| 117 | + if(attr=="cls"){ | |
| 118 | + el.className = o["cls"]; | |
| 119 | + }else{ | |
| 120 | + if(useSet) el.setAttribute(attr, o[attr]); | |
| 121 | + else el[attr] = o[attr]; | |
| 122 | + } | |
| 123 | + } | |
| 124 | + Ext.DomHelper.applyStyles(el, o.style); | |
| 125 | + var cn = o.children || o.cn; | |
| 126 | + if(cn){ | |
| 127 | + createDom(cn, el); | |
| 128 | + } else if(o.html){ | |
| 129 | + el.innerHTML = o.html; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + if(parentNode){ | |
| 133 | + parentNode.appendChild(el); | |
| 134 | + } | |
| 135 | + return el; | |
| 136 | + }; | |
| 137 | + | |
| 138 | + var ieTable = function(depth, s, h, e){ | |
| 139 | + tempTableEl.innerHTML = [s, h, e].join(''); | |
| 140 | + var i = -1, el = tempTableEl; | |
| 141 | + while(++i < depth){ | |
| 142 | + el = el.firstChild; | |
| 143 | + } | |
| 144 | + return el; | |
| 145 | + }; | |
| 146 | + | |
| 147 | + // kill repeat to save bytes | |
| 148 | + var ts = '<table>', | |
| 149 | + te = '</table>', | |
| 150 | + tbs = ts+'<tbody>', | |
| 151 | + tbe = '</tbody>'+te, | |
| 152 | + trs = tbs + '<tr>', | |
| 153 | + tre = '</tr>'+tbe; | |
| 154 | + | |
| 155 | + /** | |
| 156 | + * @ignore | |
| 157 | + * Nasty code for IE's broken table implementation | |
| 158 | + */ | |
| 159 | + var insertIntoTable = function(tag, where, el, html){ | |
| 160 | + if(!tempTableEl){ | |
| 161 | + tempTableEl = document.createElement('div'); | |
| 162 | + } | |
| 163 | + var node; | |
| 164 | + var before = null; | |
| 165 | + if(tag == 'td'){ | |
| 166 | + if(where == 'afterbegin' || where == 'beforeend'){ // INTO a TD | |
| 167 | + return; | |
| 168 | + } | |
| 169 | + if(where == 'beforebegin'){ | |
| 170 | + before = el; | |
| 171 | + el = el.parentNode; | |
| 172 | + } else{ | |
| 173 | + before = el.nextSibling; | |
| 174 | + el = el.parentNode; | |
| 175 | + } | |
| 176 | + node = ieTable(4, trs, html, tre); | |
| 177 | + } | |
| 178 | + else if(tag == 'tr'){ | |
| 179 | + if(where == 'beforebegin'){ | |
| 180 | + before = el; | |
| 181 | + el = el.parentNode; | |
| 182 | + node = ieTable(3, tbs, html, tbe); | |
| 183 | + } else if(where == 'afterend'){ | |
| 184 | + before = el.nextSibling; | |
| 185 | + el = el.parentNode; | |
| 186 | + node = ieTable(3, tbs, html, tbe); | |
| 187 | + } else{ // INTO a TR | |
| 188 | + if(where == 'afterbegin'){ | |
| 189 | + before = el.firstChild; | |
| 190 | + } | |
| 191 | + node = ieTable(4, trs, html, tre); | |
| 192 | + } | |
| 193 | + } else if(tag == 'tbody'){ | |
| 194 | + if(where == 'beforebegin'){ | |
| 195 | + before = el; | |
| 196 | + el = el.parentNode; | |
| 197 | + node = ieTable(2, ts, html, te); | |
| 198 | + } else if(where == 'afterend'){ | |
| 199 | + before = el.nextSibling; | |
| 200 | + el = el.parentNode; | |
| 201 | + node = ieTable(2, ts, html, te); | |
| 202 | + } else{ | |
| 203 | + if(where == 'afterbegin'){ | |
| 204 | + before = el.firstChild; | |
| 205 | + } | |
| 206 | + node = ieTable(3, tbs, html, tbe); | |
| 207 | + } | |
| 208 | + } else{ // TABLE | |
| 209 | + if(where == 'beforebegin' || where == 'afterend'){ // OUTSIDE the table | |
| 210 | + return; | |
| 211 | + } | |
| 212 | + if(where == 'afterbegin'){ | |
| 213 | + before = el.firstChild; | |
| 214 | + } | |
| 215 | + node = ieTable(2, ts, html, te); | |
| 216 | + } | |
| 217 | + el.insertBefore(node, before); | |
| 218 | + return node; | |
| 219 | + }; | |
| 220 | + | |
| 221 | + | |
| 222 | + return { | |
| 223 | + /** True to force the use of DOM instead of html fragments @type Boolean */ | |
| 224 | + useDom : false, | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Returns the markup for the passed Element(s) config. | |
| 228 | + * @param {Object} o The DOM object spec (and children) | |
| 229 | + * @return {String} | |
| 230 | + */ | |
| 231 | + markup : function(o){ | |
| 232 | + return createHtml(o); | |
| 233 | + }, | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Applies a style specification to an element. | |
| 237 | + * @param {String/HTMLElement} el The element to apply styles to | |
| 238 | + * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or | |
| 239 | + * a function which returns such a specification. | |
| 240 | + */ | |
| 241 | + applyStyles : function(el, styles){ | |
| 242 | + if(styles){ | |
| 243 | + el = Ext.fly(el); | |
| 244 | + if(typeof styles == "string"){ | |
| 245 | + var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi; | |
| 246 | + var matches; | |
| 247 | + while ((matches = re.exec(styles)) != null){ | |
| 248 | + el.setStyle(matches[1], matches[2]); | |
| 249 | + } | |
| 250 | + }else if (typeof styles == "object"){ | |
| 251 | + for (var style in styles){ | |
| 252 | + el.setStyle(style, styles[style]); | |
| 253 | + } | |
| 254 | + }else if (typeof styles == "function"){ | |
| 255 | + Ext.DomHelper.applyStyles(el, styles.call()); | |
| 256 | + } | |
| 257 | + } | |
| 258 | + }, | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * Inserts an HTML fragment into the DOM. | |
| 262 | + * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd. | |
| 263 | + * @param {HTMLElement} el The context element | |
| 264 | + * @param {String} html The HTML fragmenet | |
| 265 | + * @return {HTMLElement} The new node | |
| 266 | + */ | |
| 267 | + insertHtml : function(where, el, html){ | |
| 268 | + where = where.toLowerCase(); | |
| 269 | + if(el.insertAdjacentHTML){ | |
| 270 | + if(tableRe.test(el.tagName)){ | |
| 271 | + var rs; | |
| 272 | + if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){ | |
| 273 | + return rs; | |
| 274 | + } | |
| 275 | + } | |
| 276 | + switch(where){ | |
| 277 | + case "beforebegin": | |
| 278 | + el.insertAdjacentHTML('BeforeBegin', html); | |
| 279 | + return el.previousSibling; | |
| 280 | + case "afterbegin": | |
| 281 | + el.insertAdjacentHTML('AfterBegin', html); | |
| 282 | + return el.firstChild; | |
| 283 | + case "beforeend": | |
| 284 | + el.insertAdjacentHTML('BeforeEnd', html); | |
| 285 | + return el.lastChild; | |
| 286 | + case "afterend": | |
| 287 | + el.insertAdjacentHTML('AfterEnd', html); | |
| 288 | + return el.nextSibling; | |
| 289 | + } | |
| 290 | + throw 'Illegal insertion point -> "' + where + '"'; | |
| 291 | + } | |
| 292 | + var range = el.ownerDocument.createRange(); | |
| 293 | + var frag; | |
| 294 | + switch(where){ | |
| 295 | + case "beforebegin": | |
| 296 | + range.setStartBefore(el); | |
| 297 | + frag = range.createContextualFragment(html); | |
| 298 | + el.parentNode.insertBefore(frag, el); | |
| 299 | + return el.previousSibling; | |
| 300 | + case "afterbegin": | |
| 301 | + if(el.firstChild){ | |
| 302 | + range.setStartBefore(el.firstChild); | |
| 303 | + frag = range.createContextualFragment(html); | |
| 304 | + el.insertBefore(frag, el.firstChild); | |
| 305 | + return el.firstChild; | |
| 306 | + }else{ | |
| 307 | + el.innerHTML = html; | |
| 308 | + return el.firstChild; | |
| 309 | + } | |
| 310 | + case "beforeend": | |
| 311 | + if(el.lastChild){ | |
| 312 | + range.setStartAfter(el.lastChild); | |
| 313 | + frag = range.createContextualFragment(html); | |
| 314 | + el.appendChild(frag); | |
| 315 | + return el.lastChild; | |
| 316 | + }else{ | |
| 317 | + el.innerHTML = html; | |
| 318 | + return el.lastChild; | |
| 319 | + } | |
| 320 | + case "afterend": | |
| 321 | + range.setStartAfter(el); | |
| 322 | + frag = range.createContextualFragment(html); | |
| 323 | + el.parentNode.insertBefore(frag, el.nextSibling); | |
| 324 | + return el.nextSibling; | |
| 325 | + } | |
| 326 | + throw 'Illegal insertion point -> "' + where + '"'; | |
| 327 | + }, | |
| 328 | + | |
| 329 | + /** | |
| 330 | + * Creates new DOM element(s) and inserts them before el. | |
| 331 | + * @param {Mixed} el The context element | |
| 332 | + * @param {Object/String} o The DOM object spec (and children) or raw HTML blob | |
| 333 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element | |
| 334 | + * @return {HTMLElement/Ext.Element} The new node | |
| 335 | + */ | |
| 336 | + insertBefore : function(el, o, returnElement){ | |
| 337 | + return this.doInsert(el, o, returnElement, "beforeBegin"); | |
| 338 | + }, | |
| 339 | + | |
| 340 | + /** | |
| 341 | + * Creates new DOM element(s) and inserts them after el. | |
| 342 | + * @param {Mixed} el The context element | |
| 343 | + * @param {Object} o The DOM object spec (and children) | |
| 344 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element | |
| 345 | + * @return {HTMLElement/Ext.Element} The new node | |
| 346 | + */ | |
| 347 | + insertAfter : function(el, o, returnElement){ | |
| 348 | + return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling"); | |
| 349 | + }, | |
| 350 | + | |
| 351 | + /** | |
| 352 | + * Creates new DOM element(s) and inserts them as the first child of el. | |
| 353 | + * @param {Mixed} el The context element | |
| 354 | + * @param {Object/String} o The DOM object spec (and children) or raw HTML blob | |
| 355 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element | |
| 356 | + * @return {HTMLElement/Ext.Element} The new node | |
| 357 | + */ | |
| 358 | + insertFirst : function(el, o, returnElement){ | |
| 359 | + return this.doInsert(el, o, returnElement, "afterBegin", "firstChild"); | |
| 360 | + }, | |
| 361 | + | |
| 362 | + // private | |
| 363 | + doInsert : function(el, o, returnElement, pos, sibling){ | |
| 364 | + el = Ext.getDom(el); | |
| 365 | + var newNode; | |
| 366 | + if(this.useDom){ | |
| 367 | + newNode = createDom(o, null); | |
| 368 | + (sibling === "firstChild" ? el : el.parentNode).insertBefore(newNode, sibling ? el[sibling] : el); | |
| 369 | + }else{ | |
| 370 | + var html = createHtml(o); | |
| 371 | + newNode = this.insertHtml(pos, el, html); | |
| 372 | + } | |
| 373 | + return returnElement ? Ext.get(newNode, true) : newNode; | |
| 374 | + }, | |
| 375 | + | |
| 376 | + /** | |
| 377 | + * Creates new DOM element(s) and appends them to el. | |
| 378 | + * @param {Mixed} el The context element | |
| 379 | + * @param {Object/String} o The DOM object spec (and children) or raw HTML blob | |
| 380 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element | |
| 381 | + * @return {HTMLElement/Ext.Element} The new node | |
| 382 | + */ | |
| 383 | + append : function(el, o, returnElement){ | |
| 384 | + el = Ext.getDom(el); | |
| 385 | + var newNode; | |
| 386 | + if(this.useDom){ | |
| 387 | + newNode = createDom(o, null); | |
| 388 | + el.appendChild(newNode); | |
| 389 | + }else{ | |
| 390 | + var html = createHtml(o); | |
| 391 | + newNode = this.insertHtml("beforeEnd", el, html); | |
| 392 | + } | |
| 393 | + return returnElement ? Ext.get(newNode, true) : newNode; | |
| 394 | + }, | |
| 395 | + | |
| 396 | + /** | |
| 397 | + * Creates new DOM element(s) and overwrites the contents of el with them. | |
| 398 | + * @param {Mixed} el The context element | |
| 399 | + * @param {Object/String} o The DOM object spec (and children) or raw HTML blob | |
| 400 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element | |
| 401 | + * @return {HTMLElement/Ext.Element} The new node | |
| 402 | + */ | |
| 403 | + overwrite : function(el, o, returnElement){ | |
| 404 | + el = Ext.getDom(el); | |
| 405 | + el.innerHTML = createHtml(o); | |
| 406 | + return returnElement ? Ext.get(el.firstChild, true) : el.firstChild; | |
| 407 | + }, | |
| 408 | + | |
| 409 | + /** | |
| 410 | + * Creates a new Ext.Template from the DOM object spec. | |
| 411 | + * @param {Object} o The DOM object spec (and children) | |
| 412 | + * @return {Ext.Template} The new template | |
| 413 | + */ | |
| 414 | + createTemplate : function(o){ | |
| 415 | + var html = createHtml(o); | |
| 416 | + return new Ext.Template(html); | |
| 417 | + } | |
| 418 | + }; | |
| 419 | +}(); | ... | ... |
thirdpartyjs/extjs/source/core/DomQuery.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/* | |
| 10 | + * This is code is also distributed under MIT license for use | |
| 11 | + * with jQuery and prototype JavaScript libraries. | |
| 12 | + */ | |
| 13 | +/** | |
| 14 | + * @class Ext.DomQuery | |
| 15 | +Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in). | |
| 16 | +<p> | |
| 17 | +DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p> | |
| 18 | + | |
| 19 | +<p> | |
| 20 | +All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure. | |
| 21 | +</p> | |
| 22 | +<h4>Element Selectors:</h4> | |
| 23 | +<ul class="list"> | |
| 24 | + <li> <b>*</b> any element</li> | |
| 25 | + <li> <b>E</b> an element with the tag E</li> | |
| 26 | + <li> <b>E F</b> All descendent elements of E that have the tag F</li> | |
| 27 | + <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li> | |
| 28 | + <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li> | |
| 29 | + <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li> | |
| 30 | +</ul> | |
| 31 | +<h4>Attribute Selectors:</h4> | |
| 32 | +<p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p> | |
| 33 | +<ul class="list"> | |
| 34 | + <li> <b>E[foo]</b> has an attribute "foo"</li> | |
| 35 | + <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li> | |
| 36 | + <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li> | |
| 37 | + <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li> | |
| 38 | + <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li> | |
| 39 | + <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li> | |
| 40 | + <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li> | |
| 41 | +</ul> | |
| 42 | +<h4>Pseudo Classes:</h4> | |
| 43 | +<ul class="list"> | |
| 44 | + <li> <b>E:first-child</b> E is the first child of its parent</li> | |
| 45 | + <li> <b>E:last-child</b> E is the last child of its parent</li> | |
| 46 | + <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li> | |
| 47 | + <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li> | |
| 48 | + <li> <b>E:nth-child(even)</b> E is an even child of its parent</li> | |
| 49 | + <li> <b>E:only-child</b> E is the only child of its parent</li> | |
| 50 | + <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li> | |
| 51 | + <li> <b>E:first</b> the first E in the resultset</li> | |
| 52 | + <li> <b>E:last</b> the last E in the resultset</li> | |
| 53 | + <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li> | |
| 54 | + <li> <b>E:odd</b> shortcut for :nth-child(odd)</li> | |
| 55 | + <li> <b>E:even</b> shortcut for :nth-child(even)</li> | |
| 56 | + <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li> | |
| 57 | + <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li> | |
| 58 | + <li> <b>E:not(S)</b> an E element that does not match simple selector S</li> | |
| 59 | + <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li> | |
| 60 | + <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li> | |
| 61 | + <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li> | |
| 62 | +</ul> | |
| 63 | +<h4>CSS Value Selectors:</h4> | |
| 64 | +<ul class="list"> | |
| 65 | + <li> <b>E{display=none}</b> css value "display" that equals "none"</li> | |
| 66 | + <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li> | |
| 67 | + <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li> | |
| 68 | + <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li> | |
| 69 | + <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li> | |
| 70 | + <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li> | |
| 71 | +</ul> | |
| 72 | + * @singleton | |
| 73 | + */ | |
| 74 | +Ext.DomQuery = function(){ | |
| 75 | + var cache = {}, simpleCache = {}, valueCache = {}; | |
| 76 | + var nonSpace = /\S/; | |
| 77 | + var trimRe = /^\s+|\s+$/g; | |
| 78 | + var tplRe = /\{(\d+)\}/g; | |
| 79 | + var modeRe = /^(\s?[\/>+~]\s?|\s|$)/; | |
| 80 | + var tagTokenRe = /^(#)?([\w-\*]+)/; | |
| 81 | + var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/; | |
| 82 | + | |
| 83 | + function child(p, index){ | |
| 84 | + var i = 0; | |
| 85 | + var n = p.firstChild; | |
| 86 | + while(n){ | |
| 87 | + if(n.nodeType == 1){ | |
| 88 | + if(++i == index){ | |
| 89 | + return n; | |
| 90 | + } | |
| 91 | + } | |
| 92 | + n = n.nextSibling; | |
| 93 | + } | |
| 94 | + return null; | |
| 95 | + }; | |
| 96 | + | |
| 97 | + function next(n){ | |
| 98 | + while((n = n.nextSibling) && n.nodeType != 1); | |
| 99 | + return n; | |
| 100 | + }; | |
| 101 | + | |
| 102 | + function prev(n){ | |
| 103 | + while((n = n.previousSibling) && n.nodeType != 1); | |
| 104 | + return n; | |
| 105 | + }; | |
| 106 | + | |
| 107 | + function children(d){ | |
| 108 | + var n = d.firstChild, ni = -1; | |
| 109 | + while(n){ | |
| 110 | + var nx = n.nextSibling; | |
| 111 | + if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){ | |
| 112 | + d.removeChild(n); | |
| 113 | + }else{ | |
| 114 | + n.nodeIndex = ++ni; | |
| 115 | + } | |
| 116 | + n = nx; | |
| 117 | + } | |
| 118 | + return this; | |
| 119 | + }; | |
| 120 | + | |
| 121 | + function byClassName(c, a, v){ | |
| 122 | + if(!v){ | |
| 123 | + return c; | |
| 124 | + } | |
| 125 | + var r = [], ri = -1, cn; | |
| 126 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 127 | + if((' '+ci.className+' ').indexOf(v) != -1){ | |
| 128 | + r[++ri] = ci; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + return r; | |
| 132 | + }; | |
| 133 | + | |
| 134 | + function attrValue(n, attr){ | |
| 135 | + if(!n.tagName && typeof n.length != "undefined"){ | |
| 136 | + n = n[0]; | |
| 137 | + } | |
| 138 | + if(!n){ | |
| 139 | + return null; | |
| 140 | + } | |
| 141 | + if(attr == "for"){ | |
| 142 | + return n.htmlFor; | |
| 143 | + } | |
| 144 | + if(attr == "class" || attr == "className"){ | |
| 145 | + return n.className; | |
| 146 | + } | |
| 147 | + return n.getAttribute(attr) || n[attr]; | |
| 148 | + | |
| 149 | + }; | |
| 150 | + | |
| 151 | + function getNodes(ns, mode, tagName){ | |
| 152 | + var result = [], ri = -1, cs; | |
| 153 | + if(!ns){ | |
| 154 | + return result; | |
| 155 | + } | |
| 156 | + tagName = tagName || "*"; | |
| 157 | + if(typeof ns.getElementsByTagName != "undefined"){ | |
| 158 | + ns = [ns]; | |
| 159 | + } | |
| 160 | + if(!mode){ | |
| 161 | + for(var i = 0, ni; ni = ns[i]; i++){ | |
| 162 | + cs = ni.getElementsByTagName(tagName); | |
| 163 | + for(var j = 0, ci; ci = cs[j]; j++){ | |
| 164 | + result[++ri] = ci; | |
| 165 | + } | |
| 166 | + } | |
| 167 | + }else if(mode == "/" || mode == ">"){ | |
| 168 | + var utag = tagName.toUpperCase(); | |
| 169 | + for(var i = 0, ni, cn; ni = ns[i]; i++){ | |
| 170 | + cn = ni.children || ni.childNodes; | |
| 171 | + for(var j = 0, cj; cj = cn[j]; j++){ | |
| 172 | + if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){ | |
| 173 | + result[++ri] = cj; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + } | |
| 177 | + }else if(mode == "+"){ | |
| 178 | + var utag = tagName.toUpperCase(); | |
| 179 | + for(var i = 0, n; n = ns[i]; i++){ | |
| 180 | + while((n = n.nextSibling) && n.nodeType != 1); | |
| 181 | + if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){ | |
| 182 | + result[++ri] = n; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + }else if(mode == "~"){ | |
| 186 | + for(var i = 0, n; n = ns[i]; i++){ | |
| 187 | + while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName))); | |
| 188 | + if(n){ | |
| 189 | + result[++ri] = n; | |
| 190 | + } | |
| 191 | + } | |
| 192 | + } | |
| 193 | + return result; | |
| 194 | + }; | |
| 195 | + | |
| 196 | + function concat(a, b){ | |
| 197 | + if(b.slice){ | |
| 198 | + return a.concat(b); | |
| 199 | + } | |
| 200 | + for(var i = 0, l = b.length; i < l; i++){ | |
| 201 | + a[a.length] = b[i]; | |
| 202 | + } | |
| 203 | + return a; | |
| 204 | + } | |
| 205 | + | |
| 206 | + function byTag(cs, tagName){ | |
| 207 | + if(cs.tagName || cs == document){ | |
| 208 | + cs = [cs]; | |
| 209 | + } | |
| 210 | + if(!tagName){ | |
| 211 | + return cs; | |
| 212 | + } | |
| 213 | + var r = [], ri = -1; | |
| 214 | + tagName = tagName.toLowerCase(); | |
| 215 | + for(var i = 0, ci; ci = cs[i]; i++){ | |
| 216 | + if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){ | |
| 217 | + r[++ri] = ci; | |
| 218 | + } | |
| 219 | + } | |
| 220 | + return r; | |
| 221 | + }; | |
| 222 | + | |
| 223 | + function byId(cs, attr, id){ | |
| 224 | + if(cs.tagName || cs == document){ | |
| 225 | + cs = [cs]; | |
| 226 | + } | |
| 227 | + if(!id){ | |
| 228 | + return cs; | |
| 229 | + } | |
| 230 | + var r = [], ri = -1; | |
| 231 | + for(var i = 0,ci; ci = cs[i]; i++){ | |
| 232 | + if(ci && ci.id == id){ | |
| 233 | + r[++ri] = ci; | |
| 234 | + return r; | |
| 235 | + } | |
| 236 | + } | |
| 237 | + return r; | |
| 238 | + }; | |
| 239 | + | |
| 240 | + function byAttribute(cs, attr, value, op, custom){ | |
| 241 | + var r = [], ri = -1, st = custom=="{"; | |
| 242 | + var f = Ext.DomQuery.operators[op]; | |
| 243 | + for(var i = 0, ci; ci = cs[i]; i++){ | |
| 244 | + var a; | |
| 245 | + if(st){ | |
| 246 | + a = Ext.DomQuery.getStyle(ci, attr); | |
| 247 | + } | |
| 248 | + else if(attr == "class" || attr == "className"){ | |
| 249 | + a = ci.className; | |
| 250 | + }else if(attr == "for"){ | |
| 251 | + a = ci.htmlFor; | |
| 252 | + }else if(attr == "href"){ | |
| 253 | + a = ci.getAttribute("href", 2); | |
| 254 | + }else{ | |
| 255 | + a = ci.getAttribute(attr); | |
| 256 | + } | |
| 257 | + if((f && f(a, value)) || (!f && a)){ | |
| 258 | + r[++ri] = ci; | |
| 259 | + } | |
| 260 | + } | |
| 261 | + return r; | |
| 262 | + }; | |
| 263 | + | |
| 264 | + function byPseudo(cs, name, value){ | |
| 265 | + return Ext.DomQuery.pseudos[name](cs, value); | |
| 266 | + }; | |
| 267 | + | |
| 268 | + // This is for IE MSXML which does not support expandos. | |
| 269 | + // IE runs the same speed using setAttribute, however FF slows way down | |
| 270 | + // and Safari completely fails so they need to continue to use expandos. | |
| 271 | + var isIE = window.ActiveXObject ? true : false; | |
| 272 | + | |
| 273 | + // this eval is stop the compressor from | |
| 274 | + // renaming the variable to something shorter | |
| 275 | + eval("var batch = 30803;"); | |
| 276 | + | |
| 277 | + var key = 30803; | |
| 278 | + | |
| 279 | + function nodupIEXml(cs){ | |
| 280 | + var d = ++key; | |
| 281 | + cs[0].setAttribute("_nodup", d); | |
| 282 | + var r = [cs[0]]; | |
| 283 | + for(var i = 1, len = cs.length; i < len; i++){ | |
| 284 | + var c = cs[i]; | |
| 285 | + if(!c.getAttribute("_nodup") != d){ | |
| 286 | + c.setAttribute("_nodup", d); | |
| 287 | + r[r.length] = c; | |
| 288 | + } | |
| 289 | + } | |
| 290 | + for(var i = 0, len = cs.length; i < len; i++){ | |
| 291 | + cs[i].removeAttribute("_nodup"); | |
| 292 | + } | |
| 293 | + return r; | |
| 294 | + } | |
| 295 | + | |
| 296 | + function nodup(cs){ | |
| 297 | + if(!cs){ | |
| 298 | + return []; | |
| 299 | + } | |
| 300 | + var len = cs.length, c, i, r = cs, cj, ri = -1; | |
| 301 | + if(!len || typeof cs.nodeType != "undefined" || len == 1){ | |
| 302 | + return cs; | |
| 303 | + } | |
| 304 | + if(isIE && typeof cs[0].selectSingleNode != "undefined"){ | |
| 305 | + return nodupIEXml(cs); | |
| 306 | + } | |
| 307 | + var d = ++key; | |
| 308 | + cs[0]._nodup = d; | |
| 309 | + for(i = 1; c = cs[i]; i++){ | |
| 310 | + if(c._nodup != d){ | |
| 311 | + c._nodup = d; | |
| 312 | + }else{ | |
| 313 | + r = []; | |
| 314 | + for(var j = 0; j < i; j++){ | |
| 315 | + r[++ri] = cs[j]; | |
| 316 | + } | |
| 317 | + for(j = i+1; cj = cs[j]; j++){ | |
| 318 | + if(cj._nodup != d){ | |
| 319 | + cj._nodup = d; | |
| 320 | + r[++ri] = cj; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + return r; | |
| 324 | + } | |
| 325 | + } | |
| 326 | + return r; | |
| 327 | + } | |
| 328 | + | |
| 329 | + function quickDiffIEXml(c1, c2){ | |
| 330 | + var d = ++key; | |
| 331 | + for(var i = 0, len = c1.length; i < len; i++){ | |
| 332 | + c1[i].setAttribute("_qdiff", d); | |
| 333 | + } | |
| 334 | + var r = []; | |
| 335 | + for(var i = 0, len = c2.length; i < len; i++){ | |
| 336 | + if(c2[i].getAttribute("_qdiff") != d){ | |
| 337 | + r[r.length] = c2[i]; | |
| 338 | + } | |
| 339 | + } | |
| 340 | + for(var i = 0, len = c1.length; i < len; i++){ | |
| 341 | + c1[i].removeAttribute("_qdiff"); | |
| 342 | + } | |
| 343 | + return r; | |
| 344 | + } | |
| 345 | + | |
| 346 | + function quickDiff(c1, c2){ | |
| 347 | + var len1 = c1.length; | |
| 348 | + if(!len1){ | |
| 349 | + return c2; | |
| 350 | + } | |
| 351 | + if(isIE && c1[0].selectSingleNode){ | |
| 352 | + return quickDiffIEXml(c1, c2); | |
| 353 | + } | |
| 354 | + var d = ++key; | |
| 355 | + for(var i = 0; i < len1; i++){ | |
| 356 | + c1[i]._qdiff = d; | |
| 357 | + } | |
| 358 | + var r = []; | |
| 359 | + for(var i = 0, len = c2.length; i < len; i++){ | |
| 360 | + if(c2[i]._qdiff != d){ | |
| 361 | + r[r.length] = c2[i]; | |
| 362 | + } | |
| 363 | + } | |
| 364 | + return r; | |
| 365 | + } | |
| 366 | + | |
| 367 | + function quickId(ns, mode, root, id){ | |
| 368 | + if(ns == root){ | |
| 369 | + var d = root.ownerDocument || root; | |
| 370 | + return d.getElementById(id); | |
| 371 | + } | |
| 372 | + ns = getNodes(ns, mode, "*"); | |
| 373 | + return byId(ns, null, id); | |
| 374 | + } | |
| 375 | + | |
| 376 | + return { | |
| 377 | + getStyle : function(el, name){ | |
| 378 | + return Ext.fly(el).getStyle(name); | |
| 379 | + }, | |
| 380 | + /** | |
| 381 | + * Compiles a selector/xpath query into a reusable function. The returned function | |
| 382 | + * takes one parameter "root" (optional), which is the context node from where the query should start. | |
| 383 | + * @param {String} selector The selector/xpath query | |
| 384 | + * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match | |
| 385 | + * @return {Function} | |
| 386 | + */ | |
| 387 | + compile : function(path, type){ | |
| 388 | + type = type || "select"; | |
| 389 | + | |
| 390 | + var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"]; | |
| 391 | + var q = path, mode, lq; | |
| 392 | + var tk = Ext.DomQuery.matchers; | |
| 393 | + var tklen = tk.length; | |
| 394 | + var mm; | |
| 395 | + | |
| 396 | + // accept leading mode switch | |
| 397 | + var lmode = q.match(modeRe); | |
| 398 | + if(lmode && lmode[1]){ | |
| 399 | + fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";'; | |
| 400 | + q = q.replace(lmode[1], ""); | |
| 401 | + } | |
| 402 | + // strip leading slashes | |
| 403 | + while(path.substr(0, 1)=="/"){ | |
| 404 | + path = path.substr(1); | |
| 405 | + } | |
| 406 | + | |
| 407 | + while(q && lq != q){ | |
| 408 | + lq = q; | |
| 409 | + var tm = q.match(tagTokenRe); | |
| 410 | + if(type == "select"){ | |
| 411 | + if(tm){ | |
| 412 | + if(tm[1] == "#"){ | |
| 413 | + fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");'; | |
| 414 | + }else{ | |
| 415 | + fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");'; | |
| 416 | + } | |
| 417 | + q = q.replace(tm[0], ""); | |
| 418 | + }else if(q.substr(0, 1) != '@'){ | |
| 419 | + fn[fn.length] = 'n = getNodes(n, mode, "*");'; | |
| 420 | + } | |
| 421 | + }else{ | |
| 422 | + if(tm){ | |
| 423 | + if(tm[1] == "#"){ | |
| 424 | + fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");'; | |
| 425 | + }else{ | |
| 426 | + fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");'; | |
| 427 | + } | |
| 428 | + q = q.replace(tm[0], ""); | |
| 429 | + } | |
| 430 | + } | |
| 431 | + while(!(mm = q.match(modeRe))){ | |
| 432 | + var matched = false; | |
| 433 | + for(var j = 0; j < tklen; j++){ | |
| 434 | + var t = tk[j]; | |
| 435 | + var m = q.match(t.re); | |
| 436 | + if(m){ | |
| 437 | + fn[fn.length] = t.select.replace(tplRe, function(x, i){ | |
| 438 | + return m[i]; | |
| 439 | + }); | |
| 440 | + q = q.replace(m[0], ""); | |
| 441 | + matched = true; | |
| 442 | + break; | |
| 443 | + } | |
| 444 | + } | |
| 445 | + // prevent infinite loop on bad selector | |
| 446 | + if(!matched){ | |
| 447 | + throw 'Error parsing selector, parsing failed at "' + q + '"'; | |
| 448 | + } | |
| 449 | + } | |
| 450 | + if(mm[1]){ | |
| 451 | + fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";'; | |
| 452 | + q = q.replace(mm[1], ""); | |
| 453 | + } | |
| 454 | + } | |
| 455 | + fn[fn.length] = "return nodup(n);\n}"; | |
| 456 | + eval(fn.join("")); | |
| 457 | + return f; | |
| 458 | + }, | |
| 459 | + | |
| 460 | + /** | |
| 461 | + * Selects a group of elements. | |
| 462 | + * @param {String} selector The selector/xpath query (can be a comma separated list of selectors) | |
| 463 | + * @param {Node} root (optional) The start of the query (defaults to document). | |
| 464 | + * @return {Array} | |
| 465 | + */ | |
| 466 | + select : function(path, root, type){ | |
| 467 | + if(!root || root == document){ | |
| 468 | + root = document; | |
| 469 | + } | |
| 470 | + if(typeof root == "string"){ | |
| 471 | + root = document.getElementById(root); | |
| 472 | + } | |
| 473 | + var paths = path.split(","); | |
| 474 | + var results = []; | |
| 475 | + for(var i = 0, len = paths.length; i < len; i++){ | |
| 476 | + var p = paths[i].replace(trimRe, ""); | |
| 477 | + if(!cache[p]){ | |
| 478 | + cache[p] = Ext.DomQuery.compile(p); | |
| 479 | + if(!cache[p]){ | |
| 480 | + throw p + " is not a valid selector"; | |
| 481 | + } | |
| 482 | + } | |
| 483 | + var result = cache[p](root); | |
| 484 | + if(result && result != document){ | |
| 485 | + results = results.concat(result); | |
| 486 | + } | |
| 487 | + } | |
| 488 | + if(paths.length > 1){ | |
| 489 | + return nodup(results); | |
| 490 | + } | |
| 491 | + return results; | |
| 492 | + }, | |
| 493 | + | |
| 494 | + /** | |
| 495 | + * Selects a single element. | |
| 496 | + * @param {String} selector The selector/xpath query | |
| 497 | + * @param {Node} root (optional) The start of the query (defaults to document). | |
| 498 | + * @return {Element} | |
| 499 | + */ | |
| 500 | + selectNode : function(path, root){ | |
| 501 | + return Ext.DomQuery.select(path, root)[0]; | |
| 502 | + }, | |
| 503 | + | |
| 504 | + /** | |
| 505 | + * Selects the value of a node, optionally replacing null with the defaultValue. | |
| 506 | + * @param {String} selector The selector/xpath query | |
| 507 | + * @param {Node} root (optional) The start of the query (defaults to document). | |
| 508 | + * @param {String} defaultValue | |
| 509 | + * @return {String} | |
| 510 | + */ | |
| 511 | + selectValue : function(path, root, defaultValue){ | |
| 512 | + path = path.replace(trimRe, ""); | |
| 513 | + if(!valueCache[path]){ | |
| 514 | + valueCache[path] = Ext.DomQuery.compile(path, "select"); | |
| 515 | + } | |
| 516 | + var n = valueCache[path](root); | |
| 517 | + n = n[0] ? n[0] : n; | |
| 518 | + var v = (n && n.firstChild ? n.firstChild.nodeValue : null); | |
| 519 | + return ((v === null||v === undefined||v==='') ? defaultValue : v); | |
| 520 | + }, | |
| 521 | + | |
| 522 | + /** | |
| 523 | + * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified. | |
| 524 | + * @param {String} selector The selector/xpath query | |
| 525 | + * @param {Node} root (optional) The start of the query (defaults to document). | |
| 526 | + * @param {Number} defaultValue | |
| 527 | + * @return {Number} | |
| 528 | + */ | |
| 529 | + selectNumber : function(path, root, defaultValue){ | |
| 530 | + var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0); | |
| 531 | + return parseFloat(v); | |
| 532 | + }, | |
| 533 | + | |
| 534 | + /** | |
| 535 | + * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child) | |
| 536 | + * @param {String/HTMLElement/Array} el An element id, element or array of elements | |
| 537 | + * @param {String} selector The simple selector to test | |
| 538 | + * @return {Boolean} | |
| 539 | + */ | |
| 540 | + is : function(el, ss){ | |
| 541 | + if(typeof el == "string"){ | |
| 542 | + el = document.getElementById(el); | |
| 543 | + } | |
| 544 | + var isArray = Ext.isArray(el); | |
| 545 | + var result = Ext.DomQuery.filter(isArray ? el : [el], ss); | |
| 546 | + return isArray ? (result.length == el.length) : (result.length > 0); | |
| 547 | + }, | |
| 548 | + | |
| 549 | + /** | |
| 550 | + * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child) | |
| 551 | + * @param {Array} el An array of elements to filter | |
| 552 | + * @param {String} selector The simple selector to test | |
| 553 | + * @param {Boolean} nonMatches If true, it returns the elements that DON'T match | |
| 554 | + * the selector instead of the ones that match | |
| 555 | + * @return {Array} | |
| 556 | + */ | |
| 557 | + filter : function(els, ss, nonMatches){ | |
| 558 | + ss = ss.replace(trimRe, ""); | |
| 559 | + if(!simpleCache[ss]){ | |
| 560 | + simpleCache[ss] = Ext.DomQuery.compile(ss, "simple"); | |
| 561 | + } | |
| 562 | + var result = simpleCache[ss](els); | |
| 563 | + return nonMatches ? quickDiff(result, els) : result; | |
| 564 | + }, | |
| 565 | + | |
| 566 | + /** | |
| 567 | + * Collection of matching regular expressions and code snippets. | |
| 568 | + */ | |
| 569 | + matchers : [{ | |
| 570 | + re: /^\.([\w-]+)/, | |
| 571 | + select: 'n = byClassName(n, null, " {1} ");' | |
| 572 | + }, { | |
| 573 | + re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/, | |
| 574 | + select: 'n = byPseudo(n, "{1}", "{2}");' | |
| 575 | + },{ | |
| 576 | + re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/, | |
| 577 | + select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");' | |
| 578 | + }, { | |
| 579 | + re: /^#([\w-]+)/, | |
| 580 | + select: 'n = byId(n, null, "{1}");' | |
| 581 | + },{ | |
| 582 | + re: /^@([\w-]+)/, | |
| 583 | + select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};' | |
| 584 | + } | |
| 585 | + ], | |
| 586 | + | |
| 587 | + /** | |
| 588 | + * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=. | |
| 589 | + * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, > <. | |
| 590 | + */ | |
| 591 | + operators : { | |
| 592 | + "=" : function(a, v){ | |
| 593 | + return a == v; | |
| 594 | + }, | |
| 595 | + "!=" : function(a, v){ | |
| 596 | + return a != v; | |
| 597 | + }, | |
| 598 | + "^=" : function(a, v){ | |
| 599 | + return a && a.substr(0, v.length) == v; | |
| 600 | + }, | |
| 601 | + "$=" : function(a, v){ | |
| 602 | + return a && a.substr(a.length-v.length) == v; | |
| 603 | + }, | |
| 604 | + "*=" : function(a, v){ | |
| 605 | + return a && a.indexOf(v) !== -1; | |
| 606 | + }, | |
| 607 | + "%=" : function(a, v){ | |
| 608 | + return (a % v) == 0; | |
| 609 | + }, | |
| 610 | + "|=" : function(a, v){ | |
| 611 | + return a && (a == v || a.substr(0, v.length+1) == v+'-'); | |
| 612 | + }, | |
| 613 | + "~=" : function(a, v){ | |
| 614 | + return a && (' '+a+' ').indexOf(' '+v+' ') != -1; | |
| 615 | + } | |
| 616 | + }, | |
| 617 | + | |
| 618 | + /** | |
| 619 | + * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array) | |
| 620 | + * and the argument (if any) supplied in the selector. | |
| 621 | + */ | |
| 622 | + pseudos : { | |
| 623 | + "first-child" : function(c){ | |
| 624 | + var r = [], ri = -1, n; | |
| 625 | + for(var i = 0, ci; ci = n = c[i]; i++){ | |
| 626 | + while((n = n.previousSibling) && n.nodeType != 1); | |
| 627 | + if(!n){ | |
| 628 | + r[++ri] = ci; | |
| 629 | + } | |
| 630 | + } | |
| 631 | + return r; | |
| 632 | + }, | |
| 633 | + | |
| 634 | + "last-child" : function(c){ | |
| 635 | + var r = [], ri = -1, n; | |
| 636 | + for(var i = 0, ci; ci = n = c[i]; i++){ | |
| 637 | + while((n = n.nextSibling) && n.nodeType != 1); | |
| 638 | + if(!n){ | |
| 639 | + r[++ri] = ci; | |
| 640 | + } | |
| 641 | + } | |
| 642 | + return r; | |
| 643 | + }, | |
| 644 | + | |
| 645 | + "nth-child" : function(c, a) { | |
| 646 | + var r = [], ri = -1; | |
| 647 | + var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a); | |
| 648 | + var f = (m[1] || 1) - 0, l = m[2] - 0; | |
| 649 | + for(var i = 0, n; n = c[i]; i++){ | |
| 650 | + var pn = n.parentNode; | |
| 651 | + if (batch != pn._batch) { | |
| 652 | + var j = 0; | |
| 653 | + for(var cn = pn.firstChild; cn; cn = cn.nextSibling){ | |
| 654 | + if(cn.nodeType == 1){ | |
| 655 | + cn.nodeIndex = ++j; | |
| 656 | + } | |
| 657 | + } | |
| 658 | + pn._batch = batch; | |
| 659 | + } | |
| 660 | + if (f == 1) { | |
| 661 | + if (l == 0 || n.nodeIndex == l){ | |
| 662 | + r[++ri] = n; | |
| 663 | + } | |
| 664 | + } else if ((n.nodeIndex + l) % f == 0){ | |
| 665 | + r[++ri] = n; | |
| 666 | + } | |
| 667 | + } | |
| 668 | + | |
| 669 | + return r; | |
| 670 | + }, | |
| 671 | + | |
| 672 | + "only-child" : function(c){ | |
| 673 | + var r = [], ri = -1;; | |
| 674 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 675 | + if(!prev(ci) && !next(ci)){ | |
| 676 | + r[++ri] = ci; | |
| 677 | + } | |
| 678 | + } | |
| 679 | + return r; | |
| 680 | + }, | |
| 681 | + | |
| 682 | + "empty" : function(c){ | |
| 683 | + var r = [], ri = -1; | |
| 684 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 685 | + var cns = ci.childNodes, j = 0, cn, empty = true; | |
| 686 | + while(cn = cns[j]){ | |
| 687 | + ++j; | |
| 688 | + if(cn.nodeType == 1 || cn.nodeType == 3){ | |
| 689 | + empty = false; | |
| 690 | + break; | |
| 691 | + } | |
| 692 | + } | |
| 693 | + if(empty){ | |
| 694 | + r[++ri] = ci; | |
| 695 | + } | |
| 696 | + } | |
| 697 | + return r; | |
| 698 | + }, | |
| 699 | + | |
| 700 | + "contains" : function(c, v){ | |
| 701 | + var r = [], ri = -1; | |
| 702 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 703 | + if((ci.textContent||ci.innerText||'').indexOf(v) != -1){ | |
| 704 | + r[++ri] = ci; | |
| 705 | + } | |
| 706 | + } | |
| 707 | + return r; | |
| 708 | + }, | |
| 709 | + | |
| 710 | + "nodeValue" : function(c, v){ | |
| 711 | + var r = [], ri = -1; | |
| 712 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 713 | + if(ci.firstChild && ci.firstChild.nodeValue == v){ | |
| 714 | + r[++ri] = ci; | |
| 715 | + } | |
| 716 | + } | |
| 717 | + return r; | |
| 718 | + }, | |
| 719 | + | |
| 720 | + "checked" : function(c){ | |
| 721 | + var r = [], ri = -1; | |
| 722 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 723 | + if(ci.checked == true){ | |
| 724 | + r[++ri] = ci; | |
| 725 | + } | |
| 726 | + } | |
| 727 | + return r; | |
| 728 | + }, | |
| 729 | + | |
| 730 | + "not" : function(c, ss){ | |
| 731 | + return Ext.DomQuery.filter(c, ss, true); | |
| 732 | + }, | |
| 733 | + | |
| 734 | + "any" : function(c, selectors){ | |
| 735 | + var ss = selectors.split('|'); | |
| 736 | + var r = [], ri = -1, s; | |
| 737 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 738 | + for(var j = 0; s = ss[j]; j++){ | |
| 739 | + if(Ext.DomQuery.is(ci, s)){ | |
| 740 | + r[++ri] = ci; | |
| 741 | + break; | |
| 742 | + } | |
| 743 | + } | |
| 744 | + } | |
| 745 | + return r; | |
| 746 | + }, | |
| 747 | + | |
| 748 | + "odd" : function(c){ | |
| 749 | + return this["nth-child"](c, "odd"); | |
| 750 | + }, | |
| 751 | + | |
| 752 | + "even" : function(c){ | |
| 753 | + return this["nth-child"](c, "even"); | |
| 754 | + }, | |
| 755 | + | |
| 756 | + "nth" : function(c, a){ | |
| 757 | + return c[a-1] || []; | |
| 758 | + }, | |
| 759 | + | |
| 760 | + "first" : function(c){ | |
| 761 | + return c[0] || []; | |
| 762 | + }, | |
| 763 | + | |
| 764 | + "last" : function(c){ | |
| 765 | + return c[c.length-1] || []; | |
| 766 | + }, | |
| 767 | + | |
| 768 | + "has" : function(c, ss){ | |
| 769 | + var s = Ext.DomQuery.select; | |
| 770 | + var r = [], ri = -1; | |
| 771 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 772 | + if(s(ss, ci).length > 0){ | |
| 773 | + r[++ri] = ci; | |
| 774 | + } | |
| 775 | + } | |
| 776 | + return r; | |
| 777 | + }, | |
| 778 | + | |
| 779 | + "next" : function(c, ss){ | |
| 780 | + var is = Ext.DomQuery.is; | |
| 781 | + var r = [], ri = -1; | |
| 782 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 783 | + var n = next(ci); | |
| 784 | + if(n && is(n, ss)){ | |
| 785 | + r[++ri] = ci; | |
| 786 | + } | |
| 787 | + } | |
| 788 | + return r; | |
| 789 | + }, | |
| 790 | + | |
| 791 | + "prev" : function(c, ss){ | |
| 792 | + var is = Ext.DomQuery.is; | |
| 793 | + var r = [], ri = -1; | |
| 794 | + for(var i = 0, ci; ci = c[i]; i++){ | |
| 795 | + var n = prev(ci); | |
| 796 | + if(n && is(n, ss)){ | |
| 797 | + r[++ri] = ci; | |
| 798 | + } | |
| 799 | + } | |
| 800 | + return r; | |
| 801 | + } | |
| 802 | + } | |
| 803 | + }; | |
| 804 | +}(); | |
| 805 | + | |
| 806 | +/** | |
| 807 | + * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Ext.DomQuery#select} | |
| 808 | + * @param {String} path The selector/xpath query | |
| 809 | + * @param {Node} root (optional) The start of the query (defaults to document). | |
| 810 | + * @return {Array} | |
| 811 | + * @member Ext | |
| 812 | + * @method query | |
| 813 | + */ | |
| 814 | +Ext.query = Ext.DomQuery.select; | ... | ... |
thirdpartyjs/extjs/source/core/Element.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * @class Ext.Element | |
| 11 | + * Represents an Element in the DOM.<br><br> | |
| 12 | + * Usage:<br> | |
| 13 | +<pre><code> | |
| 14 | +// by id | |
| 15 | +var el = Ext.get("my-div"); | |
| 16 | + | |
| 17 | +// by DOM element reference | |
| 18 | +var el = Ext.get(myDivElement); | |
| 19 | +</code></pre> | |
| 20 | + * <b>Animations</b><br /> | |
| 21 | + * Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter | |
| 22 | + * should either be a boolean (true) or an object literal with animation options. Note that the supported Element animation | |
| 23 | + * options are a subset of the {@link Ext.Fx} animation options specific to Fx effects. The Element animation options are: | |
| 24 | +<pre> | |
| 25 | +Option Default Description | |
| 26 | +--------- -------- --------------------------------------------- | |
| 27 | +duration .35 The duration of the animation in seconds | |
| 28 | +easing easeOut The easing method | |
| 29 | +callback none A function to execute when the anim completes | |
| 30 | +scope this The scope (this) of the callback function | |
| 31 | +</pre> | |
| 32 | +* Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or | |
| 33 | +* manipulate the animation. Here's an example: | |
| 34 | +<pre><code> | |
| 35 | +var el = Ext.get("my-div"); | |
| 36 | + | |
| 37 | +// no animation | |
| 38 | +el.setWidth(100); | |
| 39 | + | |
| 40 | +// default animation | |
| 41 | +el.setWidth(100, true); | |
| 42 | + | |
| 43 | +// animation with some options set | |
| 44 | +el.setWidth(100, { | |
| 45 | + duration: 1, | |
| 46 | + callback: this.foo, | |
| 47 | + scope: this | |
| 48 | +}); | |
| 49 | + | |
| 50 | +// using the "anim" property to get the Anim object | |
| 51 | +var opt = { | |
| 52 | + duration: 1, | |
| 53 | + callback: this.foo, | |
| 54 | + scope: this | |
| 55 | +}; | |
| 56 | +el.setWidth(100, opt); | |
| 57 | +... | |
| 58 | +if(opt.anim.isAnimated()){ | |
| 59 | + opt.anim.stop(); | |
| 60 | +} | |
| 61 | +</code></pre> | |
| 62 | +* <b> Composite (Collections of) Elements</b><br /> | |
| 63 | + * For working with collections of Elements, see {@link Ext.CompositeElement} | |
| 64 | + * @constructor Create a new Element directly. | |
| 65 | + * @param {String/HTMLElement} element | |
| 66 | + * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class). | |
| 67 | + */ | |
| 68 | +(function(){ | |
| 69 | +var D = Ext.lib.Dom; | |
| 70 | +var E = Ext.lib.Event; | |
| 71 | +var A = Ext.lib.Anim; | |
| 72 | + | |
| 73 | +// local style camelizing for speed | |
| 74 | +var propCache = {}; | |
| 75 | +var camelRe = /(-[a-z])/gi; | |
| 76 | +var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); }; | |
| 77 | +var view = document.defaultView; | |
| 78 | + | |
| 79 | +Ext.Element = function(element, forceNew){ | |
| 80 | + var dom = typeof element == "string" ? | |
| 81 | + document.getElementById(element) : element; | |
| 82 | + if(!dom){ // invalid id/element | |
| 83 | + return null; | |
| 84 | + } | |
| 85 | + var id = dom.id; | |
| 86 | + if(forceNew !== true && id && Ext.Element.cache[id]){ // element object already exists | |
| 87 | + return Ext.Element.cache[id]; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * The DOM element | |
| 92 | + * @type HTMLElement | |
| 93 | + */ | |
| 94 | + this.dom = dom; | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * The DOM element ID | |
| 98 | + * @type String | |
| 99 | + */ | |
| 100 | + this.id = id || Ext.id(dom); | |
| 101 | +}; | |
| 102 | + | |
| 103 | +var El = Ext.Element; | |
| 104 | + | |
| 105 | +El.prototype = { | |
| 106 | + /** | |
| 107 | + * The element's default display mode (defaults to "") | |
| 108 | + * @type String | |
| 109 | + */ | |
| 110 | + originalDisplay : "", | |
| 111 | + | |
| 112 | + visibilityMode : 1, | |
| 113 | + /** | |
| 114 | + * The default unit to append to CSS values where a unit isn't provided (defaults to px). | |
| 115 | + * @type String | |
| 116 | + */ | |
| 117 | + defaultUnit : "px", | |
| 118 | + /** | |
| 119 | + * Sets the element's visibility mode. When setVisible() is called it | |
| 120 | + * will use this to determine whether to set the visibility or the display property. | |
| 121 | + * @param visMode Element.VISIBILITY or Element.DISPLAY | |
| 122 | + * @return {Ext.Element} this | |
| 123 | + */ | |
| 124 | + setVisibilityMode : function(visMode){ | |
| 125 | + this.visibilityMode = visMode; | |
| 126 | + return this; | |
| 127 | + }, | |
| 128 | + /** | |
| 129 | + * Convenience method for setVisibilityMode(Element.DISPLAY) | |
| 130 | + * @param {String} display (optional) What to set display to when visible | |
| 131 | + * @return {Ext.Element} this | |
| 132 | + */ | |
| 133 | + enableDisplayMode : function(display){ | |
| 134 | + this.setVisibilityMode(El.DISPLAY); | |
| 135 | + if(typeof display != "undefined") this.originalDisplay = display; | |
| 136 | + return this; | |
| 137 | + }, | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child) | |
| 141 | + * @param {String} selector The simple selector to test | |
| 142 | + * @param {Number/Mixed} maxDepth (optional) The max depth to | |
| 143 | + search as a number or element (defaults to 10 || document.body) | |
| 144 | + * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node | |
| 145 | + * @return {HTMLElement} The matching DOM node (or null if no match was found) | |
| 146 | + */ | |
| 147 | + findParent : function(simpleSelector, maxDepth, returnEl){ | |
| 148 | + var p = this.dom, b = document.body, depth = 0, dq = Ext.DomQuery, stopEl; | |
| 149 | + maxDepth = maxDepth || 50; | |
| 150 | + if(typeof maxDepth != "number"){ | |
| 151 | + stopEl = Ext.getDom(maxDepth); | |
| 152 | + maxDepth = 10; | |
| 153 | + } | |
| 154 | + while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){ | |
| 155 | + if(dq.is(p, simpleSelector)){ | |
| 156 | + return returnEl ? Ext.get(p) : p; | |
| 157 | + } | |
| 158 | + depth++; | |
| 159 | + p = p.parentNode; | |
| 160 | + } | |
| 161 | + return null; | |
| 162 | + }, | |
| 163 | + | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child) | |
| 167 | + * @param {String} selector The simple selector to test | |
| 168 | + * @param {Number/Mixed} maxDepth (optional) The max depth to | |
| 169 | + search as a number or element (defaults to 10 || document.body) | |
| 170 | + * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node | |
| 171 | + * @return {HTMLElement} The matching DOM node (or null if no match was found) | |
| 172 | + */ | |
| 173 | + findParentNode : function(simpleSelector, maxDepth, returnEl){ | |
| 174 | + var p = Ext.fly(this.dom.parentNode, '_internal'); | |
| 175 | + return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null; | |
| 176 | + }, | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child). | |
| 180 | + * This is a shortcut for findParentNode() that always returns an Ext.Element. | |
| 181 | + * @param {String} selector The simple selector to test | |
| 182 | + * @param {Number/Mixed} maxDepth (optional) The max depth to | |
| 183 | + search as a number or element (defaults to 10 || document.body) | |
| 184 | + * @return {Ext.Element} The matching DOM node (or null if no match was found) | |
| 185 | + */ | |
| 186 | + up : function(simpleSelector, maxDepth){ | |
| 187 | + return this.findParentNode(simpleSelector, maxDepth, true); | |
| 188 | + }, | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child) | |
| 194 | + * @param {String} selector The simple selector to test | |
| 195 | + * @return {Boolean} True if this element matches the selector, else false | |
| 196 | + */ | |
| 197 | + is : function(simpleSelector){ | |
| 198 | + return Ext.DomQuery.is(this.dom, simpleSelector); | |
| 199 | + }, | |
| 200 | + | |
| 201 | + /** | |
| 202 | + * Perform animation on this element. | |
| 203 | + * @param {Object} args The animation control args | |
| 204 | + * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35) | |
| 205 | + * @param {Function} onComplete (optional) Function to call when animation completes | |
| 206 | + * @param {String} easing (optional) Easing method to use (defaults to 'easeOut') | |
| 207 | + * @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll' | |
| 208 | + * @return {Ext.Element} this | |
| 209 | + */ | |
| 210 | + animate : function(args, duration, onComplete, easing, animType){ | |
| 211 | + this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType); | |
| 212 | + return this; | |
| 213 | + }, | |
| 214 | + | |
| 215 | + /* | |
| 216 | + * @private Internal animation call | |
| 217 | + */ | |
| 218 | + anim : function(args, opt, animType, defaultDur, defaultEase, cb){ | |
| 219 | + animType = animType || 'run'; | |
| 220 | + opt = opt || {}; | |
| 221 | + var anim = Ext.lib.Anim[animType]( | |
| 222 | + this.dom, args, | |
| 223 | + (opt.duration || defaultDur) || .35, | |
| 224 | + (opt.easing || defaultEase) || 'easeOut', | |
| 225 | + function(){ | |
| 226 | + Ext.callback(cb, this); | |
| 227 | + Ext.callback(opt.callback, opt.scope || this, [this, opt]); | |
| 228 | + }, | |
| 229 | + this | |
| 230 | + ); | |
| 231 | + opt.anim = anim; | |
| 232 | + return anim; | |
| 233 | + }, | |
| 234 | + | |
| 235 | + // private legacy anim prep | |
| 236 | + preanim : function(a, i){ | |
| 237 | + return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]}); | |
| 238 | + }, | |
| 239 | + | |
| 240 | + /** | |
| 241 | + * Removes worthless text nodes | |
| 242 | + * @param {Boolean} forceReclean (optional) By default the element | |
| 243 | + * keeps track if it has been cleaned already so | |
| 244 | + * you can call this over and over. However, if you update the element and | |
| 245 | + * need to force a reclean, you can pass true. | |
| 246 | + */ | |
| 247 | + clean : function(forceReclean){ | |
| 248 | + if(this.isCleaned && forceReclean !== true){ | |
| 249 | + return this; | |
| 250 | + } | |
| 251 | + var ns = /\S/; | |
| 252 | + var d = this.dom, n = d.firstChild, ni = -1; | |
| 253 | + while(n){ | |
| 254 | + var nx = n.nextSibling; | |
| 255 | + if(n.nodeType == 3 && !ns.test(n.nodeValue)){ | |
| 256 | + d.removeChild(n); | |
| 257 | + }else{ | |
| 258 | + n.nodeIndex = ++ni; | |
| 259 | + } | |
| 260 | + n = nx; | |
| 261 | + } | |
| 262 | + this.isCleaned = true; | |
| 263 | + return this; | |
| 264 | + }, | |
| 265 | + | |
| 266 | + /** | |
| 267 | + * Scrolls this element into view within the passed container. | |
| 268 | + * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a | |
| 269 | + * string (id), dom node, or Ext.Element. | |
| 270 | + * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true) | |
| 271 | + * @return {Ext.Element} this | |
| 272 | + */ | |
| 273 | + scrollIntoView : function(container, hscroll){ | |
| 274 | + var c = Ext.getDom(container) || Ext.getBody().dom; | |
| 275 | + var el = this.dom; | |
| 276 | + | |
| 277 | + var o = this.getOffsetsTo(c), | |
| 278 | + l = o[0] + c.scrollLeft, | |
| 279 | + t = o[1] + c.scrollTop, | |
| 280 | + b = t+el.offsetHeight, | |
| 281 | + r = l+el.offsetWidth; | |
| 282 | + | |
| 283 | + var ch = c.clientHeight; | |
| 284 | + var ct = parseInt(c.scrollTop, 10); | |
| 285 | + var cl = parseInt(c.scrollLeft, 10); | |
| 286 | + var cb = ct + ch; | |
| 287 | + var cr = cl + c.clientWidth; | |
| 288 | + | |
| 289 | + if(el.offsetHeight > ch || t < ct){ | |
| 290 | + c.scrollTop = t; | |
| 291 | + }else if(b > cb){ | |
| 292 | + c.scrollTop = b-ch; | |
| 293 | + } | |
| 294 | + c.scrollTop = c.scrollTop; // corrects IE, other browsers will ignore | |
| 295 | + | |
| 296 | + if(hscroll !== false){ | |
| 297 | + if(el.offsetWidth > c.clientWidth || l < cl){ | |
| 298 | + c.scrollLeft = l; | |
| 299 | + }else if(r > cr){ | |
| 300 | + c.scrollLeft = r-c.clientWidth; | |
| 301 | + } | |
| 302 | + c.scrollLeft = c.scrollLeft; | |
| 303 | + } | |
| 304 | + return this; | |
| 305 | + }, | |
| 306 | + | |
| 307 | + // private | |
| 308 | + scrollChildIntoView : function(child, hscroll){ | |
| 309 | + Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll); | |
| 310 | + }, | |
| 311 | + | |
| 312 | + /** | |
| 313 | + * Measures the element's content height and updates height to match. Note: this function uses setTimeout so | |
| 314 | + * the new height may not be available immediately. | |
| 315 | + * @param {Boolean} animate (optional) Animate the transition (defaults to false) | |
| 316 | + * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35) | |
| 317 | + * @param {Function} onComplete (optional) Function to call when animation completes | |
| 318 | + * @param {String} easing (optional) Easing method to use (defaults to easeOut) | |
| 319 | + * @return {Ext.Element} this | |
| 320 | + */ | |
| 321 | + autoHeight : function(animate, duration, onComplete, easing){ | |
| 322 | + var oldHeight = this.getHeight(); | |
| 323 | + this.clip(); | |
| 324 | + this.setHeight(1); // force clipping | |
| 325 | + setTimeout(function(){ | |
| 326 | + var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari | |
| 327 | + if(!animate){ | |
| 328 | + this.setHeight(height); | |
| 329 | + this.unclip(); | |
| 330 | + if(typeof onComplete == "function"){ | |
| 331 | + onComplete(); | |
| 332 | + } | |
| 333 | + }else{ | |
| 334 | + this.setHeight(oldHeight); // restore original height | |
| 335 | + this.setHeight(height, animate, duration, function(){ | |
| 336 | + this.unclip(); | |
| 337 | + if(typeof onComplete == "function") onComplete(); | |
| 338 | + }.createDelegate(this), easing); | |
| 339 | + } | |
| 340 | + }.createDelegate(this), 0); | |
| 341 | + return this; | |
| 342 | + }, | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * Returns true if this element is an ancestor of the passed element | |
| 346 | + * @param {HTMLElement/String} el The element to check | |
| 347 | + * @return {Boolean} True if this element is an ancestor of el, else false | |
| 348 | + */ | |
| 349 | + contains : function(el){ | |
| 350 | + if(!el){return false;} | |
| 351 | + return D.isAncestor(this.dom, el.dom ? el.dom : el); | |
| 352 | + }, | |
| 353 | + | |
| 354 | + /** | |
| 355 | + * Checks whether the element is currently visible using both visibility and display properties. | |
| 356 | + * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false) | |
| 357 | + * @return {Boolean} True if the element is currently visible, else false | |
| 358 | + */ | |
| 359 | + isVisible : function(deep) { | |
| 360 | + var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none"); | |
| 361 | + if(deep !== true || !vis){ | |
| 362 | + return vis; | |
| 363 | + } | |
| 364 | + var p = this.dom.parentNode; | |
| 365 | + while(p && p.tagName.toLowerCase() != "body"){ | |
| 366 | + if(!Ext.fly(p, '_isVisible').isVisible()){ | |
| 367 | + return false; | |
| 368 | + } | |
| 369 | + p = p.parentNode; | |
| 370 | + } | |
| 371 | + return true; | |
| 372 | + }, | |
| 373 | + | |
| 374 | + /** | |
| 375 | + * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id). | |
| 376 | + * @param {String} selector The CSS selector | |
| 377 | + * @param {Boolean} unique (optional) True to create a unique Ext.Element for each child (defaults to false, which creates a single shared flyweight object) | |
| 378 | + * @return {CompositeElement/CompositeElementLite} The composite element | |
| 379 | + */ | |
| 380 | + select : function(selector, unique){ | |
| 381 | + return El.select(selector, unique, this.dom); | |
| 382 | + }, | |
| 383 | + | |
| 384 | + /** | |
| 385 | + * Selects child nodes based on the passed CSS selector (the selector should not contain an id). | |
| 386 | + * @param {String} selector The CSS selector | |
| 387 | + * @return {Array} An array of the matched nodes | |
| 388 | + */ | |
| 389 | + query : function(selector){ | |
| 390 | + return Ext.DomQuery.select(selector, this.dom); | |
| 391 | + }, | |
| 392 | + | |
| 393 | + /** | |
| 394 | + * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id). | |
| 395 | + * @param {String} selector The CSS selector | |
| 396 | + * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false) | |
| 397 | + * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true) | |
| 398 | + */ | |
| 399 | + child : function(selector, returnDom){ | |
| 400 | + var n = Ext.DomQuery.selectNode(selector, this.dom); | |
| 401 | + return returnDom ? n : Ext.get(n); | |
| 402 | + }, | |
| 403 | + | |
| 404 | + /** | |
| 405 | + * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id). | |
| 406 | + * @param {String} selector The CSS selector | |
| 407 | + * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false) | |
| 408 | + * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true) | |
| 409 | + */ | |
| 410 | + down : function(selector, returnDom){ | |
| 411 | + var n = Ext.DomQuery.selectNode(" > " + selector, this.dom); | |
| 412 | + return returnDom ? n : Ext.get(n); | |
| 413 | + }, | |
| 414 | + | |
| 415 | + /** | |
| 416 | + * Initializes a {@link Ext.dd.DD} drag drop object for this element. | |
| 417 | + * @param {String} group The group the DD object is member of | |
| 418 | + * @param {Object} config The DD config object | |
| 419 | + * @param {Object} overrides An object containing methods to override/implement on the DD object | |
| 420 | + * @return {Ext.dd.DD} The DD object | |
| 421 | + */ | |
| 422 | + initDD : function(group, config, overrides){ | |
| 423 | + var dd = new Ext.dd.DD(Ext.id(this.dom), group, config); | |
| 424 | + return Ext.apply(dd, overrides); | |
| 425 | + }, | |
| 426 | + | |
| 427 | + /** | |
| 428 | + * Initializes a {@link Ext.dd.DDProxy} object for this element. | |
| 429 | + * @param {String} group The group the DDProxy object is member of | |
| 430 | + * @param {Object} config The DDProxy config object | |
| 431 | + * @param {Object} overrides An object containing methods to override/implement on the DDProxy object | |
| 432 | + * @return {Ext.dd.DDProxy} The DDProxy object | |
| 433 | + */ | |
| 434 | + initDDProxy : function(group, config, overrides){ | |
| 435 | + var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config); | |
| 436 | + return Ext.apply(dd, overrides); | |
| 437 | + }, | |
| 438 | + | |
| 439 | + /** | |
| 440 | + * Initializes a {@link Ext.dd.DDTarget} object for this element. | |
| 441 | + * @param {String} group The group the DDTarget object is member of | |
| 442 | + * @param {Object} config The DDTarget config object | |
| 443 | + * @param {Object} overrides An object containing methods to override/implement on the DDTarget object | |
| 444 | + * @return {Ext.dd.DDTarget} The DDTarget object | |
| 445 | + */ | |
| 446 | + initDDTarget : function(group, config, overrides){ | |
| 447 | + var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config); | |
| 448 | + return Ext.apply(dd, overrides); | |
| 449 | + }, | |
| 450 | + | |
| 451 | + /** | |
| 452 | + * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use | |
| 453 | + * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property. | |
| 454 | + * @param {Boolean} visible Whether the element is visible | |
| 455 | + * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object | |
| 456 | + * @return {Ext.Element} this | |
| 457 | + */ | |
| 458 | + setVisible : function(visible, animate){ | |
| 459 | + if(!animate || !A){ | |
| 460 | + if(this.visibilityMode == El.DISPLAY){ | |
| 461 | + this.setDisplayed(visible); | |
| 462 | + }else{ | |
| 463 | + this.fixDisplay(); | |
| 464 | + this.dom.style.visibility = visible ? "visible" : "hidden"; | |
| 465 | + } | |
| 466 | + }else{ | |
| 467 | + // closure for composites | |
| 468 | + var dom = this.dom; | |
| 469 | + var visMode = this.visibilityMode; | |
| 470 | + if(visible){ | |
| 471 | + this.setOpacity(.01); | |
| 472 | + this.setVisible(true); | |
| 473 | + } | |
| 474 | + this.anim({opacity: { to: (visible?1:0) }}, | |
| 475 | + this.preanim(arguments, 1), | |
| 476 | + null, .35, 'easeIn', function(){ | |
| 477 | + if(!visible){ | |
| 478 | + if(visMode == El.DISPLAY){ | |
| 479 | + dom.style.display = "none"; | |
| 480 | + }else{ | |
| 481 | + dom.style.visibility = "hidden"; | |
| 482 | + } | |
| 483 | + Ext.get(dom).setOpacity(1); | |
| 484 | + } | |
| 485 | + }); | |
| 486 | + } | |
| 487 | + return this; | |
| 488 | + }, | |
| 489 | + | |
| 490 | + /** | |
| 491 | + * Returns true if display is not "none" | |
| 492 | + * @return {Boolean} | |
| 493 | + */ | |
| 494 | + isDisplayed : function() { | |
| 495 | + return this.getStyle("display") != "none"; | |
| 496 | + }, | |
| 497 | + | |
| 498 | + /** | |
| 499 | + * Toggles the element's visibility or display, depending on visibility mode. | |
| 500 | + * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object | |
| 501 | + * @return {Ext.Element} this | |
| 502 | + */ | |
| 503 | + toggle : function(animate){ | |
| 504 | + this.setVisible(!this.isVisible(), this.preanim(arguments, 0)); | |
| 505 | + return this; | |
| 506 | + }, | |
| 507 | + | |
| 508 | + /** | |
| 509 | + * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true. | |
| 510 | + * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly. | |
| 511 | + * @return {Ext.Element} this | |
| 512 | + */ | |
| 513 | + setDisplayed : function(value) { | |
| 514 | + if(typeof value == "boolean"){ | |
| 515 | + value = value ? this.originalDisplay : "none"; | |
| 516 | + } | |
| 517 | + this.setStyle("display", value); | |
| 518 | + return this; | |
| 519 | + }, | |
| 520 | + | |
| 521 | + /** | |
| 522 | + * Tries to focus the element. Any exceptions are caught and ignored. | |
| 523 | + * @return {Ext.Element} this | |
| 524 | + */ | |
| 525 | + focus : function() { | |
| 526 | + try{ | |
| 527 | + this.dom.focus(); | |
| 528 | + }catch(e){} | |
| 529 | + return this; | |
| 530 | + }, | |
| 531 | + | |
| 532 | + /** | |
| 533 | + * Tries to blur the element. Any exceptions are caught and ignored. | |
| 534 | + * @return {Ext.Element} this | |
| 535 | + */ | |
| 536 | + blur : function() { | |
| 537 | + try{ | |
| 538 | + this.dom.blur(); | |
| 539 | + }catch(e){} | |
| 540 | + return this; | |
| 541 | + }, | |
| 542 | + | |
| 543 | + /** | |
| 544 | + * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out. | |
| 545 | + * @param {String/Array} className The CSS class to add, or an array of classes | |
| 546 | + * @return {Ext.Element} this | |
| 547 | + */ | |
| 548 | + addClass : function(className){ | |
| 549 | + if(Ext.isArray(className)){ | |
| 550 | + for(var i = 0, len = className.length; i < len; i++) { | |
| 551 | + this.addClass(className[i]); | |
| 552 | + } | |
| 553 | + }else{ | |
| 554 | + if(className && !this.hasClass(className)){ | |
| 555 | + this.dom.className = this.dom.className + " " + className; | |
| 556 | + } | |
| 557 | + } | |
| 558 | + return this; | |
| 559 | + }, | |
| 560 | + | |
| 561 | + /** | |
| 562 | + * Adds one or more CSS classes to this element and removes the same class(es) from all siblings. | |
| 563 | + * @param {String/Array} className The CSS class to add, or an array of classes | |
| 564 | + * @return {Ext.Element} this | |
| 565 | + */ | |
| 566 | + radioClass : function(className){ | |
| 567 | + var siblings = this.dom.parentNode.childNodes; | |
| 568 | + for(var i = 0; i < siblings.length; i++) { | |
| 569 | + var s = siblings[i]; | |
| 570 | + if(s.nodeType == 1){ | |
| 571 | + Ext.get(s).removeClass(className); | |
| 572 | + } | |
| 573 | + } | |
| 574 | + this.addClass(className); | |
| 575 | + return this; | |
| 576 | + }, | |
| 577 | + | |
| 578 | + /** | |
| 579 | + * Removes one or more CSS classes from the element. | |
| 580 | + * @param {String/Array} className The CSS class to remove, or an array of classes | |
| 581 | + * @return {Ext.Element} this | |
| 582 | + */ | |
| 583 | + removeClass : function(className){ | |
| 584 | + if(!className || !this.dom.className){ | |
| 585 | + return this; | |
| 586 | + } | |
| 587 | + if(Ext.isArray(className)){ | |
| 588 | + for(var i = 0, len = className.length; i < len; i++) { | |
| 589 | + this.removeClass(className[i]); | |
| 590 | + } | |
| 591 | + }else{ | |
| 592 | + if(this.hasClass(className)){ | |
| 593 | + var re = this.classReCache[className]; | |
| 594 | + if (!re) { | |
| 595 | + re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g"); | |
| 596 | + this.classReCache[className] = re; | |
| 597 | + } | |
| 598 | + this.dom.className = | |
| 599 | + this.dom.className.replace(re, " "); | |
| 600 | + } | |
| 601 | + } | |
| 602 | + return this; | |
| 603 | + }, | |
| 604 | + | |
| 605 | + // private | |
| 606 | + classReCache: {}, | |
| 607 | + | |
| 608 | + /** | |
| 609 | + * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it). | |
| 610 | + * @param {String} className The CSS class to toggle | |
| 611 | + * @return {Ext.Element} this | |
| 612 | + */ | |
| 613 | + toggleClass : function(className){ | |
| 614 | + if(this.hasClass(className)){ | |
| 615 | + this.removeClass(className); | |
| 616 | + }else{ | |
| 617 | + this.addClass(className); | |
| 618 | + } | |
| 619 | + return this; | |
| 620 | + }, | |
| 621 | + | |
| 622 | + /** | |
| 623 | + * Checks if the specified CSS class exists on this element's DOM node. | |
| 624 | + * @param {String} className The CSS class to check for | |
| 625 | + * @return {Boolean} True if the class exists, else false | |
| 626 | + */ | |
| 627 | + hasClass : function(className){ | |
| 628 | + return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1; | |
| 629 | + }, | |
| 630 | + | |
| 631 | + /** | |
| 632 | + * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added. | |
| 633 | + * @param {String} oldClassName The CSS class to replace | |
| 634 | + * @param {String} newClassName The replacement CSS class | |
| 635 | + * @return {Ext.Element} this | |
| 636 | + */ | |
| 637 | + replaceClass : function(oldClassName, newClassName){ | |
| 638 | + this.removeClass(oldClassName); | |
| 639 | + this.addClass(newClassName); | |
| 640 | + return this; | |
| 641 | + }, | |
| 642 | + | |
| 643 | + /** | |
| 644 | + * Returns an object with properties matching the styles requested. | |
| 645 | + * For example, el.getStyles('color', 'font-size', 'width') might return | |
| 646 | + * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}. | |
| 647 | + * @param {String} style1 A style name | |
| 648 | + * @param {String} style2 A style name | |
| 649 | + * @param {String} etc. | |
| 650 | + * @return {Object} The style object | |
| 651 | + */ | |
| 652 | + getStyles : function(){ | |
| 653 | + var a = arguments, len = a.length, r = {}; | |
| 654 | + for(var i = 0; i < len; i++){ | |
| 655 | + r[a[i]] = this.getStyle(a[i]); | |
| 656 | + } | |
| 657 | + return r; | |
| 658 | + }, | |
| 659 | + | |
| 660 | + /** | |
| 661 | + * Normalizes currentStyle and computedStyle. | |
| 662 | + * @param {String} property The style property whose value is returned. | |
| 663 | + * @return {String} The current value of the style property for this element. | |
| 664 | + */ | |
| 665 | + getStyle : function(){ | |
| 666 | + return view && view.getComputedStyle ? | |
| 667 | + function(prop){ | |
| 668 | + var el = this.dom, v, cs, camel; | |
| 669 | + if(prop == 'float'){ | |
| 670 | + prop = "cssFloat"; | |
| 671 | + } | |
| 672 | + if(v = el.style[prop]){ | |
| 673 | + return v; | |
| 674 | + } | |
| 675 | + if(cs = view.getComputedStyle(el, "")){ | |
| 676 | + if(!(camel = propCache[prop])){ | |
| 677 | + camel = propCache[prop] = prop.replace(camelRe, camelFn); | |
| 678 | + } | |
| 679 | + return cs[camel]; | |
| 680 | + } | |
| 681 | + return null; | |
| 682 | + } : | |
| 683 | + function(prop){ | |
| 684 | + var el = this.dom, v, cs, camel; | |
| 685 | + if(prop == 'opacity'){ | |
| 686 | + if(typeof el.style.filter == 'string'){ | |
| 687 | + var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i); | |
| 688 | + if(m){ | |
| 689 | + var fv = parseFloat(m[1]); | |
| 690 | + if(!isNaN(fv)){ | |
| 691 | + return fv ? fv / 100 : 0; | |
| 692 | + } | |
| 693 | + } | |
| 694 | + } | |
| 695 | + return 1; | |
| 696 | + }else if(prop == 'float'){ | |
| 697 | + prop = "styleFloat"; | |
| 698 | + } | |
| 699 | + if(!(camel = propCache[prop])){ | |
| 700 | + camel = propCache[prop] = prop.replace(camelRe, camelFn); | |
| 701 | + } | |
| 702 | + if(v = el.style[camel]){ | |
| 703 | + return v; | |
| 704 | + } | |
| 705 | + if(cs = el.currentStyle){ | |
| 706 | + return cs[camel]; | |
| 707 | + } | |
| 708 | + return null; | |
| 709 | + }; | |
| 710 | + }(), | |
| 711 | + | |
| 712 | + /** | |
| 713 | + * Wrapper for setting style properties, also takes single object parameter of multiple styles. | |
| 714 | + * @param {String/Object} property The style property to be set, or an object of multiple styles. | |
| 715 | + * @param {String} value (optional) The value to apply to the given property, or null if an object was passed. | |
| 716 | + * @return {Ext.Element} this | |
| 717 | + */ | |
| 718 | + setStyle : function(prop, value){ | |
| 719 | + if(typeof prop == "string"){ | |
| 720 | + var camel; | |
| 721 | + if(!(camel = propCache[prop])){ | |
| 722 | + camel = propCache[prop] = prop.replace(camelRe, camelFn); | |
| 723 | + } | |
| 724 | + if(camel == 'opacity') { | |
| 725 | + this.setOpacity(value); | |
| 726 | + }else{ | |
| 727 | + this.dom.style[camel] = value; | |
| 728 | + } | |
| 729 | + }else{ | |
| 730 | + for(var style in prop){ | |
| 731 | + if(typeof prop[style] != "function"){ | |
| 732 | + this.setStyle(style, prop[style]); | |
| 733 | + } | |
| 734 | + } | |
| 735 | + } | |
| 736 | + return this; | |
| 737 | + }, | |
| 738 | + | |
| 739 | + /** | |
| 740 | + * More flexible version of {@link #setStyle} for setting style properties. | |
| 741 | + * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or | |
| 742 | + * a function which returns such a specification. | |
| 743 | + * @return {Ext.Element} this | |
| 744 | + */ | |
| 745 | + applyStyles : function(style){ | |
| 746 | + Ext.DomHelper.applyStyles(this.dom, style); | |
| 747 | + return this; | |
| 748 | + }, | |
| 749 | + | |
| 750 | + /** | |
| 751 | + * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 752 | + * @return {Number} The X position of the element | |
| 753 | + */ | |
| 754 | + getX : function(){ | |
| 755 | + return D.getX(this.dom); | |
| 756 | + }, | |
| 757 | + | |
| 758 | + /** | |
| 759 | + * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 760 | + * @return {Number} The Y position of the element | |
| 761 | + */ | |
| 762 | + getY : function(){ | |
| 763 | + return D.getY(this.dom); | |
| 764 | + }, | |
| 765 | + | |
| 766 | + /** | |
| 767 | + * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 768 | + * @return {Array} The XY position of the element | |
| 769 | + */ | |
| 770 | + getXY : function(){ | |
| 771 | + return D.getXY(this.dom); | |
| 772 | + }, | |
| 773 | + | |
| 774 | + /** | |
| 775 | + * Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates. | |
| 776 | + * @param {Mixed} element The element to get the offsets from. | |
| 777 | + * @return {Array} The XY page offsets (e.g. [100, -200]) | |
| 778 | + */ | |
| 779 | + getOffsetsTo : function(el){ | |
| 780 | + var o = this.getXY(); | |
| 781 | + var e = Ext.fly(el, '_internal').getXY(); | |
| 782 | + return [o[0]-e[0],o[1]-e[1]]; | |
| 783 | + }, | |
| 784 | + | |
| 785 | + /** | |
| 786 | + * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 787 | + * @param {Number} The X position of the element | |
| 788 | + * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object | |
| 789 | + * @return {Ext.Element} this | |
| 790 | + */ | |
| 791 | + setX : function(x, animate){ | |
| 792 | + if(!animate || !A){ | |
| 793 | + D.setX(this.dom, x); | |
| 794 | + }else{ | |
| 795 | + this.setXY([x, this.getY()], this.preanim(arguments, 1)); | |
| 796 | + } | |
| 797 | + return this; | |
| 798 | + }, | |
| 799 | + | |
| 800 | + /** | |
| 801 | + * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 802 | + * @param {Number} The Y position of the element | |
| 803 | + * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object | |
| 804 | + * @return {Ext.Element} this | |
| 805 | + */ | |
| 806 | + setY : function(y, animate){ | |
| 807 | + if(!animate || !A){ | |
| 808 | + D.setY(this.dom, y); | |
| 809 | + }else{ | |
| 810 | + this.setXY([this.getX(), y], this.preanim(arguments, 1)); | |
| 811 | + } | |
| 812 | + return this; | |
| 813 | + }, | |
| 814 | + | |
| 815 | + /** | |
| 816 | + * Sets the element's left position directly using CSS style (instead of {@link #setX}). | |
| 817 | + * @param {String} left The left CSS property value | |
| 818 | + * @return {Ext.Element} this | |
| 819 | + */ | |
| 820 | + setLeft : function(left){ | |
| 821 | + this.setStyle("left", this.addUnits(left)); | |
| 822 | + return this; | |
| 823 | + }, | |
| 824 | + | |
| 825 | + /** | |
| 826 | + * Sets the element's top position directly using CSS style (instead of {@link #setY}). | |
| 827 | + * @param {String} top The top CSS property value | |
| 828 | + * @return {Ext.Element} this | |
| 829 | + */ | |
| 830 | + setTop : function(top){ | |
| 831 | + this.setStyle("top", this.addUnits(top)); | |
| 832 | + return this; | |
| 833 | + }, | |
| 834 | + | |
| 835 | + /** | |
| 836 | + * Sets the element's CSS right style. | |
| 837 | + * @param {String} right The right CSS property value | |
| 838 | + * @return {Ext.Element} this | |
| 839 | + */ | |
| 840 | + setRight : function(right){ | |
| 841 | + this.setStyle("right", this.addUnits(right)); | |
| 842 | + return this; | |
| 843 | + }, | |
| 844 | + | |
| 845 | + /** | |
| 846 | + * Sets the element's CSS bottom style. | |
| 847 | + * @param {String} bottom The bottom CSS property value | |
| 848 | + * @return {Ext.Element} this | |
| 849 | + */ | |
| 850 | + setBottom : function(bottom){ | |
| 851 | + this.setStyle("bottom", this.addUnits(bottom)); | |
| 852 | + return this; | |
| 853 | + }, | |
| 854 | + | |
| 855 | + /** | |
| 856 | + * Sets the position of the element in page coordinates, regardless of how the element is positioned. | |
| 857 | + * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 858 | + * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based) | |
| 859 | + * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object | |
| 860 | + * @return {Ext.Element} this | |
| 861 | + */ | |
| 862 | + setXY : function(pos, animate){ | |
| 863 | + if(!animate || !A){ | |
| 864 | + D.setXY(this.dom, pos); | |
| 865 | + }else{ | |
| 866 | + this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion'); | |
| 867 | + } | |
| 868 | + return this; | |
| 869 | + }, | |
| 870 | + | |
| 871 | + /** | |
| 872 | + * Sets the position of the element in page coordinates, regardless of how the element is positioned. | |
| 873 | + * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 874 | + * @param {Number} x X value for new position (coordinates are page-based) | |
| 875 | + * @param {Number} y Y value for new position (coordinates are page-based) | |
| 876 | + * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object | |
| 877 | + * @return {Ext.Element} this | |
| 878 | + */ | |
| 879 | + setLocation : function(x, y, animate){ | |
| 880 | + this.setXY([x, y], this.preanim(arguments, 2)); | |
| 881 | + return this; | |
| 882 | + }, | |
| 883 | + | |
| 884 | + /** | |
| 885 | + * Sets the position of the element in page coordinates, regardless of how the element is positioned. | |
| 886 | + * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). | |
| 887 | + * @param {Number} x X value for new position (coordinates are page-based) | |
| 888 | + * @param {Number} y Y value for new position (coordinates are page-based) | |
| 889 | + * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object | |
| 890 | + * @return {Ext.Element} this | |
| 891 | + */ | |
| 892 | + moveTo : function(x, y, animate){ | |
| 893 | + this.setXY([x, y], this.preanim(arguments, 2)); | |
| 894 | + return this; | |
| 895 | + }, | |
| 896 | + | |
| 897 | + /** | |
| 898 | + * Returns the region of the given element. | |
| 899 | + * The element must be part of the DOM tree to have a region (display:none or elements not appended return false). | |
| 900 | + * @return {Region} A Ext.lib.Region containing "top, left, bottom, right" member data. | |
| 901 | + */ | |
| 902 | + getRegion : function(){ | |
| 903 | + return D.getRegion(this.dom); | |
| 904 | + }, | |
| 905 | + | |
| 906 | + /** | |
| 907 | + * Returns the offset height of the element | |
| 908 | + * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding | |
| 909 | + * @return {Number} The element's height | |
| 910 | + */ | |
| 911 | + getHeight : function(contentHeight){ | |
| 912 | + var h = this.dom.offsetHeight || 0; | |
| 913 | + h = contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb"); | |
| 914 | + return h < 0 ? 0 : h; | |
| 915 | + }, | |
| 916 | + | |
| 917 | + /** | |
| 918 | + * Returns the offset width of the element | |
| 919 | + * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding | |
| 920 | + * @return {Number} The element's width | |
| 921 | + */ | |
| 922 | + getWidth : function(contentWidth){ | |
| 923 | + var w = this.dom.offsetWidth || 0; | |
| 924 | + w = contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr"); | |
| 925 | + return w < 0 ? 0 : w; | |
| 926 | + }, | |
| 927 | + | |
| 928 | + /** | |
| 929 | + * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders | |
| 930 | + * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements | |
| 931 | + * if a height has not been set using CSS. | |
| 932 | + * @return {Number} | |
| 933 | + */ | |
| 934 | + getComputedHeight : function(){ | |
| 935 | + var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight); | |
| 936 | + if(!h){ | |
| 937 | + h = parseInt(this.getStyle('height'), 10) || 0; | |
| 938 | + if(!this.isBorderBox()){ | |
| 939 | + h += this.getFrameWidth('tb'); | |
| 940 | + } | |
| 941 | + } | |
| 942 | + return h; | |
| 943 | + }, | |
| 944 | + | |
| 945 | + /** | |
| 946 | + * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders | |
| 947 | + * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements | |
| 948 | + * if a width has not been set using CSS. | |
| 949 | + * @return {Number} | |
| 950 | + */ | |
| 951 | + getComputedWidth : function(){ | |
| 952 | + var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth); | |
| 953 | + if(!w){ | |
| 954 | + w = parseInt(this.getStyle('width'), 10) || 0; | |
| 955 | + if(!this.isBorderBox()){ | |
| 956 | + w += this.getFrameWidth('lr'); | |
| 957 | + } | |
| 958 | + } | |
| 959 | + return w; | |
| 960 | + }, | |
| 961 | + | |
| 962 | + /** | |
| 963 | + * Returns the size of the element. | |
| 964 | + * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding | |
| 965 | + * @return {Object} An object containing the element's size {width: (element width), height: (element height)} | |
| 966 | + */ | |
| 967 | + getSize : function(contentSize){ | |
| 968 | + return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)}; | |
| 969 | + }, | |
| 970 | + | |
| 971 | + getStyleSize : function(){ | |
| 972 | + var w, h, d = this.dom, s = d.style; | |
| 973 | + if(s.width && s.width != 'auto'){ | |
| 974 | + w = parseInt(s.width, 10); | |
| 975 | + if(Ext.isBorderBox){ | |
| 976 | + w -= this.getFrameWidth('lr'); | |
| 977 | + } | |
| 978 | + } | |
| 979 | + if(s.height && s.height != 'auto'){ | |
| 980 | + h = parseInt(s.height, 10); | |
| 981 | + if(Ext.isBorderBox){ | |
| 982 | + h -= this.getFrameWidth('tb'); | |
| 983 | + } | |
| 984 | + } | |
| 985 | + return {width: w || this.getWidth(true), height: h || this.getHeight(true)}; | |
| 986 | + | |
| 987 | + }, | |
| 988 | + | |
| 989 | + /** | |
| 990 | + * Returns the width and height of the viewport. | |
| 991 | + * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)} | |
| 992 | + */ | |
| 993 | + getViewSize : function(){ | |
| 994 | + var d = this.dom, doc = document, aw = 0, ah = 0; | |
| 995 | + if(d == doc || d == doc.body){ | |
| 996 | + return {width : D.getViewWidth(), height: D.getViewHeight()}; | |
| 997 | + }else{ | |
| 998 | + return { | |
| 999 | + width : d.clientWidth, | |
| 1000 | + height: d.clientHeight | |
| 1001 | + }; | |
| 1002 | + } | |
| 1003 | + }, | |
| 1004 | + | |
| 1005 | + /** | |
| 1006 | + * Returns the value of the "value" attribute | |
| 1007 | + * @param {Boolean} asNumber true to parse the value as a number | |
| 1008 | + * @return {String/Number} | |
| 1009 | + */ | |
| 1010 | + getValue : function(asNumber){ | |
| 1011 | + return asNumber ? parseInt(this.dom.value, 10) : this.dom.value; | |
| 1012 | + }, | |
| 1013 | + | |
| 1014 | + // private | |
| 1015 | + adjustWidth : function(width){ | |
| 1016 | + if(typeof width == "number"){ | |
| 1017 | + if(this.autoBoxAdjust && !this.isBorderBox()){ | |
| 1018 | + width -= (this.getBorderWidth("lr") + this.getPadding("lr")); | |
| 1019 | + } | |
| 1020 | + if(width < 0){ | |
| 1021 | + width = 0; | |
| 1022 | + } | |
| 1023 | + } | |
| 1024 | + return width; | |
| 1025 | + }, | |
| 1026 | + | |
| 1027 | + // private | |
| 1028 | + adjustHeight : function(height){ | |
| 1029 | + if(typeof height == "number"){ | |
| 1030 | + if(this.autoBoxAdjust && !this.isBorderBox()){ | |
| 1031 | + height -= (this.getBorderWidth("tb") + this.getPadding("tb")); | |
| 1032 | + } | |
| 1033 | + if(height < 0){ | |
| 1034 | + height = 0; | |
| 1035 | + } | |
| 1036 | + } | |
| 1037 | + return height; | |
| 1038 | + }, | |
| 1039 | + | |
| 1040 | + /** | |
| 1041 | + * Set the width of the element | |
| 1042 | + * @param {Number} width The new width | |
| 1043 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1044 | + * @return {Ext.Element} this | |
| 1045 | + */ | |
| 1046 | + setWidth : function(width, animate){ | |
| 1047 | + width = this.adjustWidth(width); | |
| 1048 | + if(!animate || !A){ | |
| 1049 | + this.dom.style.width = this.addUnits(width); | |
| 1050 | + }else{ | |
| 1051 | + this.anim({width: {to: width}}, this.preanim(arguments, 1)); | |
| 1052 | + } | |
| 1053 | + return this; | |
| 1054 | + }, | |
| 1055 | + | |
| 1056 | + /** | |
| 1057 | + * Set the height of the element | |
| 1058 | + * @param {Number} height The new height | |
| 1059 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1060 | + * @return {Ext.Element} this | |
| 1061 | + */ | |
| 1062 | + setHeight : function(height, animate){ | |
| 1063 | + height = this.adjustHeight(height); | |
| 1064 | + if(!animate || !A){ | |
| 1065 | + this.dom.style.height = this.addUnits(height); | |
| 1066 | + }else{ | |
| 1067 | + this.anim({height: {to: height}}, this.preanim(arguments, 1)); | |
| 1068 | + } | |
| 1069 | + return this; | |
| 1070 | + }, | |
| 1071 | + | |
| 1072 | + /** | |
| 1073 | + * Set the size of the element. If animation is true, both width an height will be animated concurrently. | |
| 1074 | + * @param {Number} width The new width | |
| 1075 | + * @param {Number} height The new height | |
| 1076 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1077 | + * @return {Ext.Element} this | |
| 1078 | + */ | |
| 1079 | + setSize : function(width, height, animate){ | |
| 1080 | + if(typeof width == "object"){ // in case of object from getSize() | |
| 1081 | + height = width.height; width = width.width; | |
| 1082 | + } | |
| 1083 | + width = this.adjustWidth(width); height = this.adjustHeight(height); | |
| 1084 | + if(!animate || !A){ | |
| 1085 | + this.dom.style.width = this.addUnits(width); | |
| 1086 | + this.dom.style.height = this.addUnits(height); | |
| 1087 | + }else{ | |
| 1088 | + this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2)); | |
| 1089 | + } | |
| 1090 | + return this; | |
| 1091 | + }, | |
| 1092 | + | |
| 1093 | + /** | |
| 1094 | + * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently. | |
| 1095 | + * @param {Number} x X value for new position (coordinates are page-based) | |
| 1096 | + * @param {Number} y Y value for new position (coordinates are page-based) | |
| 1097 | + * @param {Number} width The new width | |
| 1098 | + * @param {Number} height The new height | |
| 1099 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1100 | + * @return {Ext.Element} this | |
| 1101 | + */ | |
| 1102 | + setBounds : function(x, y, width, height, animate){ | |
| 1103 | + if(!animate || !A){ | |
| 1104 | + this.setSize(width, height); | |
| 1105 | + this.setLocation(x, y); | |
| 1106 | + }else{ | |
| 1107 | + width = this.adjustWidth(width); height = this.adjustHeight(height); | |
| 1108 | + this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}}, | |
| 1109 | + this.preanim(arguments, 4), 'motion'); | |
| 1110 | + } | |
| 1111 | + return this; | |
| 1112 | + }, | |
| 1113 | + | |
| 1114 | + /** | |
| 1115 | + * Sets the element's position and size the specified region. If animation is true then width, height, x and y will be animated concurrently. | |
| 1116 | + * @param {Ext.lib.Region} region The region to fill | |
| 1117 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1118 | + * @return {Ext.Element} this | |
| 1119 | + */ | |
| 1120 | + setRegion : function(region, animate){ | |
| 1121 | + this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1)); | |
| 1122 | + return this; | |
| 1123 | + }, | |
| 1124 | + | |
| 1125 | + /** | |
| 1126 | + * Appends an event handler to this element. The shorthand version {@link #on} is equivalent. | |
| 1127 | + * @param {String} eventName The type of event to handle | |
| 1128 | + * @param {Function} fn The handler function the event invokes. This function is passed | |
| 1129 | + * the following parameters:<ul> | |
| 1130 | + * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li> | |
| 1131 | + * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event. | |
| 1132 | + * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li> | |
| 1133 | + * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li> | |
| 1134 | + * </ul> | |
| 1135 | + * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults | |
| 1136 | + * to this Element. | |
| 1137 | + * @param {Object} options (optional) An object containing handler configuration properties. | |
| 1138 | + * This may contain any of the following properties:<ul> | |
| 1139 | + * <li>scope {Object} : The scope in which to execute the handler function. The handler function's "this" context.</li> | |
| 1140 | + * <li>delegate {String} : A simple selector to filter the target or look for a descendant of the target</li> | |
| 1141 | + * <li>stopEvent {Boolean} : True to stop the event. That is stop propagation, and prevent the default action.</li> | |
| 1142 | + * <li>preventDefault {Boolean} : True to prevent the default action</li> | |
| 1143 | + * <li>stopPropagation {Boolean} : True to prevent event propagation</li> | |
| 1144 | + * <li>normalized {Boolean} : False to pass a browser event to the handler function instead of an Ext.EventObject</li> | |
| 1145 | + * <li>delay {Number} : The number of milliseconds to delay the invocation of the handler after te event fires.</li> | |
| 1146 | + * <li>single {Boolean} : True to add a handler to handle just the next firing of the event, and then remove itself.</li> | |
| 1147 | + * <li>buffer {Number} : Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed | |
| 1148 | + * by the specified number of milliseconds. If the event fires again within that time, the original | |
| 1149 | + * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li> | |
| 1150 | + * </ul><br> | |
| 1151 | + * <p> | |
| 1152 | + * <b>Combining Options</b><br> | |
| 1153 | + * In the following examples, the shorthand form {@link #on} is used rather than the more verbose | |
| 1154 | + * addListener. The two are equivalent. Using the options argument, it is possible to combine different | |
| 1155 | + * types of listeners:<br> | |
| 1156 | + * <br> | |
| 1157 | + * A normalized, delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the | |
| 1158 | + * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;"> | |
| 1159 | + * Code:<pre><code> | |
| 1160 | +el.on('click', this.onClick, this, { | |
| 1161 | + single: true, | |
| 1162 | + delay: 100, | |
| 1163 | + stopEvent : true, | |
| 1164 | + forumId: 4 | |
| 1165 | +});</code></pre></p> | |
| 1166 | + * <p> | |
| 1167 | + * <b>Attaching multiple handlers in 1 call</b><br> | |
| 1168 | + * The method also allows for a single argument to be passed which is a config object containing properties | |
| 1169 | + * which specify multiple handlers.</p> | |
| 1170 | + * <p> | |
| 1171 | + * Code:<pre><code></p> | |
| 1172 | +el.on({ | |
| 1173 | + 'click' : { | |
| 1174 | + fn: this.onClick, | |
| 1175 | + scope: this, | |
| 1176 | + delay: 100 | |
| 1177 | + }, | |
| 1178 | + 'mouseover' : { | |
| 1179 | + fn: this.onMouseOver, | |
| 1180 | + scope: this | |
| 1181 | + }, | |
| 1182 | + 'mouseout' : { | |
| 1183 | + fn: this.onMouseOut, | |
| 1184 | + scope: this | |
| 1185 | + } | |
| 1186 | +});</code></pre> | |
| 1187 | + * <p> | |
| 1188 | + * Or a shorthand syntax:<br> | |
| 1189 | + * Code:<pre><code></p> | |
| 1190 | +el.on({ | |
| 1191 | + 'click' : this.onClick, | |
| 1192 | + 'mouseover' : this.onMouseOver, | |
| 1193 | + 'mouseout' : this.onMouseOut, | |
| 1194 | + scope: this | |
| 1195 | +});</code></pre> | |
| 1196 | + */ | |
| 1197 | + addListener : function(eventName, fn, scope, options){ | |
| 1198 | + Ext.EventManager.on(this.dom, eventName, fn, scope || this, options); | |
| 1199 | + }, | |
| 1200 | + | |
| 1201 | + /** | |
| 1202 | + * Removes an event handler from this element. The shorthand version {@link #un} is equivalent. Example: | |
| 1203 | + * <pre><code> | |
| 1204 | +el.removeListener('click', this.handlerFn); | |
| 1205 | +// or | |
| 1206 | +el.un('click', this.handlerFn); | |
| 1207 | +</code></pre> | |
| 1208 | + * @param {String} eventName the type of event to remove | |
| 1209 | + * @param {Function} fn the method the event invokes | |
| 1210 | + * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults | |
| 1211 | + * to this Element. | |
| 1212 | + * @return {Ext.Element} this | |
| 1213 | + */ | |
| 1214 | + removeListener : function(eventName, fn, scope){ | |
| 1215 | + Ext.EventManager.removeListener(this.dom, eventName, fn, scope || this); | |
| 1216 | + return this; | |
| 1217 | + }, | |
| 1218 | + | |
| 1219 | + /** | |
| 1220 | + * Removes all previous added listeners from this element | |
| 1221 | + * @return {Ext.Element} this | |
| 1222 | + */ | |
| 1223 | + removeAllListeners : function(){ | |
| 1224 | + Ext.EventManager.removeAll(this.dom); | |
| 1225 | + return this; | |
| 1226 | + }, | |
| 1227 | + | |
| 1228 | + /** | |
| 1229 | + * Create an event handler on this element such that when the event fires and is handled by this element, | |
| 1230 | + * it will be relayed to another object (i.e., fired again as if it originated from that object instead). | |
| 1231 | + * @param {String} eventName The type of event to relay | |
| 1232 | + * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context | |
| 1233 | + * for firing the relayed event | |
| 1234 | + */ | |
| 1235 | + relayEvent : function(eventName, observable){ | |
| 1236 | + this.on(eventName, function(e){ | |
| 1237 | + observable.fireEvent(eventName, e); | |
| 1238 | + }); | |
| 1239 | + }, | |
| 1240 | + | |
| 1241 | + /** | |
| 1242 | + * Set the opacity of the element | |
| 1243 | + * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc | |
| 1244 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1245 | + * @return {Ext.Element} this | |
| 1246 | + */ | |
| 1247 | + setOpacity : function(opacity, animate){ | |
| 1248 | + if(!animate || !A){ | |
| 1249 | + var s = this.dom.style; | |
| 1250 | + if(Ext.isIE){ | |
| 1251 | + s.zoom = 1; | |
| 1252 | + s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") + | |
| 1253 | + (opacity == 1 ? "" : " alpha(opacity=" + opacity * 100 + ")"); | |
| 1254 | + }else{ | |
| 1255 | + s.opacity = opacity; | |
| 1256 | + } | |
| 1257 | + }else{ | |
| 1258 | + this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn'); | |
| 1259 | + } | |
| 1260 | + return this; | |
| 1261 | + }, | |
| 1262 | + | |
| 1263 | + /** | |
| 1264 | + * Gets the left X coordinate | |
| 1265 | + * @param {Boolean} local True to get the local css position instead of page coordinate | |
| 1266 | + * @return {Number} | |
| 1267 | + */ | |
| 1268 | + getLeft : function(local){ | |
| 1269 | + if(!local){ | |
| 1270 | + return this.getX(); | |
| 1271 | + }else{ | |
| 1272 | + return parseInt(this.getStyle("left"), 10) || 0; | |
| 1273 | + } | |
| 1274 | + }, | |
| 1275 | + | |
| 1276 | + /** | |
| 1277 | + * Gets the right X coordinate of the element (element X position + element width) | |
| 1278 | + * @param {Boolean} local True to get the local css position instead of page coordinate | |
| 1279 | + * @return {Number} | |
| 1280 | + */ | |
| 1281 | + getRight : function(local){ | |
| 1282 | + if(!local){ | |
| 1283 | + return this.getX() + this.getWidth(); | |
| 1284 | + }else{ | |
| 1285 | + return (this.getLeft(true) + this.getWidth()) || 0; | |
| 1286 | + } | |
| 1287 | + }, | |
| 1288 | + | |
| 1289 | + /** | |
| 1290 | + * Gets the top Y coordinate | |
| 1291 | + * @param {Boolean} local True to get the local css position instead of page coordinate | |
| 1292 | + * @return {Number} | |
| 1293 | + */ | |
| 1294 | + getTop : function(local) { | |
| 1295 | + if(!local){ | |
| 1296 | + return this.getY(); | |
| 1297 | + }else{ | |
| 1298 | + return parseInt(this.getStyle("top"), 10) || 0; | |
| 1299 | + } | |
| 1300 | + }, | |
| 1301 | + | |
| 1302 | + /** | |
| 1303 | + * Gets the bottom Y coordinate of the element (element Y position + element height) | |
| 1304 | + * @param {Boolean} local True to get the local css position instead of page coordinate | |
| 1305 | + * @return {Number} | |
| 1306 | + */ | |
| 1307 | + getBottom : function(local){ | |
| 1308 | + if(!local){ | |
| 1309 | + return this.getY() + this.getHeight(); | |
| 1310 | + }else{ | |
| 1311 | + return (this.getTop(true) + this.getHeight()) || 0; | |
| 1312 | + } | |
| 1313 | + }, | |
| 1314 | + | |
| 1315 | + /** | |
| 1316 | + * Initializes positioning on this element. If a desired position is not passed, it will make the | |
| 1317 | + * the element positioned relative IF it is not already positioned. | |
| 1318 | + * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed" | |
| 1319 | + * @param {Number} zIndex (optional) The zIndex to apply | |
| 1320 | + * @param {Number} x (optional) Set the page X position | |
| 1321 | + * @param {Number} y (optional) Set the page Y position | |
| 1322 | + */ | |
| 1323 | + position : function(pos, zIndex, x, y){ | |
| 1324 | + if(!pos){ | |
| 1325 | + if(this.getStyle('position') == 'static'){ | |
| 1326 | + this.setStyle('position', 'relative'); | |
| 1327 | + } | |
| 1328 | + }else{ | |
| 1329 | + this.setStyle("position", pos); | |
| 1330 | + } | |
| 1331 | + if(zIndex){ | |
| 1332 | + this.setStyle("z-index", zIndex); | |
| 1333 | + } | |
| 1334 | + if(x !== undefined && y !== undefined){ | |
| 1335 | + this.setXY([x, y]); | |
| 1336 | + }else if(x !== undefined){ | |
| 1337 | + this.setX(x); | |
| 1338 | + }else if(y !== undefined){ | |
| 1339 | + this.setY(y); | |
| 1340 | + } | |
| 1341 | + }, | |
| 1342 | + | |
| 1343 | + /** | |
| 1344 | + * Clear positioning back to the default when the document was loaded | |
| 1345 | + * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'. | |
| 1346 | + * @return {Ext.Element} this | |
| 1347 | + */ | |
| 1348 | + clearPositioning : function(value){ | |
| 1349 | + value = value ||''; | |
| 1350 | + this.setStyle({ | |
| 1351 | + "left": value, | |
| 1352 | + "right": value, | |
| 1353 | + "top": value, | |
| 1354 | + "bottom": value, | |
| 1355 | + "z-index": "", | |
| 1356 | + "position" : "static" | |
| 1357 | + }); | |
| 1358 | + return this; | |
| 1359 | + }, | |
| 1360 | + | |
| 1361 | + /** | |
| 1362 | + * Gets an object with all CSS positioning properties. Useful along with setPostioning to get | |
| 1363 | + * snapshot before performing an update and then restoring the element. | |
| 1364 | + * @return {Object} | |
| 1365 | + */ | |
| 1366 | + getPositioning : function(){ | |
| 1367 | + var l = this.getStyle("left"); | |
| 1368 | + var t = this.getStyle("top"); | |
| 1369 | + return { | |
| 1370 | + "position" : this.getStyle("position"), | |
| 1371 | + "left" : l, | |
| 1372 | + "right" : l ? "" : this.getStyle("right"), | |
| 1373 | + "top" : t, | |
| 1374 | + "bottom" : t ? "" : this.getStyle("bottom"), | |
| 1375 | + "z-index" : this.getStyle("z-index") | |
| 1376 | + }; | |
| 1377 | + }, | |
| 1378 | + | |
| 1379 | + /** | |
| 1380 | + * Gets the width of the border(s) for the specified side(s) | |
| 1381 | + * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example, | |
| 1382 | + * passing lr would get the border (l)eft width + the border (r)ight width. | |
| 1383 | + * @return {Number} The width of the sides passed added together | |
| 1384 | + */ | |
| 1385 | + getBorderWidth : function(side){ | |
| 1386 | + return this.addStyles(side, El.borders); | |
| 1387 | + }, | |
| 1388 | + | |
| 1389 | + /** | |
| 1390 | + * Gets the width of the padding(s) for the specified side(s) | |
| 1391 | + * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example, | |
| 1392 | + * passing lr would get the padding (l)eft + the padding (r)ight. | |
| 1393 | + * @return {Number} The padding of the sides passed added together | |
| 1394 | + */ | |
| 1395 | + getPadding : function(side){ | |
| 1396 | + return this.addStyles(side, El.paddings); | |
| 1397 | + }, | |
| 1398 | + | |
| 1399 | + /** | |
| 1400 | + * Set positioning with an object returned by getPositioning(). | |
| 1401 | + * @param {Object} posCfg | |
| 1402 | + * @return {Ext.Element} this | |
| 1403 | + */ | |
| 1404 | + setPositioning : function(pc){ | |
| 1405 | + this.applyStyles(pc); | |
| 1406 | + if(pc.right == "auto"){ | |
| 1407 | + this.dom.style.right = ""; | |
| 1408 | + } | |
| 1409 | + if(pc.bottom == "auto"){ | |
| 1410 | + this.dom.style.bottom = ""; | |
| 1411 | + } | |
| 1412 | + return this; | |
| 1413 | + }, | |
| 1414 | + | |
| 1415 | + // private | |
| 1416 | + fixDisplay : function(){ | |
| 1417 | + if(this.getStyle("display") == "none"){ | |
| 1418 | + this.setStyle("visibility", "hidden"); | |
| 1419 | + this.setStyle("display", this.originalDisplay); // first try reverting to default | |
| 1420 | + if(this.getStyle("display") == "none"){ // if that fails, default to block | |
| 1421 | + this.setStyle("display", "block"); | |
| 1422 | + } | |
| 1423 | + } | |
| 1424 | + }, | |
| 1425 | + | |
| 1426 | + // private | |
| 1427 | + setOverflow : function(v){ | |
| 1428 | + if(v=='auto' && Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug | |
| 1429 | + this.dom.style.overflow = 'hidden'; | |
| 1430 | + (function(){this.dom.style.overflow = 'auto';}).defer(1, this); | |
| 1431 | + }else{ | |
| 1432 | + this.dom.style.overflow = v; | |
| 1433 | + } | |
| 1434 | + }, | |
| 1435 | + | |
| 1436 | + /** | |
| 1437 | + * Quick set left and top adding default units | |
| 1438 | + * @param {String} left The left CSS property value | |
| 1439 | + * @param {String} top The top CSS property value | |
| 1440 | + * @return {Ext.Element} this | |
| 1441 | + */ | |
| 1442 | + setLeftTop : function(left, top){ | |
| 1443 | + this.dom.style.left = this.addUnits(left); | |
| 1444 | + this.dom.style.top = this.addUnits(top); | |
| 1445 | + return this; | |
| 1446 | + }, | |
| 1447 | + | |
| 1448 | + /** | |
| 1449 | + * Move this element relative to its current position. | |
| 1450 | + * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down"). | |
| 1451 | + * @param {Number} distance How far to move the element in pixels | |
| 1452 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1453 | + * @return {Ext.Element} this | |
| 1454 | + */ | |
| 1455 | + move : function(direction, distance, animate){ | |
| 1456 | + var xy = this.getXY(); | |
| 1457 | + direction = direction.toLowerCase(); | |
| 1458 | + switch(direction){ | |
| 1459 | + case "l": | |
| 1460 | + case "left": | |
| 1461 | + this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2)); | |
| 1462 | + break; | |
| 1463 | + case "r": | |
| 1464 | + case "right": | |
| 1465 | + this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2)); | |
| 1466 | + break; | |
| 1467 | + case "t": | |
| 1468 | + case "top": | |
| 1469 | + case "up": | |
| 1470 | + this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2)); | |
| 1471 | + break; | |
| 1472 | + case "b": | |
| 1473 | + case "bottom": | |
| 1474 | + case "down": | |
| 1475 | + this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2)); | |
| 1476 | + break; | |
| 1477 | + } | |
| 1478 | + return this; | |
| 1479 | + }, | |
| 1480 | + | |
| 1481 | + /** | |
| 1482 | + * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove | |
| 1483 | + * @return {Ext.Element} this | |
| 1484 | + */ | |
| 1485 | + clip : function(){ | |
| 1486 | + if(!this.isClipped){ | |
| 1487 | + this.isClipped = true; | |
| 1488 | + this.originalClip = { | |
| 1489 | + "o": this.getStyle("overflow"), | |
| 1490 | + "x": this.getStyle("overflow-x"), | |
| 1491 | + "y": this.getStyle("overflow-y") | |
| 1492 | + }; | |
| 1493 | + this.setStyle("overflow", "hidden"); | |
| 1494 | + this.setStyle("overflow-x", "hidden"); | |
| 1495 | + this.setStyle("overflow-y", "hidden"); | |
| 1496 | + } | |
| 1497 | + return this; | |
| 1498 | + }, | |
| 1499 | + | |
| 1500 | + /** | |
| 1501 | + * Return clipping (overflow) to original clipping before clip() was called | |
| 1502 | + * @return {Ext.Element} this | |
| 1503 | + */ | |
| 1504 | + unclip : function(){ | |
| 1505 | + if(this.isClipped){ | |
| 1506 | + this.isClipped = false; | |
| 1507 | + var o = this.originalClip; | |
| 1508 | + if(o.o){this.setStyle("overflow", o.o);} | |
| 1509 | + if(o.x){this.setStyle("overflow-x", o.x);} | |
| 1510 | + if(o.y){this.setStyle("overflow-y", o.y);} | |
| 1511 | + } | |
| 1512 | + return this; | |
| 1513 | + }, | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + /** | |
| 1517 | + * Gets the x,y coordinates specified by the anchor position on the element. | |
| 1518 | + * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo} | |
| 1519 | + * for details on supported anchor positions. | |
| 1520 | + * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead | |
| 1521 | + * of page coordinates | |
| 1522 | + * @param {Object} size (optional) An object containing the size to use for calculating anchor position | |
| 1523 | + * {width: (target width), height: (target height)} (defaults to the element's current size) | |
| 1524 | + * @return {Array} [x, y] An array containing the element's x and y coordinates | |
| 1525 | + */ | |
| 1526 | + getAnchorXY : function(anchor, local, s){ | |
| 1527 | + //Passing a different size is useful for pre-calculating anchors, | |
| 1528 | + //especially for anchored animations that change the el size. | |
| 1529 | + | |
| 1530 | + var w, h, vp = false; | |
| 1531 | + if(!s){ | |
| 1532 | + var d = this.dom; | |
| 1533 | + if(d == document.body || d == document){ | |
| 1534 | + vp = true; | |
| 1535 | + w = D.getViewWidth(); h = D.getViewHeight(); | |
| 1536 | + }else{ | |
| 1537 | + w = this.getWidth(); h = this.getHeight(); | |
| 1538 | + } | |
| 1539 | + }else{ | |
| 1540 | + w = s.width; h = s.height; | |
| 1541 | + } | |
| 1542 | + var x = 0, y = 0, r = Math.round; | |
| 1543 | + switch((anchor || "tl").toLowerCase()){ | |
| 1544 | + case "c": | |
| 1545 | + x = r(w*.5); | |
| 1546 | + y = r(h*.5); | |
| 1547 | + break; | |
| 1548 | + case "t": | |
| 1549 | + x = r(w*.5); | |
| 1550 | + y = 0; | |
| 1551 | + break; | |
| 1552 | + case "l": | |
| 1553 | + x = 0; | |
| 1554 | + y = r(h*.5); | |
| 1555 | + break; | |
| 1556 | + case "r": | |
| 1557 | + x = w; | |
| 1558 | + y = r(h*.5); | |
| 1559 | + break; | |
| 1560 | + case "b": | |
| 1561 | + x = r(w*.5); | |
| 1562 | + y = h; | |
| 1563 | + break; | |
| 1564 | + case "tl": | |
| 1565 | + x = 0; | |
| 1566 | + y = 0; | |
| 1567 | + break; | |
| 1568 | + case "bl": | |
| 1569 | + x = 0; | |
| 1570 | + y = h; | |
| 1571 | + break; | |
| 1572 | + case "br": | |
| 1573 | + x = w; | |
| 1574 | + y = h; | |
| 1575 | + break; | |
| 1576 | + case "tr": | |
| 1577 | + x = w; | |
| 1578 | + y = 0; | |
| 1579 | + break; | |
| 1580 | + } | |
| 1581 | + if(local === true){ | |
| 1582 | + return [x, y]; | |
| 1583 | + } | |
| 1584 | + if(vp){ | |
| 1585 | + var sc = this.getScroll(); | |
| 1586 | + return [x + sc.left, y + sc.top]; | |
| 1587 | + } | |
| 1588 | + //Add the element's offset xy | |
| 1589 | + var o = this.getXY(); | |
| 1590 | + return [x+o[0], y+o[1]]; | |
| 1591 | + }, | |
| 1592 | + | |
| 1593 | + /** | |
| 1594 | + * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the | |
| 1595 | + * supported position values. | |
| 1596 | + * @param {Mixed} element The element to align to. | |
| 1597 | + * @param {String} position The position to align to. | |
| 1598 | + * @param {Array} offsets (optional) Offset the positioning by [x, y] | |
| 1599 | + * @return {Array} [x, y] | |
| 1600 | + */ | |
| 1601 | + getAlignToXY : function(el, p, o){ | |
| 1602 | + el = Ext.get(el); | |
| 1603 | + if(!el || !el.dom){ | |
| 1604 | + throw "Element.alignToXY with an element that doesn't exist"; | |
| 1605 | + } | |
| 1606 | + var d = this.dom; | |
| 1607 | + var c = false; //constrain to viewport | |
| 1608 | + var p1 = "", p2 = ""; | |
| 1609 | + o = o || [0,0]; | |
| 1610 | + | |
| 1611 | + if(!p){ | |
| 1612 | + p = "tl-bl"; | |
| 1613 | + }else if(p == "?"){ | |
| 1614 | + p = "tl-bl?"; | |
| 1615 | + }else if(p.indexOf("-") == -1){ | |
| 1616 | + p = "tl-" + p; | |
| 1617 | + } | |
| 1618 | + p = p.toLowerCase(); | |
| 1619 | + var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/); | |
| 1620 | + if(!m){ | |
| 1621 | + throw "Element.alignTo with an invalid alignment " + p; | |
| 1622 | + } | |
| 1623 | + p1 = m[1]; p2 = m[2]; c = !!m[3]; | |
| 1624 | + | |
| 1625 | + //Subtract the aligned el's internal xy from the target's offset xy | |
| 1626 | + //plus custom offset to get the aligned el's new offset xy | |
| 1627 | + var a1 = this.getAnchorXY(p1, true); | |
| 1628 | + var a2 = el.getAnchorXY(p2, false); | |
| 1629 | + | |
| 1630 | + var x = a2[0] - a1[0] + o[0]; | |
| 1631 | + var y = a2[1] - a1[1] + o[1]; | |
| 1632 | + | |
| 1633 | + if(c){ | |
| 1634 | + //constrain the aligned el to viewport if necessary | |
| 1635 | + var w = this.getWidth(), h = this.getHeight(), r = el.getRegion(); | |
| 1636 | + // 5px of margin for ie | |
| 1637 | + var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5; | |
| 1638 | + | |
| 1639 | + //If we are at a viewport boundary and the aligned el is anchored on a target border that is | |
| 1640 | + //perpendicular to the vp border, allow the aligned el to slide on that border, | |
| 1641 | + //otherwise swap the aligned el to the opposite border of the target. | |
| 1642 | + var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1); | |
| 1643 | + var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1); | |
| 1644 | + var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t")); | |
| 1645 | + var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r")); | |
| 1646 | + | |
| 1647 | + var doc = document; | |
| 1648 | + var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5; | |
| 1649 | + var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5; | |
| 1650 | + | |
| 1651 | + if((x+w) > dw + scrollX){ | |
| 1652 | + x = swapX ? r.left-w : dw+scrollX-w; | |
| 1653 | + } | |
| 1654 | + if(x < scrollX){ | |
| 1655 | + x = swapX ? r.right : scrollX; | |
| 1656 | + } | |
| 1657 | + if((y+h) > dh + scrollY){ | |
| 1658 | + y = swapY ? r.top-h : dh+scrollY-h; | |
| 1659 | + } | |
| 1660 | + if (y < scrollY){ | |
| 1661 | + y = swapY ? r.bottom : scrollY; | |
| 1662 | + } | |
| 1663 | + } | |
| 1664 | + return [x,y]; | |
| 1665 | + }, | |
| 1666 | + | |
| 1667 | + // private | |
| 1668 | + getConstrainToXY : function(){ | |
| 1669 | + var os = {top:0, left:0, bottom:0, right: 0}; | |
| 1670 | + | |
| 1671 | + return function(el, local, offsets, proposedXY){ | |
| 1672 | + el = Ext.get(el); | |
| 1673 | + offsets = offsets ? Ext.applyIf(offsets, os) : os; | |
| 1674 | + | |
| 1675 | + var vw, vh, vx = 0, vy = 0; | |
| 1676 | + if(el.dom == document.body || el.dom == document){ | |
| 1677 | + vw = Ext.lib.Dom.getViewWidth(); | |
| 1678 | + vh = Ext.lib.Dom.getViewHeight(); | |
| 1679 | + }else{ | |
| 1680 | + vw = el.dom.clientWidth; | |
| 1681 | + vh = el.dom.clientHeight; | |
| 1682 | + if(!local){ | |
| 1683 | + var vxy = el.getXY(); | |
| 1684 | + vx = vxy[0]; | |
| 1685 | + vy = vxy[1]; | |
| 1686 | + } | |
| 1687 | + } | |
| 1688 | + | |
| 1689 | + var s = el.getScroll(); | |
| 1690 | + | |
| 1691 | + vx += offsets.left + s.left; | |
| 1692 | + vy += offsets.top + s.top; | |
| 1693 | + | |
| 1694 | + vw -= offsets.right; | |
| 1695 | + vh -= offsets.bottom; | |
| 1696 | + | |
| 1697 | + var vr = vx+vw; | |
| 1698 | + var vb = vy+vh; | |
| 1699 | + | |
| 1700 | + var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]); | |
| 1701 | + var x = xy[0], y = xy[1]; | |
| 1702 | + var w = this.dom.offsetWidth, h = this.dom.offsetHeight; | |
| 1703 | + | |
| 1704 | + // only move it if it needs it | |
| 1705 | + var moved = false; | |
| 1706 | + | |
| 1707 | + // first validate right/bottom | |
| 1708 | + if((x + w) > vr){ | |
| 1709 | + x = vr - w; | |
| 1710 | + moved = true; | |
| 1711 | + } | |
| 1712 | + if((y + h) > vb){ | |
| 1713 | + y = vb - h; | |
| 1714 | + moved = true; | |
| 1715 | + } | |
| 1716 | + // then make sure top/left isn't negative | |
| 1717 | + if(x < vx){ | |
| 1718 | + x = vx; | |
| 1719 | + moved = true; | |
| 1720 | + } | |
| 1721 | + if(y < vy){ | |
| 1722 | + y = vy; | |
| 1723 | + moved = true; | |
| 1724 | + } | |
| 1725 | + return moved ? [x, y] : false; | |
| 1726 | + }; | |
| 1727 | + }(), | |
| 1728 | + | |
| 1729 | + // private | |
| 1730 | + adjustForConstraints : function(xy, parent, offsets){ | |
| 1731 | + return this.getConstrainToXY(parent || document, false, offsets, xy) || xy; | |
| 1732 | + }, | |
| 1733 | + | |
| 1734 | + /** | |
| 1735 | + * Aligns this element with another element relative to the specified anchor points. If the other element is the | |
| 1736 | + * document it aligns it to the viewport. | |
| 1737 | + * The position parameter is optional, and can be specified in any one of the following formats: | |
| 1738 | + * <ul> | |
| 1739 | + * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li> | |
| 1740 | + * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point. | |
| 1741 | + * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been | |
| 1742 | + * deprecated in favor of the newer two anchor syntax below</i>.</li> | |
| 1743 | + * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the | |
| 1744 | + * element's anchor point, and the second value is used as the target's anchor point.</li> | |
| 1745 | + * </ul> | |
| 1746 | + * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of | |
| 1747 | + * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to | |
| 1748 | + * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than | |
| 1749 | + * that specified in order to enforce the viewport constraints. | |
| 1750 | + * Following are all of the supported anchor positions: | |
| 1751 | +<pre> | |
| 1752 | +Value Description | |
| 1753 | +----- ----------------------------- | |
| 1754 | +tl The top left corner (default) | |
| 1755 | +t The center of the top edge | |
| 1756 | +tr The top right corner | |
| 1757 | +l The center of the left edge | |
| 1758 | +c In the center of the element | |
| 1759 | +r The center of the right edge | |
| 1760 | +bl The bottom left corner | |
| 1761 | +b The center of the bottom edge | |
| 1762 | +br The bottom right corner | |
| 1763 | +</pre> | |
| 1764 | +Example Usage: | |
| 1765 | +<pre><code> | |
| 1766 | +// align el to other-el using the default positioning ("tl-bl", non-constrained) | |
| 1767 | +el.alignTo("other-el"); | |
| 1768 | + | |
| 1769 | +// align the top left corner of el with the top right corner of other-el (constrained to viewport) | |
| 1770 | +el.alignTo("other-el", "tr?"); | |
| 1771 | + | |
| 1772 | +// align the bottom right corner of el with the center left edge of other-el | |
| 1773 | +el.alignTo("other-el", "br-l?"); | |
| 1774 | + | |
| 1775 | +// align the center of el with the bottom left corner of other-el and | |
| 1776 | +// adjust the x position by -6 pixels (and the y position by 0) | |
| 1777 | +el.alignTo("other-el", "c-bl", [-6, 0]); | |
| 1778 | +</code></pre> | |
| 1779 | + * @param {Mixed} element The element to align to. | |
| 1780 | + * @param {String} position The position to align to. | |
| 1781 | + * @param {Array} offsets (optional) Offset the positioning by [x, y] | |
| 1782 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1783 | + * @return {Ext.Element} this | |
| 1784 | + */ | |
| 1785 | + alignTo : function(element, position, offsets, animate){ | |
| 1786 | + var xy = this.getAlignToXY(element, position, offsets); | |
| 1787 | + this.setXY(xy, this.preanim(arguments, 3)); | |
| 1788 | + return this; | |
| 1789 | + }, | |
| 1790 | + | |
| 1791 | + /** | |
| 1792 | + * Anchors an element to another element and realigns it when the window is resized. | |
| 1793 | + * @param {Mixed} element The element to align to. | |
| 1794 | + * @param {String} position The position to align to. | |
| 1795 | + * @param {Array} offsets (optional) Offset the positioning by [x, y] | |
| 1796 | + * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object | |
| 1797 | + * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter | |
| 1798 | + * is a number, it is used as the buffer delay (defaults to 50ms). | |
| 1799 | + * @param {Function} callback The function to call after the animation finishes | |
| 1800 | + * @return {Ext.Element} this | |
| 1801 | + */ | |
| 1802 | + anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){ | |
| 1803 | + var action = function(){ | |
| 1804 | + this.alignTo(el, alignment, offsets, animate); | |
| 1805 | + Ext.callback(callback, this); | |
| 1806 | + }; | |
| 1807 | + Ext.EventManager.onWindowResize(action, this); | |
| 1808 | + var tm = typeof monitorScroll; | |
| 1809 | + if(tm != 'undefined'){ | |
| 1810 | + Ext.EventManager.on(window, 'scroll', action, this, | |
| 1811 | + {buffer: tm == 'number' ? monitorScroll : 50}); | |
| 1812 | + } | |
| 1813 | + action.call(this); // align immediately | |
| 1814 | + return this; | |
| 1815 | + }, | |
| 1816 | + /** | |
| 1817 | + * Clears any opacity settings from this element. Required in some cases for IE. | |
| 1818 | + * @return {Ext.Element} this | |
| 1819 | + */ | |
| 1820 | + clearOpacity : function(){ | |
| 1821 | + if (window.ActiveXObject) { | |
| 1822 | + if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){ | |
| 1823 | + this.dom.style.filter = ""; | |
| 1824 | + } | |
| 1825 | + } else { | |
| 1826 | + this.dom.style.opacity = ""; | |
| 1827 | + this.dom.style["-moz-opacity"] = ""; | |
| 1828 | + this.dom.style["-khtml-opacity"] = ""; | |
| 1829 | + } | |
| 1830 | + return this; | |
| 1831 | + }, | |
| 1832 | + | |
| 1833 | + /** | |
| 1834 | + * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}. | |
| 1835 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1836 | + * @return {Ext.Element} this | |
| 1837 | + */ | |
| 1838 | + hide : function(animate){ | |
| 1839 | + this.setVisible(false, this.preanim(arguments, 0)); | |
| 1840 | + return this; | |
| 1841 | + }, | |
| 1842 | + | |
| 1843 | + /** | |
| 1844 | + * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}. | |
| 1845 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 1846 | + * @return {Ext.Element} this | |
| 1847 | + */ | |
| 1848 | + show : function(animate){ | |
| 1849 | + this.setVisible(true, this.preanim(arguments, 0)); | |
| 1850 | + return this; | |
| 1851 | + }, | |
| 1852 | + | |
| 1853 | + /** | |
| 1854 | + * @private Test if size has a unit, otherwise appends the default | |
| 1855 | + */ | |
| 1856 | + addUnits : function(size){ | |
| 1857 | + return Ext.Element.addUnits(size, this.defaultUnit); | |
| 1858 | + }, | |
| 1859 | + | |
| 1860 | + /** | |
| 1861 | + * Update the innerHTML of this element, optionally searching for and processing scripts | |
| 1862 | + * @param {String} html The new HTML | |
| 1863 | + * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false) | |
| 1864 | + * @param {Function} callback (optional) For async script loading you can be notified when the update completes | |
| 1865 | + * @return {Ext.Element} this | |
| 1866 | + */ | |
| 1867 | + update : function(html, loadScripts, callback){ | |
| 1868 | + if(typeof html == "undefined"){ | |
| 1869 | + html = ""; | |
| 1870 | + } | |
| 1871 | + if(loadScripts !== true){ | |
| 1872 | + this.dom.innerHTML = html; | |
| 1873 | + if(typeof callback == "function"){ | |
| 1874 | + callback(); | |
| 1875 | + } | |
| 1876 | + return this; | |
| 1877 | + } | |
| 1878 | + var id = Ext.id(); | |
| 1879 | + var dom = this.dom; | |
| 1880 | + | |
| 1881 | + html += '<span id="' + id + '"></span>'; | |
| 1882 | + | |
| 1883 | + E.onAvailable(id, function(){ | |
| 1884 | + var hd = document.getElementsByTagName("head")[0]; | |
| 1885 | + var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig; | |
| 1886 | + var srcRe = /\ssrc=([\'\"])(.*?)\1/i; | |
| 1887 | + var typeRe = /\stype=([\'\"])(.*?)\1/i; | |
| 1888 | + | |
| 1889 | + var match; | |
| 1890 | + while(match = re.exec(html)){ | |
| 1891 | + var attrs = match[1]; | |
| 1892 | + var srcMatch = attrs ? attrs.match(srcRe) : false; | |
| 1893 | + if(srcMatch && srcMatch[2]){ | |
| 1894 | + var s = document.createElement("script"); | |
| 1895 | + s.src = srcMatch[2]; | |
| 1896 | + var typeMatch = attrs.match(typeRe); | |
| 1897 | + if(typeMatch && typeMatch[2]){ | |
| 1898 | + s.type = typeMatch[2]; | |
| 1899 | + } | |
| 1900 | + hd.appendChild(s); | |
| 1901 | + }else if(match[2] && match[2].length > 0){ | |
| 1902 | + if(window.execScript) { | |
| 1903 | + window.execScript(match[2]); | |
| 1904 | + } else { | |
| 1905 | + window.eval(match[2]); | |
| 1906 | + } | |
| 1907 | + } | |
| 1908 | + } | |
| 1909 | + var el = document.getElementById(id); | |
| 1910 | + if(el){Ext.removeNode(el);} | |
| 1911 | + if(typeof callback == "function"){ | |
| 1912 | + callback(); | |
| 1913 | + } | |
| 1914 | + }); | |
| 1915 | + dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, ""); | |
| 1916 | + return this; | |
| 1917 | + }, | |
| 1918 | + | |
| 1919 | + /** | |
| 1920 | + * Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object | |
| 1921 | + * parameter as {@link Ext.Updater#update} | |
| 1922 | + * @return {Ext.Element} this | |
| 1923 | + */ | |
| 1924 | + load : function(){ | |
| 1925 | + var um = this.getUpdater(); | |
| 1926 | + um.update.apply(um, arguments); | |
| 1927 | + return this; | |
| 1928 | + }, | |
| 1929 | + | |
| 1930 | + /** | |
| 1931 | + * Gets this element's Updater | |
| 1932 | + * @return {Ext.Updater} The Updater | |
| 1933 | + */ | |
| 1934 | + getUpdater : function(){ | |
| 1935 | + if(!this.updateManager){ | |
| 1936 | + this.updateManager = new Ext.Updater(this); | |
| 1937 | + } | |
| 1938 | + return this.updateManager; | |
| 1939 | + }, | |
| 1940 | + | |
| 1941 | + /** | |
| 1942 | + * Disables text selection for this element (normalized across browsers) | |
| 1943 | + * @return {Ext.Element} this | |
| 1944 | + */ | |
| 1945 | + unselectable : function(){ | |
| 1946 | + this.dom.unselectable = "on"; | |
| 1947 | + this.swallowEvent("selectstart", true); | |
| 1948 | + this.applyStyles("-moz-user-select:none;-khtml-user-select:none;"); | |
| 1949 | + this.addClass("x-unselectable"); | |
| 1950 | + return this; | |
| 1951 | + }, | |
| 1952 | + | |
| 1953 | + /** | |
| 1954 | + * Calculates the x, y to center this element on the screen | |
| 1955 | + * @return {Array} The x, y values [x, y] | |
| 1956 | + */ | |
| 1957 | + getCenterXY : function(){ | |
| 1958 | + return this.getAlignToXY(document, 'c-c'); | |
| 1959 | + }, | |
| 1960 | + | |
| 1961 | + /** | |
| 1962 | + * Centers the Element in either the viewport, or another Element. | |
| 1963 | + * @param {Mixed} centerIn (optional) The element in which to center the element. | |
| 1964 | + */ | |
| 1965 | + center : function(centerIn){ | |
| 1966 | + this.alignTo(centerIn || document, 'c-c'); | |
| 1967 | + return this; | |
| 1968 | + }, | |
| 1969 | + | |
| 1970 | + /** | |
| 1971 | + * Tests various css rules/browsers to determine if this element uses a border box | |
| 1972 | + * @return {Boolean} | |
| 1973 | + */ | |
| 1974 | + isBorderBox : function(){ | |
| 1975 | + return noBoxAdjust[this.dom.tagName.toLowerCase()] || Ext.isBorderBox; | |
| 1976 | + }, | |
| 1977 | + | |
| 1978 | + /** | |
| 1979 | + * Return a box {x, y, width, height} that can be used to set another elements | |
| 1980 | + * size/location to match this element. | |
| 1981 | + * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned. | |
| 1982 | + * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y. | |
| 1983 | + * @return {Object} box An object in the format {x, y, width, height} | |
| 1984 | + */ | |
| 1985 | + getBox : function(contentBox, local){ | |
| 1986 | + var xy; | |
| 1987 | + if(!local){ | |
| 1988 | + xy = this.getXY(); | |
| 1989 | + }else{ | |
| 1990 | + var left = parseInt(this.getStyle("left"), 10) || 0; | |
| 1991 | + var top = parseInt(this.getStyle("top"), 10) || 0; | |
| 1992 | + xy = [left, top]; | |
| 1993 | + } | |
| 1994 | + var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx; | |
| 1995 | + if(!contentBox){ | |
| 1996 | + bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h}; | |
| 1997 | + }else{ | |
| 1998 | + var l = this.getBorderWidth("l")+this.getPadding("l"); | |
| 1999 | + var r = this.getBorderWidth("r")+this.getPadding("r"); | |
| 2000 | + var t = this.getBorderWidth("t")+this.getPadding("t"); | |
| 2001 | + var b = this.getBorderWidth("b")+this.getPadding("b"); | |
| 2002 | + bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)}; | |
| 2003 | + } | |
| 2004 | + bx.right = bx.x + bx.width; | |
| 2005 | + bx.bottom = bx.y + bx.height; | |
| 2006 | + return bx; | |
| 2007 | + }, | |
| 2008 | + | |
| 2009 | + /** | |
| 2010 | + * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth() | |
| 2011 | + for more information about the sides. | |
| 2012 | + * @param {String} sides | |
| 2013 | + * @return {Number} | |
| 2014 | + */ | |
| 2015 | + getFrameWidth : function(sides, onlyContentBox){ | |
| 2016 | + return onlyContentBox && Ext.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides)); | |
| 2017 | + }, | |
| 2018 | + | |
| 2019 | + /** | |
| 2020 | + * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently. | |
| 2021 | + * @param {Object} box The box to fill {x, y, width, height} | |
| 2022 | + * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically | |
| 2023 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 2024 | + * @return {Ext.Element} this | |
| 2025 | + */ | |
| 2026 | + setBox : function(box, adjust, animate){ | |
| 2027 | + var w = box.width, h = box.height; | |
| 2028 | + if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){ | |
| 2029 | + w -= (this.getBorderWidth("lr") + this.getPadding("lr")); | |
| 2030 | + h -= (this.getBorderWidth("tb") + this.getPadding("tb")); | |
| 2031 | + } | |
| 2032 | + this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2)); | |
| 2033 | + return this; | |
| 2034 | + }, | |
| 2035 | + | |
| 2036 | + /** | |
| 2037 | + * Forces the browser to repaint this element | |
| 2038 | + * @return {Ext.Element} this | |
| 2039 | + */ | |
| 2040 | + repaint : function(){ | |
| 2041 | + var dom = this.dom; | |
| 2042 | + this.addClass("x-repaint"); | |
| 2043 | + setTimeout(function(){ | |
| 2044 | + Ext.get(dom).removeClass("x-repaint"); | |
| 2045 | + }, 1); | |
| 2046 | + return this; | |
| 2047 | + }, | |
| 2048 | + | |
| 2049 | + /** | |
| 2050 | + * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed, | |
| 2051 | + * then it returns the calculated width of the sides (see getPadding) | |
| 2052 | + * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides | |
| 2053 | + * @return {Object/Number} | |
| 2054 | + */ | |
| 2055 | + getMargins : function(side){ | |
| 2056 | + if(!side){ | |
| 2057 | + return { | |
| 2058 | + top: parseInt(this.getStyle("margin-top"), 10) || 0, | |
| 2059 | + left: parseInt(this.getStyle("margin-left"), 10) || 0, | |
| 2060 | + bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0, | |
| 2061 | + right: parseInt(this.getStyle("margin-right"), 10) || 0 | |
| 2062 | + }; | |
| 2063 | + }else{ | |
| 2064 | + return this.addStyles(side, El.margins); | |
| 2065 | + } | |
| 2066 | + }, | |
| 2067 | + | |
| 2068 | + // private | |
| 2069 | + addStyles : function(sides, styles){ | |
| 2070 | + var val = 0, v, w; | |
| 2071 | + for(var i = 0, len = sides.length; i < len; i++){ | |
| 2072 | + v = this.getStyle(styles[sides.charAt(i)]); | |
| 2073 | + if(v){ | |
| 2074 | + w = parseInt(v, 10); | |
| 2075 | + if(w){ val += (w >= 0 ? w : -1 * w); } | |
| 2076 | + } | |
| 2077 | + } | |
| 2078 | + return val; | |
| 2079 | + }, | |
| 2080 | + | |
| 2081 | + /** | |
| 2082 | + * Creates a proxy element of this element | |
| 2083 | + * @param {String/Object} config The class name of the proxy element or a DomHelper config object | |
| 2084 | + * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body) | |
| 2085 | + * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false) | |
| 2086 | + * @return {Ext.Element} The new proxy element | |
| 2087 | + */ | |
| 2088 | + createProxy : function(config, renderTo, matchBox){ | |
| 2089 | + config = typeof config == "object" ? | |
| 2090 | + config : {tag : "div", cls: config}; | |
| 2091 | + | |
| 2092 | + var proxy; | |
| 2093 | + if(renderTo){ | |
| 2094 | + proxy = Ext.DomHelper.append(renderTo, config, true); | |
| 2095 | + }else { | |
| 2096 | + proxy = Ext.DomHelper.insertBefore(this.dom, config, true); | |
| 2097 | + } | |
| 2098 | + if(matchBox){ | |
| 2099 | + proxy.setBox(this.getBox()); | |
| 2100 | + } | |
| 2101 | + return proxy; | |
| 2102 | + }, | |
| 2103 | + | |
| 2104 | + /** | |
| 2105 | + * Puts a mask over this element to disable user interaction. Requires core.css. | |
| 2106 | + * This method can only be applied to elements which accept child nodes. | |
| 2107 | + * @param {String} msg (optional) A message to display in the mask | |
| 2108 | + * @param {String} msgCls (optional) A css class to apply to the msg element | |
| 2109 | + * @return {Element} The mask element | |
| 2110 | + */ | |
| 2111 | + mask : function(msg, msgCls){ | |
| 2112 | + if(this.getStyle("position") == "static"){ | |
| 2113 | + this.setStyle("position", "relative"); | |
| 2114 | + } | |
| 2115 | + if(this._maskMsg){ | |
| 2116 | + this._maskMsg.remove(); | |
| 2117 | + } | |
| 2118 | + if(this._mask){ | |
| 2119 | + this._mask.remove(); | |
| 2120 | + } | |
| 2121 | + | |
| 2122 | + this._mask = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask"}, true); | |
| 2123 | + | |
| 2124 | + this.addClass("x-masked"); | |
| 2125 | + this._mask.setDisplayed(true); | |
| 2126 | + if(typeof msg == 'string'){ | |
| 2127 | + this._maskMsg = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask-msg", cn:{tag:'div'}}, true); | |
| 2128 | + var mm = this._maskMsg; | |
| 2129 | + mm.dom.className = msgCls ? "ext-el-mask-msg " + msgCls : "ext-el-mask-msg"; | |
| 2130 | + mm.dom.firstChild.innerHTML = msg; | |
| 2131 | + mm.setDisplayed(true); | |
| 2132 | + mm.center(this); | |
| 2133 | + } | |
| 2134 | + if(Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically | |
| 2135 | + this._mask.setSize(this.dom.clientWidth, this.getHeight()); | |
| 2136 | + } | |
| 2137 | + return this._mask; | |
| 2138 | + }, | |
| 2139 | + | |
| 2140 | + /** | |
| 2141 | + * Removes a previously applied mask. | |
| 2142 | + */ | |
| 2143 | + unmask : function(){ | |
| 2144 | + if(this._mask){ | |
| 2145 | + if(this._maskMsg){ | |
| 2146 | + this._maskMsg.remove(); | |
| 2147 | + delete this._maskMsg; | |
| 2148 | + } | |
| 2149 | + this._mask.remove(); | |
| 2150 | + delete this._mask; | |
| 2151 | + } | |
| 2152 | + this.removeClass("x-masked"); | |
| 2153 | + }, | |
| 2154 | + | |
| 2155 | + /** | |
| 2156 | + * Returns true if this element is masked | |
| 2157 | + * @return {Boolean} | |
| 2158 | + */ | |
| 2159 | + isMasked : function(){ | |
| 2160 | + return this._mask && this._mask.isVisible(); | |
| 2161 | + }, | |
| 2162 | + | |
| 2163 | + /** | |
| 2164 | + * Creates an iframe shim for this element to keep selects and other windowed objects from | |
| 2165 | + * showing through. | |
| 2166 | + * @return {Ext.Element} The new shim element | |
| 2167 | + */ | |
| 2168 | + createShim : function(){ | |
| 2169 | + var el = document.createElement('iframe'); | |
| 2170 | + el.frameBorder = '0'; | |
| 2171 | + el.className = 'ext-shim'; | |
| 2172 | + if(Ext.isIE && Ext.isSecure){ | |
| 2173 | + el.src = Ext.SSL_SECURE_URL; | |
| 2174 | + } | |
| 2175 | + var shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom)); | |
| 2176 | + shim.autoBoxAdjust = false; | |
| 2177 | + return shim; | |
| 2178 | + }, | |
| 2179 | + | |
| 2180 | + /** | |
| 2181 | + * Removes this element from the DOM and deletes it from the cache | |
| 2182 | + */ | |
| 2183 | + remove : function(){ | |
| 2184 | + Ext.removeNode(this.dom); | |
| 2185 | + delete El.cache[this.dom.id]; | |
| 2186 | + }, | |
| 2187 | + | |
| 2188 | + /** | |
| 2189 | + * Sets up event handlers to call the passed functions when the mouse is over this element. Automatically | |
| 2190 | + * filters child element mouse events. | |
| 2191 | + * @param {Function} overFn | |
| 2192 | + * @param {Function} outFn | |
| 2193 | + * @param {Object} scope (optional) | |
| 2194 | + * @return {Ext.Element} this | |
| 2195 | + */ | |
| 2196 | + hover : function(overFn, outFn, scope){ | |
| 2197 | + var preOverFn = function(e){ | |
| 2198 | + if(!e.within(this, true)){ | |
| 2199 | + overFn.apply(scope || this, arguments); | |
| 2200 | + } | |
| 2201 | + }; | |
| 2202 | + var preOutFn = function(e){ | |
| 2203 | + if(!e.within(this, true)){ | |
| 2204 | + outFn.apply(scope || this, arguments); | |
| 2205 | + } | |
| 2206 | + }; | |
| 2207 | + this.on("mouseover", preOverFn, this.dom); | |
| 2208 | + this.on("mouseout", preOutFn, this.dom); | |
| 2209 | + return this; | |
| 2210 | + }, | |
| 2211 | + | |
| 2212 | + /** | |
| 2213 | + * Sets up event handlers to add and remove a css class when the mouse is over this element | |
| 2214 | + * @param {String} className | |
| 2215 | + * @return {Ext.Element} this | |
| 2216 | + */ | |
| 2217 | + addClassOnOver : function(className){ | |
| 2218 | + this.hover( | |
| 2219 | + function(){ | |
| 2220 | + Ext.fly(this, '_internal').addClass(className); | |
| 2221 | + }, | |
| 2222 | + function(){ | |
| 2223 | + Ext.fly(this, '_internal').removeClass(className); | |
| 2224 | + } | |
| 2225 | + ); | |
| 2226 | + return this; | |
| 2227 | + }, | |
| 2228 | + | |
| 2229 | + /** | |
| 2230 | + * Sets up event handlers to add and remove a css class when this element has the focus | |
| 2231 | + * @param {String} className | |
| 2232 | + * @return {Ext.Element} this | |
| 2233 | + */ | |
| 2234 | + addClassOnFocus : function(className){ | |
| 2235 | + this.on("focus", function(){ | |
| 2236 | + Ext.fly(this, '_internal').addClass(className); | |
| 2237 | + }, this.dom); | |
| 2238 | + this.on("blur", function(){ | |
| 2239 | + Ext.fly(this, '_internal').removeClass(className); | |
| 2240 | + }, this.dom); | |
| 2241 | + return this; | |
| 2242 | + }, | |
| 2243 | + /** | |
| 2244 | + * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect) | |
| 2245 | + * @param {String} className | |
| 2246 | + * @return {Ext.Element} this | |
| 2247 | + */ | |
| 2248 | + addClassOnClick : function(className){ | |
| 2249 | + var dom = this.dom; | |
| 2250 | + this.on("mousedown", function(){ | |
| 2251 | + Ext.fly(dom, '_internal').addClass(className); | |
| 2252 | + var d = Ext.getDoc(); | |
| 2253 | + var fn = function(){ | |
| 2254 | + Ext.fly(dom, '_internal').removeClass(className); | |
| 2255 | + d.removeListener("mouseup", fn); | |
| 2256 | + }; | |
| 2257 | + d.on("mouseup", fn); | |
| 2258 | + }); | |
| 2259 | + return this; | |
| 2260 | + }, | |
| 2261 | + | |
| 2262 | + /** | |
| 2263 | + * Stops the specified event from bubbling and optionally prevents the default action | |
| 2264 | + * @param {String} eventName | |
| 2265 | + * @param {Boolean} preventDefault (optional) true to prevent the default action too | |
| 2266 | + * @return {Ext.Element} this | |
| 2267 | + */ | |
| 2268 | + swallowEvent : function(eventName, preventDefault){ | |
| 2269 | + var fn = function(e){ | |
| 2270 | + e.stopPropagation(); | |
| 2271 | + if(preventDefault){ | |
| 2272 | + e.preventDefault(); | |
| 2273 | + } | |
| 2274 | + }; | |
| 2275 | + if(Ext.isArray(eventName)){ | |
| 2276 | + for(var i = 0, len = eventName.length; i < len; i++){ | |
| 2277 | + this.on(eventName[i], fn); | |
| 2278 | + } | |
| 2279 | + return this; | |
| 2280 | + } | |
| 2281 | + this.on(eventName, fn); | |
| 2282 | + return this; | |
| 2283 | + }, | |
| 2284 | + | |
| 2285 | + /** | |
| 2286 | + * Gets the parent node for this element, optionally chaining up trying to match a selector | |
| 2287 | + * @param {String} selector (optional) Find a parent node that matches the passed simple selector | |
| 2288 | + * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element | |
| 2289 | + * @return {Ext.Element/HTMLElement} The parent node or null | |
| 2290 | + */ | |
| 2291 | + parent : function(selector, returnDom){ | |
| 2292 | + return this.matchNode('parentNode', 'parentNode', selector, returnDom); | |
| 2293 | + }, | |
| 2294 | + | |
| 2295 | + /** | |
| 2296 | + * Gets the next sibling, skipping text nodes | |
| 2297 | + * @param {String} selector (optional) Find the next sibling that matches the passed simple selector | |
| 2298 | + * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element | |
| 2299 | + * @return {Ext.Element/HTMLElement} The next sibling or null | |
| 2300 | + */ | |
| 2301 | + next : function(selector, returnDom){ | |
| 2302 | + return this.matchNode('nextSibling', 'nextSibling', selector, returnDom); | |
| 2303 | + }, | |
| 2304 | + | |
| 2305 | + /** | |
| 2306 | + * Gets the previous sibling, skipping text nodes | |
| 2307 | + * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector | |
| 2308 | + * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element | |
| 2309 | + * @return {Ext.Element/HTMLElement} The previous sibling or null | |
| 2310 | + */ | |
| 2311 | + prev : function(selector, returnDom){ | |
| 2312 | + return this.matchNode('previousSibling', 'previousSibling', selector, returnDom); | |
| 2313 | + }, | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + /** | |
| 2317 | + * Gets the first child, skipping text nodes | |
| 2318 | + * @param {String} selector (optional) Find the next sibling that matches the passed simple selector | |
| 2319 | + * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element | |
| 2320 | + * @return {Ext.Element/HTMLElement} The first child or null | |
| 2321 | + */ | |
| 2322 | + first : function(selector, returnDom){ | |
| 2323 | + return this.matchNode('nextSibling', 'firstChild', selector, returnDom); | |
| 2324 | + }, | |
| 2325 | + | |
| 2326 | + /** | |
| 2327 | + * Gets the last child, skipping text nodes | |
| 2328 | + * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector | |
| 2329 | + * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element | |
| 2330 | + * @return {Ext.Element/HTMLElement} The last child or null | |
| 2331 | + */ | |
| 2332 | + last : function(selector, returnDom){ | |
| 2333 | + return this.matchNode('previousSibling', 'lastChild', selector, returnDom); | |
| 2334 | + }, | |
| 2335 | + | |
| 2336 | + matchNode : function(dir, start, selector, returnDom){ | |
| 2337 | + var n = this.dom[start]; | |
| 2338 | + while(n){ | |
| 2339 | + if(n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))){ | |
| 2340 | + return !returnDom ? Ext.get(n) : n; | |
| 2341 | + } | |
| 2342 | + n = n[dir]; | |
| 2343 | + } | |
| 2344 | + return null; | |
| 2345 | + }, | |
| 2346 | + | |
| 2347 | + /** | |
| 2348 | + * Appends the passed element(s) to this element | |
| 2349 | + * @param {String/HTMLElement/Array/Element/CompositeElement} el | |
| 2350 | + * @return {Ext.Element} this | |
| 2351 | + */ | |
| 2352 | + appendChild: function(el){ | |
| 2353 | + el = Ext.get(el); | |
| 2354 | + el.appendTo(this); | |
| 2355 | + return this; | |
| 2356 | + }, | |
| 2357 | + | |
| 2358 | + /** | |
| 2359 | + * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element. | |
| 2360 | + * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be | |
| 2361 | + * automatically generated with the specified attributes. | |
| 2362 | + * @param {HTMLElement} insertBefore (optional) a child element of this element | |
| 2363 | + * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element | |
| 2364 | + * @return {Ext.Element} The new child element | |
| 2365 | + */ | |
| 2366 | + createChild: function(config, insertBefore, returnDom){ | |
| 2367 | + config = config || {tag:'div'}; | |
| 2368 | + if(insertBefore){ | |
| 2369 | + return Ext.DomHelper.insertBefore(insertBefore, config, returnDom !== true); | |
| 2370 | + } | |
| 2371 | + return Ext.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true); | |
| 2372 | + }, | |
| 2373 | + | |
| 2374 | + /** | |
| 2375 | + * Appends this element to the passed element | |
| 2376 | + * @param {Mixed} el The new parent element | |
| 2377 | + * @return {Ext.Element} this | |
| 2378 | + */ | |
| 2379 | + appendTo: function(el){ | |
| 2380 | + el = Ext.getDom(el); | |
| 2381 | + el.appendChild(this.dom); | |
| 2382 | + return this; | |
| 2383 | + }, | |
| 2384 | + | |
| 2385 | + /** | |
| 2386 | + * Inserts this element before the passed element in the DOM | |
| 2387 | + * @param {Mixed} el The element before which this element will be inserted | |
| 2388 | + * @return {Ext.Element} this | |
| 2389 | + */ | |
| 2390 | + insertBefore: function(el){ | |
| 2391 | + el = Ext.getDom(el); | |
| 2392 | + el.parentNode.insertBefore(this.dom, el); | |
| 2393 | + return this; | |
| 2394 | + }, | |
| 2395 | + | |
| 2396 | + /** | |
| 2397 | + * Inserts this element after the passed element in the DOM | |
| 2398 | + * @param {Mixed} el The element to insert after | |
| 2399 | + * @return {Ext.Element} this | |
| 2400 | + */ | |
| 2401 | + insertAfter: function(el){ | |
| 2402 | + el = Ext.getDom(el); | |
| 2403 | + el.parentNode.insertBefore(this.dom, el.nextSibling); | |
| 2404 | + return this; | |
| 2405 | + }, | |
| 2406 | + | |
| 2407 | + /** | |
| 2408 | + * Inserts (or creates) an element (or DomHelper config) as the first child of this element | |
| 2409 | + * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert | |
| 2410 | + * @return {Ext.Element} The new child | |
| 2411 | + */ | |
| 2412 | + insertFirst: function(el, returnDom){ | |
| 2413 | + el = el || {}; | |
| 2414 | + if(typeof el == 'object' && !el.nodeType && !el.dom){ // dh config | |
| 2415 | + return this.createChild(el, this.dom.firstChild, returnDom); | |
| 2416 | + }else{ | |
| 2417 | + el = Ext.getDom(el); | |
| 2418 | + this.dom.insertBefore(el, this.dom.firstChild); | |
| 2419 | + return !returnDom ? Ext.get(el) : el; | |
| 2420 | + } | |
| 2421 | + }, | |
| 2422 | + | |
| 2423 | + /** | |
| 2424 | + * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element | |
| 2425 | + * @param {Mixed/Object/Array} el The id, element to insert or a DomHelper config to create and insert *or* an array of any of those. | |
| 2426 | + * @param {String} where (optional) 'before' or 'after' defaults to before | |
| 2427 | + * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element | |
| 2428 | + * @return {Ext.Element} the inserted Element | |
| 2429 | + */ | |
| 2430 | + insertSibling: function(el, where, returnDom){ | |
| 2431 | + var rt; | |
| 2432 | + if(Ext.isArray(el)){ | |
| 2433 | + for(var i = 0, len = el.length; i < len; i++){ | |
| 2434 | + rt = this.insertSibling(el[i], where, returnDom); | |
| 2435 | + } | |
| 2436 | + return rt; | |
| 2437 | + } | |
| 2438 | + where = where ? where.toLowerCase() : 'before'; | |
| 2439 | + el = el || {}; | |
| 2440 | + var refNode = where == 'before' ? this.dom : this.dom.nextSibling; | |
| 2441 | + | |
| 2442 | + if(typeof el == 'object' && !el.nodeType && !el.dom){ // dh config | |
| 2443 | + if(where == 'after' && !this.dom.nextSibling){ | |
| 2444 | + rt = Ext.DomHelper.append(this.dom.parentNode, el, !returnDom); | |
| 2445 | + }else{ | |
| 2446 | + rt = Ext.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom); | |
| 2447 | + } | |
| 2448 | + | |
| 2449 | + }else{ | |
| 2450 | + rt = this.dom.parentNode.insertBefore(Ext.getDom(el), refNode); | |
| 2451 | + if(!returnDom){ | |
| 2452 | + rt = Ext.get(rt); | |
| 2453 | + } | |
| 2454 | + } | |
| 2455 | + return rt; | |
| 2456 | + }, | |
| 2457 | + | |
| 2458 | + /** | |
| 2459 | + * Creates and wraps this element with another element | |
| 2460 | + * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div | |
| 2461 | + * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element | |
| 2462 | + * @return {HTMLElement/Element} The newly created wrapper element | |
| 2463 | + */ | |
| 2464 | + wrap: function(config, returnDom){ | |
| 2465 | + if(!config){ | |
| 2466 | + config = {tag: "div"}; | |
| 2467 | + } | |
| 2468 | + var newEl = Ext.DomHelper.insertBefore(this.dom, config, !returnDom); | |
| 2469 | + newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom); | |
| 2470 | + return newEl; | |
| 2471 | + }, | |
| 2472 | + | |
| 2473 | + /** | |
| 2474 | + * Replaces the passed element with this element | |
| 2475 | + * @param {Mixed} el The element to replace | |
| 2476 | + * @return {Ext.Element} this | |
| 2477 | + */ | |
| 2478 | + replace: function(el){ | |
| 2479 | + el = Ext.get(el); | |
| 2480 | + this.insertBefore(el); | |
| 2481 | + el.remove(); | |
| 2482 | + return this; | |
| 2483 | + }, | |
| 2484 | + | |
| 2485 | + /** | |
| 2486 | + * Replaces this element with the passed element | |
| 2487 | + * @param {Mixed/Object} el The new element or a DomHelper config of an element to create | |
| 2488 | + * @return {Ext.Element} this | |
| 2489 | + */ | |
| 2490 | + replaceWith: function(el){ | |
| 2491 | + if(typeof el == 'object' && !el.nodeType && !el.dom){ // dh config | |
| 2492 | + el = this.insertSibling(el, 'before'); | |
| 2493 | + }else{ | |
| 2494 | + el = Ext.getDom(el); | |
| 2495 | + this.dom.parentNode.insertBefore(el, this.dom); | |
| 2496 | + } | |
| 2497 | + El.uncache(this.id); | |
| 2498 | + this.dom.parentNode.removeChild(this.dom); | |
| 2499 | + this.dom = el; | |
| 2500 | + this.id = Ext.id(el); | |
| 2501 | + El.cache[this.id] = this; | |
| 2502 | + return this; | |
| 2503 | + }, | |
| 2504 | + | |
| 2505 | + /** | |
| 2506 | + * Inserts an html fragment into this element | |
| 2507 | + * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd. | |
| 2508 | + * @param {String} html The HTML fragment | |
| 2509 | + * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false) | |
| 2510 | + * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted) | |
| 2511 | + */ | |
| 2512 | + insertHtml : function(where, html, returnEl){ | |
| 2513 | + var el = Ext.DomHelper.insertHtml(where, this.dom, html); | |
| 2514 | + return returnEl ? Ext.get(el) : el; | |
| 2515 | + }, | |
| 2516 | + | |
| 2517 | + /** | |
| 2518 | + * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function) | |
| 2519 | + * @param {Object} o The object with the attributes | |
| 2520 | + * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos. | |
| 2521 | + * @return {Ext.Element} this | |
| 2522 | + */ | |
| 2523 | + set : function(o, useSet){ | |
| 2524 | + var el = this.dom; | |
| 2525 | + useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet; | |
| 2526 | + for(var attr in o){ | |
| 2527 | + if(attr == "style" || typeof o[attr] == "function") continue; | |
| 2528 | + if(attr=="cls"){ | |
| 2529 | + el.className = o["cls"]; | |
| 2530 | + }else if(o.hasOwnProperty(attr)){ | |
| 2531 | + if(useSet) el.setAttribute(attr, o[attr]); | |
| 2532 | + else el[attr] = o[attr]; | |
| 2533 | + } | |
| 2534 | + } | |
| 2535 | + if(o.style){ | |
| 2536 | + Ext.DomHelper.applyStyles(el, o.style); | |
| 2537 | + } | |
| 2538 | + return this; | |
| 2539 | + }, | |
| 2540 | + | |
| 2541 | + /** | |
| 2542 | + * Convenience method for constructing a KeyMap | |
| 2543 | + * @param {Number/Array/Object/String} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options: | |
| 2544 | + * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)} | |
| 2545 | + * @param {Function} fn The function to call | |
| 2546 | + * @param {Object} scope (optional) The scope of the function | |
| 2547 | + * @return {Ext.KeyMap} The KeyMap created | |
| 2548 | + */ | |
| 2549 | + addKeyListener : function(key, fn, scope){ | |
| 2550 | + var config; | |
| 2551 | + if(typeof key != "object" || Ext.isArray(key)){ | |
| 2552 | + config = { | |
| 2553 | + key: key, | |
| 2554 | + fn: fn, | |
| 2555 | + scope: scope | |
| 2556 | + }; | |
| 2557 | + }else{ | |
| 2558 | + config = { | |
| 2559 | + key : key.key, | |
| 2560 | + shift : key.shift, | |
| 2561 | + ctrl : key.ctrl, | |
| 2562 | + alt : key.alt, | |
| 2563 | + fn: fn, | |
| 2564 | + scope: scope | |
| 2565 | + }; | |
| 2566 | + } | |
| 2567 | + return new Ext.KeyMap(this, config); | |
| 2568 | + }, | |
| 2569 | + | |
| 2570 | + /** | |
| 2571 | + * Creates a KeyMap for this element | |
| 2572 | + * @param {Object} config The KeyMap config. See {@link Ext.KeyMap} for more details | |
| 2573 | + * @return {Ext.KeyMap} The KeyMap created | |
| 2574 | + */ | |
| 2575 | + addKeyMap : function(config){ | |
| 2576 | + return new Ext.KeyMap(this, config); | |
| 2577 | + }, | |
| 2578 | + | |
| 2579 | + /** | |
| 2580 | + * Returns true if this element is scrollable. | |
| 2581 | + * @return {Boolean} | |
| 2582 | + */ | |
| 2583 | + isScrollable : function(){ | |
| 2584 | + var dom = this.dom; | |
| 2585 | + return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth; | |
| 2586 | + }, | |
| 2587 | + | |
| 2588 | + /** | |
| 2589 | + * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll(). | |
| 2590 | + * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values. | |
| 2591 | + * @param {Number} value The new scroll value | |
| 2592 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 2593 | + * @return {Element} this | |
| 2594 | + */ | |
| 2595 | + scrollTo : function(side, value, animate){ | |
| 2596 | + var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop"; | |
| 2597 | + if(!animate || !A){ | |
| 2598 | + this.dom[prop] = value; | |
| 2599 | + }else{ | |
| 2600 | + var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value]; | |
| 2601 | + this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll'); | |
| 2602 | + } | |
| 2603 | + return this; | |
| 2604 | + }, | |
| 2605 | + | |
| 2606 | + /** | |
| 2607 | + * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is | |
| 2608 | + * within this element's scrollable range. | |
| 2609 | + * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down"). | |
| 2610 | + * @param {Number} distance How far to scroll the element in pixels | |
| 2611 | + * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object | |
| 2612 | + * @return {Boolean} Returns true if a scroll was triggered or false if the element | |
| 2613 | + * was scrolled as far as it could go. | |
| 2614 | + */ | |
| 2615 | + scroll : function(direction, distance, animate){ | |
| 2616 | + if(!this.isScrollable()){ | |
| 2617 | + return; | |
| 2618 | + } | |
| 2619 | + var el = this.dom; | |
| 2620 | + var l = el.scrollLeft, t = el.scrollTop; | |
| 2621 | + var w = el.scrollWidth, h = el.scrollHeight; | |
| 2622 | + var cw = el.clientWidth, ch = el.clientHeight; | |
| 2623 | + direction = direction.toLowerCase(); | |
| 2624 | + var scrolled = false; | |
| 2625 | + var a = this.preanim(arguments, 2); | |
| 2626 | + switch(direction){ | |
| 2627 | + case "l": | |
| 2628 | + case "left": | |
| 2629 | + if(w - l > cw){ | |
| 2630 | + var v = Math.min(l + distance, w-cw); | |
| 2631 | + this.scrollTo("left", v, a); | |
| 2632 | + scrolled = true; | |
| 2633 | + } | |
| 2634 | + break; | |
| 2635 | + case "r": | |
| 2636 | + case "right": | |
| 2637 | + if(l > 0){ | |
| 2638 | + var v = Math.max(l - distance, 0); | |
| 2639 | + this.scrollTo("left", v, a); | |
| 2640 | + scrolled = true; | |
| 2641 | + } | |
| 2642 | + break; | |
| 2643 | + case "t": | |
| 2644 | + case "top": | |
| 2645 | + case "up": | |
| 2646 | + if(t > 0){ | |
| 2647 | + var v = Math.max(t - distance, 0); | |
| 2648 | + this.scrollTo("top", v, a); | |
| 2649 | + scrolled = true; | |
| 2650 | + } | |
| 2651 | + break; | |
| 2652 | + case "b": | |
| 2653 | + case "bottom": | |
| 2654 | + case "down": | |
| 2655 | + if(h - t > ch){ | |
| 2656 | + var v = Math.min(t + distance, h-ch); | |
| 2657 | + this.scrollTo("top", v, a); | |
| 2658 | + scrolled = true; | |
| 2659 | + } | |
| 2660 | + break; | |
| 2661 | + } | |
| 2662 | + return scrolled; | |
| 2663 | + }, | |
| 2664 | + | |
| 2665 | + /** | |
| 2666 | + * Translates the passed page coordinates into left/top css values for this element | |
| 2667 | + * @param {Number/Array} x The page x or an array containing [x, y] | |
| 2668 | + * @param {Number} y (optional) The page y, required if x is not an array | |
| 2669 | + * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)} | |
| 2670 | + */ | |
| 2671 | + translatePoints : function(x, y){ | |
| 2672 | + if(typeof x == 'object' || Ext.isArray(x)){ | |
| 2673 | + y = x[1]; x = x[0]; | |
| 2674 | + } | |
| 2675 | + var p = this.getStyle('position'); | |
| 2676 | + var o = this.getXY(); | |
| 2677 | + | |
| 2678 | + var l = parseInt(this.getStyle('left'), 10); | |
| 2679 | + var t = parseInt(this.getStyle('top'), 10); | |
| 2680 | + | |
| 2681 | + if(isNaN(l)){ | |
| 2682 | + l = (p == "relative") ? 0 : this.dom.offsetLeft; | |
| 2683 | + } | |
| 2684 | + if(isNaN(t)){ | |
| 2685 | + t = (p == "relative") ? 0 : this.dom.offsetTop; | |
| 2686 | + } | |
| 2687 | + | |
| 2688 | + return {left: (x - o[0] + l), top: (y - o[1] + t)}; | |
| 2689 | + }, | |
| 2690 | + | |
| 2691 | + /** | |
| 2692 | + * Returns the current scroll position of the element. | |
| 2693 | + * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)} | |
| 2694 | + */ | |
| 2695 | + getScroll : function(){ | |
| 2696 | + var d = this.dom, doc = document; | |
| 2697 | + if(d == doc || d == doc.body){ | |
| 2698 | + var l, t; | |
| 2699 | + if(Ext.isIE && Ext.isStrict){ | |
| 2700 | + l = doc.documentElement.scrollLeft || (doc.body.scrollLeft || 0); | |
| 2701 | + t = doc.documentElement.scrollTop || (doc.body.scrollTop || 0); | |
| 2702 | + }else{ | |
| 2703 | + l = window.pageXOffset || (doc.body.scrollLeft || 0); | |
| 2704 | + t = window.pageYOffset || (doc.body.scrollTop || 0); | |
| 2705 | + } | |
| 2706 | + return {left: l, top: t}; | |
| 2707 | + }else{ | |
| 2708 | + return {left: d.scrollLeft, top: d.scrollTop}; | |
| 2709 | + } | |
| 2710 | + }, | |
| 2711 | + | |
| 2712 | + /** | |
| 2713 | + * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values | |
| 2714 | + * are convert to standard 6 digit hex color. | |
| 2715 | + * @param {String} attr The css attribute | |
| 2716 | + * @param {String} defaultValue The default value to use when a valid color isn't found | |
| 2717 | + * @param {String} prefix (optional) defaults to #. Use an empty string when working with | |
| 2718 | + * color anims. | |
| 2719 | + */ | |
| 2720 | + getColor : function(attr, defaultValue, prefix){ | |
| 2721 | + var v = this.getStyle(attr); | |
| 2722 | + if(!v || v == "transparent" || v == "inherit") { | |
| 2723 | + return defaultValue; | |
| 2724 | + } | |
| 2725 | + var color = typeof prefix == "undefined" ? "#" : prefix; | |
| 2726 | + if(v.substr(0, 4) == "rgb("){ | |
| 2727 | + var rvs = v.slice(4, v.length -1).split(","); | |
| 2728 | + for(var i = 0; i < 3; i++){ | |
| 2729 | + var h = parseInt(rvs[i]); | |
| 2730 | + var s = h.toString(16); | |
| 2731 | + if(h < 16){ | |
| 2732 | + s = "0" + s; | |
| 2733 | + } | |
| 2734 | + color += s; | |
| 2735 | + } | |
| 2736 | + } else { | |
| 2737 | + if(v.substr(0, 1) == "#"){ | |
| 2738 | + if(v.length == 4) { | |
| 2739 | + for(var i = 1; i < 4; i++){ | |
| 2740 | + var c = v.charAt(i); | |
| 2741 | + color += c + c; | |
| 2742 | + } | |
| 2743 | + }else if(v.length == 7){ | |
| 2744 | + color += v.substr(1); | |
| 2745 | + } | |
| 2746 | + } | |
| 2747 | + } | |
| 2748 | + return(color.length > 5 ? color.toLowerCase() : defaultValue); | |
| 2749 | + }, | |
| 2750 | + | |
| 2751 | + /** | |
| 2752 | + * Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a | |
| 2753 | + * gradient background, rounded corners and a 4-way shadow. Example usage: | |
| 2754 | + * <pre><code> | |
| 2755 | +// Basic box wrap | |
| 2756 | +Ext.get("foo").boxWrap(); | |
| 2757 | + | |
| 2758 | +// You can also add a custom class and use CSS inheritance rules to customize the box look. | |
| 2759 | +// 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example | |
| 2760 | +// for how to create a custom box wrap style. | |
| 2761 | +Ext.get("foo").boxWrap().addClass("x-box-blue"); | |
| 2762 | +</pre></code> | |
| 2763 | + * @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box'). | |
| 2764 | + * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work, | |
| 2765 | + * so if you supply an alternate base class, make sure you also supply all of the necessary rules. | |
| 2766 | + * @return {Ext.Element} this | |
| 2767 | + */ | |
| 2768 | + boxWrap : function(cls){ | |
| 2769 | + cls = cls || 'x-box'; | |
| 2770 | + var el = Ext.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls))); | |
| 2771 | + el.child('.'+cls+'-mc').dom.appendChild(this.dom); | |
| 2772 | + return el; | |
| 2773 | + }, | |
| 2774 | + | |
| 2775 | + /** | |
| 2776 | + * Returns the value of a namespaced attribute from the element's underlying DOM node. | |
| 2777 | + * @param {String} namespace The namespace in which to look for the attribute | |
| 2778 | + * @param {String} name The attribute name | |
| 2779 | + * @return {String} The attribute value | |
| 2780 | + */ | |
| 2781 | + getAttributeNS : Ext.isIE ? function(ns, name){ | |
| 2782 | + var d = this.dom; | |
| 2783 | + var type = typeof d[ns+":"+name]; | |
| 2784 | + if(type != 'undefined' && type != 'unknown'){ | |
| 2785 | + return d[ns+":"+name]; | |
| 2786 | + } | |
| 2787 | + return d[name]; | |
| 2788 | + } : function(ns, name){ | |
| 2789 | + var d = this.dom; | |
| 2790 | + return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name]; | |
| 2791 | + }, | |
| 2792 | + | |
| 2793 | + /** | |
| 2794 | + * Returns the width in pixels of the passed text, or the width of the text in this Element. | |
| 2795 | + * @param {String} text The text to measure. Defaults to the innerHTML of the element. | |
| 2796 | + * @param {Number} min (Optional) The minumum value to return. | |
| 2797 | + * @param {Number} max (Optional) The maximum value to return. | |
| 2798 | + * @return {Number} The text width in pixels. | |
| 2799 | + */ | |
| 2800 | + getTextWidth : function(text, min, max){ | |
| 2801 | + return (Ext.util.TextMetrics.measure(this.dom, Ext.value(text, this.dom.innerHTML, true)).width).constrain(min || 0, max || 1000000); | |
| 2802 | + } | |
| 2803 | +}; | |
| 2804 | + | |
| 2805 | +var ep = El.prototype; | |
| 2806 | + | |
| 2807 | +/** | |
| 2808 | + * Appends an event handler (shorthand for {@link #addListener}). | |
| 2809 | + * @param {String} eventName The type of event to handle | |
| 2810 | + * @param {Function} fn The handler function the event invokes | |
| 2811 | + * @param {Object} scope (optional) The scope (this element) of the handler function | |
| 2812 | + * @param {Object} options (optional) An object containing standard {@link #addListener} options | |
| 2813 | + * @member Ext.Element | |
| 2814 | + * @method on | |
| 2815 | + */ | |
| 2816 | +ep.on = ep.addListener; | |
| 2817 | + // backwards compat | |
| 2818 | +ep.mon = ep.addListener; | |
| 2819 | + | |
| 2820 | +ep.getUpdateManager = ep.getUpdater; | |
| 2821 | + | |
| 2822 | +/** | |
| 2823 | + * Removes an event handler from this element (shorthand for {@link #removeListener}). | |
| 2824 | + * @param {String} eventName the type of event to remove | |
| 2825 | + * @param {Function} fn the method the event invokes | |
| 2826 | + * @return {Ext.Element} this | |
| 2827 | + * @member Ext.Element | |
| 2828 | + * @method un | |
| 2829 | + */ | |
| 2830 | +ep.un = ep.removeListener; | |
| 2831 | + | |
| 2832 | +/** | |
| 2833 | + * true to automatically adjust width and height settings for box-model issues (default to true) | |
| 2834 | + */ | |
| 2835 | +ep.autoBoxAdjust = true; | |
| 2836 | + | |
| 2837 | +// private | |
| 2838 | +El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i; | |
| 2839 | + | |
| 2840 | +// private | |
| 2841 | +El.addUnits = function(v, defaultUnit){ | |
| 2842 | + if(v === "" || v == "auto"){ | |
| 2843 | + return v; | |
| 2844 | + } | |
| 2845 | + if(v === undefined){ | |
| 2846 | + return ''; | |
| 2847 | + } | |
| 2848 | + if(typeof v == "number" || !El.unitPattern.test(v)){ | |
| 2849 | + return v + (defaultUnit || 'px'); | |
| 2850 | + } | |
| 2851 | + return v; | |
| 2852 | +}; | |
| 2853 | + | |
| 2854 | +// special markup used throughout Ext when box wrapping elements | |
| 2855 | +El.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>'; | |
| 2856 | +/** | |
| 2857 | + * Visibility mode constant - Use visibility to hide element | |
| 2858 | + * @static | |
| 2859 | + * @type Number | |
| 2860 | + */ | |
| 2861 | +El.VISIBILITY = 1; | |
| 2862 | +/** | |
| 2863 | + * Visibility mode constant - Use display to hide element | |
| 2864 | + * @static | |
| 2865 | + * @type Number | |
| 2866 | + */ | |
| 2867 | +El.DISPLAY = 2; | |
| 2868 | + | |
| 2869 | +El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"}; | |
| 2870 | +El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"}; | |
| 2871 | +El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"}; | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | +/** | |
| 2876 | + * @private | |
| 2877 | + */ | |
| 2878 | +El.cache = {}; | |
| 2879 | + | |
| 2880 | +var docEl; | |
| 2881 | + | |
| 2882 | +/** | |
| 2883 | + * Static method to retrieve Ext.Element objects. | |
| 2884 | + * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method | |
| 2885 | + * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by | |
| 2886 | + * its ID, use {@link Ext.ComponentMgr#get}.</p> | |
| 2887 | + * <p>Uses simple caching to consistently return the same object. | |
| 2888 | + * Automatically fixes if an object was recreated with the same id via AJAX or DOM.</p> | |
| 2889 | + * @param {Mixed} el The id of the node, a DOM Node or an existing Element. | |
| 2890 | + * @return {Element} The {@link Ext.Element Element} object (or null if no matching element was found) | |
| 2891 | + * @static | |
| 2892 | + */ | |
| 2893 | +El.get = function(el){ | |
| 2894 | + var ex, elm, id; | |
| 2895 | + if(!el){ return null; } | |
| 2896 | + if(typeof el == "string"){ // element id | |
| 2897 | + if(!(elm = document.getElementById(el))){ | |
| 2898 | + return null; | |
| 2899 | + } | |
| 2900 | + if(ex = El.cache[el]){ | |
| 2901 | + ex.dom = elm; | |
| 2902 | + }else{ | |
| 2903 | + ex = El.cache[el] = new El(elm); | |
| 2904 | + } | |
| 2905 | + return ex; | |
| 2906 | + }else if(el.tagName){ // dom element | |
| 2907 | + if(!(id = el.id)){ | |
| 2908 | + id = Ext.id(el); | |
| 2909 | + } | |
| 2910 | + if(ex = El.cache[id]){ | |
| 2911 | + ex.dom = el; | |
| 2912 | + }else{ | |
| 2913 | + ex = El.cache[id] = new El(el); | |
| 2914 | + } | |
| 2915 | + return ex; | |
| 2916 | + }else if(el instanceof El){ | |
| 2917 | + if(el != docEl){ | |
| 2918 | + el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid, | |
| 2919 | + // catch case where it hasn't been appended | |
| 2920 | + El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it | |
| 2921 | + } | |
| 2922 | + return el; | |
| 2923 | + }else if(el.isComposite){ | |
| 2924 | + return el; | |
| 2925 | + }else if(Ext.isArray(el)){ | |
| 2926 | + return El.select(el); | |
| 2927 | + }else if(el == document){ | |
| 2928 | + // create a bogus element object representing the document object | |
| 2929 | + if(!docEl){ | |
| 2930 | + var f = function(){}; | |
| 2931 | + f.prototype = El.prototype; | |
| 2932 | + docEl = new f(); | |
| 2933 | + docEl.dom = document; | |
| 2934 | + } | |
| 2935 | + return docEl; | |
| 2936 | + } | |
| 2937 | + return null; | |
| 2938 | +}; | |
| 2939 | + | |
| 2940 | +// private | |
| 2941 | +El.uncache = function(el){ | |
| 2942 | + for(var i = 0, a = arguments, len = a.length; i < len; i++) { | |
| 2943 | + if(a[i]){ | |
| 2944 | + delete El.cache[a[i].id || a[i]]; | |
| 2945 | + } | |
| 2946 | + } | |
| 2947 | +}; | |
| 2948 | + | |
| 2949 | +// private | |
| 2950 | +// Garbage collection - uncache elements/purge listeners on orphaned elements | |
| 2951 | +// so we don't hold a reference and cause the browser to retain them | |
| 2952 | +El.garbageCollect = function(){ | |
| 2953 | + if(!Ext.enableGarbageCollector){ | |
| 2954 | + clearInterval(El.collectorThread); | |
| 2955 | + return; | |
| 2956 | + } | |
| 2957 | + for(var eid in El.cache){ | |
| 2958 | + var el = El.cache[eid], d = el.dom; | |
| 2959 | + // ------------------------------------------------------- | |
| 2960 | + // Determining what is garbage: | |
| 2961 | + // ------------------------------------------------------- | |
| 2962 | + // !d | |
| 2963 | + // dom node is null, definitely garbage | |
| 2964 | + // ------------------------------------------------------- | |
| 2965 | + // !d.parentNode | |
| 2966 | + // no parentNode == direct orphan, definitely garbage | |
| 2967 | + // ------------------------------------------------------- | |
| 2968 | + // !d.offsetParent && !document.getElementById(eid) | |
| 2969 | + // display none elements have no offsetParent so we will | |
| 2970 | + // also try to look it up by it's id. However, check | |
| 2971 | + // offsetParent first so we don't do unneeded lookups. | |
| 2972 | + // This enables collection of elements that are not orphans | |
| 2973 | + // directly, but somewhere up the line they have an orphan | |
| 2974 | + // parent. | |
| 2975 | + // ------------------------------------------------------- | |
| 2976 | + if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){ | |
| 2977 | + delete El.cache[eid]; | |
| 2978 | + if(d && Ext.enableListenerCollection){ | |
| 2979 | + Ext.EventManager.removeAll(d); | |
| 2980 | + } | |
| 2981 | + } | |
| 2982 | + } | |
| 2983 | +} | |
| 2984 | +El.collectorThreadId = setInterval(El.garbageCollect, 30000); | |
| 2985 | + | |
| 2986 | +var flyFn = function(){}; | |
| 2987 | +flyFn.prototype = El.prototype; | |
| 2988 | +var _cls = new flyFn(); | |
| 2989 | + | |
| 2990 | +// dom is optional | |
| 2991 | +El.Flyweight = function(dom){ | |
| 2992 | + this.dom = dom; | |
| 2993 | +}; | |
| 2994 | + | |
| 2995 | +El.Flyweight.prototype = _cls; | |
| 2996 | +El.Flyweight.prototype.isFlyweight = true; | |
| 2997 | + | |
| 2998 | +El._flyweights = {}; | |
| 2999 | +/** | |
| 3000 | + * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element - | |
| 3001 | + * the dom node can be overwritten by other code. | |
| 3002 | + * @param {String/HTMLElement} el The dom node or id | |
| 3003 | + * @param {String} named (optional) Allows for creation of named reusable flyweights to | |
| 3004 | + * prevent conflicts (e.g. internally Ext uses "_internal") | |
| 3005 | + * @static | |
| 3006 | + * @return {Element} The shared Element object (or null if no matching element was found) | |
| 3007 | + */ | |
| 3008 | +El.fly = function(el, named){ | |
| 3009 | + named = named || '_global'; | |
| 3010 | + el = Ext.getDom(el); | |
| 3011 | + if(!el){ | |
| 3012 | + return null; | |
| 3013 | + } | |
| 3014 | + if(!El._flyweights[named]){ | |
| 3015 | + El._flyweights[named] = new El.Flyweight(); | |
| 3016 | + } | |
| 3017 | + El._flyweights[named].dom = el; | |
| 3018 | + return El._flyweights[named]; | |
| 3019 | +}; | |
| 3020 | + | |
| 3021 | +/** | |
| 3022 | + * Static method to retrieve Element objects. Uses simple caching to consistently return the same object. | |
| 3023 | + * Automatically fixes if an object was recreated with the same id via AJAX or DOM. | |
| 3024 | + * Shorthand of {@link Ext.Element#get} | |
| 3025 | + * @param {Mixed} el The id of the node, a DOM Node or an existing Element. | |
| 3026 | + * @return {Element} The Element object | |
| 3027 | + * @member Ext | |
| 3028 | + * @method get | |
| 3029 | + */ | |
| 3030 | +Ext.get = El.get; | |
| 3031 | +/** | |
| 3032 | + * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element - | |
| 3033 | + * the dom node can be overwritten by other code. | |
| 3034 | + * Shorthand of {@link Ext.Element#fly} | |
| 3035 | + * @param {String/HTMLElement} el The dom node or id | |
| 3036 | + * @param {String} named (optional) Allows for creation of named reusable flyweights to | |
| 3037 | + * prevent conflicts (e.g. internally Ext uses "_internal") | |
| 3038 | + * @static | |
| 3039 | + * @return {Element} The shared Element object | |
| 3040 | + * @member Ext | |
| 3041 | + * @method fly | |
| 3042 | + */ | |
| 3043 | +Ext.fly = El.fly; | |
| 3044 | + | |
| 3045 | +// speedy lookup for elements never to box adjust | |
| 3046 | +var noBoxAdjust = Ext.isStrict ? { | |
| 3047 | + select:1 | |
| 3048 | +} : { | |
| 3049 | + input:1, select:1, textarea:1 | |
| 3050 | +}; | |
| 3051 | +if(Ext.isIE || Ext.isGecko){ | |
| 3052 | + noBoxAdjust['button'] = 1; | |
| 3053 | +} | |
| 3054 | + | |
| 3055 | + | |
| 3056 | +Ext.EventManager.on(window, 'unload', function(){ | |
| 3057 | + delete El.cache; | |
| 3058 | + delete El._flyweights; | |
| 3059 | +}); | |
| 3060 | +})(); | |
| 0 | 3061 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/core/EventManager.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * @class Ext.EventManager | |
| 11 | + * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides | |
| 12 | + * several useful events directly. | |
| 13 | + * See {@link Ext.EventObject} for more details on normalized event objects. | |
| 14 | + * @singleton | |
| 15 | + */ | |
| 16 | +Ext.EventManager = function(){ | |
| 17 | + var docReadyEvent, docReadyProcId, docReadyState = false; | |
| 18 | + var resizeEvent, resizeTask, textEvent, textSize; | |
| 19 | + var E = Ext.lib.Event; | |
| 20 | + var D = Ext.lib.Dom; | |
| 21 | + // fix parser confusion | |
| 22 | + var xname = 'Ex' + 't'; | |
| 23 | + | |
| 24 | + var elHash = {}; | |
| 25 | + | |
| 26 | + var addListener = function(el, ename, fn, wrap, scope){ | |
| 27 | + var id = Ext.id(el); | |
| 28 | + if(!elHash[id]){ | |
| 29 | + elHash[id] = {}; | |
| 30 | + } | |
| 31 | + var es = elHash[id]; | |
| 32 | + if(!es[ename]){ | |
| 33 | + es[ename] = []; | |
| 34 | + } | |
| 35 | + var ls = es[ename]; | |
| 36 | + ls.push({ | |
| 37 | + id: id, | |
| 38 | + ename: ename, | |
| 39 | + fn: fn, | |
| 40 | + wrap: wrap, | |
| 41 | + scope: scope | |
| 42 | + }); | |
| 43 | + | |
| 44 | + E.on(el, ename, wrap); | |
| 45 | + | |
| 46 | + if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery | |
| 47 | + el.addEventListener("DOMMouseScroll", wrap, false); | |
| 48 | + E.on(window, 'unload', function(){ | |
| 49 | + el.removeEventListener("DOMMouseScroll", wrap, false); | |
| 50 | + }); | |
| 51 | + } | |
| 52 | + if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document | |
| 53 | + Ext.EventManager.stoppedMouseDownEvent.addListener(wrap); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + var removeListener = function(el, ename, fn, scope){ | |
| 58 | + el = Ext.getDom(el); | |
| 59 | + var id = Ext.id(el), es = elHash[id], wrap; | |
| 60 | + if(es){ | |
| 61 | + var ls = es[ename], l; | |
| 62 | + if(ls){ | |
| 63 | + for(var i = 0, len = ls.length; i < len; i++){ | |
| 64 | + l = ls[i]; | |
| 65 | + if(l.fn == fn && (!scope || l.scope == scope)){ | |
| 66 | + wrap = l.wrap; | |
| 67 | + E.un(el, ename, wrap); | |
| 68 | + ls.splice(i, 1); | |
| 69 | + break; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + } | |
| 73 | + } | |
| 74 | + if(ename == "mousewheel" && el.addEventListener && wrap){ | |
| 75 | + el.removeEventListener("DOMMouseScroll", wrap, false); | |
| 76 | + } | |
| 77 | + if(ename == "mousedown" && el == document && wrap){ // fix stopped mousedowns on the document | |
| 78 | + Ext.EventManager.stoppedMouseDownEvent.removeListener(wrap); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + var removeAll = function(el){ | |
| 83 | + el = Ext.getDom(el); | |
| 84 | + var id = Ext.id(el), es = elHash[id], ls; | |
| 85 | + if(es){ | |
| 86 | + for(var ename in es){ | |
| 87 | + if(es.hasOwnProperty(ename)){ | |
| 88 | + ls = es[ename]; | |
| 89 | + for(var i = 0, len = ls.length; i < len; i++){ | |
| 90 | + E.un(el, ename, ls[i].wrap); | |
| 91 | + ls[i] = null; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + es[ename] = null; | |
| 95 | + } | |
| 96 | + delete elHash[id]; | |
| 97 | + } | |
| 98 | + } | |
| 99 | + | |
| 100 | + var fireDocReady = function(){ | |
| 101 | + if(!docReadyState){ | |
| 102 | + docReadyState = Ext.isReady = true; | |
| 103 | + if(Ext.isGecko || Ext.isOpera) { | |
| 104 | + document.removeEventListener("DOMContentLoaded", fireDocReady, false); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + if(docReadyProcId){ | |
| 108 | + clearInterval(docReadyProcId); | |
| 109 | + docReadyProcId = null; | |
| 110 | + } | |
| 111 | + if(docReadyEvent){ | |
| 112 | + docReadyEvent.fire(); | |
| 113 | + docReadyEvent.clearListeners(); | |
| 114 | + } | |
| 115 | + }; | |
| 116 | + | |
| 117 | + var initDocReady = function(){ | |
| 118 | + docReadyEvent = new Ext.util.Event(); | |
| 119 | + | |
| 120 | + if(Ext.isReady){ | |
| 121 | + return; | |
| 122 | + } | |
| 123 | + | |
| 124 | + // no matter what, make sure it fires on load | |
| 125 | + E.on(window, 'load', fireDocReady); | |
| 126 | + | |
| 127 | + if(Ext.isGecko || Ext.isOpera) { | |
| 128 | + document.addEventListener('DOMContentLoaded', fireDocReady, false); | |
| 129 | + } | |
| 130 | + else if(Ext.isIE){ | |
| 131 | + docReadyProcId = setInterval(function(){ | |
| 132 | + try{ | |
| 133 | + // throws errors until DOM is ready | |
| 134 | + Ext.isReady || (document.documentElement.doScroll('left')); | |
| 135 | + }catch(e){ | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + fireDocReady(); // no errors, fire | |
| 139 | + }, 5); | |
| 140 | + | |
| 141 | + document.onreadystatechange = function(){ | |
| 142 | + if(document.readyState == 'complete'){ | |
| 143 | + document.onreadystatechange = null; | |
| 144 | + fireDocReady(); | |
| 145 | + } | |
| 146 | + }; | |
| 147 | + } | |
| 148 | + else if(Ext.isSafari){ | |
| 149 | + docReadyProcId = setInterval(function(){ | |
| 150 | + var rs = document.readyState; | |
| 151 | + if(rs == 'complete') { | |
| 152 | + fireDocReady(); | |
| 153 | + } | |
| 154 | + }, 10); | |
| 155 | + } | |
| 156 | + }; | |
| 157 | + | |
| 158 | + var createBuffered = function(h, o){ | |
| 159 | + var task = new Ext.util.DelayedTask(h); | |
| 160 | + return function(e){ | |
| 161 | + // create new event object impl so new events don't wipe out properties | |
| 162 | + e = new Ext.EventObjectImpl(e); | |
| 163 | + task.delay(o.buffer, h, null, [e]); | |
| 164 | + }; | |
| 165 | + }; | |
| 166 | + | |
| 167 | + var createSingle = function(h, el, ename, fn, scope){ | |
| 168 | + return function(e){ | |
| 169 | + Ext.EventManager.removeListener(el, ename, fn, scope); | |
| 170 | + h(e); | |
| 171 | + }; | |
| 172 | + }; | |
| 173 | + | |
| 174 | + var createDelayed = function(h, o){ | |
| 175 | + return function(e){ | |
| 176 | + // create new event object impl so new events don't wipe out properties | |
| 177 | + e = new Ext.EventObjectImpl(e); | |
| 178 | + setTimeout(function(){ | |
| 179 | + h(e); | |
| 180 | + }, o.delay || 10); | |
| 181 | + }; | |
| 182 | + }; | |
| 183 | + | |
| 184 | + var listen = function(element, ename, opt, fn, scope){ | |
| 185 | + var o = (!opt || typeof opt == "boolean") ? {} : opt; | |
| 186 | + fn = fn || o.fn; scope = scope || o.scope; | |
| 187 | + var el = Ext.getDom(element); | |
| 188 | + if(!el){ | |
| 189 | + throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.'; | |
| 190 | + } | |
| 191 | + var h = function(e){ | |
| 192 | + // prevent errors while unload occurring | |
| 193 | + if(!window[xname]){ | |
| 194 | + return; | |
| 195 | + } | |
| 196 | + e = Ext.EventObject.setEvent(e); | |
| 197 | + var t; | |
| 198 | + if(o.delegate){ | |
| 199 | + t = e.getTarget(o.delegate, el); | |
| 200 | + if(!t){ | |
| 201 | + return; | |
| 202 | + } | |
| 203 | + }else{ | |
| 204 | + t = e.target; | |
| 205 | + } | |
| 206 | + if(o.stopEvent === true){ | |
| 207 | + e.stopEvent(); | |
| 208 | + } | |
| 209 | + if(o.preventDefault === true){ | |
| 210 | + e.preventDefault(); | |
| 211 | + } | |
| 212 | + if(o.stopPropagation === true){ | |
| 213 | + e.stopPropagation(); | |
| 214 | + } | |
| 215 | + | |
| 216 | + if(o.normalized === false){ | |
| 217 | + e = e.browserEvent; | |
| 218 | + } | |
| 219 | + | |
| 220 | + fn.call(scope || el, e, t, o); | |
| 221 | + }; | |
| 222 | + if(o.delay){ | |
| 223 | + h = createDelayed(h, o); | |
| 224 | + } | |
| 225 | + if(o.single){ | |
| 226 | + h = createSingle(h, el, ename, fn, scope); | |
| 227 | + } | |
| 228 | + if(o.buffer){ | |
| 229 | + h = createBuffered(h, o); | |
| 230 | + } | |
| 231 | + | |
| 232 | + addListener(el, ename, fn, h, scope); | |
| 233 | + return h; | |
| 234 | + }; | |
| 235 | + | |
| 236 | + var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/; | |
| 237 | + var pub = { | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * Appends an event handler to an element. The shorthand version {@link #on} is equivalent. Typically you will | |
| 241 | + * use {@link Ext.Element#addListener} directly on an Element in favor of calling this version. | |
| 242 | + * @param {String/HTMLElement} el The html element or id to assign the event handler to | |
| 243 | + * @param {String} eventName The type of event to listen for | |
| 244 | + * @param {Function} handler The handler function the event invokes This function is passed | |
| 245 | + * the following parameters:<ul> | |
| 246 | + * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li> | |
| 247 | + * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event. | |
| 248 | + * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li> | |
| 249 | + * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li> | |
| 250 | + * </ul> | |
| 251 | + * @param {Object} scope (optional) The scope in which to execute the handler | |
| 252 | + * function (the handler function's "this" context) | |
| 253 | + * @param {Object} options (optional) An object containing handler configuration properties. | |
| 254 | + * This may contain any of the following properties:<ul> | |
| 255 | + * <li>scope {Object} : The scope in which to execute the handler function. The handler function's "this" context.</li> | |
| 256 | + * <li>delegate {String} : A simple selector to filter the target or look for a descendant of the target</li> | |
| 257 | + * <li>stopEvent {Boolean} : True to stop the event. That is stop propagation, and prevent the default action.</li> | |
| 258 | + * <li>preventDefault {Boolean} : True to prevent the default action</li> | |
| 259 | + * <li>stopPropagation {Boolean} : True to prevent event propagation</li> | |
| 260 | + * <li>normalized {Boolean} : False to pass a browser event to the handler function instead of an Ext.EventObject</li> | |
| 261 | + * <li>delay {Number} : The number of milliseconds to delay the invocation of the handler after te event fires.</li> | |
| 262 | + * <li>single {Boolean} : True to add a handler to handle just the next firing of the event, and then remove itself.</li> | |
| 263 | + * <li>buffer {Number} : Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed | |
| 264 | + * by the specified number of milliseconds. If the event fires again within that time, the original | |
| 265 | + * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li> | |
| 266 | + * </ul><br> | |
| 267 | + * <p>See {@link Ext.Element#addListener} for examples of how to use these options.</p> | |
| 268 | + */ | |
| 269 | + addListener : function(element, eventName, fn, scope, options){ | |
| 270 | + if(typeof eventName == "object"){ | |
| 271 | + var o = eventName; | |
| 272 | + for(var e in o){ | |
| 273 | + if(propRe.test(e)){ | |
| 274 | + continue; | |
| 275 | + } | |
| 276 | + if(typeof o[e] == "function"){ | |
| 277 | + // shared options | |
| 278 | + listen(element, e, o, o[e], o.scope); | |
| 279 | + }else{ | |
| 280 | + // individual options | |
| 281 | + listen(element, e, o[e]); | |
| 282 | + } | |
| 283 | + } | |
| 284 | + return; | |
| 285 | + } | |
| 286 | + return listen(element, eventName, options, fn, scope); | |
| 287 | + }, | |
| 288 | + | |
| 289 | + /** | |
| 290 | + * Removes an event handler from an element. The shorthand version {@link #un} is equivalent. Typically | |
| 291 | + * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version. | |
| 292 | + * @param {String/HTMLElement} el The id or html element from which to remove the event | |
| 293 | + * @param {String} eventName The type of event | |
| 294 | + * @param {Function} fn The handler function to remove | |
| 295 | + */ | |
| 296 | + removeListener : function(element, eventName, fn, scope){ | |
| 297 | + return removeListener(element, eventName, fn, scope); | |
| 298 | + }, | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * Removes all event handers from an element. Typically you will use {@link Ext.Element#removeAllListeners} | |
| 302 | + * directly on an Element in favor of calling this version. | |
| 303 | + * @param {String/HTMLElement} el The id or html element from which to remove the event | |
| 304 | + */ | |
| 305 | + removeAll : function(element){ | |
| 306 | + return removeAll(element); | |
| 307 | + }, | |
| 308 | + | |
| 309 | + /** | |
| 310 | + * Fires when the document is ready (before onload and before images are loaded). Can be | |
| 311 | + * accessed shorthanded as Ext.onReady(). | |
| 312 | + * @param {Function} fn The method the event invokes | |
| 313 | + * @param {Object} scope (optional) An object that becomes the scope of the handler | |
| 314 | + * @param {boolean} options (optional) An object containing standard {@link #addListener} options | |
| 315 | + */ | |
| 316 | + onDocumentReady : function(fn, scope, options){ | |
| 317 | + if(!docReadyEvent){ | |
| 318 | + initDocReady(); | |
| 319 | + } | |
| 320 | + if(docReadyState || Ext.isReady){ // if it already fired | |
| 321 | + options || (options = {}); | |
| 322 | + fn.defer(options.delay||0, scope); | |
| 323 | + }else{ | |
| 324 | + docReadyEvent.addListener(fn, scope, options); | |
| 325 | + } | |
| 326 | + }, | |
| 327 | + | |
| 328 | + /** | |
| 329 | + * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers. | |
| 330 | + * @param {Function} fn The method the event invokes | |
| 331 | + * @param {Object} scope An object that becomes the scope of the handler | |
| 332 | + * @param {boolean} options | |
| 333 | + */ | |
| 334 | + onWindowResize : function(fn, scope, options){ | |
| 335 | + if(!resizeEvent){ | |
| 336 | + resizeEvent = new Ext.util.Event(); | |
| 337 | + resizeTask = new Ext.util.DelayedTask(function(){ | |
| 338 | + resizeEvent.fire(D.getViewWidth(), D.getViewHeight()); | |
| 339 | + }); | |
| 340 | + E.on(window, "resize", this.fireWindowResize, this); | |
| 341 | + } | |
| 342 | + resizeEvent.addListener(fn, scope, options); | |
| 343 | + }, | |
| 344 | + | |
| 345 | + // exposed only to allow manual firing | |
| 346 | + fireWindowResize : function(){ | |
| 347 | + if(resizeEvent){ | |
| 348 | + if((Ext.isIE||Ext.isAir) && resizeTask){ | |
| 349 | + resizeTask.delay(50); | |
| 350 | + }else{ | |
| 351 | + resizeEvent.fire(D.getViewWidth(), D.getViewHeight()); | |
| 352 | + } | |
| 353 | + } | |
| 354 | + }, | |
| 355 | + | |
| 356 | + /** | |
| 357 | + * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size. | |
| 358 | + * @param {Function} fn The method the event invokes | |
| 359 | + * @param {Object} scope An object that becomes the scope of the handler | |
| 360 | + * @param {boolean} options | |
| 361 | + */ | |
| 362 | + onTextResize : function(fn, scope, options){ | |
| 363 | + if(!textEvent){ | |
| 364 | + textEvent = new Ext.util.Event(); | |
| 365 | + var textEl = new Ext.Element(document.createElement('div')); | |
| 366 | + textEl.dom.className = 'x-text-resize'; | |
| 367 | + textEl.dom.innerHTML = 'X'; | |
| 368 | + textEl.appendTo(document.body); | |
| 369 | + textSize = textEl.dom.offsetHeight; | |
| 370 | + setInterval(function(){ | |
| 371 | + if(textEl.dom.offsetHeight != textSize){ | |
| 372 | + textEvent.fire(textSize, textSize = textEl.dom.offsetHeight); | |
| 373 | + } | |
| 374 | + }, this.textResizeInterval); | |
| 375 | + } | |
| 376 | + textEvent.addListener(fn, scope, options); | |
| 377 | + }, | |
| 378 | + | |
| 379 | + /** | |
| 380 | + * Removes the passed window resize listener. | |
| 381 | + * @param {Function} fn The method the event invokes | |
| 382 | + * @param {Object} scope The scope of handler | |
| 383 | + */ | |
| 384 | + removeResizeListener : function(fn, scope){ | |
| 385 | + if(resizeEvent){ | |
| 386 | + resizeEvent.removeListener(fn, scope); | |
| 387 | + } | |
| 388 | + }, | |
| 389 | + | |
| 390 | + // private | |
| 391 | + fireResize : function(){ | |
| 392 | + if(resizeEvent){ | |
| 393 | + resizeEvent.fire(D.getViewWidth(), D.getViewHeight()); | |
| 394 | + } | |
| 395 | + }, | |
| 396 | + /** | |
| 397 | + * Url used for onDocumentReady with using SSL (defaults to Ext.SSL_SECURE_URL) | |
| 398 | + */ | |
| 399 | + ieDeferSrc : false, | |
| 400 | + /** | |
| 401 | + * The frequency, in milliseconds, to check for text resize events (defaults to 50) | |
| 402 | + */ | |
| 403 | + textResizeInterval : 50 | |
| 404 | + }; | |
| 405 | + /** | |
| 406 | + * Appends an event handler to an element. Shorthand for {@link #addListener}. | |
| 407 | + * @param {String/HTMLElement} el The html element or id to assign the event handler to | |
| 408 | + * @param {String} eventName The type of event to listen for | |
| 409 | + * @param {Function} handler The handler function the event invokes | |
| 410 | + * @param {Object} scope (optional) The scope in which to execute the handler | |
| 411 | + * function (the handler function's "this" context) | |
| 412 | + * @param {Object} options (optional) An object containing standard {@link #addListener} options | |
| 413 | + * @member Ext.EventManager | |
| 414 | + * @method on | |
| 415 | + */ | |
| 416 | + pub.on = pub.addListener; | |
| 417 | + /** | |
| 418 | + * Removes an event handler from an element. Shorthand for {@link #removeListener}. | |
| 419 | + * @param {String/HTMLElement} el The id or html element from which to remove the event | |
| 420 | + * @param {String} eventName The type of event | |
| 421 | + * @param {Function} fn The handler function to remove | |
| 422 | + * @return {Boolean} True if a listener was actually removed, else false | |
| 423 | + * @member Ext.EventManager | |
| 424 | + * @method un | |
| 425 | + */ | |
| 426 | + pub.un = pub.removeListener; | |
| 427 | + | |
| 428 | + pub.stoppedMouseDownEvent = new Ext.util.Event(); | |
| 429 | + return pub; | |
| 430 | +}(); | |
| 431 | +/** | |
| 432 | + * Fires when the document is ready (before onload and before images are loaded). Shorthand of {@link Ext.EventManager#onDocumentReady}. | |
| 433 | + * @param {Function} fn The method the event invokes | |
| 434 | + * @param {Object} scope An object that becomes the scope of the handler | |
| 435 | + * @param {boolean} override If true, the obj passed in becomes | |
| 436 | + * the execution scope of the listener | |
| 437 | + * @member Ext | |
| 438 | + * @method onReady | |
| 439 | + */ | |
| 440 | +Ext.onReady = Ext.EventManager.onDocumentReady; | |
| 441 | + | |
| 442 | + | |
| 443 | +// Initialize doc classes | |
| 444 | +(function(){ | |
| 445 | + var initExtCss = function(){ | |
| 446 | + // find the body element | |
| 447 | + var bd = document.body || document.getElementsByTagName('body')[0]; | |
| 448 | + if(!bd){ return false; } | |
| 449 | + var cls = [' ', | |
| 450 | + Ext.isIE ? "ext-ie " + (Ext.isIE6 ? 'ext-ie6' : 'ext-ie7') | |
| 451 | + : Ext.isGecko ? "ext-gecko " + (Ext.isGecko2 ? 'ext-gecko2' : 'ext-gecko3') | |
| 452 | + : Ext.isOpera ? "ext-opera" | |
| 453 | + : Ext.isSafari ? "ext-safari" : ""]; | |
| 454 | + | |
| 455 | + if(Ext.isMac){ | |
| 456 | + cls.push("ext-mac"); | |
| 457 | + } | |
| 458 | + if(Ext.isLinux){ | |
| 459 | + cls.push("ext-linux"); | |
| 460 | + } | |
| 461 | + if(Ext.isBorderBox){ | |
| 462 | + cls.push('ext-border-box'); | |
| 463 | + } | |
| 464 | + if(Ext.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie" | |
| 465 | + var p = bd.parentNode; | |
| 466 | + if(p){ | |
| 467 | + p.className += ' ext-strict'; | |
| 468 | + } | |
| 469 | + } | |
| 470 | + bd.className += cls.join(' '); | |
| 471 | + return true; | |
| 472 | + } | |
| 473 | + | |
| 474 | + if(!initExtCss()){ | |
| 475 | + Ext.onReady(initExtCss); | |
| 476 | + } | |
| 477 | +})(); | |
| 478 | + | |
| 479 | +/** | |
| 480 | + * @class Ext.EventObject | |
| 481 | + * EventObject exposes the Yahoo! UI Event functionality directly on the object | |
| 482 | + * passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code | |
| 483 | + * Example: | |
| 484 | + * <pre><code> | |
| 485 | + function handleClick(e){ // e is not a standard event object, it is a Ext.EventObject | |
| 486 | + e.preventDefault(); | |
| 487 | + var target = e.getTarget(); | |
| 488 | + ... | |
| 489 | + } | |
| 490 | + var myDiv = Ext.get("myDiv"); | |
| 491 | + myDiv.on("click", handleClick); | |
| 492 | + //or | |
| 493 | + Ext.EventManager.on("myDiv", 'click', handleClick); | |
| 494 | + Ext.EventManager.addListener("myDiv", 'click', handleClick); | |
| 495 | + </code></pre> | |
| 496 | + * @singleton | |
| 497 | + */ | |
| 498 | +Ext.EventObject = function(){ | |
| 499 | + | |
| 500 | + var E = Ext.lib.Event; | |
| 501 | + | |
| 502 | + // safari keypress events for special keys return bad keycodes | |
| 503 | + var safariKeys = { | |
| 504 | + 3 : 13, // enter | |
| 505 | + 63234 : 37, // left | |
| 506 | + 63235 : 39, // right | |
| 507 | + 63232 : 38, // up | |
| 508 | + 63233 : 40, // down | |
| 509 | + 63276 : 33, // page up | |
| 510 | + 63277 : 34, // page down | |
| 511 | + 63272 : 46, // delete | |
| 512 | + 63273 : 36, // home | |
| 513 | + 63275 : 35 // end | |
| 514 | + }; | |
| 515 | + | |
| 516 | + // normalize button clicks | |
| 517 | + var btnMap = Ext.isIE ? {1:0,4:1,2:2} : | |
| 518 | + (Ext.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2}); | |
| 519 | + | |
| 520 | + Ext.EventObjectImpl = function(e){ | |
| 521 | + if(e){ | |
| 522 | + this.setEvent(e.browserEvent || e); | |
| 523 | + } | |
| 524 | + }; | |
| 525 | + | |
| 526 | + Ext.EventObjectImpl.prototype = { | |
| 527 | + /** The normal browser event */ | |
| 528 | + browserEvent : null, | |
| 529 | + /** The button pressed in a mouse event */ | |
| 530 | + button : -1, | |
| 531 | + /** True if the shift key was down during the event */ | |
| 532 | + shiftKey : false, | |
| 533 | + /** True if the control key was down during the event */ | |
| 534 | + ctrlKey : false, | |
| 535 | + /** True if the alt key was down during the event */ | |
| 536 | + altKey : false, | |
| 537 | + | |
| 538 | + /** Key constant @type Number */ | |
| 539 | + BACKSPACE: 8, | |
| 540 | + /** Key constant @type Number */ | |
| 541 | + TAB: 9, | |
| 542 | + /** Key constant @type Number */ | |
| 543 | + NUM_CENTER: 12, | |
| 544 | + /** Key constant @type Number */ | |
| 545 | + ENTER: 13, | |
| 546 | + /** Key constant @type Number */ | |
| 547 | + RETURN: 13, | |
| 548 | + /** Key constant @type Number */ | |
| 549 | + SHIFT: 16, | |
| 550 | + /** Key constant @type Number */ | |
| 551 | + CTRL: 17, | |
| 552 | + CONTROL : 17, // legacy | |
| 553 | + /** Key constant @type Number */ | |
| 554 | + ALT: 18, | |
| 555 | + /** Key constant @type Number */ | |
| 556 | + PAUSE: 19, | |
| 557 | + /** Key constant @type Number */ | |
| 558 | + CAPS_LOCK: 20, | |
| 559 | + /** Key constant @type Number */ | |
| 560 | + ESC: 27, | |
| 561 | + /** Key constant @type Number */ | |
| 562 | + SPACE: 32, | |
| 563 | + /** Key constant @type Number */ | |
| 564 | + PAGE_UP: 33, | |
| 565 | + PAGEUP : 33, // legacy | |
| 566 | + /** Key constant @type Number */ | |
| 567 | + PAGE_DOWN: 34, | |
| 568 | + PAGEDOWN : 34, // legacy | |
| 569 | + /** Key constant @type Number */ | |
| 570 | + END: 35, | |
| 571 | + /** Key constant @type Number */ | |
| 572 | + HOME: 36, | |
| 573 | + /** Key constant @type Number */ | |
| 574 | + LEFT: 37, | |
| 575 | + /** Key constant @type Number */ | |
| 576 | + UP: 38, | |
| 577 | + /** Key constant @type Number */ | |
| 578 | + RIGHT: 39, | |
| 579 | + /** Key constant @type Number */ | |
| 580 | + DOWN: 40, | |
| 581 | + /** Key constant @type Number */ | |
| 582 | + PRINT_SCREEN: 44, | |
| 583 | + /** Key constant @type Number */ | |
| 584 | + INSERT: 45, | |
| 585 | + /** Key constant @type Number */ | |
| 586 | + DELETE: 46, | |
| 587 | + /** Key constant @type Number */ | |
| 588 | + ZERO: 48, | |
| 589 | + /** Key constant @type Number */ | |
| 590 | + ONE: 49, | |
| 591 | + /** Key constant @type Number */ | |
| 592 | + TWO: 50, | |
| 593 | + /** Key constant @type Number */ | |
| 594 | + THREE: 51, | |
| 595 | + /** Key constant @type Number */ | |
| 596 | + FOUR: 52, | |
| 597 | + /** Key constant @type Number */ | |
| 598 | + FIVE: 53, | |
| 599 | + /** Key constant @type Number */ | |
| 600 | + SIX: 54, | |
| 601 | + /** Key constant @type Number */ | |
| 602 | + SEVEN: 55, | |
| 603 | + /** Key constant @type Number */ | |
| 604 | + EIGHT: 56, | |
| 605 | + /** Key constant @type Number */ | |
| 606 | + NINE: 57, | |
| 607 | + /** Key constant @type Number */ | |
| 608 | + A: 65, | |
| 609 | + /** Key constant @type Number */ | |
| 610 | + B: 66, | |
| 611 | + /** Key constant @type Number */ | |
| 612 | + C: 67, | |
| 613 | + /** Key constant @type Number */ | |
| 614 | + D: 68, | |
| 615 | + /** Key constant @type Number */ | |
| 616 | + E: 69, | |
| 617 | + /** Key constant @type Number */ | |
| 618 | + F: 70, | |
| 619 | + /** Key constant @type Number */ | |
| 620 | + G: 71, | |
| 621 | + /** Key constant @type Number */ | |
| 622 | + H: 72, | |
| 623 | + /** Key constant @type Number */ | |
| 624 | + I: 73, | |
| 625 | + /** Key constant @type Number */ | |
| 626 | + J: 74, | |
| 627 | + /** Key constant @type Number */ | |
| 628 | + K: 75, | |
| 629 | + /** Key constant @type Number */ | |
| 630 | + L: 76, | |
| 631 | + /** Key constant @type Number */ | |
| 632 | + M: 77, | |
| 633 | + /** Key constant @type Number */ | |
| 634 | + N: 78, | |
| 635 | + /** Key constant @type Number */ | |
| 636 | + O: 79, | |
| 637 | + /** Key constant @type Number */ | |
| 638 | + P: 80, | |
| 639 | + /** Key constant @type Number */ | |
| 640 | + Q: 81, | |
| 641 | + /** Key constant @type Number */ | |
| 642 | + R: 82, | |
| 643 | + /** Key constant @type Number */ | |
| 644 | + S: 83, | |
| 645 | + /** Key constant @type Number */ | |
| 646 | + T: 84, | |
| 647 | + /** Key constant @type Number */ | |
| 648 | + U: 85, | |
| 649 | + /** Key constant @type Number */ | |
| 650 | + V: 86, | |
| 651 | + /** Key constant @type Number */ | |
| 652 | + W: 87, | |
| 653 | + /** Key constant @type Number */ | |
| 654 | + X: 88, | |
| 655 | + /** Key constant @type Number */ | |
| 656 | + Y: 89, | |
| 657 | + /** Key constant @type Number */ | |
| 658 | + Z: 90, | |
| 659 | + /** Key constant @type Number */ | |
| 660 | + CONTEXT_MENU: 93, | |
| 661 | + /** Key constant @type Number */ | |
| 662 | + NUM_ZERO: 96, | |
| 663 | + /** Key constant @type Number */ | |
| 664 | + NUM_ONE: 97, | |
| 665 | + /** Key constant @type Number */ | |
| 666 | + NUM_TWO: 98, | |
| 667 | + /** Key constant @type Number */ | |
| 668 | + NUM_THREE: 99, | |
| 669 | + /** Key constant @type Number */ | |
| 670 | + NUM_FOUR: 100, | |
| 671 | + /** Key constant @type Number */ | |
| 672 | + NUM_FIVE: 101, | |
| 673 | + /** Key constant @type Number */ | |
| 674 | + NUM_SIX: 102, | |
| 675 | + /** Key constant @type Number */ | |
| 676 | + NUM_SEVEN: 103, | |
| 677 | + /** Key constant @type Number */ | |
| 678 | + NUM_EIGHT: 104, | |
| 679 | + /** Key constant @type Number */ | |
| 680 | + NUM_NINE: 105, | |
| 681 | + /** Key constant @type Number */ | |
| 682 | + NUM_MULTIPLY: 106, | |
| 683 | + /** Key constant @type Number */ | |
| 684 | + NUM_PLUS: 107, | |
| 685 | + /** Key constant @type Number */ | |
| 686 | + NUM_MINUS: 109, | |
| 687 | + /** Key constant @type Number */ | |
| 688 | + NUM_PERIOD: 110, | |
| 689 | + /** Key constant @type Number */ | |
| 690 | + NUM_DIVISION: 111, | |
| 691 | + /** Key constant @type Number */ | |
| 692 | + F1: 112, | |
| 693 | + /** Key constant @type Number */ | |
| 694 | + F2: 113, | |
| 695 | + /** Key constant @type Number */ | |
| 696 | + F3: 114, | |
| 697 | + /** Key constant @type Number */ | |
| 698 | + F4: 115, | |
| 699 | + /** Key constant @type Number */ | |
| 700 | + F5: 116, | |
| 701 | + /** Key constant @type Number */ | |
| 702 | + F6: 117, | |
| 703 | + /** Key constant @type Number */ | |
| 704 | + F7: 118, | |
| 705 | + /** Key constant @type Number */ | |
| 706 | + F8: 119, | |
| 707 | + /** Key constant @type Number */ | |
| 708 | + F9: 120, | |
| 709 | + /** Key constant @type Number */ | |
| 710 | + F10: 121, | |
| 711 | + /** Key constant @type Number */ | |
| 712 | + F11: 122, | |
| 713 | + /** Key constant @type Number */ | |
| 714 | + F12: 123, | |
| 715 | + | |
| 716 | + /** @private */ | |
| 717 | + setEvent : function(e){ | |
| 718 | + if(e == this || (e && e.browserEvent)){ // already wrapped | |
| 719 | + return e; | |
| 720 | + } | |
| 721 | + this.browserEvent = e; | |
| 722 | + if(e){ | |
| 723 | + // normalize buttons | |
| 724 | + this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1); | |
| 725 | + if(e.type == 'click' && this.button == -1){ | |
| 726 | + this.button = 0; | |
| 727 | + } | |
| 728 | + this.type = e.type; | |
| 729 | + this.shiftKey = e.shiftKey; | |
| 730 | + // mac metaKey behaves like ctrlKey | |
| 731 | + this.ctrlKey = e.ctrlKey || e.metaKey; | |
| 732 | + this.altKey = e.altKey; | |
| 733 | + // in getKey these will be normalized for the mac | |
| 734 | + this.keyCode = e.keyCode; | |
| 735 | + this.charCode = e.charCode; | |
| 736 | + // cache the target for the delayed and or buffered events | |
| 737 | + this.target = E.getTarget(e); | |
| 738 | + // same for XY | |
| 739 | + this.xy = E.getXY(e); | |
| 740 | + }else{ | |
| 741 | + this.button = -1; | |
| 742 | + this.shiftKey = false; | |
| 743 | + this.ctrlKey = false; | |
| 744 | + this.altKey = false; | |
| 745 | + this.keyCode = 0; | |
| 746 | + this.charCode = 0; | |
| 747 | + this.target = null; | |
| 748 | + this.xy = [0, 0]; | |
| 749 | + } | |
| 750 | + return this; | |
| 751 | + }, | |
| 752 | + | |
| 753 | + /** | |
| 754 | + * Stop the event (preventDefault and stopPropagation) | |
| 755 | + */ | |
| 756 | + stopEvent : function(){ | |
| 757 | + if(this.browserEvent){ | |
| 758 | + if(this.browserEvent.type == 'mousedown'){ | |
| 759 | + Ext.EventManager.stoppedMouseDownEvent.fire(this); | |
| 760 | + } | |
| 761 | + E.stopEvent(this.browserEvent); | |
| 762 | + } | |
| 763 | + }, | |
| 764 | + | |
| 765 | + /** | |
| 766 | + * Prevents the browsers default handling of the event. | |
| 767 | + */ | |
| 768 | + preventDefault : function(){ | |
| 769 | + if(this.browserEvent){ | |
| 770 | + E.preventDefault(this.browserEvent); | |
| 771 | + } | |
| 772 | + }, | |
| 773 | + | |
| 774 | + /** @private */ | |
| 775 | + isNavKeyPress : function(){ | |
| 776 | + var k = this.keyCode; | |
| 777 | + k = Ext.isSafari ? (safariKeys[k] || k) : k; | |
| 778 | + return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC; | |
| 779 | + }, | |
| 780 | + | |
| 781 | + isSpecialKey : function(){ | |
| 782 | + var k = this.keyCode; | |
| 783 | + return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 || | |
| 784 | + (k == 16) || (k == 17) || | |
| 785 | + (k >= 18 && k <= 20) || | |
| 786 | + (k >= 33 && k <= 35) || | |
| 787 | + (k >= 36 && k <= 39) || | |
| 788 | + (k >= 44 && k <= 45); | |
| 789 | + }, | |
| 790 | + | |
| 791 | + /** | |
| 792 | + * Cancels bubbling of the event. | |
| 793 | + */ | |
| 794 | + stopPropagation : function(){ | |
| 795 | + if(this.browserEvent){ | |
| 796 | + if(this.browserEvent.type == 'mousedown'){ | |
| 797 | + Ext.EventManager.stoppedMouseDownEvent.fire(this); | |
| 798 | + } | |
| 799 | + E.stopPropagation(this.browserEvent); | |
| 800 | + } | |
| 801 | + }, | |
| 802 | + | |
| 803 | + /** | |
| 804 | + * Gets the character code for the event. | |
| 805 | + * @return {Number} | |
| 806 | + */ | |
| 807 | + getCharCode : function(){ | |
| 808 | + return this.charCode || this.keyCode; | |
| 809 | + }, | |
| 810 | + | |
| 811 | + /** | |
| 812 | + * Returns a normalized keyCode for the event. | |
| 813 | + * @return {Number} The key code | |
| 814 | + */ | |
| 815 | + getKey : function(){ | |
| 816 | + var k = this.keyCode || this.charCode; | |
| 817 | + return Ext.isSafari ? (safariKeys[k] || k) : k; | |
| 818 | + }, | |
| 819 | + | |
| 820 | + /** | |
| 821 | + * Gets the x coordinate of the event. | |
| 822 | + * @return {Number} | |
| 823 | + */ | |
| 824 | + getPageX : function(){ | |
| 825 | + return this.xy[0]; | |
| 826 | + }, | |
| 827 | + | |
| 828 | + /** | |
| 829 | + * Gets the y coordinate of the event. | |
| 830 | + * @return {Number} | |
| 831 | + */ | |
| 832 | + getPageY : function(){ | |
| 833 | + return this.xy[1]; | |
| 834 | + }, | |
| 835 | + | |
| 836 | + /** | |
| 837 | + * Gets the time of the event. | |
| 838 | + * @return {Number} | |
| 839 | + */ | |
| 840 | + getTime : function(){ | |
| 841 | + if(this.browserEvent){ | |
| 842 | + return E.getTime(this.browserEvent); | |
| 843 | + } | |
| 844 | + return null; | |
| 845 | + }, | |
| 846 | + | |
| 847 | + /** | |
| 848 | + * Gets the page coordinates of the event. | |
| 849 | + * @return {Array} The xy values like [x, y] | |
| 850 | + */ | |
| 851 | + getXY : function(){ | |
| 852 | + return this.xy; | |
| 853 | + }, | |
| 854 | + | |
| 855 | + /** | |
| 856 | + * Gets the target for the event. | |
| 857 | + * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target | |
| 858 | + * @param {Number/Mixed} maxDepth (optional) The max depth to | |
| 859 | + search as a number or element (defaults to 10 || document.body) | |
| 860 | + * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node | |
| 861 | + * @return {HTMLelement} | |
| 862 | + */ | |
| 863 | + getTarget : function(selector, maxDepth, returnEl){ | |
| 864 | + return selector ? Ext.fly(this.target).findParent(selector, maxDepth, returnEl) : (returnEl ? Ext.get(this.target) : this.target); | |
| 865 | + }, | |
| 866 | + | |
| 867 | + /** | |
| 868 | + * Gets the related target. | |
| 869 | + * @return {HTMLElement} | |
| 870 | + */ | |
| 871 | + getRelatedTarget : function(){ | |
| 872 | + if(this.browserEvent){ | |
| 873 | + return E.getRelatedTarget(this.browserEvent); | |
| 874 | + } | |
| 875 | + return null; | |
| 876 | + }, | |
| 877 | + | |
| 878 | + /** | |
| 879 | + * Normalizes mouse wheel delta across browsers | |
| 880 | + * @return {Number} The delta | |
| 881 | + */ | |
| 882 | + getWheelDelta : function(){ | |
| 883 | + var e = this.browserEvent; | |
| 884 | + var delta = 0; | |
| 885 | + if(e.wheelDelta){ /* IE/Opera. */ | |
| 886 | + delta = e.wheelDelta/120; | |
| 887 | + }else if(e.detail){ /* Mozilla case. */ | |
| 888 | + delta = -e.detail/3; | |
| 889 | + } | |
| 890 | + return delta; | |
| 891 | + }, | |
| 892 | + | |
| 893 | + /** | |
| 894 | + * Returns true if the control, meta, shift or alt key was pressed during this event. | |
| 895 | + * @return {Boolean} | |
| 896 | + */ | |
| 897 | + hasModifier : function(){ | |
| 898 | + return ((this.ctrlKey || this.altKey) || this.shiftKey) ? true : false; | |
| 899 | + }, | |
| 900 | + | |
| 901 | + /** | |
| 902 | + * Returns true if the target of this event is a child of el. If the target is el, it returns false. | |
| 903 | + * Example usage:<pre><code> | |
| 904 | +// Handle click on any child of an element | |
| 905 | +Ext.getBody().on('click', function(e){ | |
| 906 | + if(e.within('some-el')){ | |
| 907 | + alert('Clicked on a child of some-el!'); | |
| 908 | + } | |
| 909 | +}); | |
| 910 | + | |
| 911 | +// Handle click directly on an element, ignoring clicks on child nodes | |
| 912 | +Ext.getBody().on('click', function(e,t){ | |
| 913 | + if((t.id == 'some-el') && !e.within(t, true)){ | |
| 914 | + alert('Clicked directly on some-el!'); | |
| 915 | + } | |
| 916 | +}); | |
| 917 | +</code></pre> | |
| 918 | + * @param {Mixed} el The id, DOM element or Ext.Element to check | |
| 919 | + * @param {Boolean} related (optional) true to test if the related target is within el instead of the target | |
| 920 | + * @return {Boolean} | |
| 921 | + */ | |
| 922 | + within : function(el, related){ | |
| 923 | + var t = this[related ? "getRelatedTarget" : "getTarget"](); | |
| 924 | + return t && Ext.fly(el).contains(t); | |
| 925 | + }, | |
| 926 | + | |
| 927 | + getPoint : function(){ | |
| 928 | + return new Ext.lib.Point(this.xy[0], this.xy[1]); | |
| 929 | + } | |
| 930 | + }; | |
| 931 | + | |
| 932 | + return new Ext.EventObjectImpl(); | |
| 933 | +}(); | |
| 0 | 934 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/core/Ext.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | + | |
| 10 | +Ext = {version: '2.2'}; | |
| 11 | + | |
| 12 | +// for old browsers | |
| 13 | +window["undefined"] = window["undefined"]; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * @class Ext | |
| 17 | + * Ext core utilities and functions. | |
| 18 | + * @singleton | |
| 19 | + */ | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * Copies all the properties of config to obj. | |
| 23 | + * @param {Object} obj The receiver of the properties | |
| 24 | + * @param {Object} config The source of the properties | |
| 25 | + * @param {Object} defaults A different object that will also be applied for default values | |
| 26 | + * @return {Object} returns obj | |
| 27 | + * @member Ext apply | |
| 28 | + */ | |
| 29 | +Ext.apply = function(o, c, defaults){ | |
| 30 | + if(defaults){ | |
| 31 | + // no "this" reference for friendly out of scope calls | |
| 32 | + Ext.apply(o, defaults); | |
| 33 | + } | |
| 34 | + if(o && c && typeof c == 'object'){ | |
| 35 | + for(var p in c){ | |
| 36 | + o[p] = c[p]; | |
| 37 | + } | |
| 38 | + } | |
| 39 | + return o; | |
| 40 | +}; | |
| 41 | + | |
| 42 | +(function(){ | |
| 43 | + var idSeed = 0; | |
| 44 | + var ua = navigator.userAgent.toLowerCase(); | |
| 45 | + | |
| 46 | + var isStrict = document.compatMode == "CSS1Compat", | |
| 47 | + isOpera = ua.indexOf("opera") > -1, | |
| 48 | + isSafari = (/webkit|khtml/).test(ua), | |
| 49 | + isSafari3 = isSafari && ua.indexOf('webkit/5') != -1, | |
| 50 | + isIE = !isOpera && ua.indexOf("msie") > -1, | |
| 51 | + isIE7 = !isOpera && ua.indexOf("msie 7") > -1, | |
| 52 | + isGecko = !isSafari && ua.indexOf("gecko") > -1, | |
| 53 | + isGecko3 = !isSafari && ua.indexOf("rv:1.9") > -1, | |
| 54 | + isBorderBox = isIE && !isStrict, | |
| 55 | + isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1), | |
| 56 | + isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1), | |
| 57 | + isAir = (ua.indexOf("adobeair") != -1), | |
| 58 | + isLinux = (ua.indexOf("linux") != -1), | |
| 59 | + isSecure = window.location.href.toLowerCase().indexOf("https") === 0; | |
| 60 | + | |
| 61 | + // remove css image flicker | |
| 62 | + if(isIE && !isIE7){ | |
| 63 | + try{ | |
| 64 | + document.execCommand("BackgroundImageCache", false, true); | |
| 65 | + }catch(e){} | |
| 66 | + } | |
| 67 | + | |
| 68 | + Ext.apply(Ext, { | |
| 69 | + /** | |
| 70 | + * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode | |
| 71 | + * @type Boolean | |
| 72 | + */ | |
| 73 | + isStrict : isStrict, | |
| 74 | + /** | |
| 75 | + * True if the page is running over SSL | |
| 76 | + * @type Boolean | |
| 77 | + */ | |
| 78 | + isSecure : isSecure, | |
| 79 | + /** | |
| 80 | + * True when the document is fully initialized and ready for action | |
| 81 | + * @type Boolean | |
| 82 | + */ | |
| 83 | + isReady : false, | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * True to automatically uncache orphaned Ext.Elements periodically (defaults to true) | |
| 87 | + * @type Boolean | |
| 88 | + */ | |
| 89 | + enableGarbageCollector : true, | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * True to automatically purge event listeners after uncaching an element (defaults to false). | |
| 93 | + * Note: this only happens if enableGarbageCollector is true. | |
| 94 | + * @type Boolean | |
| 95 | + */ | |
| 96 | + enableListenerCollection:false, | |
| 97 | + | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent | |
| 101 | + * the IE insecure content warning (defaults to javascript:false). | |
| 102 | + * @type String | |
| 103 | + */ | |
| 104 | + SSL_SECURE_URL : "javascript:false", | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images. (Defaults to | |
| 108 | + * "http://extjs.com/s.gif" and you should change this to a URL on your server). | |
| 109 | + * @type String | |
| 110 | + */ | |
| 111 | + BLANK_IMAGE_URL : "http:/"+"/extjs.com/s.gif", | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * A reusable empty function | |
| 115 | + * @property | |
| 116 | + * @type Function | |
| 117 | + */ | |
| 118 | + emptyFn : function(){}, | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * Copies all the properties of config to obj if they don't already exist. | |
| 122 | + * @param {Object} obj The receiver of the properties | |
| 123 | + * @param {Object} config The source of the properties | |
| 124 | + * @return {Object} returns obj | |
| 125 | + */ | |
| 126 | + applyIf : function(o, c){ | |
| 127 | + if(o && c){ | |
| 128 | + for(var p in c){ | |
| 129 | + if(typeof o[p] == "undefined"){ o[p] = c[p]; } | |
| 130 | + } | |
| 131 | + } | |
| 132 | + return o; | |
| 133 | + }, | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Applies event listeners to elements by selectors when the document is ready. | |
| 137 | + * The event name is specified with an @ suffix. | |
| 138 | +<pre><code> | |
| 139 | +Ext.addBehaviors({ | |
| 140 | + // add a listener for click on all anchors in element with id foo | |
| 141 | + '#foo a@click' : function(e, t){ | |
| 142 | + // do something | |
| 143 | + }, | |
| 144 | + | |
| 145 | + // add the same listener to multiple selectors (separated by comma BEFORE the @) | |
| 146 | + '#foo a, #bar span.some-class@mouseover' : function(){ | |
| 147 | + // do something | |
| 148 | + } | |
| 149 | +}); | |
| 150 | +</code></pre> | |
| 151 | + * @param {Object} obj The list of behaviors to apply | |
| 152 | + */ | |
| 153 | + addBehaviors : function(o){ | |
| 154 | + if(!Ext.isReady){ | |
| 155 | + Ext.onReady(function(){ | |
| 156 | + Ext.addBehaviors(o); | |
| 157 | + }); | |
| 158 | + return; | |
| 159 | + } | |
| 160 | + var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times | |
| 161 | + for(var b in o){ | |
| 162 | + var parts = b.split('@'); | |
| 163 | + if(parts[1]){ // for Object prototype breakers | |
| 164 | + var s = parts[0]; | |
| 165 | + if(!cache[s]){ | |
| 166 | + cache[s] = Ext.select(s); | |
| 167 | + } | |
| 168 | + cache[s].on(parts[1], o[b]); | |
| 169 | + } | |
| 170 | + } | |
| 171 | + cache = null; | |
| 172 | + }, | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Generates unique ids. If the element already has an id, it is unchanged | |
| 176 | + * @param {Mixed} el (optional) The element to generate an id for | |
| 177 | + * @param {String} prefix (optional) Id prefix (defaults "ext-gen") | |
| 178 | + * @return {String} The generated Id. | |
| 179 | + */ | |
| 180 | + id : function(el, prefix){ | |
| 181 | + prefix = prefix || "ext-gen"; | |
| 182 | + el = Ext.getDom(el); | |
| 183 | + var id = prefix + (++idSeed); | |
| 184 | + return el ? (el.id ? el.id : (el.id = id)) : id; | |
| 185 | + }, | |
| 186 | + | |
| 187 | + /** | |
| 188 | + * Extends one class with another class and optionally overrides members with the passed literal. This class | |
| 189 | + * also adds the function "override()" to the class that can be used to override | |
| 190 | + * members on an instance. | |
| 191 | + * * <p> | |
| 192 | + * This function also supports a 2-argument call in which the subclass's constructor is | |
| 193 | + * not passed as an argument. In this form, the parameters are as follows:</p><p> | |
| 194 | + * <div class="mdetail-params"><ul> | |
| 195 | + * <li><code>superclass</code> | |
| 196 | + * <div class="sub-desc">The class being extended</div></li> | |
| 197 | + * <li><code>overrides</code> | |
| 198 | + * <div class="sub-desc">A literal with members which are copied into the subclass's | |
| 199 | + * prototype, and are therefore shared among all instances of the new class.<p> | |
| 200 | + * This may contain a special member named <tt><b>constructor</b></tt>. This is used | |
| 201 | + * to define the constructor of the new class, and is returned. If this property is | |
| 202 | + * <i>not</i> specified, a constructor is generated and returned which just calls the | |
| 203 | + * superclass's constructor passing on its parameters.</p></div></li> | |
| 204 | + * </ul></div></p><p> | |
| 205 | + * For example, to create a subclass of the Ext GridPanel: | |
| 206 | + * <pre><code> | |
| 207 | + MyGridPanel = Ext.extend(Ext.grid.GridPanel, { | |
| 208 | + constructor: function(config) { | |
| 209 | + // Your preprocessing here | |
| 210 | + MyGridPanel.superclass.constructor.apply(this, arguments); | |
| 211 | + // Your postprocessing here | |
| 212 | + }, | |
| 213 | + | |
| 214 | + yourMethod: function() { | |
| 215 | + // etc. | |
| 216 | + } | |
| 217 | + }); | |
| 218 | +</code></pre> | |
| 219 | + * </p> | |
| 220 | + * @param {Function} subclass The class inheriting the functionality | |
| 221 | + * @param {Function} superclass The class being extended | |
| 222 | + * @param {Object} overrides (optional) A literal with members which are copied into the subclass's | |
| 223 | + * prototype, and are therefore shared between all instances of the new class. | |
| 224 | + * @return {Function} The subclass constructor. | |
| 225 | + * @method extend | |
| 226 | + */ | |
| 227 | + extend : function(){ | |
| 228 | + // inline overrides | |
| 229 | + var io = function(o){ | |
| 230 | + for(var m in o){ | |
| 231 | + this[m] = o[m]; | |
| 232 | + } | |
| 233 | + }; | |
| 234 | + var oc = Object.prototype.constructor; | |
| 235 | + | |
| 236 | + return function(sb, sp, overrides){ | |
| 237 | + if(typeof sp == 'object'){ | |
| 238 | + overrides = sp; | |
| 239 | + sp = sb; | |
| 240 | + sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);}; | |
| 241 | + } | |
| 242 | + var F = function(){}, sbp, spp = sp.prototype; | |
| 243 | + F.prototype = spp; | |
| 244 | + sbp = sb.prototype = new F(); | |
| 245 | + sbp.constructor=sb; | |
| 246 | + sb.superclass=spp; | |
| 247 | + if(spp.constructor == oc){ | |
| 248 | + spp.constructor=sp; | |
| 249 | + } | |
| 250 | + sb.override = function(o){ | |
| 251 | + Ext.override(sb, o); | |
| 252 | + }; | |
| 253 | + sbp.override = io; | |
| 254 | + Ext.override(sb, overrides); | |
| 255 | + sb.extend = function(o){Ext.extend(sb, o);}; | |
| 256 | + return sb; | |
| 257 | + }; | |
| 258 | + }(), | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name. | |
| 262 | + * Usage:<pre><code> | |
| 263 | +Ext.override(MyClass, { | |
| 264 | + newMethod1: function(){ | |
| 265 | + // etc. | |
| 266 | + }, | |
| 267 | + newMethod2: function(foo){ | |
| 268 | + // etc. | |
| 269 | + } | |
| 270 | +}); | |
| 271 | + </code></pre> | |
| 272 | + * @param {Object} origclass The class to override | |
| 273 | + * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal | |
| 274 | + * containing one or more methods. | |
| 275 | + * @method override | |
| 276 | + */ | |
| 277 | + override : function(origclass, overrides){ | |
| 278 | + if(overrides){ | |
| 279 | + var p = origclass.prototype; | |
| 280 | + for(var method in overrides){ | |
| 281 | + p[method] = overrides[method]; | |
| 282 | + } | |
| 283 | + } | |
| 284 | + }, | |
| 285 | + | |
| 286 | + /** | |
| 287 | + * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage: | |
| 288 | + * <pre><code> | |
| 289 | +Ext.namespace('Company', 'Company.data'); | |
| 290 | +Company.Widget = function() { ... } | |
| 291 | +Company.data.CustomStore = function(config) { ... } | |
| 292 | +</code></pre> | |
| 293 | + * @param {String} namespace1 | |
| 294 | + * @param {String} namespace2 | |
| 295 | + * @param {String} etc | |
| 296 | + * @method namespace | |
| 297 | + */ | |
| 298 | + namespace : function(){ | |
| 299 | + var a=arguments, o=null, i, j, d, rt; | |
| 300 | + for (i=0; i<a.length; ++i) { | |
| 301 | + d=a[i].split("."); | |
| 302 | + rt = d[0]; | |
| 303 | + eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';'); | |
| 304 | + for (j=1; j<d.length; ++j) { | |
| 305 | + o[d[j]]=o[d[j]] || {}; | |
| 306 | + o=o[d[j]]; | |
| 307 | + } | |
| 308 | + } | |
| 309 | + }, | |
| 310 | + | |
| 311 | + /** | |
| 312 | + * Takes an object and converts it to an encoded URL. e.g. Ext.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value. | |
| 313 | + * @param {Object} o | |
| 314 | + * @return {String} | |
| 315 | + */ | |
| 316 | + urlEncode : function(o){ | |
| 317 | + if(!o){ | |
| 318 | + return ""; | |
| 319 | + } | |
| 320 | + var buf = []; | |
| 321 | + for(var key in o){ | |
| 322 | + var ov = o[key], k = encodeURIComponent(key); | |
| 323 | + var type = typeof ov; | |
| 324 | + if(type == 'undefined'){ | |
| 325 | + buf.push(k, "=&"); | |
| 326 | + }else if(type != "function" && type != "object"){ | |
| 327 | + buf.push(k, "=", encodeURIComponent(ov), "&"); | |
| 328 | + }else if(Ext.isArray(ov)){ | |
| 329 | + if (ov.length) { | |
| 330 | + for(var i = 0, len = ov.length; i < len; i++) { | |
| 331 | + buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&"); | |
| 332 | + } | |
| 333 | + } else { | |
| 334 | + buf.push(k, "=&"); | |
| 335 | + } | |
| 336 | + } | |
| 337 | + } | |
| 338 | + buf.pop(); | |
| 339 | + return buf.join(""); | |
| 340 | + }, | |
| 341 | + | |
| 342 | + /** | |
| 343 | + * Takes an encoded URL and and converts it to an object. e.g. Ext.urlDecode("foo=1&bar=2"); would return {foo: 1, bar: 2} or Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", true); would return {foo: 1, bar: [2, 3, 4]}. | |
| 344 | + * @param {String} string | |
| 345 | + * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false). | |
| 346 | + * @return {Object} A literal with members | |
| 347 | + */ | |
| 348 | + urlDecode : function(string, overwrite){ | |
| 349 | + if(!string || !string.length){ | |
| 350 | + return {}; | |
| 351 | + } | |
| 352 | + var obj = {}; | |
| 353 | + var pairs = string.split('&'); | |
| 354 | + var pair, name, value; | |
| 355 | + for(var i = 0, len = pairs.length; i < len; i++){ | |
| 356 | + pair = pairs[i].split('='); | |
| 357 | + name = decodeURIComponent(pair[0]); | |
| 358 | + value = decodeURIComponent(pair[1]); | |
| 359 | + if(overwrite !== true){ | |
| 360 | + if(typeof obj[name] == "undefined"){ | |
| 361 | + obj[name] = value; | |
| 362 | + }else if(typeof obj[name] == "string"){ | |
| 363 | + obj[name] = [obj[name]]; | |
| 364 | + obj[name].push(value); | |
| 365 | + }else{ | |
| 366 | + obj[name].push(value); | |
| 367 | + } | |
| 368 | + }else{ | |
| 369 | + obj[name] = value; | |
| 370 | + } | |
| 371 | + } | |
| 372 | + return obj; | |
| 373 | + }, | |
| 374 | + | |
| 375 | + /** | |
| 376 | + * Iterates an array calling the passed function with each item, stopping if your function returns false. If the | |
| 377 | + * passed array is not really an array, your function is called once with it. | |
| 378 | + * The supplied function is called with (Object item, Number index, Array allItems). | |
| 379 | + * @param {Array/NodeList/Mixed} array | |
| 380 | + * @param {Function} fn | |
| 381 | + * @param {Object} scope | |
| 382 | + */ | |
| 383 | + each : function(array, fn, scope){ | |
| 384 | + if(typeof array.length == "undefined" || typeof array == "string"){ | |
| 385 | + array = [array]; | |
| 386 | + } | |
| 387 | + for(var i = 0, len = array.length; i < len; i++){ | |
| 388 | + if(fn.call(scope || array[i], array[i], i, array) === false){ return i; }; | |
| 389 | + } | |
| 390 | + }, | |
| 391 | + | |
| 392 | + // deprecated | |
| 393 | + combine : function(){ | |
| 394 | + var as = arguments, l = as.length, r = []; | |
| 395 | + for(var i = 0; i < l; i++){ | |
| 396 | + var a = as[i]; | |
| 397 | + if(Ext.isArray(a)){ | |
| 398 | + r = r.concat(a); | |
| 399 | + }else if(a.length !== undefined && !a.substr){ | |
| 400 | + r = r.concat(Array.prototype.slice.call(a, 0)); | |
| 401 | + }else{ | |
| 402 | + r.push(a); | |
| 403 | + } | |
| 404 | + } | |
| 405 | + return r; | |
| 406 | + }, | |
| 407 | + | |
| 408 | + /** | |
| 409 | + * Escapes the passed string for use in a regular expression | |
| 410 | + * @param {String} str | |
| 411 | + * @return {String} | |
| 412 | + */ | |
| 413 | + escapeRe : function(s) { | |
| 414 | + return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1"); | |
| 415 | + }, | |
| 416 | + | |
| 417 | + // internal | |
| 418 | + callback : function(cb, scope, args, delay){ | |
| 419 | + if(typeof cb == "function"){ | |
| 420 | + if(delay){ | |
| 421 | + cb.defer(delay, scope, args || []); | |
| 422 | + }else{ | |
| 423 | + cb.apply(scope, args || []); | |
| 424 | + } | |
| 425 | + } | |
| 426 | + }, | |
| 427 | + | |
| 428 | + /** | |
| 429 | + * Return the dom node for the passed string (id), dom node, or Ext.Element | |
| 430 | + * @param {Mixed} el | |
| 431 | + * @return HTMLElement | |
| 432 | + */ | |
| 433 | + getDom : function(el){ | |
| 434 | + if(!el || !document){ | |
| 435 | + return null; | |
| 436 | + } | |
| 437 | + return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el); | |
| 438 | + }, | |
| 439 | + | |
| 440 | + /** | |
| 441 | + * Returns the current HTML document object as an {@link Ext.Element}. | |
| 442 | + * @return Ext.Element The document | |
| 443 | + */ | |
| 444 | + getDoc : function(){ | |
| 445 | + return Ext.get(document); | |
| 446 | + }, | |
| 447 | + | |
| 448 | + /** | |
| 449 | + * Returns the current document body as an {@link Ext.Element}. | |
| 450 | + * @return Ext.Element The document body | |
| 451 | + */ | |
| 452 | + getBody : function(){ | |
| 453 | + return Ext.get(document.body || document.documentElement); | |
| 454 | + }, | |
| 455 | + | |
| 456 | + /** | |
| 457 | + * Shorthand for {@link Ext.ComponentMgr#get} | |
| 458 | + * @param {String} id | |
| 459 | + * @return Ext.Component | |
| 460 | + */ | |
| 461 | + getCmp : function(id){ | |
| 462 | + return Ext.ComponentMgr.get(id); | |
| 463 | + }, | |
| 464 | + | |
| 465 | + /** | |
| 466 | + * Utility method for validating that a value is numeric, returning the specified default value if it is not. | |
| 467 | + * @param {Mixed} value Should be a number, but any type will be handled appropriately | |
| 468 | + * @param {Number} defaultValue The value to return if the original value is non-numeric | |
| 469 | + * @return {Number} Value, if numeric, else defaultValue | |
| 470 | + */ | |
| 471 | + num : function(v, defaultValue){ | |
| 472 | + if(typeof v != 'number'){ | |
| 473 | + return defaultValue; | |
| 474 | + } | |
| 475 | + return v; | |
| 476 | + }, | |
| 477 | + | |
| 478 | + /** | |
| 479 | + * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the | |
| 480 | + * DOM (if applicable) and calling their destroy functions (if available). This method is primarily | |
| 481 | + * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of | |
| 482 | + * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be | |
| 483 | + * passed into this function in a single call as separate arguments. | |
| 484 | + * @param {Mixed} arg1 An {@link Ext.Element} or {@link Ext.Component} to destroy | |
| 485 | + * @param {Mixed} arg2 (optional) | |
| 486 | + * @param {Mixed} etc... (optional) | |
| 487 | + */ | |
| 488 | + destroy : function(){ | |
| 489 | + for(var i = 0, a = arguments, len = a.length; i < len; i++) { | |
| 490 | + var as = a[i]; | |
| 491 | + if(as){ | |
| 492 | + if(typeof as.destroy == 'function'){ | |
| 493 | + as.destroy(); | |
| 494 | + } | |
| 495 | + else if(as.dom){ | |
| 496 | + as.removeAllListeners(); | |
| 497 | + as.remove(); | |
| 498 | + } | |
| 499 | + } | |
| 500 | + } | |
| 501 | + }, | |
| 502 | + | |
| 503 | + /** | |
| 504 | + * Removes a DOM node from the document. The body node will be ignored if passed in. | |
| 505 | + * @param {HTMLElement} node The node to remove | |
| 506 | + */ | |
| 507 | + removeNode : isIE ? function(){ | |
| 508 | + var d; | |
| 509 | + return function(n){ | |
| 510 | + if(n && n.tagName != 'BODY'){ | |
| 511 | + d = d || document.createElement('div'); | |
| 512 | + d.appendChild(n); | |
| 513 | + d.innerHTML = ''; | |
| 514 | + } | |
| 515 | + } | |
| 516 | + }() : function(n){ | |
| 517 | + if(n && n.parentNode && n.tagName != 'BODY'){ | |
| 518 | + n.parentNode.removeChild(n); | |
| 519 | + } | |
| 520 | + }, | |
| 521 | + | |
| 522 | + // inpired by a similar function in mootools library | |
| 523 | + /** | |
| 524 | + * Returns the type of object that is passed in. If the object passed in is null or undefined it | |
| 525 | + * return false otherwise it returns one of the following values:<ul> | |
| 526 | + * <li><b>string</b>: If the object passed is a string</li> | |
| 527 | + * <li><b>number</b>: If the object passed is a number</li> | |
| 528 | + * <li><b>boolean</b>: If the object passed is a boolean value</li> | |
| 529 | + * <li><b>function</b>: If the object passed is a function reference</li> | |
| 530 | + * <li><b>object</b>: If the object passed is an object</li> | |
| 531 | + * <li><b>array</b>: If the object passed is an array</li> | |
| 532 | + * <li><b>regexp</b>: If the object passed is a regular expression</li> | |
| 533 | + * <li><b>element</b>: If the object passed is a DOM Element</li> | |
| 534 | + * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li> | |
| 535 | + * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li> | |
| 536 | + * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li> | |
| 537 | + * @param {Mixed} object | |
| 538 | + * @return {String} | |
| 539 | + */ | |
| 540 | + type : function(o){ | |
| 541 | + if(o === undefined || o === null){ | |
| 542 | + return false; | |
| 543 | + } | |
| 544 | + if(o.htmlElement){ | |
| 545 | + return 'element'; | |
| 546 | + } | |
| 547 | + var t = typeof o; | |
| 548 | + if(t == 'object' && o.nodeName) { | |
| 549 | + switch(o.nodeType) { | |
| 550 | + case 1: return 'element'; | |
| 551 | + case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace'; | |
| 552 | + } | |
| 553 | + } | |
| 554 | + if(t == 'object' || t == 'function') { | |
| 555 | + switch(o.constructor) { | |
| 556 | + case Array: return 'array'; | |
| 557 | + case RegExp: return 'regexp'; | |
| 558 | + } | |
| 559 | + if(typeof o.length == 'number' && typeof o.item == 'function') { | |
| 560 | + return 'nodelist'; | |
| 561 | + } | |
| 562 | + } | |
| 563 | + return t; | |
| 564 | + }, | |
| 565 | + | |
| 566 | + /** | |
| 567 | + * Returns true if the passed value is null, undefined or an empty string (optional). | |
| 568 | + * @param {Mixed} value The value to test | |
| 569 | + * @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty | |
| 570 | + * @return {Boolean} | |
| 571 | + */ | |
| 572 | + isEmpty : function(v, allowBlank){ | |
| 573 | + return v === null || v === undefined || (!allowBlank ? v === '' : false); | |
| 574 | + }, | |
| 575 | + | |
| 576 | + value : function(v, defaultValue, allowBlank){ | |
| 577 | + return Ext.isEmpty(v, allowBlank) ? defaultValue : v; | |
| 578 | + }, | |
| 579 | + | |
| 580 | + /** | |
| 581 | + * Returns true if the passed object is a JavaScript array, otherwise false. | |
| 582 | + * @param {Object} The object to test | |
| 583 | + * @return {Boolean} | |
| 584 | + */ | |
| 585 | + isArray : function(v){ | |
| 586 | + return v && typeof v.length == 'number' && typeof v.splice == 'function'; | |
| 587 | + }, | |
| 588 | + | |
| 589 | + /** | |
| 590 | + * Returns true if the passed object is a JavaScript date object, otherwise false. | |
| 591 | + * @param {Object} The object to test | |
| 592 | + * @return {Boolean} | |
| 593 | + */ | |
| 594 | + isDate : function(v){ | |
| 595 | + return v && typeof v.getFullYear == 'function'; | |
| 596 | + }, | |
| 597 | + | |
| 598 | + /** | |
| 599 | + * True if the detected browser is Opera. | |
| 600 | + * @type Boolean | |
| 601 | + */ | |
| 602 | + isOpera : isOpera, | |
| 603 | + /** | |
| 604 | + * True if the detected browser is Safari. | |
| 605 | + * @type Boolean | |
| 606 | + */ | |
| 607 | + isSafari : isSafari, | |
| 608 | + /** | |
| 609 | + * True if the detected browser is Safari 3.x. | |
| 610 | + * @type Boolean | |
| 611 | + */ | |
| 612 | + isSafari3 : isSafari3, | |
| 613 | + /** | |
| 614 | + * True if the detected browser is Safari 2.x. | |
| 615 | + * @type Boolean | |
| 616 | + */ | |
| 617 | + isSafari2 : isSafari && !isSafari3, | |
| 618 | + /** | |
| 619 | + * True if the detected browser is Internet Explorer. | |
| 620 | + * @type Boolean | |
| 621 | + */ | |
| 622 | + isIE : isIE, | |
| 623 | + /** | |
| 624 | + * True if the detected browser is Internet Explorer 6.x. | |
| 625 | + * @type Boolean | |
| 626 | + */ | |
| 627 | + isIE6 : isIE && !isIE7, | |
| 628 | + /** | |
| 629 | + * True if the detected browser is Internet Explorer 7.x. | |
| 630 | + * @type Boolean | |
| 631 | + */ | |
| 632 | + isIE7 : isIE7, | |
| 633 | + /** | |
| 634 | + * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox). | |
| 635 | + * @type Boolean | |
| 636 | + */ | |
| 637 | + isGecko : isGecko, | |
| 638 | + /** | |
| 639 | + * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x). | |
| 640 | + * @type Boolean | |
| 641 | + */ | |
| 642 | + isGecko2 : isGecko && !isGecko3, | |
| 643 | + /** | |
| 644 | + * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x). | |
| 645 | + * @type Boolean | |
| 646 | + */ | |
| 647 | + isGecko3 : isGecko3, | |
| 648 | + /** | |
| 649 | + * True if the detected browser is Internet Explorer running in non-strict mode. | |
| 650 | + * @type Boolean | |
| 651 | + */ | |
| 652 | + isBorderBox : isBorderBox, | |
| 653 | + /** | |
| 654 | + * True if the detected platform is Linux. | |
| 655 | + * @type Boolean | |
| 656 | + */ | |
| 657 | + isLinux : isLinux, | |
| 658 | + /** | |
| 659 | + * True if the detected platform is Windows. | |
| 660 | + * @type Boolean | |
| 661 | + */ | |
| 662 | + isWindows : isWindows, | |
| 663 | + /** | |
| 664 | + * True if the detected platform is Mac OS. | |
| 665 | + * @type Boolean | |
| 666 | + */ | |
| 667 | + isMac : isMac, | |
| 668 | + /** | |
| 669 | + * True if the detected platform is Adobe Air. | |
| 670 | + * @type Boolean | |
| 671 | + */ | |
| 672 | + isAir : isAir, | |
| 673 | + | |
| 674 | + /** | |
| 675 | + * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash, | |
| 676 | + * you may want to set this to true. | |
| 677 | + * @type Boolean | |
| 678 | + */ | |
| 679 | + useShims : ((isIE && !isIE7) || (isMac && isGecko && !isGecko3)) | |
| 680 | + }); | |
| 681 | + | |
| 682 | + // in intellij using keyword "namespace" causes parsing errors | |
| 683 | + Ext.ns = Ext.namespace; | |
| 684 | +})(); | |
| 685 | + | |
| 686 | +Ext.ns("Ext", "Ext.util", "Ext.grid", "Ext.dd", "Ext.tree", "Ext.data", | |
| 687 | + "Ext.form", "Ext.menu", "Ext.state", "Ext.lib", "Ext.layout", "Ext.app", "Ext.ux"); | |
| 688 | + | |
| 689 | + | |
| 690 | +/** | |
| 691 | + * @class Function | |
| 692 | + * These functions are available on every Function object (any JavaScript function). | |
| 693 | + */ | |
| 694 | +Ext.apply(Function.prototype, { | |
| 695 | + /** | |
| 696 | + * Creates a callback that passes arguments[0], arguments[1], arguments[2], ... | |
| 697 | + * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code> | |
| 698 | + * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the | |
| 699 | + * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always | |
| 700 | + * executes in the window scope. | |
| 701 | + * <p>This method is required when you want to pass arguments to a callback function. If no arguments | |
| 702 | + * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn). | |
| 703 | + * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function | |
| 704 | + * would simply execute immediately when the code is parsed. Example usage: | |
| 705 | + * <pre><code> | |
| 706 | +var sayHi = function(name){ | |
| 707 | + alert('Hi, ' + name); | |
| 708 | +} | |
| 709 | + | |
| 710 | +// clicking the button alerts "Hi, Fred" | |
| 711 | +new Ext.Button({ | |
| 712 | + text: 'Say Hi', | |
| 713 | + renderTo: Ext.getBody(), | |
| 714 | + handler: sayHi.createCallback('Fred') | |
| 715 | +}); | |
| 716 | +</code></pre> | |
| 717 | + * @return {Function} The new function | |
| 718 | + */ | |
| 719 | + createCallback : function(/*args...*/){ | |
| 720 | + // make args available, in function below | |
| 721 | + var args = arguments; | |
| 722 | + var method = this; | |
| 723 | + return function() { | |
| 724 | + return method.apply(window, args); | |
| 725 | + }; | |
| 726 | + }, | |
| 727 | + | |
| 728 | + /** | |
| 729 | + * Creates a delegate (callback) that sets the scope to obj. | |
| 730 | + * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code> | |
| 731 | + * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the | |
| 732 | + * callback points to obj. Example usage: | |
| 733 | + * <pre><code> | |
| 734 | +var sayHi = function(name){ | |
| 735 | + // Note this use of "this.text" here. This function expects to | |
| 736 | + // execute within a scope that contains a text property. In this | |
| 737 | + // example, the "this" variable is pointing to the btn object that | |
| 738 | + // was passed in createDelegate below. | |
| 739 | + alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.'); | |
| 740 | +} | |
| 741 | + | |
| 742 | +var btn = new Ext.Button({ | |
| 743 | + text: 'Say Hi', | |
| 744 | + renderTo: Ext.getBody() | |
| 745 | +}); | |
| 746 | + | |
| 747 | +// This callback will execute in the scope of the | |
| 748 | +// button instance. Clicking the button alerts | |
| 749 | +// "Hi, Fred. You clicked the "Say Hi" button." | |
| 750 | +btn.on('click', sayHi.createDelegate(btn, ['Fred'])); | |
| 751 | +</code></pre> | |
| 752 | + * @param {Object} obj (optional) The object for which the scope is set | |
| 753 | + * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) | |
| 754 | + * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding, | |
| 755 | + * if a number the args are inserted at the specified position | |
| 756 | + * @return {Function} The new function | |
| 757 | + */ | |
| 758 | + createDelegate : function(obj, args, appendArgs){ | |
| 759 | + var method = this; | |
| 760 | + return function() { | |
| 761 | + var callArgs = args || arguments; | |
| 762 | + if(appendArgs === true){ | |
| 763 | + callArgs = Array.prototype.slice.call(arguments, 0); | |
| 764 | + callArgs = callArgs.concat(args); | |
| 765 | + }else if(typeof appendArgs == "number"){ | |
| 766 | + callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first | |
| 767 | + var applyArgs = [appendArgs, 0].concat(args); // create method call params | |
| 768 | + Array.prototype.splice.apply(callArgs, applyArgs); // splice them in | |
| 769 | + } | |
| 770 | + return method.apply(obj || window, callArgs); | |
| 771 | + }; | |
| 772 | + }, | |
| 773 | + | |
| 774 | + /** | |
| 775 | + * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage: | |
| 776 | + * <pre><code> | |
| 777 | +var sayHi = function(name){ | |
| 778 | + alert('Hi, ' + name); | |
| 779 | +} | |
| 780 | + | |
| 781 | +// executes immediately: | |
| 782 | +sayHi('Fred'); | |
| 783 | + | |
| 784 | +// executes after 2 seconds: | |
| 785 | +sayHi.defer(2000, this, ['Fred']); | |
| 786 | + | |
| 787 | +// this syntax is sometimes useful for deferring | |
| 788 | +// execution of an anonymous function: | |
| 789 | +(function(){ | |
| 790 | + alert('Anonymous'); | |
| 791 | +}).defer(100); | |
| 792 | +</code></pre> | |
| 793 | + * @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately) | |
| 794 | + * @param {Object} obj (optional) The object for which the scope is set | |
| 795 | + * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) | |
| 796 | + * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding, | |
| 797 | + * if a number the args are inserted at the specified position | |
| 798 | + * @return {Number} The timeout id that can be used with clearTimeout | |
| 799 | + */ | |
| 800 | + defer : function(millis, obj, args, appendArgs){ | |
| 801 | + var fn = this.createDelegate(obj, args, appendArgs); | |
| 802 | + if(millis){ | |
| 803 | + return setTimeout(fn, millis); | |
| 804 | + } | |
| 805 | + fn(); | |
| 806 | + return 0; | |
| 807 | + }, | |
| 808 | + | |
| 809 | + /** | |
| 810 | + * Create a combined function call sequence of the original function + the passed function. | |
| 811 | + * The resulting function returns the results of the original function. | |
| 812 | + * The passed fcn is called with the parameters of the original function. Example usage: | |
| 813 | + * <pre><code> | |
| 814 | +var sayHi = function(name){ | |
| 815 | + alert('Hi, ' + name); | |
| 816 | +} | |
| 817 | + | |
| 818 | +sayHi('Fred'); // alerts "Hi, Fred" | |
| 819 | + | |
| 820 | +var sayGoodbye = sayHi.createSequence(function(name){ | |
| 821 | + alert('Bye, ' + name); | |
| 822 | +}); | |
| 823 | + | |
| 824 | +sayGoodbye('Fred'); // both alerts show | |
| 825 | +</code></pre> | |
| 826 | + * @param {Function} fcn The function to sequence | |
| 827 | + * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window) | |
| 828 | + * @return {Function} The new function | |
| 829 | + */ | |
| 830 | + createSequence : function(fcn, scope){ | |
| 831 | + if(typeof fcn != "function"){ | |
| 832 | + return this; | |
| 833 | + } | |
| 834 | + var method = this; | |
| 835 | + return function() { | |
| 836 | + var retval = method.apply(this || window, arguments); | |
| 837 | + fcn.apply(scope || this || window, arguments); | |
| 838 | + return retval; | |
| 839 | + }; | |
| 840 | + }, | |
| 841 | + | |
| 842 | + /** | |
| 843 | + * Creates an interceptor function. The passed fcn is called before the original one. If it returns false, | |
| 844 | + * the original one is not called. The resulting function returns the results of the original function. | |
| 845 | + * The passed fcn is called with the parameters of the original function. Example usage: | |
| 846 | + * <pre><code> | |
| 847 | +var sayHi = function(name){ | |
| 848 | + alert('Hi, ' + name); | |
| 849 | +} | |
| 850 | + | |
| 851 | +sayHi('Fred'); // alerts "Hi, Fred" | |
| 852 | + | |
| 853 | +// create a new function that validates input without | |
| 854 | +// directly modifying the original function: | |
| 855 | +var sayHiToFriend = sayHi.createInterceptor(function(name){ | |
| 856 | + return name == 'Brian'; | |
| 857 | +}); | |
| 858 | + | |
| 859 | +sayHiToFriend('Fred'); // no alert | |
| 860 | +sayHiToFriend('Brian'); // alerts "Hi, Brian" | |
| 861 | +</code></pre> | |
| 862 | + * @param {Function} fcn The function to call before the original | |
| 863 | + * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window) | |
| 864 | + * @return {Function} The new function | |
| 865 | + */ | |
| 866 | + createInterceptor : function(fcn, scope){ | |
| 867 | + if(typeof fcn != "function"){ | |
| 868 | + return this; | |
| 869 | + } | |
| 870 | + var method = this; | |
| 871 | + return function() { | |
| 872 | + fcn.target = this; | |
| 873 | + fcn.method = method; | |
| 874 | + if(fcn.apply(scope || this || window, arguments) === false){ | |
| 875 | + return; | |
| 876 | + } | |
| 877 | + return method.apply(this || window, arguments); | |
| 878 | + }; | |
| 879 | + } | |
| 880 | +}); | |
| 881 | + | |
| 882 | +/** | |
| 883 | + * @class String | |
| 884 | + * These functions are available as static methods on the JavaScript String object. | |
| 885 | + */ | |
| 886 | +Ext.applyIf(String, { | |
| 887 | + | |
| 888 | + /** | |
| 889 | + * Escapes the passed string for ' and \ | |
| 890 | + * @param {String} string The string to escape | |
| 891 | + * @return {String} The escaped string | |
| 892 | + * @static | |
| 893 | + */ | |
| 894 | + escape : function(string) { | |
| 895 | + return string.replace(/('|\\)/g, "\\$1"); | |
| 896 | + }, | |
| 897 | + | |
| 898 | + /** | |
| 899 | + * Pads the left side of a string with a specified character. This is especially useful | |
| 900 | + * for normalizing number and date strings. Example usage: | |
| 901 | + * <pre><code> | |
| 902 | +var s = String.leftPad('123', 5, '0'); | |
| 903 | +// s now contains the string: '00123' | |
| 904 | +</code></pre> | |
| 905 | + * @param {String} string The original string | |
| 906 | + * @param {Number} size The total length of the output string | |
| 907 | + * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ") | |
| 908 | + * @return {String} The padded string | |
| 909 | + * @static | |
| 910 | + */ | |
| 911 | + leftPad : function (val, size, ch) { | |
| 912 | + var result = new String(val); | |
| 913 | + if(!ch) { | |
| 914 | + ch = " "; | |
| 915 | + } | |
| 916 | + while (result.length < size) { | |
| 917 | + result = ch + result; | |
| 918 | + } | |
| 919 | + return result.toString(); | |
| 920 | + }, | |
| 921 | + | |
| 922 | + /** | |
| 923 | + * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each | |
| 924 | + * token must be unique, and must increment in the format {0}, {1}, etc. Example usage: | |
| 925 | + * <pre><code> | |
| 926 | +var cls = 'my-class', text = 'Some text'; | |
| 927 | +var s = String.format('<div class="{0}">{1}</div>', cls, text); | |
| 928 | +// s now contains the string: '<div class="my-class">Some text</div>' | |
| 929 | +</code></pre> | |
| 930 | + * @param {String} string The tokenized string to be formatted | |
| 931 | + * @param {String} value1 The value to replace token {0} | |
| 932 | + * @param {String} value2 Etc... | |
| 933 | + * @return {String} The formatted string | |
| 934 | + * @static | |
| 935 | + */ | |
| 936 | + format : function(format){ | |
| 937 | + var args = Array.prototype.slice.call(arguments, 1); | |
| 938 | + return format.replace(/\{(\d+)\}/g, function(m, i){ | |
| 939 | + return args[i]; | |
| 940 | + }); | |
| 941 | + } | |
| 942 | +}); | |
| 943 | + | |
| 944 | +/** | |
| 945 | + * Utility function that allows you to easily switch a string between two alternating values. The passed value | |
| 946 | + * is compared to the current string, and if they are equal, the other value that was passed in is returned. If | |
| 947 | + * they are already different, the first value passed in is returned. Note that this method returns the new value | |
| 948 | + * but does not change the current string. | |
| 949 | + * <pre><code> | |
| 950 | +// alternate sort directions | |
| 951 | +sort = sort.toggle('ASC', 'DESC'); | |
| 952 | + | |
| 953 | +// instead of conditional logic: | |
| 954 | +sort = (sort == 'ASC' ? 'DESC' : 'ASC'); | |
| 955 | +</code></pre> | |
| 956 | + * @param {String} value The value to compare to the current string | |
| 957 | + * @param {String} other The new value to use if the string already equals the first value passed in | |
| 958 | + * @return {String} The new value | |
| 959 | + */ | |
| 960 | +String.prototype.toggle = function(value, other){ | |
| 961 | + return this == value ? other : value; | |
| 962 | +}; | |
| 963 | + | |
| 964 | +/** | |
| 965 | + * Trims whitespace from either end of a string, leaving spaces within the string intact. Example: | |
| 966 | + * <pre><code> | |
| 967 | +var s = ' foo bar '; | |
| 968 | +alert('-' + s + '-'); //alerts "- foo bar -" | |
| 969 | +alert('-' + s.trim() + '-'); //alerts "-foo bar-" | |
| 970 | +</code></pre> | |
| 971 | + * @return {String} The trimmed string | |
| 972 | + */ | |
| 973 | +String.prototype.trim = function(){ | |
| 974 | + var re = /^\s+|\s+$/g; | |
| 975 | + return function(){ return this.replace(re, ""); }; | |
| 976 | +}(); | |
| 977 | +/** | |
| 978 | + * @class Number | |
| 979 | + */ | |
| 980 | +Ext.applyIf(Number.prototype, { | |
| 981 | + /** | |
| 982 | + * Checks whether or not the current number is within a desired range. If the number is already within the | |
| 983 | + * range it is returned, otherwise the min or max value is returned depending on which side of the range is | |
| 984 | + * exceeded. Note that this method returns the constrained value but does not change the current number. | |
| 985 | + * @param {Number} min The minimum number in the range | |
| 986 | + * @param {Number} max The maximum number in the range | |
| 987 | + * @return {Number} The constrained value if outside the range, otherwise the current value | |
| 988 | + */ | |
| 989 | + constrain : function(min, max){ | |
| 990 | + return Math.min(Math.max(this, min), max); | |
| 991 | + } | |
| 992 | +}); | |
| 993 | +/** | |
| 994 | + * @class Array | |
| 995 | + */ | |
| 996 | +Ext.applyIf(Array.prototype, { | |
| 997 | + /** | |
| 998 | + * Checks whether or not the specified object exists in the array. | |
| 999 | + * @param {Object} o The object to check for | |
| 1000 | + * @return {Number} The index of o in the array (or -1 if it is not found) | |
| 1001 | + */ | |
| 1002 | + indexOf : function(o){ | |
| 1003 | + for (var i = 0, len = this.length; i < len; i++){ | |
| 1004 | + if(this[i] == o) return i; | |
| 1005 | + } | |
| 1006 | + return -1; | |
| 1007 | + }, | |
| 1008 | + | |
| 1009 | + /** | |
| 1010 | + * Removes the specified object from the array. If the object is not found nothing happens. | |
| 1011 | + * @param {Object} o The object to remove | |
| 1012 | + * @return {Array} this array | |
| 1013 | + */ | |
| 1014 | + remove : function(o){ | |
| 1015 | + var index = this.indexOf(o); | |
| 1016 | + if(index != -1){ | |
| 1017 | + this.splice(index, 1); | |
| 1018 | + } | |
| 1019 | + return this; | |
| 1020 | + } | |
| 1021 | +}); | |
| 1022 | + | |
| 1023 | +/** | |
| 1024 | + Returns the number of milliseconds between this date and date | |
| 1025 | + @param {Date} date (optional) Defaults to now | |
| 1026 | + @return {Number} The diff in milliseconds | |
| 1027 | + @member Date getElapsed | |
| 1028 | + */ | |
| 1029 | +Date.prototype.getElapsed = function(date) { | |
| 1030 | + return Math.abs((date || new Date()).getTime()-this.getTime()); | |
| 1031 | +}; | ... | ... |
thirdpartyjs/extjs/source/core/Fx.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | + | |
| 10 | +//Notifies Element that fx methods are available | |
| 11 | +Ext.enableFx = true; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * @class Ext.Fx | |
| 15 | + * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied | |
| 16 | + * to the {@link Ext.Element} interface when included, so all effects calls should be performed via Element. | |
| 17 | + * Conversely, since the effects are not actually defined in Element, Ext.Fx <b>must</b> be included in order for the | |
| 18 | + * Element effects to work.</p><br/> | |
| 19 | + * | |
| 20 | + * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that | |
| 21 | + * they return the Element object itself as the method return value, it is not always possible to mix the two in a single | |
| 22 | + * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced. | |
| 23 | + * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason, | |
| 24 | + * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the | |
| 25 | + * expected results and should be done with care.</p><br/> | |
| 26 | + * | |
| 27 | + * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element | |
| 28 | + * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p> | |
| 29 | +<pre> | |
| 30 | +Value Description | |
| 31 | +----- ----------------------------- | |
| 32 | +tl The top left corner | |
| 33 | +t The center of the top edge | |
| 34 | +tr The top right corner | |
| 35 | +l The center of the left edge | |
| 36 | +r The center of the right edge | |
| 37 | +bl The bottom left corner | |
| 38 | +b The center of the bottom edge | |
| 39 | +br The bottom right corner | |
| 40 | +</pre> | |
| 41 | + * <b>Although some Fx methods accept specific custom config parameters, the ones shown in the Config Options section | |
| 42 | + * below are common options that can be passed to any Fx method.</b> | |
| 43 | + * | |
| 44 | + * @cfg {Function} callback A function called when the effect is finished. Note that effects are queued internally by the | |
| 45 | + * Fx class, so do not need to use the callback parameter to specify another effect -- effects can simply be chained together | |
| 46 | + * and called in sequence (e.g., el.slideIn().highlight();). The callback is intended for any additional code that should | |
| 47 | + * run once a particular effect has completed. The Element being operated upon is passed as the first parameter. | |
| 48 | + * @cfg {Object} scope The scope of the effect function | |
| 49 | + * @cfg {String} easing A valid Easing value for the effect | |
| 50 | + * @cfg {String} afterCls A css class to apply after the effect | |
| 51 | + * @cfg {Number} duration The length of time (in seconds) that the effect should last | |
| 52 | + * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes | |
| 53 | + * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to | |
| 54 | + * effects that end with the element being visually hidden, ignored otherwise) | |
| 55 | + * @cfg {String/Object/Function} afterStyle A style specification string, e.g. "width:100px", or an object in the form {width:"100px"}, or | |
| 56 | + * a function which returns such a specification that will be applied to the Element after the effect finishes | |
| 57 | + * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs | |
| 58 | + * @cfg {Boolean} concurrent Whether to allow subsequently-queued effects to run at the same time as the current effect, or to ensure that they run in sequence | |
| 59 | + * @cfg {Boolean} stopFx Whether subsequent effects should be stopped and removed after the current effect finishes | |
| 60 | + */ | |
| 61 | +Ext.Fx = { | |
| 62 | + /** | |
| 63 | + * Slides the element into view. An anchor point can be optionally passed to set the point of | |
| 64 | + * origin for the slide effect. This function automatically handles wrapping the element with | |
| 65 | + * a fixed-size container if needed. See the Fx class overview for valid anchor point options. | |
| 66 | + * Usage: | |
| 67 | + *<pre><code> | |
| 68 | +// default: slide the element in from the top | |
| 69 | +el.slideIn(); | |
| 70 | + | |
| 71 | +// custom: slide the element in from the right with a 2-second duration | |
| 72 | +el.slideIn('r', { duration: 2 }); | |
| 73 | + | |
| 74 | +// common config options shown with default values | |
| 75 | +el.slideIn('t', { | |
| 76 | + easing: 'easeOut', | |
| 77 | + duration: .5 | |
| 78 | +}); | |
| 79 | +</code></pre> | |
| 80 | + * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't') | |
| 81 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 82 | + * @return {Ext.Element} The Element | |
| 83 | + */ | |
| 84 | + slideIn : function(anchor, o){ | |
| 85 | + var el = this.getFxEl(); | |
| 86 | + o = o || {}; | |
| 87 | + | |
| 88 | + el.queueFx(o, function(){ | |
| 89 | + | |
| 90 | + anchor = anchor || "t"; | |
| 91 | + | |
| 92 | + // fix display to visibility | |
| 93 | + this.fixDisplay(); | |
| 94 | + | |
| 95 | + // restore values after effect | |
| 96 | + var r = this.getFxRestore(); | |
| 97 | + var b = this.getBox(); | |
| 98 | + // fixed size for slide | |
| 99 | + this.setSize(b); | |
| 100 | + | |
| 101 | + // wrap if needed | |
| 102 | + var wrap = this.fxWrap(r.pos, o, "hidden"); | |
| 103 | + | |
| 104 | + var st = this.dom.style; | |
| 105 | + st.visibility = "visible"; | |
| 106 | + st.position = "absolute"; | |
| 107 | + | |
| 108 | + // clear out temp styles after slide and unwrap | |
| 109 | + var after = function(){ | |
| 110 | + el.fxUnwrap(wrap, r.pos, o); | |
| 111 | + st.width = r.width; | |
| 112 | + st.height = r.height; | |
| 113 | + el.afterFx(o); | |
| 114 | + }; | |
| 115 | + // time to calc the positions | |
| 116 | + var a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height}; | |
| 117 | + | |
| 118 | + switch(anchor.toLowerCase()){ | |
| 119 | + case "t": | |
| 120 | + wrap.setSize(b.width, 0); | |
| 121 | + st.left = st.bottom = "0"; | |
| 122 | + a = {height: bh}; | |
| 123 | + break; | |
| 124 | + case "l": | |
| 125 | + wrap.setSize(0, b.height); | |
| 126 | + st.right = st.top = "0"; | |
| 127 | + a = {width: bw}; | |
| 128 | + break; | |
| 129 | + case "r": | |
| 130 | + wrap.setSize(0, b.height); | |
| 131 | + wrap.setX(b.right); | |
| 132 | + st.left = st.top = "0"; | |
| 133 | + a = {width: bw, points: pt}; | |
| 134 | + break; | |
| 135 | + case "b": | |
| 136 | + wrap.setSize(b.width, 0); | |
| 137 | + wrap.setY(b.bottom); | |
| 138 | + st.left = st.top = "0"; | |
| 139 | + a = {height: bh, points: pt}; | |
| 140 | + break; | |
| 141 | + case "tl": | |
| 142 | + wrap.setSize(0, 0); | |
| 143 | + st.right = st.bottom = "0"; | |
| 144 | + a = {width: bw, height: bh}; | |
| 145 | + break; | |
| 146 | + case "bl": | |
| 147 | + wrap.setSize(0, 0); | |
| 148 | + wrap.setY(b.y+b.height); | |
| 149 | + st.right = st.top = "0"; | |
| 150 | + a = {width: bw, height: bh, points: pt}; | |
| 151 | + break; | |
| 152 | + case "br": | |
| 153 | + wrap.setSize(0, 0); | |
| 154 | + wrap.setXY([b.right, b.bottom]); | |
| 155 | + st.left = st.top = "0"; | |
| 156 | + a = {width: bw, height: bh, points: pt}; | |
| 157 | + break; | |
| 158 | + case "tr": | |
| 159 | + wrap.setSize(0, 0); | |
| 160 | + wrap.setX(b.x+b.width); | |
| 161 | + st.left = st.bottom = "0"; | |
| 162 | + a = {width: bw, height: bh, points: pt}; | |
| 163 | + break; | |
| 164 | + } | |
| 165 | + this.dom.style.visibility = "visible"; | |
| 166 | + wrap.show(); | |
| 167 | + | |
| 168 | + arguments.callee.anim = wrap.fxanim(a, | |
| 169 | + o, | |
| 170 | + 'motion', | |
| 171 | + .5, | |
| 172 | + 'easeOut', after); | |
| 173 | + }); | |
| 174 | + return this; | |
| 175 | + }, | |
| 176 | + | |
| 177 | + /** | |
| 178 | + * Slides the element out of view. An anchor point can be optionally passed to set the end point | |
| 179 | + * for the slide effect. When the effect is completed, the element will be hidden (visibility = | |
| 180 | + * 'hidden') but block elements will still take up space in the document. The element must be removed | |
| 181 | + * from the DOM using the 'remove' config option if desired. This function automatically handles | |
| 182 | + * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options. | |
| 183 | + * Usage: | |
| 184 | + *<pre><code> | |
| 185 | +// default: slide the element out to the top | |
| 186 | +el.slideOut(); | |
| 187 | + | |
| 188 | +// custom: slide the element out to the right with a 2-second duration | |
| 189 | +el.slideOut('r', { duration: 2 }); | |
| 190 | + | |
| 191 | +// common config options shown with default values | |
| 192 | +el.slideOut('t', { | |
| 193 | + easing: 'easeOut', | |
| 194 | + duration: .5, | |
| 195 | + remove: false, | |
| 196 | + useDisplay: false | |
| 197 | +}); | |
| 198 | +</code></pre> | |
| 199 | + * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't') | |
| 200 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 201 | + * @return {Ext.Element} The Element | |
| 202 | + */ | |
| 203 | + slideOut : function(anchor, o){ | |
| 204 | + var el = this.getFxEl(); | |
| 205 | + o = o || {}; | |
| 206 | + | |
| 207 | + el.queueFx(o, function(){ | |
| 208 | + | |
| 209 | + anchor = anchor || "t"; | |
| 210 | + | |
| 211 | + // restore values after effect | |
| 212 | + var r = this.getFxRestore(); | |
| 213 | + | |
| 214 | + var b = this.getBox(); | |
| 215 | + // fixed size for slide | |
| 216 | + this.setSize(b); | |
| 217 | + | |
| 218 | + // wrap if needed | |
| 219 | + var wrap = this.fxWrap(r.pos, o, "visible"); | |
| 220 | + | |
| 221 | + var st = this.dom.style; | |
| 222 | + st.visibility = "visible"; | |
| 223 | + st.position = "absolute"; | |
| 224 | + | |
| 225 | + wrap.setSize(b); | |
| 226 | + | |
| 227 | + var after = function(){ | |
| 228 | + if(o.useDisplay){ | |
| 229 | + el.setDisplayed(false); | |
| 230 | + }else{ | |
| 231 | + el.hide(); | |
| 232 | + } | |
| 233 | + | |
| 234 | + el.fxUnwrap(wrap, r.pos, o); | |
| 235 | + | |
| 236 | + st.width = r.width; | |
| 237 | + st.height = r.height; | |
| 238 | + | |
| 239 | + el.afterFx(o); | |
| 240 | + }; | |
| 241 | + | |
| 242 | + var a, zero = {to: 0}; | |
| 243 | + switch(anchor.toLowerCase()){ | |
| 244 | + case "t": | |
| 245 | + st.left = st.bottom = "0"; | |
| 246 | + a = {height: zero}; | |
| 247 | + break; | |
| 248 | + case "l": | |
| 249 | + st.right = st.top = "0"; | |
| 250 | + a = {width: zero}; | |
| 251 | + break; | |
| 252 | + case "r": | |
| 253 | + st.left = st.top = "0"; | |
| 254 | + a = {width: zero, points: {to:[b.right, b.y]}}; | |
| 255 | + break; | |
| 256 | + case "b": | |
| 257 | + st.left = st.top = "0"; | |
| 258 | + a = {height: zero, points: {to:[b.x, b.bottom]}}; | |
| 259 | + break; | |
| 260 | + case "tl": | |
| 261 | + st.right = st.bottom = "0"; | |
| 262 | + a = {width: zero, height: zero}; | |
| 263 | + break; | |
| 264 | + case "bl": | |
| 265 | + st.right = st.top = "0"; | |
| 266 | + a = {width: zero, height: zero, points: {to:[b.x, b.bottom]}}; | |
| 267 | + break; | |
| 268 | + case "br": | |
| 269 | + st.left = st.top = "0"; | |
| 270 | + a = {width: zero, height: zero, points: {to:[b.x+b.width, b.bottom]}}; | |
| 271 | + break; | |
| 272 | + case "tr": | |
| 273 | + st.left = st.bottom = "0"; | |
| 274 | + a = {width: zero, height: zero, points: {to:[b.right, b.y]}}; | |
| 275 | + break; | |
| 276 | + } | |
| 277 | + | |
| 278 | + arguments.callee.anim = wrap.fxanim(a, | |
| 279 | + o, | |
| 280 | + 'motion', | |
| 281 | + .5, | |
| 282 | + "easeOut", after); | |
| 283 | + }); | |
| 284 | + return this; | |
| 285 | + }, | |
| 286 | + | |
| 287 | + /** | |
| 288 | + * Fades the element out while slowly expanding it in all directions. When the effect is completed, the | |
| 289 | + * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document. | |
| 290 | + * The element must be removed from the DOM using the 'remove' config option if desired. | |
| 291 | + * Usage: | |
| 292 | + *<pre><code> | |
| 293 | +// default | |
| 294 | +el.puff(); | |
| 295 | + | |
| 296 | +// common config options shown with default values | |
| 297 | +el.puff({ | |
| 298 | + easing: 'easeOut', | |
| 299 | + duration: .5, | |
| 300 | + remove: false, | |
| 301 | + useDisplay: false | |
| 302 | +}); | |
| 303 | +</code></pre> | |
| 304 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 305 | + * @return {Ext.Element} The Element | |
| 306 | + */ | |
| 307 | + puff : function(o){ | |
| 308 | + var el = this.getFxEl(); | |
| 309 | + o = o || {}; | |
| 310 | + | |
| 311 | + el.queueFx(o, function(){ | |
| 312 | + this.clearOpacity(); | |
| 313 | + this.show(); | |
| 314 | + | |
| 315 | + // restore values after effect | |
| 316 | + var r = this.getFxRestore(); | |
| 317 | + var st = this.dom.style; | |
| 318 | + | |
| 319 | + var after = function(){ | |
| 320 | + if(o.useDisplay){ | |
| 321 | + el.setDisplayed(false); | |
| 322 | + }else{ | |
| 323 | + el.hide(); | |
| 324 | + } | |
| 325 | + | |
| 326 | + el.clearOpacity(); | |
| 327 | + | |
| 328 | + el.setPositioning(r.pos); | |
| 329 | + st.width = r.width; | |
| 330 | + st.height = r.height; | |
| 331 | + st.fontSize = ''; | |
| 332 | + el.afterFx(o); | |
| 333 | + }; | |
| 334 | + | |
| 335 | + var width = this.getWidth(); | |
| 336 | + var height = this.getHeight(); | |
| 337 | + | |
| 338 | + arguments.callee.anim = this.fxanim({ | |
| 339 | + width : {to: this.adjustWidth(width * 2)}, | |
| 340 | + height : {to: this.adjustHeight(height * 2)}, | |
| 341 | + points : {by: [-(width * .5), -(height * .5)]}, | |
| 342 | + opacity : {to: 0}, | |
| 343 | + fontSize: {to:200, unit: "%"} | |
| 344 | + }, | |
| 345 | + o, | |
| 346 | + 'motion', | |
| 347 | + .5, | |
| 348 | + "easeOut", after); | |
| 349 | + }); | |
| 350 | + return this; | |
| 351 | + }, | |
| 352 | + | |
| 353 | + /** | |
| 354 | + * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television). | |
| 355 | + * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still | |
| 356 | + * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired. | |
| 357 | + * Usage: | |
| 358 | + *<pre><code> | |
| 359 | +// default | |
| 360 | +el.switchOff(); | |
| 361 | + | |
| 362 | +// all config options shown with default values | |
| 363 | +el.switchOff({ | |
| 364 | + easing: 'easeIn', | |
| 365 | + duration: .3, | |
| 366 | + remove: false, | |
| 367 | + useDisplay: false | |
| 368 | +}); | |
| 369 | +</code></pre> | |
| 370 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 371 | + * @return {Ext.Element} The Element | |
| 372 | + */ | |
| 373 | + switchOff : function(o){ | |
| 374 | + var el = this.getFxEl(); | |
| 375 | + o = o || {}; | |
| 376 | + | |
| 377 | + el.queueFx(o, function(){ | |
| 378 | + this.clearOpacity(); | |
| 379 | + this.clip(); | |
| 380 | + | |
| 381 | + // restore values after effect | |
| 382 | + var r = this.getFxRestore(); | |
| 383 | + var st = this.dom.style; | |
| 384 | + | |
| 385 | + var after = function(){ | |
| 386 | + if(o.useDisplay){ | |
| 387 | + el.setDisplayed(false); | |
| 388 | + }else{ | |
| 389 | + el.hide(); | |
| 390 | + } | |
| 391 | + | |
| 392 | + el.clearOpacity(); | |
| 393 | + el.setPositioning(r.pos); | |
| 394 | + st.width = r.width; | |
| 395 | + st.height = r.height; | |
| 396 | + | |
| 397 | + el.afterFx(o); | |
| 398 | + }; | |
| 399 | + | |
| 400 | + this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){ | |
| 401 | + this.clearOpacity(); | |
| 402 | + (function(){ | |
| 403 | + this.fxanim({ | |
| 404 | + height:{to:1}, | |
| 405 | + points:{by:[0, this.getHeight() * .5]} | |
| 406 | + }, o, 'motion', 0.3, 'easeIn', after); | |
| 407 | + }).defer(100, this); | |
| 408 | + }); | |
| 409 | + }); | |
| 410 | + return this; | |
| 411 | + }, | |
| 412 | + | |
| 413 | + /** | |
| 414 | + * Highlights the Element by setting a color (applies to the background-color by default, but can be | |
| 415 | + * changed using the "attr" config option) and then fading back to the original color. If no original | |
| 416 | + * color is available, you should provide the "endColor" config option which will be cleared after the animation. | |
| 417 | + * Usage: | |
| 418 | +<pre><code> | |
| 419 | +// default: highlight background to yellow | |
| 420 | +el.highlight(); | |
| 421 | + | |
| 422 | +// custom: highlight foreground text to blue for 2 seconds | |
| 423 | +el.highlight("0000ff", { attr: 'color', duration: 2 }); | |
| 424 | + | |
| 425 | +// common config options shown with default values | |
| 426 | +el.highlight("ffff9c", { | |
| 427 | + attr: "background-color", //can be any valid CSS property (attribute) that supports a color value | |
| 428 | + endColor: (current color) or "ffffff", | |
| 429 | + easing: 'easeIn', | |
| 430 | + duration: 1 | |
| 431 | +}); | |
| 432 | +</code></pre> | |
| 433 | + * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c') | |
| 434 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 435 | + * @return {Ext.Element} The Element | |
| 436 | + */ | |
| 437 | + highlight : function(color, o){ | |
| 438 | + var el = this.getFxEl(); | |
| 439 | + o = o || {}; | |
| 440 | + | |
| 441 | + el.queueFx(o, function(){ | |
| 442 | + color = color || "ffff9c"; | |
| 443 | + var attr = o.attr || "backgroundColor"; | |
| 444 | + | |
| 445 | + this.clearOpacity(); | |
| 446 | + this.show(); | |
| 447 | + | |
| 448 | + var origColor = this.getColor(attr); | |
| 449 | + var restoreColor = this.dom.style[attr]; | |
| 450 | + var endColor = (o.endColor || origColor) || "ffffff"; | |
| 451 | + | |
| 452 | + var after = function(){ | |
| 453 | + el.dom.style[attr] = restoreColor; | |
| 454 | + el.afterFx(o); | |
| 455 | + }; | |
| 456 | + | |
| 457 | + var a = {}; | |
| 458 | + a[attr] = {from: color, to: endColor}; | |
| 459 | + arguments.callee.anim = this.fxanim(a, | |
| 460 | + o, | |
| 461 | + 'color', | |
| 462 | + 1, | |
| 463 | + 'easeIn', after); | |
| 464 | + }); | |
| 465 | + return this; | |
| 466 | + }, | |
| 467 | + | |
| 468 | + /** | |
| 469 | + * Shows a ripple of exploding, attenuating borders to draw attention to an Element. | |
| 470 | + * Usage: | |
| 471 | +<pre><code> | |
| 472 | +// default: a single light blue ripple | |
| 473 | +el.frame(); | |
| 474 | + | |
| 475 | +// custom: 3 red ripples lasting 3 seconds total | |
| 476 | +el.frame("ff0000", 3, { duration: 3 }); | |
| 477 | + | |
| 478 | +// common config options shown with default values | |
| 479 | +el.frame("C3DAF9", 1, { | |
| 480 | + duration: 1 //duration of entire animation (not each individual ripple) | |
| 481 | + // Note: Easing is not configurable and will be ignored if included | |
| 482 | +}); | |
| 483 | +</code></pre> | |
| 484 | + * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9'). | |
| 485 | + * @param {Number} count (optional) The number of ripples to display (defaults to 1) | |
| 486 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 487 | + * @return {Ext.Element} The Element | |
| 488 | + */ | |
| 489 | + frame : function(color, count, o){ | |
| 490 | + var el = this.getFxEl(); | |
| 491 | + o = o || {}; | |
| 492 | + | |
| 493 | + el.queueFx(o, function(){ | |
| 494 | + color = color || "#C3DAF9"; | |
| 495 | + if(color.length == 6){ | |
| 496 | + color = "#" + color; | |
| 497 | + } | |
| 498 | + count = count || 1; | |
| 499 | + var duration = o.duration || 1; | |
| 500 | + this.show(); | |
| 501 | + | |
| 502 | + var b = this.getBox(); | |
| 503 | + var animFn = function(){ | |
| 504 | + var proxy = Ext.getBody().createChild({ | |
| 505 | + style:{ | |
| 506 | + visbility:"hidden", | |
| 507 | + position:"absolute", | |
| 508 | + "z-index":"35000", // yee haw | |
| 509 | + border:"0px solid " + color | |
| 510 | + } | |
| 511 | + }); | |
| 512 | + var scale = Ext.isBorderBox ? 2 : 1; | |
| 513 | + proxy.animate({ | |
| 514 | + top:{from:b.y, to:b.y - 20}, | |
| 515 | + left:{from:b.x, to:b.x - 20}, | |
| 516 | + borderWidth:{from:0, to:10}, | |
| 517 | + opacity:{from:1, to:0}, | |
| 518 | + height:{from:b.height, to:(b.height + (20*scale))}, | |
| 519 | + width:{from:b.width, to:(b.width + (20*scale))} | |
| 520 | + }, duration, function(){ | |
| 521 | + proxy.remove(); | |
| 522 | + if(--count > 0){ | |
| 523 | + animFn(); | |
| 524 | + }else{ | |
| 525 | + el.afterFx(o); | |
| 526 | + } | |
| 527 | + }); | |
| 528 | + }; | |
| 529 | + animFn.call(this); | |
| 530 | + }); | |
| 531 | + return this; | |
| 532 | + }, | |
| 533 | + | |
| 534 | + /** | |
| 535 | + * Creates a pause before any subsequent queued effects begin. If there are | |
| 536 | + * no effects queued after the pause it will have no effect. | |
| 537 | + * Usage: | |
| 538 | +<pre><code> | |
| 539 | +el.pause(1); | |
| 540 | +</code></pre> | |
| 541 | + * @param {Number} seconds The length of time to pause (in seconds) | |
| 542 | + * @return {Ext.Element} The Element | |
| 543 | + */ | |
| 544 | + pause : function(seconds){ | |
| 545 | + var el = this.getFxEl(); | |
| 546 | + var o = {}; | |
| 547 | + | |
| 548 | + el.queueFx(o, function(){ | |
| 549 | + setTimeout(function(){ | |
| 550 | + el.afterFx(o); | |
| 551 | + }, seconds * 1000); | |
| 552 | + }); | |
| 553 | + return this; | |
| 554 | + }, | |
| 555 | + | |
| 556 | + /** | |
| 557 | + * Fade an element in (from transparent to opaque). The ending opacity can be specified | |
| 558 | + * using the "endOpacity" config option. | |
| 559 | + * Usage: | |
| 560 | +<pre><code> | |
| 561 | +// default: fade in from opacity 0 to 100% | |
| 562 | +el.fadeIn(); | |
| 563 | + | |
| 564 | +// custom: fade in from opacity 0 to 75% over 2 seconds | |
| 565 | +el.fadeIn({ endOpacity: .75, duration: 2}); | |
| 566 | + | |
| 567 | +// common config options shown with default values | |
| 568 | +el.fadeIn({ | |
| 569 | + endOpacity: 1, //can be any value between 0 and 1 (e.g. .5) | |
| 570 | + easing: 'easeOut', | |
| 571 | + duration: .5 | |
| 572 | +}); | |
| 573 | +</code></pre> | |
| 574 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 575 | + * @return {Ext.Element} The Element | |
| 576 | + */ | |
| 577 | + fadeIn : function(o){ | |
| 578 | + var el = this.getFxEl(); | |
| 579 | + o = o || {}; | |
| 580 | + el.queueFx(o, function(){ | |
| 581 | + this.setOpacity(0); | |
| 582 | + this.fixDisplay(); | |
| 583 | + this.dom.style.visibility = 'visible'; | |
| 584 | + var to = o.endOpacity || 1; | |
| 585 | + arguments.callee.anim = this.fxanim({opacity:{to:to}}, | |
| 586 | + o, null, .5, "easeOut", function(){ | |
| 587 | + if(to == 1){ | |
| 588 | + this.clearOpacity(); | |
| 589 | + } | |
| 590 | + el.afterFx(o); | |
| 591 | + }); | |
| 592 | + }); | |
| 593 | + return this; | |
| 594 | + }, | |
| 595 | + | |
| 596 | + /** | |
| 597 | + * Fade an element out (from opaque to transparent). The ending opacity can be specified | |
| 598 | + * using the "endOpacity" config option. Note that IE may require useDisplay:true in order | |
| 599 | + * to redisplay correctly. | |
| 600 | + * Usage: | |
| 601 | +<pre><code> | |
| 602 | +// default: fade out from the element's current opacity to 0 | |
| 603 | +el.fadeOut(); | |
| 604 | + | |
| 605 | +// custom: fade out from the element's current opacity to 25% over 2 seconds | |
| 606 | +el.fadeOut({ endOpacity: .25, duration: 2}); | |
| 607 | + | |
| 608 | +// common config options shown with default values | |
| 609 | +el.fadeOut({ | |
| 610 | + endOpacity: 0, //can be any value between 0 and 1 (e.g. .5) | |
| 611 | + easing: 'easeOut', | |
| 612 | + duration: .5, | |
| 613 | + remove: false, | |
| 614 | + useDisplay: false | |
| 615 | +}); | |
| 616 | +</code></pre> | |
| 617 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 618 | + * @return {Ext.Element} The Element | |
| 619 | + */ | |
| 620 | + fadeOut : function(o){ | |
| 621 | + var el = this.getFxEl(); | |
| 622 | + o = o || {}; | |
| 623 | + el.queueFx(o, function(){ | |
| 624 | + arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}}, | |
| 625 | + o, null, .5, "easeOut", function(){ | |
| 626 | + if(this.visibilityMode == Ext.Element.DISPLAY || o.useDisplay){ | |
| 627 | + this.dom.style.display = "none"; | |
| 628 | + }else{ | |
| 629 | + this.dom.style.visibility = "hidden"; | |
| 630 | + } | |
| 631 | + this.clearOpacity(); | |
| 632 | + el.afterFx(o); | |
| 633 | + }); | |
| 634 | + }); | |
| 635 | + return this; | |
| 636 | + }, | |
| 637 | + | |
| 638 | + /** | |
| 639 | + * Animates the transition of an element's dimensions from a starting height/width | |
| 640 | + * to an ending height/width. | |
| 641 | + * Usage: | |
| 642 | +<pre><code> | |
| 643 | +// change height and width to 100x100 pixels | |
| 644 | +el.scale(100, 100); | |
| 645 | + | |
| 646 | +// common config options shown with default values. The height and width will default to | |
| 647 | +// the element's existing values if passed as null. | |
| 648 | +el.scale( | |
| 649 | + [element's width], | |
| 650 | + [element's height], { | |
| 651 | + easing: 'easeOut', | |
| 652 | + duration: .35 | |
| 653 | + } | |
| 654 | +); | |
| 655 | +</code></pre> | |
| 656 | + * @param {Number} width The new width (pass undefined to keep the original width) | |
| 657 | + * @param {Number} height The new height (pass undefined to keep the original height) | |
| 658 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 659 | + * @return {Ext.Element} The Element | |
| 660 | + */ | |
| 661 | + scale : function(w, h, o){ | |
| 662 | + this.shift(Ext.apply({}, o, { | |
| 663 | + width: w, | |
| 664 | + height: h | |
| 665 | + })); | |
| 666 | + return this; | |
| 667 | + }, | |
| 668 | + | |
| 669 | + /** | |
| 670 | + * Animates the transition of any combination of an element's dimensions, xy position and/or opacity. | |
| 671 | + * Any of these properties not specified in the config object will not be changed. This effect | |
| 672 | + * requires that at least one new dimension, position or opacity setting must be passed in on | |
| 673 | + * the config object in order for the function to have any effect. | |
| 674 | + * Usage: | |
| 675 | +<pre><code> | |
| 676 | +// slide the element horizontally to x position 200 while changing the height and opacity | |
| 677 | +el.shift({ x: 200, height: 50, opacity: .8 }); | |
| 678 | + | |
| 679 | +// common config options shown with default values. | |
| 680 | +el.shift({ | |
| 681 | + width: [element's width], | |
| 682 | + height: [element's height], | |
| 683 | + x: [element's x position], | |
| 684 | + y: [element's y position], | |
| 685 | + opacity: [element's opacity], | |
| 686 | + easing: 'easeOut', | |
| 687 | + duration: .35 | |
| 688 | +}); | |
| 689 | +</code></pre> | |
| 690 | + * @param {Object} options Object literal with any of the Fx config options | |
| 691 | + * @return {Ext.Element} The Element | |
| 692 | + */ | |
| 693 | + shift : function(o){ | |
| 694 | + var el = this.getFxEl(); | |
| 695 | + o = o || {}; | |
| 696 | + el.queueFx(o, function(){ | |
| 697 | + var a = {}, w = o.width, h = o.height, x = o.x, y = o.y, op = o.opacity; | |
| 698 | + if(w !== undefined){ | |
| 699 | + a.width = {to: this.adjustWidth(w)}; | |
| 700 | + } | |
| 701 | + if(h !== undefined){ | |
| 702 | + a.height = {to: this.adjustHeight(h)}; | |
| 703 | + } | |
| 704 | + if(o.left !== undefined){ | |
| 705 | + a.left = {to: o.left}; | |
| 706 | + } | |
| 707 | + if(o.top !== undefined){ | |
| 708 | + a.top = {to: o.top}; | |
| 709 | + } | |
| 710 | + if(o.right !== undefined){ | |
| 711 | + a.right = {to: o.right}; | |
| 712 | + } | |
| 713 | + if(o.bottom !== undefined){ | |
| 714 | + a.bottom = {to: o.bottom}; | |
| 715 | + } | |
| 716 | + if(x !== undefined || y !== undefined){ | |
| 717 | + a.points = {to: [ | |
| 718 | + x !== undefined ? x : this.getX(), | |
| 719 | + y !== undefined ? y : this.getY() | |
| 720 | + ]}; | |
| 721 | + } | |
| 722 | + if(op !== undefined){ | |
| 723 | + a.opacity = {to: op}; | |
| 724 | + } | |
| 725 | + if(o.xy !== undefined){ | |
| 726 | + a.points = {to: o.xy}; | |
| 727 | + } | |
| 728 | + arguments.callee.anim = this.fxanim(a, | |
| 729 | + o, 'motion', .35, "easeOut", function(){ | |
| 730 | + el.afterFx(o); | |
| 731 | + }); | |
| 732 | + }); | |
| 733 | + return this; | |
| 734 | + }, | |
| 735 | + | |
| 736 | + /** | |
| 737 | + * Slides the element while fading it out of view. An anchor point can be optionally passed to set the | |
| 738 | + * ending point of the effect. | |
| 739 | + * Usage: | |
| 740 | + *<pre><code> | |
| 741 | +// default: slide the element downward while fading out | |
| 742 | +el.ghost(); | |
| 743 | + | |
| 744 | +// custom: slide the element out to the right with a 2-second duration | |
| 745 | +el.ghost('r', { duration: 2 }); | |
| 746 | + | |
| 747 | +// common config options shown with default values | |
| 748 | +el.ghost('b', { | |
| 749 | + easing: 'easeOut', | |
| 750 | + duration: .5, | |
| 751 | + remove: false, | |
| 752 | + useDisplay: false | |
| 753 | +}); | |
| 754 | +</code></pre> | |
| 755 | + * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b') | |
| 756 | + * @param {Object} options (optional) Object literal with any of the Fx config options | |
| 757 | + * @return {Ext.Element} The Element | |
| 758 | + */ | |
| 759 | + ghost : function(anchor, o){ | |
| 760 | + var el = this.getFxEl(); | |
| 761 | + o = o || {}; | |
| 762 | + | |
| 763 | + el.queueFx(o, function(){ | |
| 764 | + anchor = anchor || "b"; | |
| 765 | + | |
| 766 | + // restore values after effect | |
| 767 | + var r = this.getFxRestore(); | |
| 768 | + var w = this.getWidth(), | |
| 769 | + h = this.getHeight(); | |
| 770 | + | |
| 771 | + var st = this.dom.style; | |
| 772 | + | |
| 773 | + var after = function(){ | |
| 774 | + if(o.useDisplay){ | |
| 775 | + el.setDisplayed(false); | |
| 776 | + }else{ | |
| 777 | + el.hide(); | |
| 778 | + } | |
| 779 | + | |
| 780 | + el.clearOpacity(); | |
| 781 | + el.setPositioning(r.pos); | |
| 782 | + st.width = r.width; | |
| 783 | + st.height = r.height; | |
| 784 | + | |
| 785 | + el.afterFx(o); | |
| 786 | + }; | |
| 787 | + | |
| 788 | + var a = {opacity: {to: 0}, points: {}}, pt = a.points; | |
| 789 | + switch(anchor.toLowerCase()){ | |
| 790 | + case "t": | |
| 791 | + pt.by = [0, -h]; | |
| 792 | + break; | |
| 793 | + case "l": | |
| 794 | + pt.by = [-w, 0]; | |
| 795 | + break; | |
| 796 | + case "r": | |
| 797 | + pt.by = [w, 0]; | |
| 798 | + break; | |
| 799 | + case "b": | |
| 800 | + pt.by = [0, h]; | |
| 801 | + break; | |
| 802 | + case "tl": | |
| 803 | + pt.by = [-w, -h]; | |
| 804 | + break; | |
| 805 | + case "bl": | |
| 806 | + pt.by = [-w, h]; | |
| 807 | + break; | |
| 808 | + case "br": | |
| 809 | + pt.by = [w, h]; | |
| 810 | + break; | |
| 811 | + case "tr": | |
| 812 | + pt.by = [w, -h]; | |
| 813 | + break; | |
| 814 | + } | |
| 815 | + | |
| 816 | + arguments.callee.anim = this.fxanim(a, | |
| 817 | + o, | |
| 818 | + 'motion', | |
| 819 | + .5, | |
| 820 | + "easeOut", after); | |
| 821 | + }); | |
| 822 | + return this; | |
| 823 | + }, | |
| 824 | + | |
| 825 | + /** | |
| 826 | + * Ensures that all effects queued after syncFx is called on the element are | |
| 827 | + * run concurrently. This is the opposite of {@link #sequenceFx}. | |
| 828 | + * @return {Ext.Element} The Element | |
| 829 | + */ | |
| 830 | + syncFx : function(){ | |
| 831 | + this.fxDefaults = Ext.apply(this.fxDefaults || {}, { | |
| 832 | + block : false, | |
| 833 | + concurrent : true, | |
| 834 | + stopFx : false | |
| 835 | + }); | |
| 836 | + return this; | |
| 837 | + }, | |
| 838 | + | |
| 839 | + /** | |
| 840 | + * Ensures that all effects queued after sequenceFx is called on the element are | |
| 841 | + * run in sequence. This is the opposite of {@link #syncFx}. | |
| 842 | + * @return {Ext.Element} The Element | |
| 843 | + */ | |
| 844 | + sequenceFx : function(){ | |
| 845 | + this.fxDefaults = Ext.apply(this.fxDefaults || {}, { | |
| 846 | + block : false, | |
| 847 | + concurrent : false, | |
| 848 | + stopFx : false | |
| 849 | + }); | |
| 850 | + return this; | |
| 851 | + }, | |
| 852 | + | |
| 853 | + /* @private */ | |
| 854 | + nextFx : function(){ | |
| 855 | + var ef = this.fxQueue[0]; | |
| 856 | + if(ef){ | |
| 857 | + ef.call(this); | |
| 858 | + } | |
| 859 | + }, | |
| 860 | + | |
| 861 | + /** | |
| 862 | + * Returns true if the element has any effects actively running or queued, else returns false. | |
| 863 | + * @return {Boolean} True if element has active effects, else false | |
| 864 | + */ | |
| 865 | + hasActiveFx : function(){ | |
| 866 | + return this.fxQueue && this.fxQueue[0]; | |
| 867 | + }, | |
| 868 | + | |
| 869 | + /** | |
| 870 | + * Stops any running effects and clears the element's internal effects queue if it contains | |
| 871 | + * any additional effects that haven't started yet. | |
| 872 | + * @return {Ext.Element} The Element | |
| 873 | + */ | |
| 874 | + stopFx : function(){ | |
| 875 | + if(this.hasActiveFx()){ | |
| 876 | + var cur = this.fxQueue[0]; | |
| 877 | + if(cur && cur.anim && cur.anim.isAnimated()){ | |
| 878 | + this.fxQueue = [cur]; // clear out others | |
| 879 | + cur.anim.stop(true); | |
| 880 | + } | |
| 881 | + } | |
| 882 | + return this; | |
| 883 | + }, | |
| 884 | + | |
| 885 | + /* @private */ | |
| 886 | + beforeFx : function(o){ | |
| 887 | + if(this.hasActiveFx() && !o.concurrent){ | |
| 888 | + if(o.stopFx){ | |
| 889 | + this.stopFx(); | |
| 890 | + return true; | |
| 891 | + } | |
| 892 | + return false; | |
| 893 | + } | |
| 894 | + return true; | |
| 895 | + }, | |
| 896 | + | |
| 897 | + /** | |
| 898 | + * Returns true if the element is currently blocking so that no other effect can be queued | |
| 899 | + * until this effect is finished, else returns false if blocking is not set. This is commonly | |
| 900 | + * used to ensure that an effect initiated by a user action runs to completion prior to the | |
| 901 | + * same effect being restarted (e.g., firing only one effect even if the user clicks several times). | |
| 902 | + * @return {Boolean} True if blocking, else false | |
| 903 | + */ | |
| 904 | + hasFxBlock : function(){ | |
| 905 | + var q = this.fxQueue; | |
| 906 | + return q && q[0] && q[0].block; | |
| 907 | + }, | |
| 908 | + | |
| 909 | + /* @private */ | |
| 910 | + queueFx : function(o, fn){ | |
| 911 | + if(!this.fxQueue){ | |
| 912 | + this.fxQueue = []; | |
| 913 | + } | |
| 914 | + if(!this.hasFxBlock()){ | |
| 915 | + Ext.applyIf(o, this.fxDefaults); | |
| 916 | + if(!o.concurrent){ | |
| 917 | + var run = this.beforeFx(o); | |
| 918 | + fn.block = o.block; | |
| 919 | + this.fxQueue.push(fn); | |
| 920 | + if(run){ | |
| 921 | + this.nextFx(); | |
| 922 | + } | |
| 923 | + }else{ | |
| 924 | + fn.call(this); | |
| 925 | + } | |
| 926 | + } | |
| 927 | + return this; | |
| 928 | + }, | |
| 929 | + | |
| 930 | + /* @private */ | |
| 931 | + fxWrap : function(pos, o, vis){ | |
| 932 | + var wrap; | |
| 933 | + if(!o.wrap || !(wrap = Ext.get(o.wrap))){ | |
| 934 | + var wrapXY; | |
| 935 | + if(o.fixPosition){ | |
| 936 | + wrapXY = this.getXY(); | |
| 937 | + } | |
| 938 | + var div = document.createElement("div"); | |
| 939 | + div.style.visibility = vis; | |
| 940 | + wrap = Ext.get(this.dom.parentNode.insertBefore(div, this.dom)); | |
| 941 | + wrap.setPositioning(pos); | |
| 942 | + if(wrap.getStyle("position") == "static"){ | |
| 943 | + wrap.position("relative"); | |
| 944 | + } | |
| 945 | + this.clearPositioning('auto'); | |
| 946 | + wrap.clip(); | |
| 947 | + wrap.dom.appendChild(this.dom); | |
| 948 | + if(wrapXY){ | |
| 949 | + wrap.setXY(wrapXY); | |
| 950 | + } | |
| 951 | + } | |
| 952 | + return wrap; | |
| 953 | + }, | |
| 954 | + | |
| 955 | + /* @private */ | |
| 956 | + fxUnwrap : function(wrap, pos, o){ | |
| 957 | + this.clearPositioning(); | |
| 958 | + this.setPositioning(pos); | |
| 959 | + if(!o.wrap){ | |
| 960 | + wrap.dom.parentNode.insertBefore(this.dom, wrap.dom); | |
| 961 | + wrap.remove(); | |
| 962 | + } | |
| 963 | + }, | |
| 964 | + | |
| 965 | + /* @private */ | |
| 966 | + getFxRestore : function(){ | |
| 967 | + var st = this.dom.style; | |
| 968 | + return {pos: this.getPositioning(), width: st.width, height : st.height}; | |
| 969 | + }, | |
| 970 | + | |
| 971 | + /* @private */ | |
| 972 | + afterFx : function(o){ | |
| 973 | + if(o.afterStyle){ | |
| 974 | + this.applyStyles(o.afterStyle); | |
| 975 | + } | |
| 976 | + if(o.afterCls){ | |
| 977 | + this.addClass(o.afterCls); | |
| 978 | + } | |
| 979 | + if(o.remove === true){ | |
| 980 | + this.remove(); | |
| 981 | + } | |
| 982 | + Ext.callback(o.callback, o.scope, [this]); | |
| 983 | + if(!o.concurrent){ | |
| 984 | + this.fxQueue.shift(); | |
| 985 | + this.nextFx(); | |
| 986 | + } | |
| 987 | + }, | |
| 988 | + | |
| 989 | + /* @private */ | |
| 990 | + getFxEl : function(){ // support for composite element fx | |
| 991 | + return Ext.get(this.dom); | |
| 992 | + }, | |
| 993 | + | |
| 994 | + /* @private */ | |
| 995 | + fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){ | |
| 996 | + animType = animType || 'run'; | |
| 997 | + opt = opt || {}; | |
| 998 | + var anim = Ext.lib.Anim[animType]( | |
| 999 | + this.dom, args, | |
| 1000 | + (opt.duration || defaultDur) || .35, | |
| 1001 | + (opt.easing || defaultEase) || 'easeOut', | |
| 1002 | + function(){ | |
| 1003 | + Ext.callback(cb, this); | |
| 1004 | + }, | |
| 1005 | + this | |
| 1006 | + ); | |
| 1007 | + opt.anim = anim; | |
| 1008 | + return anim; | |
| 1009 | + } | |
| 1010 | +}; | |
| 1011 | + | |
| 1012 | +// backwords compat | |
| 1013 | +Ext.Fx.resize = Ext.Fx.scale; | |
| 1014 | + | |
| 1015 | +//When included, Ext.Fx is automatically applied to Element so that all basic | |
| 1016 | +//effects are available directly via the Element API | |
| 1017 | +Ext.apply(Ext.Element.prototype, Ext.Fx); | ... | ... |
thirdpartyjs/extjs/source/core/Template.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | +* @class Ext.Template | |
| 11 | +* Represents an HTML fragment template. Templates can be precompiled for greater performance. | |
| 12 | +* For a list of available format functions, see {@link Ext.util.Format}.<br /> | |
| 13 | +* Usage: | |
| 14 | +<pre><code> | |
| 15 | +var t = new Ext.Template( | |
| 16 | + '<div name="{id}">', | |
| 17 | + '<span class="{cls}">{name:trim} {value:ellipsis(10)}</span>', | |
| 18 | + '</div>' | |
| 19 | +); | |
| 20 | +t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'}); | |
| 21 | +</code></pre> | |
| 22 | +* For more information see this blog post with examples: <a href="http://www.jackslocum.com/blog/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">DomHelper - Create Elements using DOM, HTML fragments and Templates</a>. | |
| 23 | +* @constructor | |
| 24 | +* @param {String/Array} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("") | |
| 25 | +*/ | |
| 26 | +Ext.Template = function(html){ | |
| 27 | + var a = arguments; | |
| 28 | + if(Ext.isArray(html)){ | |
| 29 | + html = html.join(""); | |
| 30 | + }else if(a.length > 1){ | |
| 31 | + var buf = []; | |
| 32 | + for(var i = 0, len = a.length; i < len; i++){ | |
| 33 | + if(typeof a[i] == 'object'){ | |
| 34 | + Ext.apply(this, a[i]); | |
| 35 | + }else{ | |
| 36 | + buf[buf.length] = a[i]; | |
| 37 | + } | |
| 38 | + } | |
| 39 | + html = buf.join(''); | |
| 40 | + } | |
| 41 | + /**@private*/ | |
| 42 | + this.html = html; | |
| 43 | + if(this.compiled){ | |
| 44 | + this.compile(); | |
| 45 | + } | |
| 46 | +}; | |
| 47 | +Ext.Template.prototype = { | |
| 48 | + /** | |
| 49 | + * Returns an HTML fragment of this template with the specified values applied. | |
| 50 | + * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | |
| 51 | + * @return {String} The HTML fragment | |
| 52 | + */ | |
| 53 | + applyTemplate : function(values){ | |
| 54 | + if(this.compiled){ | |
| 55 | + return this.compiled(values); | |
| 56 | + } | |
| 57 | + var useF = this.disableFormats !== true; | |
| 58 | + var fm = Ext.util.Format, tpl = this; | |
| 59 | + var fn = function(m, name, format, args){ | |
| 60 | + if(format && useF){ | |
| 61 | + if(format.substr(0, 5) == "this."){ | |
| 62 | + return tpl.call(format.substr(5), values[name], values); | |
| 63 | + }else{ | |
| 64 | + if(args){ | |
| 65 | + // quoted values are required for strings in compiled templates, | |
| 66 | + // but for non compiled we need to strip them | |
| 67 | + // quoted reversed for jsmin | |
| 68 | + var re = /^\s*['"](.*)["']\s*$/; | |
| 69 | + args = args.split(','); | |
| 70 | + for(var i = 0, len = args.length; i < len; i++){ | |
| 71 | + args[i] = args[i].replace(re, "$1"); | |
| 72 | + } | |
| 73 | + args = [values[name]].concat(args); | |
| 74 | + }else{ | |
| 75 | + args = [values[name]]; | |
| 76 | + } | |
| 77 | + return fm[format].apply(fm, args); | |
| 78 | + } | |
| 79 | + }else{ | |
| 80 | + return values[name] !== undefined ? values[name] : ""; | |
| 81 | + } | |
| 82 | + }; | |
| 83 | + return this.html.replace(this.re, fn); | |
| 84 | + }, | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Sets the HTML used as the template and optionally compiles it. | |
| 88 | + * @param {String} html | |
| 89 | + * @param {Boolean} compile (optional) True to compile the template (defaults to undefined) | |
| 90 | + * @return {Ext.Template} this | |
| 91 | + */ | |
| 92 | + set : function(html, compile){ | |
| 93 | + this.html = html; | |
| 94 | + this.compiled = null; | |
| 95 | + if(compile){ | |
| 96 | + this.compile(); | |
| 97 | + } | |
| 98 | + return this; | |
| 99 | + }, | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * True to disable format functions (defaults to false) | |
| 103 | + * @type Boolean | |
| 104 | + */ | |
| 105 | + disableFormats : false, | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * The regular expression used to match template variables | |
| 109 | + * @type RegExp | |
| 110 | + * @property | |
| 111 | + */ | |
| 112 | + re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Compiles the template into an internal function, eliminating the RegEx overhead. | |
| 116 | + * @return {Ext.Template} this | |
| 117 | + */ | |
| 118 | + compile : function(){ | |
| 119 | + var fm = Ext.util.Format; | |
| 120 | + var useF = this.disableFormats !== true; | |
| 121 | + var sep = Ext.isGecko ? "+" : ","; | |
| 122 | + var fn = function(m, name, format, args){ | |
| 123 | + if(format && useF){ | |
| 124 | + args = args ? ',' + args : ""; | |
| 125 | + if(format.substr(0, 5) != "this."){ | |
| 126 | + format = "fm." + format + '('; | |
| 127 | + }else{ | |
| 128 | + format = 'this.call("'+ format.substr(5) + '", '; | |
| 129 | + args = ", values"; | |
| 130 | + } | |
| 131 | + }else{ | |
| 132 | + args= ''; format = "(values['" + name + "'] == undefined ? '' : "; | |
| 133 | + } | |
| 134 | + return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'"; | |
| 135 | + }; | |
| 136 | + var body; | |
| 137 | + // branched to use + in gecko and [].join() in others | |
| 138 | + if(Ext.isGecko){ | |
| 139 | + body = "this.compiled = function(values){ return '" + | |
| 140 | + this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) + | |
| 141 | + "';};"; | |
| 142 | + }else{ | |
| 143 | + body = ["this.compiled = function(values){ return ['"]; | |
| 144 | + body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn)); | |
| 145 | + body.push("'].join('');};"); | |
| 146 | + body = body.join(''); | |
| 147 | + } | |
| 148 | + eval(body); | |
| 149 | + return this; | |
| 150 | + }, | |
| 151 | + | |
| 152 | + // private function used to call members | |
| 153 | + call : function(fnName, value, allValues){ | |
| 154 | + return this[fnName](value, allValues); | |
| 155 | + }, | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Applies the supplied values to the template and inserts the new node(s) as the first child of el. | |
| 159 | + * @param {Mixed} el The context element | |
| 160 | + * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | |
| 161 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined) | |
| 162 | + * @return {HTMLElement/Ext.Element} The new node or Element | |
| 163 | + */ | |
| 164 | + insertFirst: function(el, values, returnElement){ | |
| 165 | + return this.doInsert('afterBegin', el, values, returnElement); | |
| 166 | + }, | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Applies the supplied values to the template and inserts the new node(s) before el. | |
| 170 | + * @param {Mixed} el The context element | |
| 171 | + * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | |
| 172 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined) | |
| 173 | + * @return {HTMLElement/Ext.Element} The new node or Element | |
| 174 | + */ | |
| 175 | + insertBefore: function(el, values, returnElement){ | |
| 176 | + return this.doInsert('beforeBegin', el, values, returnElement); | |
| 177 | + }, | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * Applies the supplied values to the template and inserts the new node(s) after el. | |
| 181 | + * @param {Mixed} el The context element | |
| 182 | + * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | |
| 183 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined) | |
| 184 | + * @return {HTMLElement/Ext.Element} The new node or Element | |
| 185 | + */ | |
| 186 | + insertAfter : function(el, values, returnElement){ | |
| 187 | + return this.doInsert('afterEnd', el, values, returnElement); | |
| 188 | + }, | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * Applies the supplied values to the template and appends the new node(s) to el. | |
| 192 | + * @param {Mixed} el The context element | |
| 193 | + * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | |
| 194 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined) | |
| 195 | + * @return {HTMLElement/Ext.Element} The new node or Element | |
| 196 | + */ | |
| 197 | + append : function(el, values, returnElement){ | |
| 198 | + return this.doInsert('beforeEnd', el, values, returnElement); | |
| 199 | + }, | |
| 200 | + | |
| 201 | + doInsert : function(where, el, values, returnEl){ | |
| 202 | + el = Ext.getDom(el); | |
| 203 | + var newNode = Ext.DomHelper.insertHtml(where, el, this.applyTemplate(values)); | |
| 204 | + return returnEl ? Ext.get(newNode, true) : newNode; | |
| 205 | + }, | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * Applies the supplied values to the template and overwrites the content of el with the new node(s). | |
| 209 | + * @param {Mixed} el The context element | |
| 210 | + * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | |
| 211 | + * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined) | |
| 212 | + * @return {HTMLElement/Ext.Element} The new node or Element | |
| 213 | + */ | |
| 214 | + overwrite : function(el, values, returnElement){ | |
| 215 | + el = Ext.getDom(el); | |
| 216 | + el.innerHTML = this.applyTemplate(values); | |
| 217 | + return returnElement ? Ext.get(el.firstChild, true) : el.firstChild; | |
| 218 | + } | |
| 219 | +}; | |
| 220 | +/** | |
| 221 | + * Alias for {@link #applyTemplate} | |
| 222 | + * Returns an HTML fragment of this template with the specified values applied. | |
| 223 | + * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | |
| 224 | + * @return {String} The HTML fragment | |
| 225 | + * @member Ext.Template | |
| 226 | + * @method apply | |
| 227 | + */ | |
| 228 | +Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate; | |
| 229 | + | |
| 230 | +// backwards compat | |
| 231 | +Ext.DomHelper.Template = Ext.Template; | |
| 232 | + | |
| 233 | +/** | |
| 234 | + * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML. | |
| 235 | + * @param {String/HTMLElement} el A DOM element or its id | |
| 236 | + * @param {Object} config A configuration object | |
| 237 | + * @return {Ext.Template} The created template | |
| 238 | + * @static | |
| 239 | + */ | |
| 240 | +Ext.Template.from = function(el, config){ | |
| 241 | + el = Ext.getDom(el); | |
| 242 | + return new Ext.Template(el.value || el.innerHTML, config || ''); | |
| 243 | +}; | |
| 0 | 244 | \ No newline at end of file | ... | ... |
thirdpartyjs/extjs/source/core/UpdateManager.js
0 → 100644
| 1 | +/* | |
| 2 | + * Ext JS Library 2.2 | |
| 3 | + * Copyright(c) 2006-2008, Ext JS, LLC. | |
| 4 | + * licensing@extjs.com | |
| 5 | + * | |
| 6 | + * http://extjs.com/license | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * @class Ext.Updater | |
| 11 | + * @extends Ext.util.Observable | |
| 12 | + * Provides AJAX-style update capabilities for Element objects. Updater can be used to {@link #update} an Element once, | |
| 13 | + * or you can use {@link #startAutoRefresh} to set up an auto-updating Element on a specific interval.<br><br> | |
| 14 | + * Usage:<br> | |
| 15 | + * <pre><code> | |
| 16 | + * // Get it from a Ext.Element object | |
| 17 | + * var el = Ext.get("foo"); | |
| 18 | + * var mgr = el.getUpdater(); | |
| 19 | + * mgr.update({ | |
| 20 | + url: "http://myserver.com/index.php", | |
| 21 | + params: { | |
| 22 | + param1: "foo", | |
| 23 | + param2: "bar" | |
| 24 | + } | |
| 25 | + * }); | |
| 26 | + * ... | |
| 27 | + * mgr.formUpdate("myFormId", "http://myserver.com/index.php"); | |
| 28 | + * <br> | |
| 29 | + * // or directly (returns the same Updater instance) | |
| 30 | + * var mgr = new Ext.Updater("myElementId"); | |
| 31 | + * mgr.startAutoRefresh(60, "http://myserver.com/index.php"); | |
| 32 | + * mgr.on("update", myFcnNeedsToKnow); | |
| 33 | + * <br> | |
| 34 | + * // short handed call directly from the element object | |
| 35 | + * Ext.get("foo").load({ | |
| 36 | + url: "bar.php", | |
| 37 | + scripts: true, | |
| 38 | + params: "param1=foo&param2=bar", | |
| 39 | + text: "Loading Foo..." | |
| 40 | + * }); | |
| 41 | + * </code></pre> | |
| 42 | + * @constructor | |
| 43 | + * Create new Updater directly. | |
| 44 | + * @param {Mixed} el The element to update | |
| 45 | + * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already | |
| 46 | + * has an Updater and if it does it returns the same instance. This will skip that check (useful for extending this class). | |
| 47 | + */ | |
| 48 | +Ext.Updater = Ext.extend(Ext.util.Observable, { | |
| 49 | + constructor: function(el, forceNew){ | |
| 50 | + el = Ext.get(el); | |
| 51 | + if(!forceNew && el.updateManager){ | |
| 52 | + return el.updateManager; | |
| 53 | + } | |
| 54 | + /** | |
| 55 | + * The Element object | |
| 56 | + * @type Ext.Element | |
| 57 | + */ | |
| 58 | + this.el = el; | |
| 59 | + /** | |
| 60 | + * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true. | |
| 61 | + * @type String | |
| 62 | + */ | |
| 63 | + this.defaultUrl = null; | |
| 64 | + | |
| 65 | + this.addEvents( | |
| 66 | + /** | |
| 67 | + * @event beforeupdate | |
| 68 | + * Fired before an update is made, return false from your handler and the update is cancelled. | |
| 69 | + * @param {Ext.Element} el | |
| 70 | + * @param {String/Object/Function} url | |
| 71 | + * @param {String/Object} params | |
| 72 | + */ | |
| 73 | + "beforeupdate", | |
| 74 | + /** | |
| 75 | + * @event update | |
| 76 | + * Fired after successful update is made. | |
| 77 | + * @param {Ext.Element} el | |
| 78 | + * @param {Object} oResponseObject The response Object | |
| 79 | + */ | |
| 80 | + "update", | |
| 81 | + /** | |
| 82 | + * @event failure | |
| 83 | + * Fired on update failure. | |
| 84 | + * @param {Ext.Element} el | |
| 85 | + * @param {Object} oResponseObject The response Object | |
| 86 | + */ | |
| 87 | + "failure" | |
| 88 | + ); | |
| 89 | + var d = Ext.Updater.defaults; | |
| 90 | + /** | |
| 91 | + * Blank page URL to use with SSL file uploads (defaults to {@link Ext.Updater.defaults#sslBlankUrl}). | |
| 92 | + * @type String | |
| 93 | + */ | |
| 94 | + this.sslBlankUrl = d.sslBlankUrl; | |
| 95 | + /** | |
| 96 | + * Whether to append unique parameter on get request to disable caching (defaults to {@link Ext.Updater.defaults#disableCaching}). | |
| 97 | + * @type Boolean | |
| 98 | + */ | |
| 99 | + this.disableCaching = d.disableCaching; | |
| 100 | + /** | |
| 101 | + * Text for loading indicator (defaults to {@link Ext.Updater.defaults#indicatorText}). | |
| 102 | + * @type String | |
| 103 | + */ | |
| 104 | + this.indicatorText = d.indicatorText; | |
| 105 | + /** | |
| 106 | + * Whether to show indicatorText when loading (defaults to {@link Ext.Updater.defaults#showLoadIndicator}). | |
| 107 | + * @type String | |
| 108 | + */ | |
| 109 | + this.showLoadIndicator = d.showLoadIndicator; | |
| 110 | + /** | |
| 111 | + * Timeout for requests or form posts in seconds (defaults to {@link Ext.Updater.defaults#timeout}). | |
| 112 | + * @type Number | |
| 113 | + */ | |
| 114 | + this.timeout = d.timeout; | |
| 115 | + /** | |
| 116 | + * True to process scripts in the output (defaults to {@link Ext.Updater.defaults#loadScripts}). | |
| 117 | + * @type Boolean | |
| 118 | + */ | |
| 119 | + this.loadScripts = d.loadScripts; | |
| 120 | + /** | |
| 121 | + * Transaction object of the current executing transaction, or null if there is no active transaction. | |
| 122 | + */ | |
| 123 | + this.transaction = null; | |
| 124 | + /** | |
| 125 | + * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments | |
| 126 | + * @type Function | |
| 127 | + */ | |
| 128 | + this.refreshDelegate = this.refresh.createDelegate(this); | |
| 129 | + /** | |
| 130 | + * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments | |
| 131 | + * @type Function | |
| 132 | + */ | |
| 133 | + this.updateDelegate = this.update.createDelegate(this); | |
| 134 | + /** | |
| 135 | + * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments | |
| 136 | + * @type Function | |
| 137 | + */ | |
| 138 | + this.formUpdateDelegate = this.formUpdate.createDelegate(this); | |
| 139 | + | |
| 140 | + if(!this.renderer){ | |
| 141 | + /** | |
| 142 | + * The renderer for this Updater (defaults to {@link Ext.Updater.BasicRenderer}). | |
| 143 | + */ | |
| 144 | + this.renderer = this.getDefaultRenderer(); | |
| 145 | + } | |
| 146 | + Ext.Updater.superclass.constructor.call(this); | |
| 147 | + }, | |
| 148 | + /** | |
| 149 | + * This is an overrideable method which returns a reference to a default | |
| 150 | + * renderer class if none is specified when creating the Ext.Updater. | |
| 151 | + * Defaults to {@link Ext.Updater.BasicRenderer} | |
| 152 | + */ | |
| 153 | + getDefaultRenderer: function() { | |
| 154 | + return new Ext.Updater.BasicRenderer(); | |
| 155 | + }, | |
| 156 | + /** | |
| 157 | + * Get the Element this Updater is bound to | |
| 158 | + * @return {Ext.Element} The element | |
| 159 | + */ | |
| 160 | + getEl : function(){ | |
| 161 | + return this.el; | |
| 162 | + }, | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Performs an <b>asynchronous</b> request, updating this element with the response. | |
| 166 | + * If params are specified it uses POST, otherwise it uses GET.<br><br> | |
| 167 | + * <b>Note:</b> Due to the asynchronous nature of remote server requests, the Element | |
| 168 | + * will not have been fully updated when the function returns. To post-process the returned | |
| 169 | + * data, use the callback option, or an <b><tt>update</tt></b> event handler. | |
| 170 | + * @param {Object} options A config object containing any of the following options:<ul> | |
| 171 | + * <li>url : <b>String/Function</b><p class="sub-desc">The URL to request or a function which | |
| 172 | + * <i>returns</i> the URL (defaults to the value of {@link Ext.Ajax#url} if not specified).</p></li> | |
| 173 | + * <li>method : <b>String</b><p class="sub-desc">The HTTP method to | |
| 174 | + * use. Defaults to POST if the <tt>params</tt> argument is present, otherwise GET.</p></li> | |
| 175 | + * <li>params : <b>String/Object/Function</b><p class="sub-desc">The | |
| 176 | + * parameters to pass to the server (defaults to none). These may be specified as a url-encoded | |
| 177 | + * string, or as an object containing properties which represent parameters, | |
| 178 | + * or as a function, which returns such an object.</p></li> | |
| 179 | + * <li>scripts : <b>Boolean</b><p class="sub-desc">If <tt>true</tt> | |
| 180 | + * any <script> tags embedded in the response text will be extracted | |
| 181 | + * and executed (defaults to {@link Ext.Updater.defaults#loadScripts}). If this option is specified, | |
| 182 | + * the callback will be called <i>after</i> the execution of the scripts.</p></li> | |
| 183 | + * <li>callback : <b>Function</b><p class="sub-desc">A function to | |
| 184 | + * be called when the response from the server arrives. The following | |
| 185 | + * parameters are passed:<ul> | |
| 186 | + * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li> | |
| 187 | + * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li> | |
| 188 | + * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li> | |
| 189 | + * <li><b>options</b> : Object<p class="sub-desc">The config object passed to the update call.</p></li></ul> | |
| 190 | + * </p></li> | |
| 191 | + * <li>scope : <b>Object</b><p class="sub-desc">The scope in which | |
| 192 | + * to execute the callback (The callback's <tt>this</tt> reference.) If the | |
| 193 | + * <tt>params</tt> argument is a function, this scope is used for that function also.</p></li> | |
| 194 | + * <li>discardUrl : <b>Boolean</b><p class="sub-desc">By default, the URL of this request becomes | |
| 195 | + * the default URL for this Updater object, and will be subsequently used in {@link #refresh} | |
| 196 | + * calls. To bypass this behavior, pass <tt>discardUrl:true</tt> (defaults to false).</p></li> | |
| 197 | + * <li>timeout : <b>Number</b><p class="sub-desc">The number of seconds to wait for a response before | |
| 198 | + * timing out (defaults to {@link Ext.Updater.defaults#timeout}).</p></li> | |
| 199 | + * <li>text : <b>String</b><p class="sub-desc">The text to use as the innerHTML of the | |
| 200 | + * {@link Ext.Updater.defaults#indicatorText} div (defaults to 'Loading...'). To replace the entire div, not | |
| 201 | + * just the text, override {@link Ext.Updater.defaults#indicatorText} directly.</p></li> | |
| 202 | + * <li>nocache : <b>Boolean</b><p class="sub-desc">Only needed for GET | |
| 203 | + * requests, this option causes an extra, auto-generated parameter to be appended to the request | |
| 204 | + * to defeat caching (defaults to {@link Ext.Updater.defaults#disableCaching}).</p></li></ul> | |
| 205 | + * <p> | |
| 206 | + * For example: | |
| 207 | +<pre><code> | |
| 208 | +um.update({ | |
| 209 | + url: "your-url.php", | |
| 210 | + params: {param1: "foo", param2: "bar"}, // or a URL encoded string | |
| 211 | + callback: yourFunction, | |
| 212 | + scope: yourObject, //(optional scope) | |
| 213 | + discardUrl: true, | |
| 214 | + nocache: true, | |
| 215 | + text: "Loading...", | |
| 216 | + timeout: 60, | |
| 217 | + scripts: false // Save time by avoiding RegExp execution. | |
| 218 | +}); | |
| 219 | +</code></pre> | |
| 220 | + */ | |
| 221 | + update : function(url, params, callback, discardUrl){ | |
| 222 | + if(this.fireEvent("beforeupdate", this.el, url, params) !== false){ | |
| 223 | + var cfg, callerScope; | |
| 224 | + if(typeof url == "object"){ // must be config object | |
| 225 | + cfg = url; | |
| 226 | + url = cfg.url; | |
| 227 | + params = params || cfg.params; | |
| 228 | + callback = callback || cfg.callback; | |
| 229 | + discardUrl = discardUrl || cfg.discardUrl; | |
| 230 | + callerScope = cfg.scope; | |
| 231 | + if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;}; | |
| 232 | + if(typeof cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";}; | |
| 233 | + if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;}; | |
| 234 | + if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;}; | |
| 235 | + } | |
| 236 | + this.showLoading(); | |
| 237 | + | |
| 238 | + if(!discardUrl){ | |
| 239 | + this.defaultUrl = url; | |
| 240 | + } | |
| 241 | + if(typeof url == "function"){ | |
| 242 | + url = url.call(this); | |
| 243 | + } | |
| 244 | + | |
| 245 | + var o = Ext.apply({}, { | |
| 246 | + url : url, | |
| 247 | + params: (typeof params == "function" && callerScope) ? params.createDelegate(callerScope) : params, | |
| 248 | + success: this.processSuccess, | |
| 249 | + failure: this.processFailure, | |
| 250 | + scope: this, | |
| 251 | + callback: undefined, | |
| 252 | + timeout: (this.timeout*1000), | |
| 253 | + disableCaching: this.disableCaching, | |
| 254 | + argument: { | |
| 255 | + "options": cfg, | |
| 256 | + "url": url, | |
| 257 | + "form": null, | |
| 258 | + "callback": callback, | |
| 259 | + "scope": callerScope || window, | |
| 260 | + "params": params | |
| 261 | + } | |
| 262 | + }, cfg); | |
| 263 | + | |
| 264 | + this.transaction = Ext.Ajax.request(o); | |
| 265 | + } | |
| 266 | + }, | |
| 267 | + | |
| 268 | + /** | |
| 269 | + * Performs an async form post, updating this element with the response. If the form has the attribute | |
| 270 | + * enctype="multipart/form-data", it assumes it's a file upload. | |
| 271 | + * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning. | |
| 272 | + * @param {String/HTMLElement} form The form Id or form element | |
| 273 | + * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used. | |
| 274 | + * @param {Boolean} reset (optional) Whether to try to reset the form after the update | |
| 275 | + * @param {Function} callback (optional) Callback when transaction is complete. The following | |
| 276 | + * parameters are passed:<ul> | |
| 277 | + * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li> | |
| 278 | + * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li> | |
| 279 | + * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li></ul> | |
| 280 | + */ | |
| 281 | + formUpdate : function(form, url, reset, callback){ | |
| 282 | + if(this.fireEvent("beforeupdate", this.el, form, url) !== false){ | |
| 283 | + if(typeof url == "function"){ | |
| 284 | + url = url.call(this); | |
| 285 | + } | |
| 286 | + form = Ext.getDom(form) | |
| 287 | + this.transaction = Ext.Ajax.request({ | |
| 288 | + form: form, | |
| 289 | + url:url, | |
| 290 | + success: this.processSuccess, | |
| 291 | + failure: this.processFailure, | |
| 292 | + scope: this, | |
| 293 | + timeout: (this.timeout*1000), | |
| 294 | + argument: { | |
| 295 | + "url": url, | |
| 296 | + "form": form, | |
| 297 | + "callback": callback, | |
| 298 | + "reset": reset | |
| 299 | + } | |
| 300 | + }); | |
| 301 | + this.showLoading.defer(1, this); | |
| 302 | + } | |
| 303 | + }, | |
| 304 | + | |
| 305 | + /** | |
| 306 | + * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately | |
| 307 | + * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess) | |
| 308 | + */ | |
| 309 | + refresh : function(callback){ | |
| 310 | + if(this.defaultUrl == null){ | |
| 311 | + return; | |
| 312 | + } | |
| 313 | + this.update(this.defaultUrl, null, callback, true); | |
| 314 | + }, | |
| 315 | + | |
| 316 | + /** | |
| 317 | + * Set this element to auto refresh. Can be canceled by calling {@link #stopAutoRefresh}. | |
| 318 | + * @param {Number} interval How often to update (in seconds). | |
| 319 | + * @param {String/Object/Function} url (optional) The url for this request, a config object in the same format | |
| 320 | + * supported by {@link #load}, or a function to call to get the url (defaults to the last used url). Note that while | |
| 321 | + * the url used in a load call can be reused by this method, other load config options will not be reused and must be | |
| 322 | + * sepcified as part of a config object passed as this paramter if needed. | |
| 323 | + * @param {String/Object} params (optional) The parameters to pass as either a url encoded string | |
| 324 | + * "¶m1=1¶m2=2" or as an object {param1: 1, param2: 2} | |
| 325 | + * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess) | |
| 326 | + * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval | |
| 327 | + */ | |
| 328 | + startAutoRefresh : function(interval, url, params, callback, refreshNow){ | |
| 329 | + if(refreshNow){ | |
| 330 | + this.update(url || this.defaultUrl, params, callback, true); | |
| 331 | + } | |
| 332 | + if(this.autoRefreshProcId){ | |
| 333 | + clearInterval(this.autoRefreshProcId); | |
| 334 | + } | |
| 335 | + this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000); | |
| 336 | + }, | |
| 337 | + | |
| 338 | + /** | |
| 339 | + * Stop auto refresh on this element. | |
| 340 | + */ | |
| 341 | + stopAutoRefresh : function(){ | |
| 342 | + if(this.autoRefreshProcId){ | |
| 343 | + clearInterval(this.autoRefreshProcId); | |
| 344 | + delete this.autoRefreshProcId; | |
| 345 | + } | |
| 346 | + }, | |
| 347 | + | |
| 348 | + /** | |
| 349 | + * Returns true if the Updater is currently set to auto refresh its content (see {@link #startAutoRefresh}), otherwise false. | |
| 350 | + */ | |
| 351 | + isAutoRefreshing : function(){ | |
| 352 | + return this.autoRefreshProcId ? true : false; | |
| 353 | + }, | |
| 354 | + | |
| 355 | + /** | |
| 356 | + * Display the element's "loading" state. By default, the element is updated with {@link #indicatorText}. This | |
| 357 | + * method may be overridden to perform a custom action while this Updater is actively updating its contents. | |
| 358 | + */ | |
| 359 | + showLoading : function(){ | |
| 360 | + if(this.showLoadIndicator){ | |
| 361 | + this.el.update(this.indicatorText); | |
| 362 | + } | |
| 363 | + }, | |
| 364 | + | |
| 365 | + // private | |
| 366 | + processSuccess : function(response){ | |
| 367 | + this.transaction = null; | |
| 368 | + if(response.argument.form && response.argument.reset){ | |
| 369 | + try{ // put in try/catch since some older FF releases had problems with this | |
| 370 | + response.argument.form.reset(); | |
| 371 | + }catch(e){} | |
| 372 | + } | |
| 373 | + if(this.loadScripts){ | |
| 374 | + this.renderer.render(this.el, response, this, | |
| 375 | + this.updateComplete.createDelegate(this, [response])); | |
| 376 | + }else{ | |
| 377 | + this.renderer.render(this.el, response, this); | |
| 378 | + this.updateComplete(response); | |
| 379 | + } | |
| 380 | + }, | |
| 381 | + | |
| 382 | + // private | |
| 383 | + updateComplete : function(response){ | |
| 384 | + this.fireEvent("update", this.el, response); | |
| 385 | + if(typeof response.argument.callback == "function"){ | |
| 386 | + response.argument.callback.call(response.argument.scope, this.el, true, response, response.argument.options); | |
| 387 | + } | |
| 388 | + }, | |
| 389 | + | |
| 390 | + // private | |
| 391 | + processFailure : function(response){ | |
| 392 | + this.transaction = null; | |
| 393 | + this.fireEvent("failure", this.el, response); | |
| 394 | + if(typeof response.argument.callback == "function"){ | |
| 395 | + response.argument.callback.call(response.argument.scope, this.el, false, response, response.argument.options); | |
| 396 | + } | |
| 397 | + }, | |
| 398 | + | |
| 399 | + /** | |
| 400 | + * Sets the content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details. | |
| 401 | + * @param {Object} renderer The object implementing the render() method | |
| 402 | + */ | |
| 403 | + setRenderer : function(renderer){ | |
| 404 | + this.renderer = renderer; | |
| 405 | + }, | |
| 406 | + | |
| 407 | + /** | |
| 408 | + * Returns the content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details. | |
| 409 | + * @return {Object} | |
| 410 | + */ | |
| 411 | + getRenderer : function(){ | |
| 412 | + return this.renderer; | |
| 413 | + }, | |
| 414 | + | |
| 415 | + /** | |
| 416 | + * Sets the default URL used for updates. | |
| 417 | + * @param {String/Function} defaultUrl The url or a function to call to get the url | |
| 418 | + */ | |
| 419 | + setDefaultUrl : function(defaultUrl){ | |
| 420 | + this.defaultUrl = defaultUrl; | |
| 421 | + }, | |
| 422 | + | |
| 423 | + /** | |
| 424 | + * Aborts the currently executing transaction, if any. | |
| 425 | + */ | |
| 426 | + abort : function(){ | |
| 427 | + if(this.transaction){ | |
| 428 | + Ext.Ajax.abort(this.transaction); | |
| 429 | + } | |
| 430 | + }, | |
| 431 | + | |
| 432 | + /** | |
| 433 | + * Returns true if an update is in progress, otherwise false. | |
| 434 | + * @return {Boolean} | |
| 435 | + */ | |
| 436 | + isUpdating : function(){ | |
| 437 | + if(this.transaction){ | |
| 438 | + return Ext.Ajax.isLoading(this.transaction); | |
| 439 | + } | |
| 440 | + return false; | |
| 441 | + } | |
| 442 | +}); | |
| 443 | + | |
| 444 | +/** | |
| 445 | + * @class Ext.Updater.defaults | |
| 446 | + * The defaults collection enables customizing the default properties of Updater | |
| 447 | + */ | |
| 448 | + Ext.Updater.defaults = { | |
| 449 | + /** | |
| 450 | + * Timeout for requests or form posts in seconds (defaults to 30 seconds). | |
| 451 | + * @type Number | |
| 452 | + */ | |
| 453 | + timeout : 30, | |
| 454 | + /** | |
| 455 | + * True to process scripts by default (defaults to false). | |
| 456 | + * @type Boolean | |
| 457 | + */ | |
| 458 | + loadScripts : false, | |
| 459 | + /** | |
| 460 | + * Blank page URL to use with SSL file uploads (defaults to {@link Ext#SSL_SECURE_URL} if set, or "javascript:false"). | |
| 461 | + * @type String | |
| 462 | + */ | |
| 463 | + sslBlankUrl : (Ext.SSL_SECURE_URL || "javascript:false"), | |
| 464 | + /** | |
| 465 | + * True to append a unique parameter to GET requests to disable caching (defaults to false). | |
| 466 | + * @type Boolean | |
| 467 | + */ | |
| 468 | + disableCaching : false, | |
| 469 | + /** | |
| 470 | + * Whether or not to show {@link #indicatorText} during loading (defaults to true). | |
| 471 | + * @type Boolean | |
| 472 | + */ | |
| 473 | + showLoadIndicator : true, | |
| 474 | + /** | |
| 475 | + * Text for loading indicator (defaults to '<div class="loading-indicator">Loading...</div>'). | |
| 476 | + * @type String | |
| 477 | + */ | |
| 478 | + indicatorText : '<div class="loading-indicator">Loading...</div>' | |
| 479 | + }; | |
| 480 | + | |
| 481 | +/** | |
| 482 | + * Static convenience method. <b>This method is deprecated in favor of el.load({url:'foo.php', ...})</b>. | |
| 483 | + * Usage: | |
| 484 | + * <pre><code>Ext.Updater.updateElement("my-div", "stuff.php");</code></pre> | |
| 485 | + * @param {Mixed} el The element to update | |
| 486 | + * @param {String} url The url | |
| 487 | + * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs | |
| 488 | + * @param {Object} options (optional) A config object with any of the Updater properties you want to set - for | |
| 489 | + * example: {disableCaching:true, indicatorText: "Loading data..."} | |
| 490 | + * @static | |
| 491 | + * @deprecated | |
| 492 | + * @member Ext.Updater | |
| 493 | + */ | |
| 494 | +Ext.Updater.updateElement = function(el, url, params, options){ | |
| 495 | + var um = Ext.get(el).getUpdater(); | |
| 496 | + Ext.apply(um, options); | |
| 497 | + um.update(url, params, options ? options.callback : null); | |
| 498 | +}; | |
| 499 | +/** | |
| 500 | + * @class Ext.Updater.BasicRenderer | |
| 501 | + * Default Content renderer. Updates the elements innerHTML with the responseText. | |
| 502 | + */ | |
| 503 | +Ext.Updater.BasicRenderer = function(){}; | |
| 504 | + | |
| 505 | +Ext.Updater.BasicRenderer.prototype = { | |
| 506 | + /** | |
| 507 | + * This is called when the transaction is completed and it's time to update the element - The BasicRenderer | |
| 508 | + * updates the elements innerHTML with the responseText - To perform a custom render (i.e. XML or JSON processing), | |
| 509 | + * create an object with a "render(el, response)" method and pass it to setRenderer on the Updater. | |
| 510 | + * @param {Ext.Element} el The element being rendered | |
| 511 | + * @param {Object} response The XMLHttpRequest object | |
| 512 | + * @param {Updater} updateManager The calling update manager | |
| 513 | + * @param {Function} callback A callback that will need to be called if loadScripts is true on the Updater | |
| 514 | + */ | |
| 515 | + render : function(el, response, updateManager, callback){ | |
| 516 | + el.update(response.responseText, updateManager.loadScripts, callback); | |
| 517 | + } | |
| 518 | +}; | |
| 519 | + | |
| 520 | +Ext.UpdateManager = Ext.Updater; | ... | ... |