o2.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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. var doc = (options && options.doc) || document;
  161. if (!doc.unid) doc.unid = _uuid();
  162. return {
  163. "noCache": !!(options && options.nocache),
  164. "reload": !!(options && options.reload),
  165. "sequence": !!(options && options.sequence),
  166. "doc": doc,
  167. "dom": (options && options.dom) || document.body,
  168. "position": "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
  169. }
  170. };
  171. var _getCssOptions = function(options){
  172. var doc = (options && options.doc) || document;
  173. if (!doc.unid) doc.unid = _uuid();
  174. return {
  175. "noCache": !!(options && options.nocache),
  176. "reload": !!(options && options.reload),
  177. "sequence": !!(options && options.sequence),
  178. "doc": doc,
  179. "dom": (options && options.dom) || null
  180. }
  181. };
  182. var _getJsOptions = function(options){
  183. var doc = (options && options.doc) || document;
  184. if (!doc.unid) doc.unid = _uuid();
  185. return {
  186. "noCache": !!(options && options.nocache),
  187. "reload": !!(options && options.reload),
  188. "sequence": (!(options && options.sequence == false)),
  189. "doc": doc
  190. }
  191. };
  192. var _getHtmlOptions = function(options){
  193. var doc = (options && options.doc) || document;
  194. if (!doc.unid) doc.unid = _uuid();
  195. return {
  196. "noCache": !!(options && options.nocache),
  197. "reload": !!(options && options.reload),
  198. "sequence": !!(options && options.sequence),
  199. "doc": doc,
  200. "dom": (options && options.dom) || null,
  201. "position": "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
  202. }
  203. };
  204. var _xhr_get = function(url, success, failure){
  205. var xhr = new _request();
  206. xhr.open("GET", url, true);
  207. var _checkCssLoaded= function(_, err){
  208. if (!(xhr.readyState == 4 || err)) return;
  209. _removeListener(xhr, 'readystatechange', _checkCssLoaded);
  210. _removeListener(xhr, 'load', _checkCssLoaded);
  211. _removeListener(xhr, 'error', _checkCssErrorLoaded);
  212. if (err) {failure(xhr); return}
  213. var status = xhr.status;
  214. status = (status == 1223) ? 204 : status;
  215. if ((status >= 200 && status < 300))
  216. success(xhr);
  217. else if ((status >= 300 && status < 400))
  218. failure(xhr);
  219. else
  220. failure(xhr);
  221. };
  222. var _checkCssErrorLoaded= function(err){ _checkCssLoaded(err) };
  223. if ("load" in xhr) _addListener(xhr, "load", _checkCssLoaded);
  224. if ("error" in xhr) _addListener(xhr, "load", _checkCssErrorLoaded);
  225. _addListener(xhr, "readystatechange", _checkCssLoaded);
  226. xhr.send();
  227. };
  228. var _loadSequence = function(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun){
  229. loadSingle(ms[n], function(module){
  230. if (module) thisLoaded.push(module);
  231. n++;
  232. if (fun) fun(module);
  233. if (n===ms.length){
  234. if (cb) cb(thisLoaded);
  235. }else{
  236. _loadSequence(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun);
  237. }
  238. }, op, uuid);
  239. };
  240. var _loadDisarray = function(ms, cb, op, thisLoaded, loadSingle, uuid, fun){
  241. var count=0;
  242. for (var i=0; i<ms.length; i++){
  243. loadSingle(ms[i], function(module){
  244. if (module) thisLoaded.push(module);
  245. count++;
  246. if (fun) fun(module);
  247. if (count===ms.length) if (cb) cb(thisLoaded);
  248. }, op, uuid);
  249. }
  250. };
  251. //use framework url
  252. var _frameworks = {
  253. "o2.core": ["/o2_core/o2/o2.core.js"],
  254. "o2.more": ["/o2_core/o2/o2.more.js"],
  255. "ie_adapter": ["/o2_lib/o2/ie_adapter.js"],
  256. "jquery": ["/o2_lib/jquery/jquery.min.js"],
  257. "mootools": ["/o2_lib/mootools/mootools-1.6.0_all.js"],
  258. "ckeditor": ["/o2_lib/htmleditor/ckeditor/ckeditor.js"],
  259. "raphael": ["/o2_lib/raphael/raphael.js"],
  260. "d3": ["/o2_lib/d3/d3.min.js"],
  261. "ace": ["/o2_lib/ace/src-noconflict/ace.js","/o2_lib/ace/src-noconflict/ext-language_tools.js"],
  262. "JSBeautifier": ["/o2_lib/JSBeautifier/beautify.js"],
  263. "JSBeautifier_css": ["/o2_lib/JSBeautifier/beautify-css.js"],
  264. "JSBeautifier_html": ["/o2_lib/JSBeautifier/beautify-html.js"],
  265. "JSONTemplate": ["/o2_lib/mootools/plugin/Template.js"],
  266. "kity": ["/o2_lib/kityminder/kity/kity.min.js"],
  267. "kityminder": ["/o2_lib/kityminder/core/dist/kityminder.core.js"]
  268. };
  269. var _loaded = {};
  270. var _loadedCss = {};
  271. var _loadedHtml = {};
  272. var _loadSingle = function(module, callback, op){
  273. var url = module;
  274. var uuid = _uuid();
  275. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uuid : addr_uri+"?v="+uuid;
  276. var key = encodeURIComponent(url+op.doc.unid);
  277. if (!op.reload) if (_loaded[key]){
  278. if (callback)callback(); return;
  279. }
  280. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  281. var s = op.doc.createElement('script');
  282. head.appendChild(s);
  283. s.id = uuid;
  284. s.src = url;
  285. var _checkScriptLoaded = function(_, isAbort, err){
  286. if (isAbort || !s.readyState || s.readyState === "loaded" || s.readyState === "complete") {
  287. var scriptObj = {"module": module, "id": uuid, "script": s, "doc": op.doc};
  288. if (!err) _loaded[key] = scriptObj;
  289. _removeListener(s, 'readystatechange', _checkScriptLoaded);
  290. _removeListener(s, 'load', _checkScriptLoaded);
  291. _removeListener(s, 'error', _checkScriptErrorLoaded);
  292. if (!isAbort || err){
  293. if (err){
  294. if (s) head.removeChild(s);
  295. if (callback)callback();
  296. }else{
  297. head.removeChild(s);
  298. if (callback)callback(scriptObj);
  299. }
  300. }
  301. }
  302. };
  303. var _checkScriptErrorLoaded = function(e, err){
  304. console.log("Error: load javascript module: "+module);
  305. _checkScriptLoaded(e, true, "error");
  306. };
  307. if ('onreadystatechange' in s) _addListener(s, 'readystatechange', _checkScriptLoaded);
  308. _addListener(s, 'load', _checkScriptLoaded);
  309. _addListener(s, 'error', _checkScriptErrorLoaded);
  310. };
  311. var _load = function(urls, options, callback){
  312. var ms = (_typeOf(urls)==="array") ? urls : [urls];
  313. var op = (_typeOf(options)==="object") ? _getJsOptions(options) : _getJsOptions(null);
  314. var cb = (_typeOf(options)==="function") ? options : callback;
  315. var modules = [];
  316. for (var i=0; i<ms.length; i++){
  317. var url = ms[i];
  318. var module = _frameworks[url] || url;
  319. if (_typeOf(module)==="array"){
  320. modules = modules.concat(module)
  321. }else{
  322. modules.push(module)
  323. }
  324. }
  325. var thisLoaded = [];
  326. if (op.sequence){
  327. _loadSequence(modules, cb, op, 0, thisLoaded, _loadSingle);
  328. }else{
  329. _loadDisarray(modules, cb, op, thisLoaded, _loadSingle);
  330. }
  331. };
  332. this.o2.load = _load;
  333. var _loadSingleCss = function(module, callback, op, uuid){
  334. var url = module;
  335. var uid = _uuid();
  336. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  337. var key = encodeURIComponent(url+op.doc.unid);
  338. if (!op.reload) if (_loadedCss[key]){ if (callback)callback(_loadedCss[key]); return; }
  339. var success = function(xhr){
  340. var cssText = xhr.responseText;
  341. try{
  342. if (cssText){
  343. if (op.dom){
  344. var rex = new RegExp("(.+)(?=\\{)", "g");
  345. var match;
  346. while ((match = rex.exec(cssText)) !== null) {
  347. var prefix = "." + uuid + " ";
  348. var rule = prefix + match[0];
  349. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  350. rex.lastIndex = rex.lastIndex + prefix.length;
  351. }
  352. }
  353. var style = op.doc.createElement("style");
  354. style.setAttribute("type", "text/css");
  355. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  356. head.appendChild(style);
  357. if(style.styleSheet){
  358. var setFunc = function(){
  359. style.styleSheet.cssText = cssText;
  360. };
  361. if(style.styleSheet.disabled){
  362. setTimeout(setFunc, 10);
  363. }else{
  364. setFunc();
  365. }
  366. }else{
  367. var cssTextNode = op.doc.createTextNode(cssText);
  368. style.appendChild(cssTextNode);
  369. }
  370. }
  371. style.id = uid;
  372. var styleObj = {"module": module, "id": uid, "style": style, "doc": op.doc};
  373. _loadedCss[key] = styleObj;
  374. if (callback) callback(styleObj);
  375. }catch (e){
  376. if (callback) callback();
  377. return;
  378. }
  379. };
  380. var failure = function(xhr){
  381. console.log("Error: load css module: "+module);
  382. if (callback) callback();
  383. };
  384. _xhr_get(url, success, failure);
  385. };
  386. var _parseDomString = function(dom, fn, sourceDoc){
  387. var doc = sourceDoc || document;
  388. var list = doc.querySelectorAll(dom);
  389. if (list.length) for (var i=0; i<list.length; i++) _parseDomElement(list[i], fn);
  390. };
  391. var _parseDomElement = function(dom, fn){
  392. if (fn) fn(dom);
  393. };
  394. var _parseDom = function(dom, fn, sourceDoc){
  395. var domType = _typeOf(dom);
  396. if (domType==="string") _parseDomString(dom, fn, sourceDoc);
  397. if (domType==="element") _parseDomElement(dom, fn);
  398. if (domType==="array") for (var i=0; i<dom.length; i++) _parseDom(dom[i], fn, sourceDoc);
  399. };
  400. var _loadCss = function(modules, options, callback){
  401. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  402. var op = (_typeOf(options)==="object") ? _getCssOptions(options) : _getCssOptions(null);
  403. var cb = (_typeOf(options)==="function") ? options : callback;
  404. var uuid = "css"+_uuid();
  405. if (op.dom) _parseDom(op.dom, function(node){ node.className += ((node.className) ? " "+uuid : uuid)}, op.doc);
  406. var thisLoaded = [];
  407. if (op.sequence){
  408. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleCss, uuid);
  409. }else{
  410. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleCss, uuid);
  411. }
  412. };
  413. var _removeCss = function(module, doc){
  414. var thisDoc = doc || document;
  415. var k = encodeURIComponent(module+(thisDoc.unid||""));
  416. var removeCss = _loadedCss[k];
  417. if (!removeCss) for (key in _loadedCss){
  418. if (_loadedCss[key].id==module){
  419. removeCss = _loadedCss[key];
  420. k = key;
  421. break;
  422. }
  423. }
  424. if (removeCss){
  425. delete _loadedCss[k];
  426. var styleNode = removeCss.doc.getElementById(removeCss.id);
  427. if (styleNode) styleNode.parentNode.removeChild(styleNode);
  428. removeCss = null;
  429. }
  430. };
  431. this.o2.loadCss = _loadCss;
  432. this.o2.removeCss = _removeCss;
  433. Element.prototype.loadCss = function(modules, options, callback){
  434. var op = (_typeOf(options)==="object") ? options : {};
  435. var cb = (_typeOf(options)==="function") ? options : callback;
  436. op.dom = this;
  437. _loadCss(modules, op, cb);
  438. };
  439. _loadSingleHtml = function(module, callback, op){
  440. var url = module;
  441. var uid = _uuid();
  442. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  443. var key = encodeURIComponent(url+op.doc.unid);
  444. if (!op.reload) if (_loadedHtml[key]){ if (callback)callback(_loadedHtml[key]); return; }
  445. var success = function(xhr){
  446. var htmlObj = {"module": module, "id": uid, "data": xhr.responseText, "doc": op.doc};
  447. _loadedHtml[key] = htmlObj;
  448. if (callback) callback(htmlObj);
  449. };
  450. var failure = function(){
  451. console.log("Error: load html module: "+module);
  452. if (callback) callback();
  453. };
  454. _xhr_get(url, success, failure);
  455. };
  456. var _injectHtml = function(op, data){
  457. if (op.dom) _parseDom(op.dom, function(node){ node.insertAdjacentHTML(op.position, data) }, op.doc);
  458. };
  459. var _loadHtml = function(modules, options, callback){
  460. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  461. var op = (_typeOf(options)==="object") ? _getHtmlOptions(options) : _getHtmlOptions(null);
  462. var cb = (_typeOf(options)==="function") ? options : callback;
  463. var thisLoaded = [];
  464. if (op.sequence){
  465. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  466. }else{
  467. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  468. }
  469. };
  470. this.o2.loadHtml = _loadHtml;
  471. Element.prototype.loadHtml = function(modules, options, callback){
  472. var op = (_typeOf(options)==="object") ? options : {};
  473. var cb = (_typeOf(options)==="function") ? options : callback;
  474. op.dom = this;
  475. _loadHtml(modules, op, cb);
  476. };
  477. var _dom = {
  478. ready: false,
  479. loaded: false,
  480. checks: [],
  481. shouldPoll: false,
  482. timer: null,
  483. testElement: document.createElement('div'),
  484. readys: [],
  485. domready: function(){
  486. clearTimeout(_dom.timer);
  487. if (_dom.ready) return;
  488. _dom.loaded = _dom.ready = true;
  489. _removeListener(document, 'DOMContentLoaded', _dom.checkReady);
  490. _removeListener(document, 'readystatechange', _dom.check);
  491. _dom.onReady();
  492. },
  493. check: function(){
  494. for (var i = _dom.checks.length; i--;) if (_dom.checks[i]() && window.MooTools && o2.core && o2.more){
  495. _dom.domready();
  496. return true;
  497. }
  498. return false;
  499. },
  500. poll: function(){
  501. clearTimeout(_dom.timer);
  502. if (!_dom.check()) _dom.timer = setTimeout(_dom.poll, 10);
  503. },
  504. /*<ltIE8>*/
  505. // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
  506. // testElement.doScroll() throws when the DOM is not ready, only in the top window
  507. doScrollWorks: function(){
  508. try {
  509. _dom.testElement.doScroll();
  510. return true;
  511. } catch (e){}
  512. return false;
  513. },
  514. /*</ltIE8>*/
  515. onReady: function(){
  516. for (var i=0; i<_dom.readys.length; i++){
  517. this.readys[i].apply(window);
  518. }
  519. },
  520. addReady: function(fn){
  521. if (_dom.loaded){
  522. if (fn) fn.apply(window);
  523. }else{
  524. if (fn) _dom.readys.push(fn);
  525. }
  526. return _dom;
  527. },
  528. checkReady: function(){
  529. _dom.checks.push(function(){return true});
  530. _dom.check();
  531. }
  532. };
  533. var _loadO2 = function(){
  534. this.o2.load("o2.core", _dom.check);
  535. this.o2.load("o2.more", _dom.check);
  536. };
  537. _addListener(document, 'DOMContentLoaded', _dom.checkReady);
  538. /*<ltIE8>*/
  539. // If doScroll works already, it can't be used to determine domready
  540. // e.g. in an iframe
  541. if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
  542. _dom.checks.push(_dom.doScrollWorks);
  543. _dom.shouldPoll = true;
  544. }
  545. /*</ltIE8>*/
  546. if (document.readyState) _dom.checks.push(function(){
  547. var state = document.readyState;
  548. return (state == 'loaded' || state == 'complete');
  549. });
  550. if ('onreadystatechange' in document) _addListener(document, 'readystatechange', _dom.check);
  551. else _dom.shouldPoll = true;
  552. if (_dom.shouldPoll) _dom.poll();
  553. if (!window.MooTools){
  554. this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
  555. }else{
  556. _loadO2();
  557. }
  558. this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
  559. })();