8d306a9bdeb422265a4e813c051e8be6ad2428d4.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. (function() {
  7. var C = YAHOO.util, J, H, G = 0, I = {};
  8. var B = navigator.userAgent.toLowerCase(), D = (B.indexOf("opera") > -1), K = (B
  9. .indexOf("safari") > -1), A = (!D && !K && B.indexOf("gecko") > -1), F = (!D && B
  10. .indexOf("msie") > -1);
  11. var E = {
  12. HYPHEN : /(-[a-z])/i
  13. };
  14. var L = function(M) {
  15. if (!E.HYPHEN.test(M)) {
  16. return M
  17. }
  18. if (I[M]) {
  19. return I[M]
  20. }
  21. while (E.HYPHEN.exec(M)) {
  22. M = M.replace(RegExp.$1, RegExp.$1.substr(1).toUpperCase())
  23. }
  24. I[M] = M;
  25. return M
  26. };
  27. if (document.defaultView && document.defaultView.getComputedStyle) {
  28. J = function(M, P) {
  29. var O = null;
  30. var N = document.defaultView.getComputedStyle(M, "");
  31. if (N) {
  32. O = N[L(P)]
  33. }
  34. return M.style[P] || O
  35. }
  36. } else {
  37. if (document.documentElement.currentStyle && F) {
  38. J = function(M, O) {
  39. switch (L(O)) {
  40. case "opacity" :
  41. var Q = 100;
  42. try {
  43. Q = M.filters["DXImageTransform.Microsoft.Alpha"].opacity
  44. } catch (P) {
  45. try {
  46. Q = M.filters("alpha").opacity
  47. } catch (P) {
  48. }
  49. }
  50. return Q / 100;
  51. break;
  52. default :
  53. var N = M.currentStyle ? M.currentStyle[O] : null;
  54. return (M.style[O] || N)
  55. }
  56. }
  57. } else {
  58. J = function(M, N) {
  59. return M.style[N]
  60. }
  61. }
  62. }
  63. if (F) {
  64. H = function(M, N, O) {
  65. switch (N) {
  66. case "opacity" :
  67. if (typeof M.style.filter == "string") {
  68. M.style.filter = "alpha(opacity=" + O * 100 + ")";
  69. if (!M.currentStyle || !M.currentStyle.hasLayout) {
  70. M.style.zoom = 1
  71. }
  72. }
  73. break;
  74. default :
  75. M.style[N] = O
  76. }
  77. }
  78. } else {
  79. H = function(M, N, O) {
  80. M.style[N] = O
  81. }
  82. }
  83. YAHOO.util.Dom = {
  84. get : function(O) {
  85. if (!O) {
  86. return null
  87. }
  88. if (typeof O != "string" && !(O instanceof Array)) {
  89. return O
  90. }
  91. if (typeof O == "string") {
  92. return document.getElementById(O)
  93. } else {
  94. var P = [];
  95. for (var N = 0, M = O.length; N < M; ++N) {
  96. P[P.length] = C.Dom.get(O[N])
  97. }
  98. return P
  99. }
  100. return null
  101. },
  102. getStyle : function(M, O) {
  103. O = L(O);
  104. var N = function(P) {
  105. return J(P, O)
  106. };
  107. return C.Dom.batch(M, N, C.Dom, true)
  108. },
  109. setStyle : function(M, O, P) {
  110. O = L(O);
  111. var N = function(Q) {
  112. H(Q, O, P)
  113. };
  114. C.Dom.batch(M, N, C.Dom, true)
  115. },
  116. getXY : function(M) {
  117. var N = function(P) {
  118. if (P.parentNode === null || P.offsetParent === null
  119. || this.getStyle(P, "display") == "none") {
  120. return false
  121. }
  122. var O = null;
  123. var U = [];
  124. var Q;
  125. if (P.getBoundingClientRect) {
  126. Q = P.getBoundingClientRect();
  127. var S = document;
  128. if (!this.inDocument(P) && parent.document != document) {
  129. S = parent.document;
  130. if (!this.isAncestor(S.documentElement, P)) {
  131. return false
  132. }
  133. }
  134. var R = Math.max(S.documentElement.scrollTop,
  135. S.body.scrollTop);
  136. var T = Math.max(S.documentElement.scrollLeft,
  137. S.body.scrollLeft);
  138. return [Q.left + T, Q.top + R]
  139. } else {
  140. U = [P.offsetLeft, P.offsetTop];
  141. O = P.offsetParent;
  142. if (O != P) {
  143. while (O) {
  144. U[0] += O.offsetLeft;
  145. U[1] += O.offsetTop;
  146. O = O.offsetParent
  147. }
  148. }
  149. if (K && this.getStyle(P, "position") == "absolute") {
  150. U[0] -= document.body.offsetLeft;
  151. U[1] -= document.body.offsetTop
  152. }
  153. }
  154. if (P.parentNode) {
  155. O = P.parentNode
  156. } else {
  157. O = null
  158. }
  159. while (O && O.tagName.toUpperCase() != "BODY"
  160. && O.tagName.toUpperCase() != "HTML") {
  161. if (C.Dom.getStyle(O, "display") != "inline") {
  162. U[0] -= O.scrollLeft;
  163. U[1] -= O.scrollTop
  164. }
  165. if (O.parentNode) {
  166. O = O.parentNode
  167. } else {
  168. O = null
  169. }
  170. }
  171. return U
  172. };
  173. return C.Dom.batch(M, N, C.Dom, true)
  174. },
  175. getX : function(M) {
  176. var N = function(O) {
  177. return C.Dom.getXY(O)[0]
  178. };
  179. return C.Dom.batch(M, N, C.Dom, true)
  180. },
  181. getY : function(M) {
  182. var N = function(O) {
  183. return C.Dom.getXY(O)[1]
  184. };
  185. return C.Dom.batch(M, N, C.Dom, true)
  186. },
  187. setXY : function(M, P, O) {
  188. var N = function(S) {
  189. var R = this.getStyle(S, "position");
  190. if (R == "static") {
  191. this.setStyle(S, "position", "relative");
  192. R = "relative"
  193. }
  194. var U = this.getXY(S);
  195. if (U === false) {
  196. return false
  197. }
  198. var T = [parseInt(this.getStyle(S, "left"), 10),
  199. parseInt(this.getStyle(S, "top"), 10)];
  200. if (isNaN(T[0])) {
  201. T[0] = (R == "relative") ? 0 : S.offsetLeft
  202. }
  203. if (isNaN(T[1])) {
  204. T[1] = (R == "relative") ? 0 : S.offsetTop
  205. }
  206. if (P[0] !== null) {
  207. S.style.left = P[0] - U[0] + T[0] + "px"
  208. }
  209. if (P[1] !== null) {
  210. S.style.top = P[1] - U[1] + T[1] + "px"
  211. }
  212. if (!O) {
  213. var Q = this.getXY(S);
  214. if ((P[0] !== null && Q[0] != P[0])
  215. || (P[1] !== null && Q[1] != P[1])) {
  216. this.setXY(S, P, true)
  217. }
  218. }
  219. };
  220. C.Dom.batch(M, N, C.Dom, true)
  221. },
  222. setX : function(N, M) {
  223. C.Dom.setXY(N, [M, null])
  224. },
  225. setY : function(M, N) {
  226. C.Dom.setXY(M, [null, N])
  227. },
  228. getRegion : function(M) {
  229. var N = function(O) {
  230. var P = new C.Region.getRegion(O);
  231. return P
  232. };
  233. return C.Dom.batch(M, N, C.Dom, true)
  234. },
  235. getClientWidth : function() {
  236. return C.Dom.getViewportWidth()
  237. },
  238. getClientHeight : function() {
  239. return C.Dom.getViewportHeight()
  240. },
  241. getElementsByClassName : function(O, M, N) {
  242. var P = function(Q) {
  243. return C.Dom.hasClass(Q, O)
  244. };
  245. return C.Dom.getElementsBy(P, M, N)
  246. },
  247. hasClass : function(O, N) {
  248. var M = new RegExp("(?:^|\\s+)" + N + "(?:\\s+|$)");
  249. var P = function(Q) {
  250. return M.test(Q["className"])
  251. };
  252. return C.Dom.batch(O, P, C.Dom, true)
  253. },
  254. addClass : function(N, M) {
  255. var O = function(P) {
  256. if (this.hasClass(P, M)) {
  257. return
  258. }
  259. P["className"] = [P["className"], M].join(" ")
  260. };
  261. C.Dom.batch(N, O, C.Dom, true)
  262. },
  263. removeClass : function(O, N) {
  264. var M = new RegExp("(?:^|\\s+)" + N + "(?:\\s+|$)", "g");
  265. var P = function(Q) {
  266. if (!this.hasClass(Q, N)) {
  267. return
  268. }
  269. var R = Q["className"];
  270. Q["className"] = R.replace(M, " ");
  271. if (this.hasClass(Q, N)) {
  272. this.removeClass(Q, N)
  273. }
  274. };
  275. C.Dom.batch(O, P, C.Dom, true)
  276. },
  277. replaceClass : function(P, N, M) {
  278. if (N === M) {
  279. return false
  280. }
  281. var O = new RegExp("(?:^|\\s+)" + N + "(?:\\s+|$)", "g");
  282. var Q = function(R) {
  283. if (!this.hasClass(R, N)) {
  284. this.addClass(R, M);
  285. return
  286. }
  287. R["className"] = R["className"].replace(O, " " + M + " ");
  288. if (this.hasClass(R, N)) {
  289. this.replaceClass(R, N, M)
  290. }
  291. };
  292. C.Dom.batch(P, Q, C.Dom, true)
  293. },
  294. generateId : function(M, O) {
  295. O = O || "yui-gen";
  296. M = M || {};
  297. var N = function(P) {
  298. if (P) {
  299. P = C.Dom.get(P)
  300. } else {
  301. P = {}
  302. }
  303. if (!P.id) {
  304. P.id = O + G++
  305. }
  306. return P.id
  307. };
  308. return C.Dom.batch(M, N, C.Dom, true)
  309. },
  310. isAncestor : function(N, O) {
  311. N = C.Dom.get(N);
  312. if (!N || !O) {
  313. return false
  314. }
  315. var M = function(Q) {
  316. if (N.contains && !K) {
  317. return N.contains(Q)
  318. } else {
  319. if (N.compareDocumentPosition) {
  320. return !!(N.compareDocumentPosition(Q) & 16)
  321. } else {
  322. var P = Q.parentNode;
  323. while (P) {
  324. if (P == N) {
  325. return true
  326. } else {
  327. if (!P.tagName
  328. || P.tagName.toUpperCase() == "HTML") {
  329. return false
  330. }
  331. }
  332. P = P.parentNode
  333. }
  334. return false
  335. }
  336. }
  337. };
  338. return C.Dom.batch(O, M, C.Dom, true)
  339. },
  340. inDocument : function(M) {
  341. var N = function(O) {
  342. return this.isAncestor(document.documentElement, O)
  343. };
  344. return C.Dom.batch(M, N, C.Dom, true)
  345. },
  346. getElementsBy : function(S, N, O) {
  347. N = N || "*";
  348. var P = [];
  349. if (O) {
  350. O = C.Dom.get(O);
  351. if (!O) {
  352. return P
  353. }
  354. } else {
  355. O = document
  356. }
  357. var R = O.getElementsByTagName(N);
  358. if (!R.length && (N == "*" && O.all)) {
  359. R = O.all
  360. }
  361. for (var Q = 0, M = R.length; Q < M; ++Q) {
  362. if (S(R[Q])) {
  363. P[P.length] = R[Q]
  364. }
  365. }
  366. return P
  367. },
  368. batch : function(Q, M, P, O) {
  369. var N = Q;
  370. Q = C.Dom.get(Q);
  371. var U = (O) ? P : window;
  372. if (!Q || Q.tagName || !Q.length) {
  373. if (!Q) {
  374. return false
  375. }
  376. return M.call(U, Q, P)
  377. }
  378. var S = [];
  379. for (var R = 0, T = Q.length; R < T; ++R) {
  380. if (!Q[R]) {
  381. N = Q[R]
  382. }
  383. S[S.length] = M.call(U, Q[R], P)
  384. }
  385. return S
  386. },
  387. getDocumentHeight : function() {
  388. var N = (document.compatMode != "CSS1Compat")
  389. ? document.body.scrollHeight
  390. : document.documentElement.scrollHeight;
  391. var M = Math.max(N, C.Dom.getViewportHeight());
  392. return M
  393. },
  394. getDocumentWidth : function() {
  395. var N = (document.compatMode != "CSS1Compat")
  396. ? document.body.scrollWidth
  397. : document.documentElement.scrollWidth;
  398. var M = Math.max(N, C.Dom.getViewportWidth());
  399. return M
  400. },
  401. getViewportHeight : function() {
  402. var M = self.innerHeight;
  403. var N = document.compatMode;
  404. if ((N || F) && !D) {
  405. M = (N == "CSS1Compat")
  406. ? document.documentElement.clientHeight
  407. : document.body.clientHeight
  408. }
  409. return M
  410. },
  411. getViewportWidth : function() {
  412. var M = self.innerWidth;
  413. var N = document.compatMode;
  414. if (N || F) {
  415. M = (N == "CSS1Compat")
  416. ? document.documentElement.clientWidth
  417. : document.body.clientWidth
  418. }
  419. return M
  420. }
  421. }
  422. })();
  423. YAHOO.util.Region = function(C, D, A, B) {
  424. this.top = C;
  425. this[1] = C;
  426. this.right = D;
  427. this.bottom = A;
  428. this.left = B;
  429. this[0] = B
  430. };
  431. YAHOO.util.Region.prototype.contains = function(A) {
  432. return (A.left >= this.left && A.right <= this.right && A.top >= this.top && A.bottom <= this.bottom)
  433. };
  434. YAHOO.util.Region.prototype.getArea = function() {
  435. return ((this.bottom - this.top) * (this.right - this.left))
  436. };
  437. YAHOO.util.Region.prototype.intersect = function(E) {
  438. var C = Math.max(this.top, E.top);
  439. var D = Math.min(this.right, E.right);
  440. var A = Math.min(this.bottom, E.bottom);
  441. var B = Math.max(this.left, E.left);
  442. if (A >= C && D >= B) {
  443. return new YAHOO.util.Region(C, D, A, B)
  444. } else {
  445. return null
  446. }
  447. };
  448. YAHOO.util.Region.prototype.union = function(E) {
  449. var C = Math.min(this.top, E.top);
  450. var D = Math.max(this.right, E.right);
  451. var A = Math.max(this.bottom, E.bottom);
  452. var B = Math.min(this.left, E.left);
  453. return new YAHOO.util.Region(C, D, A, B)
  454. };
  455. YAHOO.util.Region.prototype.toString = function() {
  456. return ("Region {" + "top: " + this.top + ", right: " + this.right
  457. + ", bottom: " + this.bottom + ", left: " + this.left + "}")
  458. };
  459. YAHOO.util.Region.getRegion = function(D) {
  460. var F = YAHOO.util.Dom.getXY(D);
  461. var C = F[1];
  462. var E = F[0] + D.offsetWidth;
  463. var A = F[1] + D.offsetHeight;
  464. var B = F[0];
  465. return new YAHOO.util.Region(C, E, A, B)
  466. };
  467. YAHOO.util.Point = function(A, B) {
  468. if (A instanceof Array) {
  469. B = A[1];
  470. A = A[0]
  471. }
  472. this.x = this.right = this.left = this[0] = A;
  473. this.y = this.top = this.bottom = this[1] = B
  474. };
  475. YAHOO.util.Point.prototype = new YAHOO.util.Region();
  476. YAHOO.register("dom", YAHOO.util.Dom, {
  477. version : "2.2.0",
  478. build : "127"
  479. });