o2.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /** ***** BEGIN LICENSE BLOCK *****
  2. * |------------------------------------------------------------------------------|
  3. * | O2OA 活力办公 创意无限 o2.js |
  4. * |------------------------------------------------------------------------------|
  5. * | Distributed under the AGPL license: |
  6. * |------------------------------------------------------------------------------|
  7. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  8. * | All rights reserved. |
  9. * |------------------------------------------------------------------------------|
  10. *
  11. * This file is part of O2OA.
  12. *
  13. * O2OA is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * O2OA is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  25. *
  26. * ***** END LICENSE BLOCK ******/
  27. /* load o2 Core
  28. * |------------------------------------------------------------------------------|
  29. * |addReady: o2.addReady(fn), |
  30. * |------------------------------------------------------------------------------|
  31. * |load: o2.load(urls, callback, reload) |
  32. * |loadCss: o2.loadCss(urls, dom, callback, reload, doc) |
  33. * |------------------------------------------------------------------------------|
  34. * |typeOf: o2.typeOf(o) |
  35. * |------------------------------------------------------------------------------|
  36. * |uuid: o2.uuid() |
  37. * |------------------------------------------------------------------------------|
  38. */
  39. (function(){
  40. var _href = window.location.href;
  41. var _debug = (_href.indexOf("debugger")!==-1);
  42. var _par = _href.substr(_href.lastIndexOf("?")+1, _href.length);
  43. var _lp = "zh-cn";
  44. if (_par){
  45. var _parList = _par.split("&");
  46. for (var i=0; i<_parList.length; i++){
  47. var _v = _parList[i];
  48. var _kv = _v.split("=");
  49. if (_kv[0].toLowerCase()==="lg") _lp = _kv[1];
  50. }
  51. }
  52. this.o2 = {
  53. "version": {
  54. "v": '2.0.0',
  55. "build": "2018.11.22",
  56. "info": "O2OA 活力办公 创意无限. Copyright © 2018, o2oa.net O2 Team All rights reserved."
  57. },
  58. "session": {
  59. "isDebugger": _debug,
  60. "path": "/o2_core/o2"
  61. },
  62. "language": _lp,
  63. "splitStr": /(,\s*){1}|(;\s*){1}/g
  64. };
  65. var _attempt = function(){
  66. for (var i = 0, l = arguments.length; i < l; i++){
  67. try {
  68. arguments[i]();
  69. return arguments[i];
  70. } catch (e){}
  71. }
  72. return null;
  73. };
  74. var _typeOf = function(item){
  75. if (item == null) return 'null';
  76. if (item.$family != null) return item.$family();
  77. if (item.constructor == window.Array) return "array";
  78. if (item.nodeName){
  79. if (item.nodeType == 1) return 'element';
  80. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  81. } else if (typeof item.length == 'number'){
  82. if (item.callee) return 'arguments';
  83. }
  84. return typeof item;
  85. };
  86. this.o2.typeOf = _typeOf;
  87. var _addListener = function(dom, type, fn){
  88. if (type == 'unload'){
  89. var old = fn, self = this;
  90. fn = function(){
  91. _removeListener(dom, 'unload', fn);
  92. old();
  93. };
  94. }
  95. if (dom.addEventListener) dom.addEventListener(type, fn, !!arguments[2]);
  96. else dom.attachEvent('on' + type, fn);
  97. };
  98. var _removeListener = function(dom, type, fn){
  99. if (dom.removeEventListener) dom.removeEventListener(type, fn, !!arguments[2]);
  100. else dom.detachEvent('on' + type, fn);
  101. };
  102. //http request class
  103. var _request = (function(){
  104. var XMLHTTP = function(){ return new XMLHttpRequest(); };
  105. var MSXML2 = function(){ return new ActiveXObject('MSXML2.XMLHTTP'); };
  106. var MSXML = function(){ return new ActiveXObject('Microsoft.XMLHTTP'); };
  107. return _attempt(XMLHTTP, MSXML2, MSXML);
  108. })();
  109. var _returnBase = function(number, base) {
  110. return (number).toString(base).toUpperCase();
  111. };
  112. var _getIntegerBits = function(val, start, end){
  113. var base16 = _returnBase(val, 16);
  114. var quadArray = new Array();
  115. var quadString = '';
  116. var i = 0;
  117. for (i = 0; i < base16.length; i++) {
  118. quadArray.push(base16.substring(i, i + 1));
  119. }
  120. for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
  121. if (!quadArray[i] || quadArray[i] == '')
  122. quadString += '0';
  123. else
  124. quadString += quadArray[i];
  125. }
  126. return quadString;
  127. };
  128. var _rand = function(max) {
  129. return Math.floor(Math.random() * (max + 1));
  130. };
  131. var _uuid = function(){
  132. var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
  133. var dc = new Date();
  134. var t = dc.getTime() - dg.getTime();
  135. var tl = _getIntegerBits(t, 0, 31);
  136. var tm = _getIntegerBits(t, 32, 47);
  137. var thv = _getIntegerBits(t, 48, 59) + '1';
  138. var csar = _getIntegerBits(_rand(4095), 0, 7);
  139. var csl = _getIntegerBits(_rand(4095), 0, 7);
  140. var n = _getIntegerBits(_rand(8191), 0, 7)
  141. + _getIntegerBits(_rand(8191), 8, 15)
  142. + _getIntegerBits(_rand(8191), 0, 7)
  143. + _getIntegerBits(_rand(8191), 8, 15)
  144. + _getIntegerBits(_rand(8191), 0, 15);
  145. return tl + tm + thv + csar + csl + n;
  146. };
  147. this.o2.uuid = _uuid;
  148. var _runCallback = function(callback, key, par){
  149. if (typeOf(callback).toLowerCase() === 'function'){
  150. if (key.toLowerCase()==="success") callback.apply(callback, par);
  151. }else{
  152. if (typeOf(callback).toLowerCase()==='object'){
  153. var name = ("on-"+key).camelCase();
  154. if (callback[name]) callback[name].apply(callback, par);
  155. }
  156. }
  157. };
  158. this.o2.runCallback = _runCallback;
  159. var _getAllOptions = function(options){
  160. return {
  161. "noCache": !!(options && options.nocache),
  162. "reload": !!(options && options.reload),
  163. "sequence": !!(options && options.sequence),
  164. "doc": (options && options.doc) || document,
  165. "dom": (options && options.dom) || document.body,
  166. "position": "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
  167. }
  168. };
  169. var _getCssOptions = function(options){
  170. return {
  171. "noCache": !!(options && options.nocache),
  172. "reload": !!(options && options.reload),
  173. "sequence": !!(options && options.sequence),
  174. "doc": (options && options.doc) || document,
  175. "dom": (options && options.dom) || null
  176. }
  177. };
  178. var _getJsOptions = function(options){
  179. return {
  180. "noCache": !!(options && options.nocache),
  181. "reload": !!(options && options.reload),
  182. "sequence": !!(options && options.sequence),
  183. "doc": (options && options.doc) || document
  184. }
  185. };
  186. var _getHtmlOptions = function(options){
  187. return {
  188. "noCache": !!(options && options.nocache),
  189. "reload": !!(options && options.reload),
  190. "sequence": !!(options && options.sequence),
  191. "doc": (options && options.doc) || document,
  192. "dom": (options && options.dom) || null,
  193. "position": "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
  194. }
  195. };
  196. var _xhr_get = function(url, success, failure){
  197. var xhr = new _request();
  198. xhr.open("GET", url, true);
  199. var _checkCssLoaded= function(_, err){
  200. if (!(xhr.readyState == 4 || err)) return;
  201. _removeListener(xhr, 'readystatechange', _checkCssLoaded);
  202. _removeListener(xhr, 'load', _checkCssLoaded);
  203. _removeListener(xhr, 'error', _checkCssErrorLoaded);
  204. if (err) {failure(xhr); return}
  205. var status = xhr.status;
  206. status = (status == 1223) ? 204 : status;
  207. if ((status >= 200 && status < 300))
  208. success(xhr);
  209. else if ((status >= 300 && status < 400))
  210. failure(xhr);
  211. else
  212. failure(xhr);
  213. };
  214. var _checkCssErrorLoaded= function(err){ _checkCssLoaded(err) };
  215. if ("load" in xhr) _addListener(xhr, "load", _checkCssLoaded);
  216. if ("error" in xhr) _addListener(xhr, "load", _checkCssErrorLoaded);
  217. _addListener(xhr, "readystatechange", _checkCssLoaded);
  218. xhr.send();
  219. };
  220. var _loadSequence = function(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun){
  221. loadSingle(ms[n], function(module){
  222. if (module) thisLoaded.push(module);
  223. n++;
  224. if (fun) fun(module);
  225. if (n===ms.length){
  226. if (cb) cb(thisLoaded);
  227. }else{
  228. _loadSequence(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun);
  229. }
  230. }, op, uuid);
  231. };
  232. var _loadDisarray = function(ms, cb, op, thisLoaded, loadSingle, uuid, fun){
  233. var count=0;
  234. for (var i=0; i<ms.length; i++){
  235. loadSingle(ms[i], function(module){
  236. if (module) thisLoaded.push(module);
  237. count++;
  238. if (fun) fun(module);
  239. if (count===ms.length) if (cb) cb(thisLoaded);
  240. }, op, uuid);
  241. }
  242. };
  243. //use framework url
  244. var _frameworks = {
  245. "o2.core": ["/o2_core/o2/o2.core.js"],
  246. "o2.more": ["/o2_core/o2/o2.more.js"],
  247. "ie_adapter": ["/o2_lib/o2/ie_adapter.js"],
  248. "jquery": ["/o2_lib/jquery/jquery.min.js"],
  249. "mootools": ["/o2_lib/mootools/mootools-1.6.0.js"],
  250. "ckeditor": ["/o2_lib/htmleditor/ckeditor/ckeditor.js"],
  251. "raphael": ["/o2_lib/raphael/raphael.js"],
  252. "d3": ["/o2_lib/d3/d3.min.js"],
  253. "ace": ["/o2_lib/ace/src-noconflict/ace.js","/o2_lib/ace/src-noconflict/ext-language_tools.js"],
  254. "JSBeautifier": ["/o2_lib/JSBeautifier/beautify.js"],
  255. "JSBeautifier_css": ["/o2_lib/JSBeautifier/beautify-css.js"],
  256. "JSBeautifier_html": ["/o2_lib/JSBeautifier/beautify-html.js"]
  257. };
  258. var _loaded = {};
  259. var _loadedCss = {};
  260. var _loadedHtml = {};
  261. var _loadSingle = function(module, callback, op){
  262. var url = module;
  263. var uuid = _uuid();
  264. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uuid : addr_uri+"?v="+uuid;
  265. var key = encodeURIComponent(url);
  266. if (!op.reload) if (_loaded[key]){ if (callback)callback(); return; }
  267. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  268. var s = op.doc.createElement('script');
  269. head.appendChild(s);
  270. s.id = uuid;
  271. s.src = url;
  272. var _checkScriptLoaded = function(_, isAbort, err){
  273. if (isAbort || !s.readyState || s.readyState === "loaded" || s.readyState === "complete") {
  274. var scriptObj = {"module": module, "id": uuid, "script": s, "doc": op.doc};
  275. if (!err) _loaded[key] = scriptObj;
  276. _removeListener(s, 'readystatechange', _checkScriptLoaded);
  277. _removeListener(s, 'load', _checkScriptLoaded);
  278. _removeListener(s, 'error', _checkScriptErrorLoaded);
  279. if (!isAbort || err){
  280. if (err){
  281. if (s) head.removeChild(s);
  282. if (callback)callback();
  283. }else{
  284. head.removeChild(s);
  285. if (callback)callback(scriptObj);
  286. }
  287. }
  288. }
  289. };
  290. var _checkScriptErrorLoaded = function(e, err){
  291. console.log("Error: load javascript module: "+module);
  292. _checkScriptLoaded(e, true, "error");
  293. };
  294. if ('onreadystatechange' in s) _addListener(s, 'readystatechange', _checkScriptLoaded);
  295. _addListener(s, 'load', _checkScriptLoaded);
  296. _addListener(s, 'error', _checkScriptErrorLoaded);
  297. };
  298. var _load = function(urls, options, callback){
  299. var ms = (_typeOf(urls)==="array") ? urls : [urls];
  300. var op = (_typeOf(options)==="object") ? _getJsOptions(options) : _getJsOptions(null);
  301. var cb = (_typeOf(options)==="function") ? options : callback;
  302. var modules = [];
  303. for (var i=0; i<ms.length; i++){
  304. var url = ms[i];
  305. var module = _frameworks[url] || url;
  306. if (_typeOf(module)==="array"){
  307. modules = modules.concat(module)
  308. }else{
  309. modules.push(module)
  310. }
  311. }
  312. var thisLoaded = [];
  313. if (op.sequence){
  314. _loadSequence(modules, cb, op, 0, thisLoaded, _loadSingle);
  315. }else{
  316. _loadDisarray(modules, cb, op, thisLoaded, _loadSingle);
  317. }
  318. };
  319. this.o2.load = _load;
  320. var _loadSingleCss = function(module, callback, op, uuid){
  321. var url = module;
  322. var uid = _uuid();
  323. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  324. var key = encodeURIComponent(url);
  325. if (!op.reload) if (_loadedCss[key]){ if (callback)callback(_loadedCss[key]); return; }
  326. var success = function(xhr){
  327. var cssText = xhr.responseText;
  328. try{
  329. if (cssText){
  330. if (op.dom){
  331. var rex = new RegExp("(.+)(?=\\{)", "g");
  332. var match;
  333. while ((match = rex.exec(cssText)) !== null) {
  334. var prefix = "." + uuid + " ";
  335. var rule = prefix + match[0];
  336. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  337. rex.lastIndex = rex.lastIndex + prefix.length;
  338. }
  339. }
  340. var style = op.doc.createElement("style");
  341. style.setAttribute("type", "text/css");
  342. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  343. head.appendChild(style);
  344. if(style.styleSheet){
  345. var setFunc = function(){
  346. style.styleSheet.cssText = cssText;
  347. };
  348. if(style.styleSheet.disabled){
  349. setTimeout(setFunc, 10);
  350. }else{
  351. setFunc();
  352. }
  353. }else{
  354. var cssTextNode = op.doc.createTextNode(cssText);
  355. style.appendChild(cssTextNode);
  356. }
  357. }
  358. style.id = uid;
  359. var styleObj = {"module": module, "id": uid, "style": style, "doc": op.doc};
  360. _loadedCss[key] = styleObj;
  361. if (callback) callback(styleObj);
  362. }catch (e){
  363. if (callback) callback();
  364. return;
  365. }
  366. };
  367. var failure = function(xhr){
  368. console.log("Error: load css module: "+module);
  369. if (callback) callback();
  370. };
  371. _xhr_get(url, success, failure);
  372. };
  373. var _parseDomString = function(dom, fn, sourceDoc){
  374. var doc = sourceDoc || document;
  375. var list = doc.querySelectorAll(dom);
  376. if (list.length) for (var i=0; i<list.length; i++) _parseDomElement(list[i], fn);
  377. };
  378. var _parseDomElement = function(dom, fn){
  379. if (fn) fn(dom);
  380. };
  381. var _parseDom = function(dom, fn, sourceDoc){
  382. var domType = _typeOf(dom);
  383. if (domType==="string") _parseDomString(dom, fn, sourceDoc);
  384. if (domType==="element") _parseDomElement(dom, fn);
  385. if (domType==="array") for (var i=0; i<dom.length; i++) _parseDom(dom[i], fn, sourceDoc);
  386. };
  387. var _loadCss = function(modules, options, callback){
  388. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  389. var op = (_typeOf(options)==="object") ? _getCssOptions(options) : _getCssOptions(null);
  390. var cb = (_typeOf(options)==="function") ? options : callback;
  391. var uuid = "css"+_uuid();
  392. if (op.dom) _parseDom(op.dom, function(node){ node.className += ((node.className) ? " "+uuid : uuid)}, op.doc);
  393. var thisLoaded = [];
  394. if (op.sequence){
  395. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleCss, uuid);
  396. }else{
  397. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleCss, uuid);
  398. }
  399. };
  400. var _removeCss = function(module){
  401. var k = encodeURIComponent(module);
  402. var removeCss = _loadedCss[k];
  403. if (!removeCss) for (key in _loadedCss){
  404. if (_loadedCss[key].id==module){
  405. removeCss = _loadedCss[key];
  406. k = key;
  407. break;
  408. }
  409. }
  410. if (removeCss){
  411. delete _loadedCss[k];
  412. var styleNode = removeCss.doc.getElementById(removeCss.id);
  413. if (styleNode) styleNode.parentNode.removeChild(styleNode);
  414. removeCss = null;
  415. }
  416. };
  417. this.o2.loadCss = _loadCss;
  418. this.o2.removeCss = _removeCss;
  419. Element.prototype.loadCss = function(modules, options, callback){
  420. var op = (_typeOf(options)==="object") ? options : {};
  421. var cb = (_typeOf(options)==="function") ? options : callback;
  422. op.dom = this;
  423. _loadCss(modules, op, cb);
  424. };
  425. _loadSingleHtml = function(module, callback, op){
  426. var url = module;
  427. var uid = _uuid();
  428. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  429. var key = encodeURIComponent(url);
  430. if (!op.reload) if (_loadedHtml[key]){ if (callback)callback(_loadedHtml[key]); return; }
  431. var success = function(xhr){
  432. var htmlObj = {"module": module, "id": uid, "data": xhr.responseText, "doc": op.doc};
  433. _loadedHtml[key] = htmlObj;
  434. if (callback) callback(htmlObj);
  435. };
  436. var failure = function(){
  437. console.log("Error: load html module: "+module);
  438. if (callback) callback();
  439. };
  440. _xhr_get(url, success, failure);
  441. };
  442. var _injectHtml = function(op, data){
  443. if (op.dom) _parseDom(op.dom, function(node){ node.insertAdjacentHTML(op.position, data) }, op.doc);
  444. };
  445. var _loadHtml = function(modules, options, callback){
  446. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  447. var op = (_typeOf(options)==="object") ? _getHtmlOptions(options) : _getHtmlOptions(null);
  448. var cb = (_typeOf(options)==="function") ? options : callback;
  449. var thisLoaded = [];
  450. if (op.sequence){
  451. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  452. }else{
  453. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  454. }
  455. };
  456. this.o2.loadHtml = _loadHtml;
  457. Element.prototype.loadHtml = function(modules, options, callback){
  458. var op = (_typeOf(options)==="object") ? options : {};
  459. var cb = (_typeOf(options)==="function") ? options : callback;
  460. op.dom = this;
  461. _loadHtml(modules, op, cb);
  462. };
  463. var _dom = {
  464. ready: false,
  465. loaded: false,
  466. checks: [],
  467. shouldPoll: false,
  468. timer: null,
  469. testElement: document.createElement('div'),
  470. readys: [],
  471. domready: function(){
  472. clearTimeout(_dom.timer);
  473. if (_dom.ready) return;
  474. _dom.loaded = _dom.ready = true;
  475. _removeListener(document, 'DOMContentLoaded', _dom.checkReady);
  476. _removeListener(document, 'readystatechange', _dom.check);
  477. _dom.onReady();
  478. },
  479. check: function(){
  480. for (var i = _dom.checks.length; i--;) if (_dom.checks[i]() && window.MooTools && o2.core && o2.more){
  481. _dom.domready();
  482. return true;
  483. }
  484. return false;
  485. },
  486. poll: function(){
  487. clearTimeout(_dom.timer);
  488. if (!_dom.check()) _dom.timer = setTimeout(_dom.poll, 10);
  489. },
  490. /*<ltIE8>*/
  491. // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
  492. // testElement.doScroll() throws when the DOM is not ready, only in the top window
  493. doScrollWorks: function(){
  494. try {
  495. _dom.testElement.doScroll();
  496. return true;
  497. } catch (e){}
  498. return false;
  499. },
  500. /*</ltIE8>*/
  501. onReady: function(){
  502. for (var i=0; i<_dom.readys.length; i++){
  503. this.readys[i].apply(window);
  504. }
  505. },
  506. addReady: function(fn){
  507. if (_dom.loaded){
  508. if (fn) fn.apply(window);
  509. }else{
  510. if (fn) _dom.readys.push(fn);
  511. }
  512. return _dom;
  513. },
  514. checkReady: function(){
  515. _dom.checks.push(function(){return true});
  516. _dom.check();
  517. }
  518. };
  519. var _loadO2 = function(){
  520. this.o2.load("o2.core", _dom.check);
  521. this.o2.load("o2.more", _dom.check);
  522. };
  523. _addListener(document, 'DOMContentLoaded', _dom.checkReady);
  524. /*<ltIE8>*/
  525. // If doScroll works already, it can't be used to determine domready
  526. // e.g. in an iframe
  527. if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
  528. _dom.checks.push(_dom.doScrollWorks);
  529. _dom.shouldPoll = true;
  530. }
  531. /*</ltIE8>*/
  532. if (document.readyState) _dom.checks.push(function(){
  533. var state = document.readyState;
  534. return (state == 'loaded' || state == 'complete');
  535. });
  536. if ('onreadystatechange' in document) _addListener(document, 'readystatechange', _dom.check);
  537. else _dom.shouldPoll = true;
  538. if (_dom.shouldPoll) _dom.poll();
  539. if (!window.MooTools) this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
  540. this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
  541. })();