nope/resources/w2ui/kickstart.min.js

3 lines
6.9 KiB
JavaScript
Raw Normal View History

2020-09-01 15:48:26 +00:00
/* kickstart 0.2.x (nightly) (c) http://w2ui.com/kickstart, vitmalina@gmail.com */
var kickStart=function(){var app={_conf:{name:"unnamed",baseURL:"",cache:!1,modules:{},verbose:!0},define:define,require:require,register:register};return window.app||(window.app=app),app;function define(n,t){function a(e){for(var r in e)Array.isArray(e[r].assets)?(app._conf.modules.hasOwnProperty(r)&&app._conf.verbose&&console.log("ERROR: module "+r+" is already registered."),app._conf.modules[r]=$.extend({assets:{}},e[r],{ready:!1,files:{}})):a(e[r])}"string"==typeof n?$.ajax({url:app._conf.baseURL+n,dataType:"text",cache:app._conf.cache,success:function(e,r,o){if("success"==r){try{n=JSON.parse(e)}catch(e){return void(app._conf.verbose&&console.log('ERROR: not valid JSON file "'+n+'".\n'+e))}a(n),"function"==typeof t&&t()}else app._conf.verbose&&console.log('ERROR: error while loading module definition from "'+n+'".')},error:function(e,r,o){app._conf.verbose&&console.log('ERROR: error while loading module definition from "'+n+'".')}}):(a(n),"function"==typeof t&&t())}function register(e,r){if(app.hasOwnProperty(e))return app._conf.verbose&&console.log("ERROR: Namespace "+e+" is already registered"),!1;if(!app._conf.modules.hasOwnProperty(e))return app._conf.verbose&&console.log("ERROR: Namespace "+e+" is not defined, first define it with kickStart.define"),!1;var o=app._conf.modules[e];app[e]=r(o.files,o),app._conf.modules[e].ready=!0}function require(names,callBack){$.isArray(names)||(names=[names]);var modCount=names.length,failed=!1,promise={ready:function(e){return promise._ready=e,promise},fail:function(e){return promise._fail=e,promise},done:function(e){return promise._done=e,promise},always:function(e){return promise._always=e,promise}};return setTimeout(function(){for(var n in names){var name=names[n];void 0!==app[name]?(modCount--,isFinished()):void 0===app._conf.modules[name]?app._conf.verbose&&console.log("ERROR: module "+name+" is not defined."):function(name){getFiles(app._conf.modules[name].assets.concat([app._conf.modules[name].start]),function(files){var start=files[app._conf.modules[name].start];delete files[app._conf.modules[name].start],app._conf.modules[name].files=files,app._conf.modules[name].ready=!0,eval(start),"function"==typeof promise._ready&&promise._ready(app._conf.modules[name]),modCount--,isFinished()})}(name)}},1),promise;function isFinished(){0==modCount&&(!0!==failed&&("function"==typeof promise._done&&promise._done(app._conf.modules[name]),"function"==typeof callBack&&callBack()),"function"==typeof promise._always&&promise._always())}}function getFiles(t,e){var a={},r=t.length;for(var i in t)!function(){var n=t[i],e=$('script[path="'+n+'"]');0<e.length?(a[n]=e.html(),s()):$.ajax({url:app._conf.baseURL+n,dataType:"text",cache:app._conf.cache,success:function(e,r,o){"success"==r?(a[n]=o.responseText,s()):app._conf.verbose&&console.log("ERROR: error while getting a file "+n+".")},error:function(e,r,o){"error"==r?app._conf.verbose&&console.log("ERROR: failed to load "+t[i]+"."):(app._conf.verbose&&console.log('ERROR: file "'+t[i]+'" is loaded, but with a parsing error(s) in line '+o.line+": "+o.message),a[n]=xhr.responseText,s())}})}();function s(){--r<=0&&e(a)}}}();kickStart.define({route:{assets:[]}}),kickStart.register("route",function(){var y=kickStart,_={},R={};window.addEventListener?window.addEventListener("hashchange",w,!1):window.attachEvent("onhashchange",w);var e={init:function(e){""===o()?r(e):w()},add:function(e,r){if("object"==typeof e){for(var o in e){var n=String("/"+o).replace(/\/{2,}/g,"/");_[n]=e[o]}return y.route}if(e=String("/"+e).replace(/\/{2,}/g,"/"),"function"==typeof y.route.trigger){var t=y.route.trigger({phase:"before",type:"add",target:"self",route:e,handler:r});if(!0===t.isCancelled)return!1}_[e]=r,"function"==typeof y.route.trigger&&y.route.trigger($.extend(t,{phase:"after"}));return y.route},remove:function(e){if(e=String("/"+e).replace(/\/{2,}/g,"/"),"function"==typeof y.route.trigger){var r=y.route.trigger({phase:"before",type:"remove",target:"self",route:e,handler:handler});if(!0===r.isCancelled)return!1}delete _[e],delete R[e],"function"==typeof y.rou