easyloader.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. * EasyUI for jQuery 1.6.10
  3. *
  4. * Copyright (c) 2009-2018 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. *
  9. */
  10. /**
  11. * easyloader - EasyUI for jQuery
  12. *
  13. */
  14. (function(){
  15. var modules = {
  16. draggable:{
  17. js:'jquery.draggable.js'
  18. },
  19. droppable:{
  20. js:'jquery.droppable.js'
  21. },
  22. resizable:{
  23. js:'jquery.resizable.js'
  24. },
  25. linkbutton:{
  26. js:'jquery.linkbutton.js',
  27. css:'linkbutton.css'
  28. },
  29. progressbar:{
  30. js:'jquery.progressbar.js',
  31. css:'progressbar.css'
  32. },
  33. tooltip:{
  34. js:'jquery.tooltip.js',
  35. css:'tooltip.css'
  36. },
  37. pagination:{
  38. js:'jquery.pagination.js',
  39. css:'pagination.css',
  40. dependencies:['linkbutton']
  41. },
  42. datagrid:{
  43. js:'jquery.datagrid.js',
  44. css:'datagrid.css',
  45. dependencies:['panel','resizable','linkbutton','pagination']
  46. },
  47. treegrid:{
  48. js:'jquery.treegrid.js',
  49. css:'tree.css',
  50. dependencies:['datagrid']
  51. },
  52. propertygrid:{
  53. js:'jquery.propertygrid.js',
  54. css:'propertygrid.css',
  55. dependencies:['datagrid']
  56. },
  57. datalist:{
  58. js:'jquery.datalist.js',
  59. css:'datalist.css',
  60. dependencies:['datagrid']
  61. },
  62. panel: {
  63. js:'jquery.panel.js',
  64. css:'panel.css'
  65. },
  66. window:{
  67. js:'jquery.window.js',
  68. css:'window.css',
  69. dependencies:['resizable','draggable','panel']
  70. },
  71. dialog:{
  72. js:'jquery.dialog.js',
  73. css:'dialog.css',
  74. dependencies:['linkbutton','window']
  75. },
  76. messager:{
  77. js:'jquery.messager.js',
  78. css:'messager.css',
  79. dependencies:['linkbutton','dialog','progressbar']
  80. },
  81. layout:{
  82. js:'jquery.layout.js',
  83. css:'layout.css',
  84. dependencies:['resizable','panel']
  85. },
  86. form:{
  87. js:'jquery.form.js'
  88. },
  89. menu:{
  90. js:'jquery.menu.js',
  91. css:'menu.css'
  92. },
  93. tabs:{
  94. js:'jquery.tabs.js',
  95. css:'tabs.css',
  96. dependencies:['panel','linkbutton']
  97. },
  98. menubutton:{
  99. js:'jquery.menubutton.js',
  100. css:'menubutton.css',
  101. dependencies:['linkbutton','menu']
  102. },
  103. splitbutton:{
  104. js:'jquery.splitbutton.js',
  105. css:'splitbutton.css',
  106. dependencies:['menubutton']
  107. },
  108. switchbutton:{
  109. js:'jquery.switchbutton.js',
  110. css:'switchbutton.css'
  111. },
  112. accordion:{
  113. js:'jquery.accordion.js',
  114. css:'accordion.css',
  115. dependencies:['panel']
  116. },
  117. calendar:{
  118. js:'jquery.calendar.js',
  119. css:'calendar.css'
  120. },
  121. textbox:{
  122. js:'jquery.textbox.js',
  123. css:'textbox.css',
  124. dependencies:['validatebox','linkbutton']
  125. },
  126. passwordbox:{
  127. js:'jquery.passwordbox.js',
  128. css:'passwordbox.css',
  129. dependencies:['textbox']
  130. },
  131. filebox:{
  132. js:'jquery.filebox.js',
  133. css:'filebox.css',
  134. dependencies:['textbox']
  135. },
  136. radiobutton:{
  137. js:'jquery.radiobutton.js',
  138. css:'radiobutton.css'
  139. },
  140. checkbox:{
  141. js:'jquery.checkbox.js',
  142. css:'checkbox.css'
  143. },
  144. sidemenu:{
  145. js:'jquery.sidemenu.js',
  146. css:'sidemenu.css',
  147. dependencies:['accordion','tree','tooltip']
  148. },
  149. combo:{
  150. js:'jquery.combo.js',
  151. css:'combo.css',
  152. dependencies:['panel','textbox']
  153. },
  154. combobox:{
  155. js:'jquery.combobox.js',
  156. css:'combobox.css',
  157. dependencies:['combo']
  158. },
  159. combotree:{
  160. js:'jquery.combotree.js',
  161. dependencies:['combo','tree']
  162. },
  163. combogrid:{
  164. js:'jquery.combogrid.js',
  165. dependencies:['combo','datagrid']
  166. },
  167. combotreegrid:{
  168. js:'jquery.combotreegrid.js',
  169. dependencies:['combo','treegrid']
  170. },
  171. tagbox:{
  172. js:'jquery.tagbox.js',
  173. dependencies:['combobox']
  174. },
  175. validatebox:{
  176. js:'jquery.validatebox.js',
  177. css:'validatebox.css',
  178. dependencies:['tooltip']
  179. },
  180. numberbox:{
  181. js:'jquery.numberbox.js',
  182. dependencies:['textbox']
  183. },
  184. searchbox:{
  185. js:'jquery.searchbox.js',
  186. css:'searchbox.css',
  187. dependencies:['menubutton','textbox']
  188. },
  189. spinner:{
  190. js:'jquery.spinner.js',
  191. css:'spinner.css',
  192. dependencies:['textbox']
  193. },
  194. numberspinner:{
  195. js:'jquery.numberspinner.js',
  196. dependencies:['spinner','numberbox']
  197. },
  198. timespinner:{
  199. js:'jquery.timespinner.js',
  200. dependencies:['spinner']
  201. },
  202. tree:{
  203. js:'jquery.tree.js',
  204. css:'tree.css',
  205. dependencies:['draggable','droppable']
  206. },
  207. datebox:{
  208. js:'jquery.datebox.js',
  209. css:'datebox.css',
  210. dependencies:['calendar','combo']
  211. },
  212. datetimebox:{
  213. js:'jquery.datetimebox.js',
  214. dependencies:['datebox','timespinner']
  215. },
  216. slider:{
  217. js:'jquery.slider.js',
  218. dependencies:['draggable']
  219. },
  220. parser:{
  221. js:'jquery.parser.js'
  222. },
  223. mobile:{
  224. js:'jquery.mobile.js'
  225. }
  226. };
  227. var locales = {
  228. 'af':'easyui-lang-af.js',
  229. 'ar':'easyui-lang-ar.js',
  230. 'bg':'easyui-lang-bg.js',
  231. 'ca':'easyui-lang-ca.js',
  232. 'cs':'easyui-lang-cs.js',
  233. 'cz':'easyui-lang-cz.js',
  234. 'da':'easyui-lang-da.js',
  235. 'de':'easyui-lang-de.js',
  236. 'el':'easyui-lang-el.js',
  237. 'en':'easyui-lang-en.js',
  238. 'es':'easyui-lang-es.js',
  239. 'fr':'easyui-lang-fr.js',
  240. 'it':'easyui-lang-it.js',
  241. 'jp':'easyui-lang-jp.js',
  242. 'nl':'easyui-lang-nl.js',
  243. 'pl':'easyui-lang-pl.js',
  244. 'pt_BR':'easyui-lang-pt_BR.js',
  245. 'ru':'easyui-lang-ru.js',
  246. 'sv_SE':'easyui-lang-sv_SE.js',
  247. 'tr':'easyui-lang-tr.js',
  248. 'zh_CN':'easyui-lang-zh_CN.js',
  249. 'zh_TW':'easyui-lang-zh_TW.js'
  250. };
  251. var queues = {};
  252. function loadJs(url, callback){
  253. var done = false;
  254. var script = document.createElement('script');
  255. script.type = 'text/javascript';
  256. script.language = 'javascript';
  257. script.src = url;
  258. script.onload = script.onreadystatechange = function(){
  259. if (!done && (!script.readyState || script.readyState == 'loaded' || script.readyState == 'complete')){
  260. done = true;
  261. script.onload = script.onreadystatechange = null;
  262. if (callback){
  263. callback.call(script);
  264. }
  265. }
  266. }
  267. document.getElementsByTagName("head")[0].appendChild(script);
  268. }
  269. function runJs(url, callback){
  270. loadJs(url, function(){
  271. document.getElementsByTagName("head")[0].removeChild(this);
  272. if (callback){
  273. callback();
  274. }
  275. });
  276. }
  277. function loadCss(url, callback){
  278. var link = document.createElement('link');
  279. link.rel = 'stylesheet';
  280. link.type = 'text/css';
  281. link.media = 'screen';
  282. link.href = url;
  283. document.getElementsByTagName('head')[0].appendChild(link);
  284. if (callback){
  285. callback.call(link);
  286. }
  287. }
  288. function loadSingle(name, callback){
  289. queues[name] = 'loading';
  290. var module = modules[name];
  291. var jsStatus = 'loading';
  292. var cssStatus = (easyloader.css && module['css']) ? 'loading' : 'loaded';
  293. if (easyloader.css && module['css']){
  294. if (/^http/i.test(module['css'])){
  295. var url = module['css'];
  296. } else {
  297. var url = easyloader.base + 'themes/' + easyloader.theme + '/' + module['css'];
  298. }
  299. loadCss(url, function(){
  300. cssStatus = 'loaded';
  301. if (jsStatus == 'loaded' && cssStatus == 'loaded'){
  302. finish();
  303. }
  304. });
  305. }
  306. if (/^http/i.test(module['js'])){
  307. var url = module['js'];
  308. } else {
  309. var url = easyloader.base + 'plugins/' + module['js'];
  310. }
  311. loadJs(url, function(){
  312. jsStatus = 'loaded';
  313. if (jsStatus == 'loaded' && cssStatus == 'loaded'){
  314. finish();
  315. }
  316. });
  317. function finish(){
  318. queues[name] = 'loaded';
  319. easyloader.onProgress(name);
  320. if (callback){
  321. callback();
  322. }
  323. }
  324. }
  325. function loadModule(name, callback){
  326. var mm = [];
  327. var doLoad = false;
  328. if (typeof name == 'string'){
  329. add(name);
  330. } else {
  331. for(var i=0; i<name.length; i++){
  332. add(name[i]);
  333. }
  334. }
  335. function add(name){
  336. if (!modules[name]) return;
  337. var d = modules[name]['dependencies'];
  338. if (d){
  339. for(var i=0; i<d.length; i++){
  340. add(d[i]);
  341. }
  342. }
  343. mm.push(name);
  344. }
  345. function finish(){
  346. if (callback){
  347. callback();
  348. }
  349. easyloader.onLoad(name);
  350. }
  351. var time = 0;
  352. function loadMm(){
  353. if (mm.length){
  354. var m = mm[0]; // the first module
  355. if (!queues[m]){
  356. doLoad = true;
  357. loadSingle(m, function(){
  358. mm.shift();
  359. loadMm();
  360. });
  361. } else if (queues[m] == 'loaded'){
  362. mm.shift();
  363. loadMm();
  364. } else {
  365. if (time < easyloader.timeout){
  366. time += 10;
  367. setTimeout(arguments.callee, 10);
  368. }
  369. }
  370. } else {
  371. if (easyloader.locale && doLoad == true && locales[easyloader.locale]){
  372. var url = easyloader.base + 'locale/' + locales[easyloader.locale];
  373. runJs(url, function(){
  374. finish();
  375. });
  376. } else {
  377. finish();
  378. }
  379. }
  380. }
  381. loadMm();
  382. }
  383. easyloader = {
  384. modules:modules,
  385. locales:locales,
  386. base:'.',
  387. theme:'default',
  388. css:true,
  389. locale:null,
  390. timeout:2000,
  391. load: function(name, callback){
  392. if (/\.css$/i.test(name)){
  393. if (/^http/i.test(name)){
  394. loadCss(name, callback);
  395. } else {
  396. loadCss(easyloader.base + name, callback);
  397. }
  398. } else if (/\.js$/i.test(name)){
  399. if (/^http/i.test(name)){
  400. loadJs(name, callback);
  401. } else {
  402. loadJs(easyloader.base + name, callback);
  403. }
  404. } else {
  405. loadModule(name, callback);
  406. }
  407. },
  408. onProgress: function(name){},
  409. onLoad: function(name){}
  410. };
  411. var scripts = document.getElementsByTagName('script');
  412. for(var i=0; i<scripts.length; i++){
  413. var src = scripts[i].src;
  414. if (!src) continue;
  415. var m = src.match(/easyloader\.js(\W|$)/i);
  416. if (m){
  417. easyloader.base = src.substring(0, m.index);
  418. }
  419. }
  420. window.using = easyloader.load;
  421. if (window.jQuery){
  422. jQuery(function(){
  423. easyloader.load('parser', function(){
  424. jQuery.parser.parse();
  425. });
  426. });
  427. }
  428. })();