lhgcore.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. *@lhgcore - JavaScript Library v1.0.0 - Date : 2009-7-14
  3. *@Copyright lhgcore.js (c) 2009 By LiHuiGang Reserved
  4. */
  5. (function() {
  6. var g = window.lhgcore = window.J = function(a, d) {
  7. return g.ret.init(a, d)
  8. };
  9. g.ret = g.prototype = {
  10. init : function(a, d) {
  11. a = (a == 'body') ? document.body : (a == 'doc') ? document : a;
  12. if ('string' == typeof (a)) {
  13. if (a.indexOf('#') == 0) {
  14. var b = (d || document).getElementById(a.substr(1));
  15. if (b)
  16. return b;
  17. else
  18. return null
  19. }
  20. var b = (d || document).getElementById(a);
  21. if (b)
  22. return g(b);
  23. else
  24. return null
  25. } else {
  26. this[0] = a;
  27. this.length = 1;
  28. return this
  29. }
  30. },
  31. html : function(t) {
  32. if (t) {
  33. this[0].innerHTML = t;
  34. return this
  35. } else
  36. return this[0].innerHTML
  37. },
  38. isnl : function() {
  39. var v = this[0].value;
  40. return (v == '' || v.length == 0) ? true : false
  41. },
  42. val : function(v) {
  43. if (v) {
  44. this[0].value = v;
  45. return this
  46. } else
  47. return this[0].value
  48. },
  49. acls : function(c, p) {
  50. this[0].className = p ? this[0].className + ' ' + c : c;
  51. return this
  52. },
  53. rcls : function() {
  54. var a = g.ie ? 'className' : 'class';
  55. this[0].removeAttribute(a, 0);
  56. return this
  57. },
  58. crte : function(e) {
  59. return this[0].createElement(e)
  60. },
  61. apch : function(c, y) {
  62. switch (y) {
  63. case 'pr':
  64. return this[0].insertBefore(c, this[0].firstChild);
  65. break;
  66. case 'be':
  67. return this[0].parentNode.insertBefore(c, this[0]);
  68. break;
  69. case 'af':
  70. return this[0].parentNode.insertBefore(c, this[0].nextSibling);
  71. break;
  72. default:
  73. return this[0].appendChild(c);
  74. break
  75. }
  76. },
  77. stcs : function(d, s) {
  78. if (typeof (d) == 'object') {
  79. for ( var n in d)
  80. this[0].style[n] = d[n];
  81. return this
  82. } else {
  83. this[0].style[d] = s;
  84. return this
  85. }
  86. },
  87. gtcs : function(p) {
  88. if (g.ie)
  89. return this[0].currentStyle[p];
  90. else
  91. return this[0].ownerDocument.defaultView.getComputedStyle(
  92. this[0], '').getPropertyValue(p)
  93. },
  94. gtag : function(n) {
  95. return this[0].getElementsByTagName(n)
  96. },
  97. attr : function(k, v) {
  98. if (typeof (k) == 'object') {
  99. for ( var n in k)
  100. this[0][n] = k[n];
  101. return this
  102. }
  103. if (v) {
  104. this[0].setAttribute(k, v, 0);
  105. return this
  106. } else {
  107. var a = this[0].attributes[k];
  108. if (a == null || !a.specified)
  109. return '';
  110. return this[0].getAttribute(k, 2)
  111. }
  112. },
  113. ratt : function(n) {
  114. var a = this[0].attributes[n];
  115. if (a == null || !a.specified)
  116. return this;
  117. this[0].removeAttribute(n, 0);
  118. return this
  119. },
  120. aevt : function(n, f) {
  121. if (g.ie)
  122. this[0].attachEvent('on' + n, f);
  123. else
  124. this[0].addEventListener(n, f, false);
  125. return this
  126. },
  127. revt : function(n, f) {
  128. if (g.ie)
  129. this[0].detachEvent('on' + n, f);
  130. else
  131. this[0].removeEventListener(n, f, false);
  132. return this
  133. },
  134. alnk : function(c) {
  135. if (g.ie)
  136. return this[0].createStyleSheet(c).owningElement;
  137. else {
  138. var e = this[0].createElement('link');
  139. e.rel = 'stylesheet';
  140. e.type = 'text/css';
  141. e.href = c;
  142. this[0].getElementsByTagName('head')[0].appendChild(e);
  143. return e
  144. }
  145. }
  146. };
  147. g.ret.init.prototype = g.ret;
  148. g.exend = g.ret.exend = function() {
  149. var a = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
  150. if (a.constructor == Boolean) {
  151. deep = a;
  152. a = arguments[1] || {};
  153. i = 2
  154. }
  155. if (typeof a != 'object' && typeof a != 'function')
  156. a = {};
  157. if (length == i) {
  158. a = this;
  159. --i
  160. }
  161. for (; i < length; i++)
  162. if ((options = arguments[i]) != null)
  163. for ( var b in options) {
  164. var c = a[b], copy = options[b];
  165. if (a === copy)
  166. continue;
  167. if (deep && copy && typeof copy == 'object'
  168. && !copy.nodeType)
  169. a[b] = g.extend(deep, c
  170. || (copy.length != null ? [] : {}), copy);
  171. else if (copy !== undefined)
  172. a[b] = copy
  173. }
  174. return a
  175. };
  176. g.ret.exend({
  177. stopac : function(o) {
  178. if (g.ie) {
  179. o = Math.round(o * 100);
  180. this[0].style.filter = (o > 100 ? '' : 'alpha(opacity=' + o
  181. + ')')
  182. } else
  183. this[0].style.opacity = o
  184. },
  185. addentex : function(n, l, p) {
  186. if (g.ie) {
  187. var o = {};
  188. o.source = this[0];
  189. o.params = p || [];
  190. o.listen = function(a) {
  191. return l.apply(o.source, [ a ].concat(o.params))
  192. };
  193. if (g.clean)
  194. g.clean.items(null, function() {
  195. o.source = null;
  196. o.params = null
  197. });
  198. this[0].attachEvent('on' + n, o.listen);
  199. this[0] = null;
  200. p = null
  201. } else
  202. this[0].addEventListener(n, function(e) {
  203. l.apply(this[0], [ e ].concat(p || []))
  204. }, false);
  205. return this
  206. },
  207. click : function(f) {
  208. this[0].onclick = f;
  209. return this
  210. },
  211. blur : function(f) {
  212. this[0].onblur = f;
  213. return this
  214. },
  215. focus : function(f) {
  216. if (f)
  217. this[0].onfocus = f;
  218. else
  219. this[0].focus();
  220. return this
  221. },
  222. msdown : function(f) {
  223. this[0].onmousedown = f;
  224. return this
  225. },
  226. msmove : function(f) {
  227. this[0].onmousemove = f;
  228. return this
  229. },
  230. msover : function(f) {
  231. this[0].onmouseover = f;
  232. return this
  233. },
  234. msout : function(f) {
  235. this[0].onmouseout = f;
  236. return this
  237. },
  238. msup : function(f) {
  239. this[0].onmouseup = f;
  240. return this
  241. },
  242. submit : function(f) {
  243. if (f)
  244. this[0].onsubmit = f;
  245. else
  246. this[0].onsubmit();
  247. return this
  248. },
  249. cmenu : function(f) {
  250. this[0].oncontextmenu = f;
  251. return this
  252. },
  253. hover : function(r, t) {
  254. this[0].onmouseover = r;
  255. this[0].onmouseout = t;
  256. return this
  257. }
  258. });
  259. g
  260. .exend({
  261. build : '1.0.0',
  262. author : 'LiHuiGang',
  263. path : function(t) {
  264. t = t || 'lhgcore.js';
  265. var a, len, sc = g('doc').gtag('script');
  266. for ( var i = 0; i < sc.length; i++) {
  267. a = sc[i].src.substr(0, g.inde(sc[i].src.toLowerCase(),
  268. t));
  269. len = a.lastIndexOf('/');
  270. if (len > 0)
  271. a = a.substr(0, len + 1);
  272. if (a)
  273. break
  274. }
  275. if (g.ie && g.inde(a, '../') != -1) {
  276. var b = window.location.href;
  277. b = b.substr(0, b.lastIndexOf('/'));
  278. while (g.inde(a, '../') >= 0) {
  279. a = a.substr(3);
  280. b = b.substr(0, b.lastIndexOf('/'))
  281. }
  282. return b + '/' + a
  283. } else
  284. return a
  285. },
  286. idtd : function(d) {
  287. return ('CSS1Compat' == (d.compatMode || 'CSS1Compat'))
  288. },
  289. rech : function(c) {
  290. if (c)
  291. return c.parentNode.removeChild(c)
  292. },
  293. gtev : function() {
  294. if (g.ie)
  295. return window.event;
  296. var a = this.gtev.caller;
  297. while (a != null) {
  298. var b = a.arguments[0];
  299. if (b && (b + '').indexOf('Event') >= 0)
  300. return b;
  301. a = a.caller
  302. }
  303. return null
  304. },
  305. trim : function(t) {
  306. return (t || '').replace(/^\s+|\s+$/g, '')
  307. },
  308. inde : function(t, s) {
  309. return t.indexOf(s)
  310. },
  311. edoc : function(a) {
  312. return a.ownerDocument || a.document
  313. },
  314. ewin : function(a) {
  315. return this.dwin(this.edoc(a))
  316. },
  317. dwin : function(d) {
  318. if (g.sa && !d.parentWindow)
  319. this.fixw(window.top);
  320. return d.parentWindow || d.defaultView
  321. },
  322. fixw : function(w) {
  323. if (w.document)
  324. w.document.parentWindow = w;
  325. for ( var i = 0; i < w.frames.length; i++)
  326. g.fixw(w.frames[i])
  327. },
  328. vsiz : function(a) {
  329. if (g.ie) {
  330. var b, doc = a.document.documentElement;
  331. if (doc && doc.clientWidth)
  332. b = doc;
  333. else
  334. b = a.document.body;
  335. if (b)
  336. return {
  337. w : b.clientWidth,
  338. h : b.clientHeight
  339. };
  340. else
  341. return {
  342. w : 0,
  343. h : 0
  344. }
  345. } else
  346. return {
  347. w : a.innerWidth,
  348. h : a.innerHeight
  349. }
  350. },
  351. spos : function(w) {
  352. if (g.ie) {
  353. var a = w.document;
  354. oPos = {
  355. x : a.documentElement.scrollLeft,
  356. y : a.documentElement.scrollTop
  357. };
  358. if (oPos.x > 0 || oPos.y > 0)
  359. return oPos;
  360. return {
  361. x : a.body.scrollLeft,
  362. y : a.body.scrollTop
  363. }
  364. } else
  365. return {
  366. x : w.pageXOffset,
  367. y : w.pageYOffset
  368. }
  369. },
  370. dpos : function(w, n) {
  371. var x = 0, y = 0, cn = n, pn = null, cw = g.ewin(cn);
  372. while (cn
  373. && !(cw == w && (cn == w.document.body || cn == w.document.documentElement))) {
  374. x += cn.offsetLeft - cn.scrollLeft;
  375. y += cn.offsetTop - cn.scrollTop;
  376. if (g.op) {
  377. var a = pn;
  378. while (a && a != cn) {
  379. x -= a.scrollLeft;
  380. y -= a.scrollTop;
  381. a = a.parentNode
  382. }
  383. }
  384. pn = cn;
  385. if (cn.offsetParent)
  386. cn = cn.offsetParent;
  387. else {
  388. if (cw != w) {
  389. cn = cw.frameElement;
  390. pn = null;
  391. if (cn)
  392. cw = cn.contentWindow.parent
  393. } else
  394. cn = null
  395. }
  396. }
  397. if (g(w.document.body).gtcs('position') != 'static'
  398. || (g.ie && g.gtan(n) == null)) {
  399. x += w.document.body.offsetLeft;
  400. y += w.document.body.offsetTop
  401. }
  402. return {
  403. 'x' : x,
  404. 'y' : y
  405. }
  406. },
  407. gtan : function(e) {
  408. var a = e;
  409. while (a != g.edoc(a).documentElement) {
  410. if (g(a).gtcs('position') != 'static')
  411. return a;
  412. a = a.parentNode
  413. }
  414. return null
  415. },
  416. canc : function(e) {
  417. if (g.ie)
  418. return false;
  419. else {
  420. if (e)
  421. e.preventDefault()
  422. }
  423. },
  424. empty : function(t) {
  425. return (t == '' || t.length == 0) ? true : false
  426. },
  427. dismn : function(e) {
  428. var a = e || window.event, el = a.srcElement || a.target, tn = el.tagName;
  429. if (!((tn == 'INPUT' && el.type == 'text') || tn == 'TEXTAREA')) {
  430. if (g.ie)
  431. return false;
  432. else {
  433. if (e)
  434. e.preventDefault()
  435. }
  436. }
  437. },
  438. nosel : function(o) {
  439. if (g.ie) {
  440. o.unselectable = 'on';
  441. var e, i = 0;
  442. while ((e = o.all[i++])) {
  443. switch (e.tagName.toLowerCase()) {
  444. case 'iframe':
  445. case 'textarea':
  446. case 'input':
  447. case 'select':
  448. break;
  449. default:
  450. e.unselectable = 'on'
  451. }
  452. }
  453. } else {
  454. if (g.mz)
  455. o.style.MozUserSelect = 'none';
  456. else if (g.sa)
  457. o.style.KhtmlUserSelect = 'none';
  458. else
  459. o.style.userSelect = 'none'
  460. }
  461. },
  462. gtvod : function() {
  463. if (g.ie)
  464. return (g.i7 ? '' : 'javascript:\'\'');
  465. return 'javascript:void(0)'
  466. }
  467. });
  468. var j = navigator.userAgent.toLowerCase();
  469. g.exend({
  470. ie : /msie/.test(j) && !/opera/.test(j),
  471. i7 : (j.match(/msie (\d+)/) || [])[1] >= 7 && !/opera/.test(j),
  472. ch : /chrome/.test(j),
  473. op : /opera/.test(j),
  474. sa : /webkit/.test(j) && !/chrome/.test(j),
  475. mz : /mozilla/.test(j) && !/(compatible|webkit)/.test(j)
  476. });
  477. g.exend({
  478. cleanup : function() {
  479. if (window._lhgcleanobj)
  480. this.citem = window._lhgcleanobj.citem;
  481. else {
  482. this.citem = [];
  483. window._lhgcleanobj = this;
  484. J(window).addentex('unload', this.lhg_clean)
  485. }
  486. }
  487. });
  488. g.exend(g.cleanup.prototype, {
  489. items : function(a, b) {
  490. this.citem.push([ a, b ])
  491. },
  492. lhg_clean : function() {
  493. if (!this._lhgcleanobj)
  494. return;
  495. var a = this._lhgcleanobj.citem;
  496. while (a.length > 0) {
  497. var b = a.pop();
  498. if (b)
  499. b[1].call(b[0])
  500. }
  501. this._lhgcleanobj = null;
  502. g = null;
  503. if (CollectGarbage)
  504. CollectGarbage()
  505. }
  506. });
  507. if (g.ie)
  508. g.clean = new g.cleanup();
  509. J
  510. .exend({
  511. panel : function(b, w) {
  512. this._win = window;
  513. var a, doc, r_win = [ this._win ];
  514. if (b) {
  515. while (this._win.parent
  516. && this._win.parent != this._win) {
  517. try {
  518. if (this._win.parent.document.domain != document.domain)
  519. break
  520. } catch (e) {
  521. break
  522. }
  523. this._win = this._win.parent;
  524. r_win.push(this._win)
  525. }
  526. }
  527. if (w) {
  528. for ( var i = 0; i < w.length; i++)
  529. r_win.push(w[i])
  530. }
  531. a = this._ifrm = J(this._win.document).crte('iframe');
  532. J(a).attr({
  533. src : 'javascript:void(0)',
  534. frameBorder : 0,
  535. scrolling : 'no'
  536. }).stcs({
  537. display : 'none',
  538. position : 'absolute',
  539. zIndex : 19700
  540. });
  541. J(this._win.document.body).apch(a);
  542. doc = this._doc = a.contentWindow.document;
  543. if (J.ie)
  544. g.clean.items(this, this.p_clean);
  545. var c = '';
  546. if (J.sa)
  547. c = '<base href="' + window.document.location + '">';
  548. doc.open();
  549. doc
  550. .write('<html><head>'
  551. + c
  552. + '<\/head><body style="margin:0px;padding:0px;"><\/body><\/html>');
  553. doc.close();
  554. for ( var i = 0; i < r_win.length; i++)
  555. J(r_win[i].document).addentex('click', this.hide, this);
  556. J(doc).aevt('contextmenu', J.dismn);
  557. this._main = J(doc.body).apch(doc.createElement('div'));
  558. this._main.style.cssFloat = 'left'
  559. }
  560. });
  561. J.exend(J.panel.prototype,
  562. {
  563. applnk : function(l) {
  564. J(this._doc).alnk(l)
  565. },
  566. show : function(x, y, e, w, h) {
  567. var a = this._main, iw, ih;
  568. J(this._ifrm).stcs('display', 'block');
  569. J(a).stcs({
  570. width : w ? w + 'px' : '',
  571. height : h ? h + 'px' : ''
  572. });
  573. iw = a.offsetWidth;
  574. ih = a.offsetHeight;
  575. if (!w)
  576. this._ifrm.style.width = '1px';
  577. if (!h)
  578. this._ifrm.style.height = '1px';
  579. iw = a.offsetWidth || a.firstChild.offsetWidth;
  580. var b = e.nodeType == 9 ? J.idtd(e) ? e.documentElement
  581. : e.body : e;
  582. var c = J.dpos(this._win, b);
  583. x += c.x;
  584. y += c.y;
  585. var d = J.vsiz(this._win), sp = J.spos(this._win), vh = d.h
  586. + sp.y, vw = d.w + sp.x;
  587. if ((x + iw) > vw)
  588. x -= x + iw - vw;
  589. if ((y + ih) > vh)
  590. y -= y + ih - vh;
  591. J(this._ifrm).stcs({
  592. left : x + 'px',
  593. top : y + 'px',
  594. width : iw + 'px',
  595. height : ih + 'px'
  596. })
  597. },
  598. hide : function(e, a) {
  599. J(a._ifrm).stcs('display', 'none')
  600. },
  601. p_clean : function() {
  602. this._main = null;
  603. this._doc = null;
  604. this._ifrm = null;
  605. this._win = null
  606. }
  607. });
  608. g.ajax = g.A = {
  609. geth : function() {
  610. try {
  611. return new ActiveXObject('Msxml2.XMLHTTP')
  612. } catch (e) {
  613. }
  614. try {
  615. return new XMLHttpRequest()
  616. } catch (e) {
  617. }
  618. return null
  619. },
  620. send : function(u, m, p, f, x) {
  621. m = m ? m.toLocaleUpperCase() : 'GET';
  622. x = x ? x : 0;
  623. p = p ? p + '&uuid=' + new Date().getTime() : null;
  624. var a = (typeof (f) == 'function'), ret;
  625. var b = this.geth();
  626. b.open(m, u, a);
  627. if (a) {
  628. b.onreadystatechange = function() {
  629. if (b.readyState == 4) {
  630. ret = (x == 0) ? b.responseText : b.responseXML;
  631. f(ret);
  632. delete (b);
  633. return
  634. } else
  635. return false
  636. }
  637. }
  638. if (m == 'GET')
  639. b.send(null);
  640. else {
  641. b.setRequestHeader('content-type',
  642. 'application/x-www-form-urlencoded');
  643. if (p)
  644. b.send(p);
  645. else
  646. return false
  647. }
  648. if (!a) {
  649. if (b.readyState == 4 && b.status == 200) {
  650. ret = (x == 0) ? b.responseText : b.responseXML;
  651. delete (b);
  652. return ret
  653. } else
  654. return false
  655. }
  656. }
  657. }
  658. })();