wind.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /*!
  2. * HeadJS The only script in your <HEAD>
  3. * Author Tero Piirainen (tipiirai)
  4. * Maintainer Robert Hoffmann (itechnology)
  5. * License MIT / http://bit.ly/mit-license
  6. *
  7. * Version 0.99
  8. * http://headjs.com
  9. */
  10. /* modify : head ==> Wind */
  11. ; (function (win, undefined) {
  12. "use strict";
  13. var doc = win.document,
  14. domWaiters = [],
  15. queue = [], // waiters for the "head ready" event
  16. handlers = {}, // user functions waiting for events
  17. assets = {}, // loadable items in various states
  18. isAsync = "async" in doc.createElement("script") || "MozAppearance" in doc.documentElement.style || win.opera,
  19. isHeadReady,
  20. isDomReady,
  21. /*** public API ***/
  22. headVar = win.head_conf && win.head_conf.head || "Wind",
  23. api = win[headVar] = (win[headVar] || function () { api.ready.apply(null, arguments); }),
  24. // states
  25. PRELOADING = 1,
  26. PRELOADED = 2,
  27. LOADING = 3,
  28. LOADED = 4;
  29. // Method 1: simply load and let browser take care of ordering
  30. if (isAsync) {
  31. api.load = function () {
  32. ///<summary>
  33. /// INFO: use cases
  34. /// head.load("http://domain.com/file.js","http://domain.com/file.js", callBack)
  35. /// head.load({ label1: "http://domain.com/file.js" }, { label2: "http://domain.com/file.js" }, callBack)
  36. ///</summary>
  37. var args = arguments,
  38. callback = args[args.length - 1],
  39. items = {};
  40. if (!isFunction(callback)) {
  41. callback = null;
  42. }
  43. each(args, function (item, i) {
  44. if (item !== callback) {
  45. item = getAsset(item);
  46. items[item.name] = item;
  47. load(item, callback && i === args.length - 2 ? function () {
  48. if (allLoaded(items)) {
  49. one(callback);
  50. }
  51. } : null);
  52. }
  53. });
  54. return api;
  55. };
  56. // Method 2: preload with text/cache hack
  57. } else {
  58. api.load = function () {
  59. var args = arguments,
  60. rest = [].slice.call(args, 1),
  61. next = rest[0];
  62. // wait for a while. immediate execution causes some browsers to ignore caching
  63. if (!isHeadReady) {
  64. queue.push(function () {
  65. api.load.apply(null, args);
  66. });
  67. return api;
  68. }
  69. // multiple arguments
  70. if (!!next) {
  71. /* Preload with text/cache hack (not good!)
  72. * http://blog.getify.com/on-script-loaders/
  73. * http://www.nczonline.net/blog/2010/12/21/thoughts-on-script-loaders/
  74. * If caching is not configured correctly on the server, then items could load twice !
  75. *************************************************************************************/
  76. each(rest, function (item) {
  77. if (!isFunction(item)) {
  78. preLoad(getAsset(item));
  79. }
  80. });
  81. // execute
  82. load(getAsset(args[0]), isFunction(next) ? next : function () {
  83. api.load.apply(null, rest);
  84. });
  85. }
  86. else {
  87. // single item
  88. load(getAsset(args[0]));
  89. }
  90. return api;
  91. };
  92. }
  93. // INFO: for retro compatibility
  94. api.js = api.load;
  95. api.test = function (test, success, failure, callback) {
  96. ///<summary>
  97. /// INFO: use cases:
  98. /// head.test(condition, null , "file.NOk" , callback);
  99. /// head.test(condition, "fileOk.js", null , callback);
  100. /// head.test(condition, "fileOk.js", "file.NOk" , callback);
  101. /// head.test(condition, "fileOk.js", ["file.NOk", "file.NOk"], callback);
  102. /// head.test({
  103. /// test : condition,
  104. /// success : [{ label1: "file1Ok.js" }, { label2: "file2Ok.js" }],
  105. /// failure : [{ label1: "file1NOk.js" }, { label2: "file2NOk.js" }],
  106. /// callback: callback
  107. /// );
  108. /// head.test({
  109. /// test : condition,
  110. /// success : ["file1Ok.js" , "file2Ok.js"],
  111. /// failure : ["file1NOk.js", "file2NOk.js"],
  112. /// callback: callback
  113. /// );
  114. ///</summary>
  115. var obj = (typeof test === 'object') ? test : {
  116. test: test,
  117. success: !!success ? isArray(success) ? success : [success] : false,
  118. failure: !!failure ? isArray(failure) ? failure : [failure] : false,
  119. callback: callback || noop
  120. };
  121. // Test Passed ?
  122. var passed = !!obj.test;
  123. // Do we have a success case
  124. if (passed && !!obj.success) {
  125. obj.success.push(obj.callback);
  126. api.load.apply(null, obj.success);
  127. }
  128. // Do we have a fail case
  129. else if (!passed && !!obj.failure) {
  130. obj.failure.push(obj.callback);
  131. api.load.apply(null, obj.failure);
  132. }
  133. else {
  134. callback();
  135. }
  136. return api;
  137. };
  138. api.ready = function (key, callback) {
  139. ///<summary>
  140. /// INFO: use cases:
  141. /// head.ready(callBack)
  142. /// head.ready(document , callBack)
  143. /// head.ready("file.js", callBack);
  144. /// head.ready("label" , callBack);
  145. ///</summary>
  146. // DOM ready check: head.ready(document, function() { });
  147. if (key === doc) {
  148. if (isDomReady) {
  149. one(callback);
  150. }
  151. else {
  152. domWaiters.push(callback);
  153. }
  154. return api;
  155. }
  156. // shift arguments
  157. if (isFunction(key)) {
  158. callback = key;
  159. key = "ALL";
  160. }
  161. // make sure arguments are sane
  162. if (typeof key !== 'string' || !isFunction(callback)) {
  163. return api;
  164. }
  165. // This can also be called when we trigger events based on filenames & labels
  166. var asset = assets[key];
  167. // item already loaded --> execute and return
  168. if (asset && asset.state === LOADED || key === 'ALL' && allLoaded() && isDomReady) {
  169. one(callback);
  170. return api;
  171. }
  172. var arr = handlers[key];
  173. if (!arr) {
  174. arr = handlers[key] = [callback];
  175. }
  176. else {
  177. arr.push(callback);
  178. }
  179. return api;
  180. };
  181. // perform this when DOM is ready
  182. api.ready(doc, function () {
  183. if (allLoaded()) {
  184. each(handlers.ALL, function (callback) {
  185. one(callback);
  186. });
  187. }
  188. if (api.feature) {
  189. api.feature("domloaded", true);
  190. }
  191. });
  192. /* private functions
  193. *********************/
  194. function noop() {
  195. // does nothing
  196. }
  197. function each(arr, callback) {
  198. if (!arr) {
  199. return;
  200. }
  201. // arguments special type
  202. if (typeof arr === 'object') {
  203. arr = [].slice.call(arr);
  204. }
  205. // do the job
  206. for (var i = 0, l = arr.length; i < l; i++) {
  207. callback.call(arr, arr[i], i);
  208. }
  209. }
  210. /* A must read: http://bonsaiden.github.com/JavaScript-Garden
  211. ************************************************************/
  212. function is(type, obj) {
  213. var clas = Object.prototype.toString.call(obj).slice(8, -1);
  214. return obj !== undefined && obj !== null && clas === type;
  215. }
  216. function isFunction(item) {
  217. return is("Function", item);
  218. }
  219. function isArray(item) {
  220. return is("Array", item);
  221. }
  222. function toLabel(url) {
  223. ///<summary>Converts a url to a file label</summary>
  224. var items = url.split("/"),
  225. name = items[items.length - 1],
  226. i = name.indexOf("?");
  227. return i !== -1 ? name.substring(0, i) : name;
  228. }
  229. // INFO: this look like a "im triggering callbacks all over the place, but only wanna run it one time function" ..should try to make everything work without it if possible
  230. // INFO: Even better. Look into promises/defered's like jQuery is doing
  231. function one(callback) {
  232. ///<summary>Execute a callback only once</summary>
  233. callback = callback || noop;
  234. if (callback._done) {
  235. return;
  236. }
  237. callback();
  238. callback._done = 1;
  239. }
  240. function getAsset(item) {
  241. ///<summary>
  242. /// Assets are in the form of
  243. /// {
  244. /// name : label,
  245. /// url : url,
  246. /// state: state
  247. /// }
  248. ///</summary>
  249. var asset = {};
  250. if (typeof item === 'object') {
  251. for (var label in item) {
  252. if (!!item[label]) {
  253. asset = {
  254. name: label,
  255. url : item[label]
  256. };
  257. }
  258. }
  259. }
  260. else {
  261. asset = {
  262. name: toLabel(item),
  263. url : item
  264. };
  265. }
  266. // is the item already existant
  267. var existing = assets[asset.name];
  268. if (existing && existing.url === asset.url) {
  269. return existing;
  270. }
  271. assets[asset.name] = asset;
  272. return asset;
  273. }
  274. function allLoaded(items) {
  275. items = items || assets;
  276. for (var name in items) {
  277. if (items.hasOwnProperty(name) && items[name].state !== LOADED) {
  278. return false;
  279. }
  280. }
  281. return true;
  282. }
  283. function onPreload(asset) {
  284. asset.state = PRELOADED;
  285. each(asset.onpreload, function (afterPreload) {
  286. afterPreload.call();
  287. });
  288. }
  289. function preLoad(asset, callback) {
  290. if (asset.state === undefined) {
  291. asset.state = PRELOADING;
  292. asset.onpreload = [];
  293. loadAsset({ url: asset.url, type: 'cache' }, function () {
  294. onPreload(asset);
  295. });
  296. }
  297. }
  298. function load(asset, callback) {
  299. ///<summary>Used with normal loading logic</summary>
  300. callback = callback || noop;
  301. if (asset.state === LOADED) {
  302. callback();
  303. return;
  304. }
  305. // INFO: why would we trigger a ready event when its not really loaded yet ?
  306. if (asset.state === LOADING) {
  307. api.ready(asset.name, callback);
  308. return;
  309. }
  310. if (asset.state === PRELOADING) {
  311. asset.onpreload.push(function () {
  312. load(asset, callback);
  313. });
  314. return;
  315. }
  316. asset.state = LOADING;
  317. loadAsset(asset, function () {
  318. asset.state = LOADED;
  319. callback();
  320. // handlers for this asset
  321. each(handlers[asset.name], function (fn) {
  322. one(fn);
  323. });
  324. // dom is ready & no assets are queued for loading
  325. // INFO: shouldn't we be doing the same test above ?
  326. if (isDomReady && allLoaded()) {
  327. each(handlers.ALL, function (fn) {
  328. one(fn);
  329. });
  330. }
  331. });
  332. }
  333. /* Parts inspired from: https://github.com/cujojs/curl
  334. ******************************************************/
  335. function loadAsset(asset, callback) {
  336. callback = callback || noop;
  337. var ele;
  338. if (/\.css[^\.]*$/.test(asset.url)) {
  339. ele = doc.createElement('link');
  340. ele.type = 'text/' + (asset.type || 'css');
  341. ele.rel = 'stylesheet';
  342. ele.href = asset.url;
  343. }
  344. else {
  345. ele = doc.createElement('script');
  346. ele.type = 'text/' + (asset.type || 'javascript');
  347. ele.src = asset.url;
  348. }
  349. ele.onload = ele.onreadystatechange = process;
  350. ele.onerror = error;
  351. /* Good read, but doesn't give much hope !
  352. * http://blog.getify.com/on-script-loaders/
  353. * http://www.nczonline.net/blog/2010/12/21/thoughts-on-script-loaders/
  354. * https://hacks.mozilla.org/2009/06/defer/
  355. */
  356. // ASYNC: load in parellel and execute as soon as possible
  357. ele.async = false;
  358. // DEFER: load in parallel but maintain execution order
  359. ele.defer = false;
  360. function error(event) {
  361. event = event || win.event;
  362. // need some more detailed error handling here
  363. // release event listeners
  364. ele.onload = ele.onreadystatechange = ele.onerror = null;
  365. // do callback
  366. callback();
  367. }
  368. function process(event) {
  369. event = event || win.event;
  370. // IE 7/8 (2 events on 1st load)
  371. // 1) event.type = readystatechange, s.readyState = loading
  372. // 2) event.type = readystatechange, s.readyState = loaded
  373. // IE 7/8 (1 event on reload)
  374. // 1) event.type = readystatechange, s.readyState = complete
  375. // event.type === 'readystatechange' && /loaded|complete/.test(s.readyState)
  376. // IE 9 (3 events on 1st load)
  377. // 1) event.type = readystatechange, s.readyState = loading
  378. // 2) event.type = readystatechange, s.readyState = loaded
  379. // 3) event.type = load , s.readyState = loaded
  380. // IE 9 (2 events on reload)
  381. // 1) event.type = readystatechange, s.readyState = complete
  382. // 2) event.type = load , s.readyState = complete
  383. // event.type === 'load' && /loaded|complete/.test(s.readyState)
  384. // event.type === 'readystatechange' && /loaded|complete/.test(s.readyState)
  385. // IE 10 (3 events on 1st load)
  386. // 1) event.type = readystatechange, s.readyState = loading
  387. // 2) event.type = load , s.readyState = complete
  388. // 3) event.type = readystatechange, s.readyState = loaded
  389. // IE 10 (3 events on reload)
  390. // 1) event.type = readystatechange, s.readyState = loaded
  391. // 2) event.type = load , s.readyState = complete
  392. // 3) event.type = readystatechange, s.readyState = complete
  393. // event.type === 'load' && /loaded|complete/.test(s.readyState)
  394. // event.type === 'readystatechange' && /complete/.test(s.readyState)
  395. // Other Browsers (1 event on 1st load)
  396. // 1) event.type = load, s.readyState = undefined
  397. // Other Browsers (1 event on reload)
  398. // 1) event.type = load, s.readyState = undefined
  399. // event.type == 'load' && s.readyState = undefined
  400. // !doc.documentMode is for IE6/7, IE8+ have documentMode
  401. if (event.type === 'load' || (/loaded|complete/.test(ele.readyState) && (!doc.documentMode || doc.documentMode < 9))) {
  402. // release event listeners
  403. ele.onload = ele.onreadystatechange = ele.onerror = null;
  404. // do callback
  405. callback();
  406. }
  407. // emulates error on browsers that don't create an exception
  408. // INFO: timeout not clearing ..why ?
  409. //asset.timeout = win.setTimeout(function () {
  410. // error({ type: "timeout" });
  411. //}, 3000);
  412. }
  413. // use insertBefore to keep IE from throwing Operation Aborted (thx Bryan Forbes!)
  414. var head = doc['head'] || doc.getElementsByTagName('head')[0];
  415. // but insert at end of head, because otherwise if it is a stylesheet, it will not ovverride values
  416. head.insertBefore(ele, head.lastChild);
  417. }
  418. /* Mix of stuff from jQuery & IEContentLoaded
  419. * http://dev.w3.org/html5/spec/the-end.html#the-end
  420. ***************************************************/
  421. function domReady() {
  422. // Make sure body exists, at least, in case IE gets a little overzealous (jQuery ticket #5443).
  423. if (!doc.body) {
  424. // let's not get nasty by setting a timeout too small.. (loop mania guaranteed if assets are queued)
  425. win.clearTimeout(api.readyTimeout);
  426. api.readyTimeout = win.setTimeout(domReady, 50);
  427. return;
  428. }
  429. if (!isDomReady) {
  430. isDomReady = true;
  431. each(domWaiters, function (fn) {
  432. one(fn);
  433. });
  434. }
  435. }
  436. function domContentLoaded() {
  437. // W3C
  438. if (doc.addEventListener) {
  439. doc.removeEventListener("DOMContentLoaded", domContentLoaded, false);
  440. domReady();
  441. }
  442. // IE
  443. else if (doc.readyState === "complete") {
  444. // we're here because readyState === "complete" in oldIE
  445. // which is good enough for us to call the dom ready!
  446. doc.detachEvent("onreadystatechange", domContentLoaded);
  447. domReady();
  448. }
  449. };
  450. // Catch cases where ready() is called after the browser event has already occurred.
  451. // we once tried to use readyState "interactive" here, but it caused issues like the one
  452. // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
  453. if (doc.readyState === "complete") {
  454. domReady();
  455. }
  456. // W3C
  457. else if (doc.addEventListener) {
  458. doc.addEventListener("DOMContentLoaded", domContentLoaded, false);
  459. // A fallback to window.onload, that will always work
  460. win.addEventListener("load", domReady, false);
  461. }
  462. // IE
  463. else {
  464. // Ensure firing before onload, maybe late but safe also for iframes
  465. doc.attachEvent("onreadystatechange", domContentLoaded);
  466. // A fallback to window.onload, that will always work
  467. win.attachEvent("onload", domReady);
  468. // If IE and not a frame
  469. // continually check to see if the document is ready
  470. var top = false;
  471. try {
  472. top = win.frameElement == null && doc.documentElement;
  473. } catch (e) { }
  474. if (top && top.doScroll) {
  475. (function doScrollCheck() {
  476. if (!isDomReady) {
  477. try {
  478. // Use the trick by Diego Perini
  479. // http://javascript.nwbox.com/IEContentLoaded/
  480. top.doScroll("left");
  481. } catch (error) {
  482. // let's not get nasty by setting a timeout too small.. (loop mania guaranteed if assets are queued)
  483. win.clearTimeout(api.readyTimeout);
  484. api.readyTimeout = win.setTimeout(doScrollCheck, 50);
  485. return;
  486. }
  487. // and execute any waiting functions
  488. domReady();
  489. }
  490. })();
  491. }
  492. }
  493. /*
  494. We wait for 300 ms before asset loading starts. for some reason this is needed
  495. to make sure assets are cached. Not sure why this happens yet. A case study:
  496. https://github.com/headjs/headjs/issues/closed#issue/83
  497. */
  498. setTimeout(function () {
  499. isHeadReady = true;
  500. each(queue, function (fn) {
  501. fn();
  502. });
  503. }, 300);
  504. // browser type & version
  505. var ua = navigator.userAgent.toLowerCase();
  506. ua = /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
  507. /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
  508. /(msie) ([\w.]+)/.exec( ua ) ||
  509. !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || [];
  510. if (ua[1] == 'msie') {
  511. ua[1] = 'ie';
  512. ua[2] = document.documentMode || ua[2];
  513. }
  514. api.browser = { version: ua[2] };
  515. api.browser[ua[1]] = true;
  516. // IE specific
  517. if (api.browser.ie) {
  518. // HTML5 support
  519. each("abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video".split("|"), function(el) {
  520. doc.createElement(el);
  521. });
  522. }
  523. })(window);
  524. /*********Wind JS*********/
  525. /*
  526. * PHPWind JS core
  527. * @Copyright : Copyright 2011, phpwind.com
  528. * @Descript : PHPWind核心JS
  529. * @Author : chaoren1641@gmail.com
  530. * @Thanks : head.js (http://headjs.com)
  531. * $Id: wind.js 21971 2012-12-17 12:11:36Z hao.lin $ :
  532. */
  533. /*
  534. * 防止浏览器不支持console报错
  535. */
  536. if(!window.console) {
  537. window.console = {};
  538. var funs = ["profiles", "memory", "_commandLineAPI", "debug", "error", "info", "log", "warn", "dir", "dirxml", "trace", "assert", "count", "markTimeline", "profile", "profileEnd", "time", "timeEnd", "timeStamp", "group", "groupCollapsed", "groupEnd"];
  539. for(var i = 0;i < funs.length; i++) {
  540. console[funs[i]] = function() {};
  541. }
  542. }
  543. /*
  544. *解决ie6下不支持背景缓存
  545. */
  546. Wind.ready(function() {
  547. if (!+'\v1' && !('maxHeight' in document.body.style)) {
  548. try{
  549. document.execCommand("BackgroundImageCache", false, true);
  550. }catch(e){}
  551. }
  552. });
  553. /*
  554. *wind core
  555. */
  556. (function(win) {
  557. var root = win.GV.DIMAUB+win.GV.JS_ROOT || location.origin + '/public/js/', //在wind.js加载之前定义GV.JS_ROOT
  558. ver = '',
  559. //定义常用JS组件别名,使用别名加载
  560. alias = {
  561. datePicker : 'datePicker/datePicker',
  562. jquery : 'jquery',
  563. colorPicker : 'colorPicker/colorPicker',
  564. tabs : 'tabs/tabs',
  565. swfobject : 'swfobject',
  566. imgready : 'imgready',
  567. //jquery util plugs
  568. ajaxForm : 'ajaxForm',
  569. cookie : 'cookie',
  570. treeview : 'treeview',
  571. treeTable : 'treeTable/treeTable',
  572. draggable : 'draggable',
  573. validate : 'validate',
  574. artDialog : 'artDialog/artDialog',
  575. iframeTools : 'artDialog/iframeTools',
  576. xd : 'xd',//Iframe跨域通信
  577. noty : 'noty/noty',
  578. jcrop : 'jcrop/js/jcrop',
  579. ajaxfileupload : 'ajaxfileupload',
  580. //native js util plugs
  581. swfupload : 'swfupload/swfupload'
  582. },
  583. //CSS路径
  584. alias_css = {
  585. colorPicker : 'colorPicker/style',
  586. artDialog : 'artDialog/skins/default',
  587. datePicker : 'datePicker/style',
  588. treeTable : 'treeTable/treeTable',
  589. jcrop : 'jcrop/css/jquery.Jcrop.min'
  590. };
  591. //add suffix and version
  592. for(var i in alias) {
  593. if (alias.hasOwnProperty(i)) {
  594. alias[i] = root + alias[i] +'.js?v=' + ver;
  595. }
  596. }
  597. for(var i in alias_css) {
  598. if (alias_css.hasOwnProperty(i)) {
  599. alias_css[i] = root + alias_css[i] +'.css?v=' + ver;
  600. }
  601. }
  602. //css loader
  603. win.Wind = win.Wind || {};
  604. //!TODO old webkit and old firefox does not support
  605. Wind.css = function(alias/*alias or path*/,callback) {
  606. var url = alias_css[alias] ? alias_css[alias] : alias
  607. var link = document.createElement('link');
  608. link.rel = 'stylesheet';
  609. link.href = url;
  610. link.onload = link.onreadystatechange = function() {//chrome link无onload事件
  611. var state = link.readyState;
  612. if (callback && !callback.done && (!state || /loaded|complete/.test(state))) {
  613. callback.done = true;
  614. callback();
  615. }
  616. }
  617. document.getElementsByTagName('head')[0].appendChild(link);
  618. };
  619. //Using the alias to load the script file
  620. Wind.use = function() {
  621. var args = arguments,len = args.length;
  622. for( var i = 0;i < len;i++ ) {
  623. if(typeof args[i] === 'string' && alias[args[i]]) {
  624. args[i] = alias[args[i]];
  625. }
  626. }
  627. Wind.js.apply(null,args);
  628. };
  629. //Wind javascript template (author: John Resig http://ejohn.org/blog/javascript-micro-templating/)
  630. var cache = {};
  631. Wind.tmpl = function (str, data) {
  632. var fn = !/\W/.test(str) ? cache[str] = cache[str] || tmpl(str) :
  633. new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" +
  634. "with(obj){p.push('" +
  635. str.replace(/[\r\t\n]/g, " ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g, "$1\r").replace(/\t=(.*?)%>/g, "',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'") + "');}return p.join('');");
  636. return data ? fn(data) : fn;
  637. };
  638. //Wind全局功能函数命名空间
  639. Wind.Util = {}
  640. })(window);