forked from stealjs/steal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
steal.production.js
23 lines (23 loc) · 11.2 KB
/
steal.production.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(function(){if(typeof steal!="undefined"&&steal.nodeType)throw"steal is defined an element's id!";var s=window.steal,n=function(){var a=document,b=a.documentElement,c=a.getElementsByTagName("head");if(c.length>0)return c[0];a=a.createElement("head");b.insertBefore(a,b.firstChild);return a},t=function(){var a=document.createElement("script");a.type="text/javascript";return a},h=function(a,b){for(var c in b)a[c]=b[c];return a},u=function(a){return a.match(/[^\/]+$/)[0]},l={msie:!!(window.attachEvent&&
!window.opera),opera:!!window.opera,safari:navigator.userAgent.indexOf("AppleWebKit/")>-1,firefox:navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("KHTML")==-1,mobilesafari:!!navigator.userAgent.match(/Apple.*Mobile.*Safari/),rhino:navigator.userAgent.match(/Rhino/)&&true},v=function(){return window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest},o=function(a){a=h({id:a.src&&steal.cleanId(a.src)},a);var b="",c="<script ",d;if(a.src){b=steal.File(a.src);
if(!b.isLocalAbsolute()&&!b.protocol())a.src=steal.root.join(a.src)}if(a.type&&a.process){b=steal.request(a.src);if(!b)throw"steal.js there is nothing at "+a.src;d=a.process(b);a.type="text/javascript";delete a.process;delete a.src}else if(a.type&&a.type!="text/javascript"&&!l.rhino){b=steal.request(a.src);if(!b)throw"steal.js there is nothing at "+a.src;a.text=b;delete a.src}for(var g in a)c+=g+"='"+a[g]+"' ";if(steal.support.load&&!steal.browser.rhino&&!d)c+=steal.loadErrorTimer(a);c+=">"+(d||"")+
"<\/script>";c+=steal.support.load?'<script type="text/javascript">steal.end()<\/script>':'<script type="text/javascript" src="'+steal.root.join("steal/end.js")+'"><\/script>';document.write(a.src||d?c:"")};steal=function(){for(var a=0;a<arguments.length;a++)steal.add(new steal.fn.init(arguments[a]));return steal};(function(){var a=function(b,c){c=document.createElement(c);b="on"+b;var d=b in c;if(!d){c.setAttribute(b,"return;");d=typeof c[b]==="function"}return d};steal.support={load:a("load","script"),
readystatechange:a("readystatechange","script"),error:a("readystatechange","script")}})();steal.fn=steal.prototype={init:function(a){if(typeof a=="function"){var b=steal.getCurrent();this.path=b;this.func=function(){steal.curDir(b);a(steal.send||window.jQuery||steal)};this.options=a}else{if(typeof a=="string")a=/\.js$/i.test(a)?{path:a}:{path:a+".js"};h(this,a);this.options=a;this.originalPath=this.path;var c=steal.File(this.path);this.path=c.normalize();this.absolute=this.originalPath.match(/^\/\//)?
steal.root.join(this.originalPath.substr(2)):c.relative()?c.joinFrom(steal.getAbsolutePath(),true):this.path;this.dir=steal.File(this.path).dir()}},run:function(){steal.cur(this);this.dependencies=[];var a=steal.options.env=="production",b=h({type:"text/javascript",compress:"true","package":"production.js"},h({src:this.path},this.options));if(this.func){this.func();steal.end()}else if(!a||this.force)if(this.type)o(b);else{steal.curDir(this.path);o(this.skipInsert?undefined:b)}else this.type||steal.curDir(this.path)},
runNow:function(){steal.curDir(this.path);return l.rhino?load(this.path):steal.insertHead(steal.root.join(this.path))}};steal.fn.init.prototype=steal.fn;steal.root=null;steal.pageDir=null;steal.extend=h;steal.browser=l;steal.File=function(a){if(this.constructor!=steal.File)return new steal.File(a);this.path=a};var f=steal.File;h(f.prototype,{clean:function(){return this.path.match(/([^\?#]*)/)[1]},dir:function(){var a=this.clean().lastIndexOf("/");a=a!=-1?this.clean().substring(0,a):"";var b=a!==
""&&a.match(/^(https?:\/|file:\/)$/);return b&&b[1]?this.clean():a},domain:function(){if(this.path.indexOf("file:")===0)return null;var a=this.path.match(/^(?:https?:\/\/)([^\/]*)/);return a?a[1]:null},join:function(a){return f(a).joinFrom(this.path)},joinFrom:function(a,b){var c=f(a);if(this.protocol())return this.domain()&&this.domain()==c.domain()?this.afterDomain():this.domain()==c.domain()?this.toReferenceFromSameDomain(a):this.path;else if(a==steal.pageDir&&!b)return this.path;else if(this.isLocalAbsolute()){if(!c.domain())return this.path;
return c.protocol()+"//"+c.domain()+this.path}else{if(a==="")return this.path.replace(/\/$/,"");b=a.split("/");c=this.path.split("/");var d=c[0];for(a.match(/\/$/)&&b.pop();d==".."&&c.length>0;){if(!b.pop())break;c.shift();d=c[0]}return b.concat(c).join("/")}},joinCurrent:function(){return this.joinFrom(steal.curDir())},relative:function(){return this.path.match(/^(https?:|file:|\/)/)===null},afterDomain:function(){return this.path.match(/https?:\/\/[^\/]*(.*)/)[1]},toReferenceFromSameDomain:function(a){var b=
this.path.split("/");a=a.split("/");for(var c="";b.length>0&&a.length>0&&b[0]==a[0];){b.shift();a.shift()}for(var d=0;d<a.length;d++)c+="../";return c+b.join("/")},isCrossDomain:function(){return this.isLocalAbsolute()?false:this.domain()!=f(window.location.href).domain()},isLocalAbsolute:function(){return this.path.indexOf("/")===0},protocol:function(){var a=this.path.match(/^(https?:|file:)/);return a&&a[0]},normalize:function(){var a=steal.curDir(),b=this.path;if(/^\/\//.test(this.path))b=this.path.substr(2);
else if(this.relative()||steal.isCurrentCrossDomain()&&!this.protocol())b=this.joinFrom(a);return b}});steal.pageDir=f(window.location.href).dir();steal.options={loadProduction:true,env:"development",production:null,encoding:"utf-8",cacheInclude:true,logLevel:0};var p=true,q=false,m="",r=null,i=[],j=[],k=[];h(steal,{setScriptOptions:function(){for(var a=document.getElementsByTagName("script"),b,c=/steal\.(production\.)?js/,d=0;d<a.length;d++){var g=a[d].src;if(g&&c.test(g)){var e=f(f(g).joinFrom(steal.pageDir)).dir();
e=/\.\.$/.test(e)?e+"/..":e.replace(/steal$/,"");if(/.+\/$/.test(e))e=e.replace(/\/$/,"");if(/steal\.production\.js/.test(g))steal.options.env="production";steal.root=f(e);if(g.indexOf("?")!=-1)b=g.split("?")[1]}}if(b)if(b.indexOf("=")>-1)b.replace(/steal\[([^\]]+)\]=([^&]+)/g,function(y,w,x){steal.options[w]=x});else{a=b.split(",");if(a[0]&&a[0].lastIndexOf(".js")>0)steal.options.startFile=a[0];else if(a[0])steal.options.app=a[0];if(a[1]&&steal.options.env!="production")steal.options.env=a[1]}},
setOldIncludeOptions:function(){h(steal.options,s)},setHashOptions:function(){window.location.hash.replace(/steal\[(\w+)\]=(\w+)/g,function(a,b,c){steal.options[b]=c})},init:function(){this.setScriptOptions();if(steal.browser.rhino)steal.options.env="development";this.setOldIncludeOptions();this.setHashOptions();if(steal.options.app)steal.options.startFile=steal.options.app+"/"+steal.options.app.match(/[^\/]+$/)[0]+".js";if(steal.options.ignoreControllers){steal.controllers=function(){return steal};
steal.controller=function(){return steal}}if(!steal.options.production&&steal.options.startFile)steal.options.production="//"+f(steal.options.startFile).dir()+"/production";if(steal.options.production)steal.options.production+=steal.options.production.indexOf(".js")==-1?".js":"";if(steal.options.env=="production"&&steal.options.loadProduction){if(steal.options.production){p=false;steal({path:steal.options.production,force:true})}}else{var a=steal.getCurrent();steal({path:"steal/dev/dev.js",ignore:true});
steal.curDir(a);if(steal.options.startFile){p=false;steal._start=new steal.fn.init(steal.options.startFile);steal.add(steal._start)}}steal.options.startFile&&steal.start()},curDir:function(a){if(a!==undefined){m=a;return steal}else return(a=f(m).dir())?a+(a.lastIndexOf("/")===a.length-1?"":"/"):a},cur:function(a){return a!==undefined?(r=a):r},isCurrentCrossDomain:function(){return f(steal.getAbsolutePath()).isCrossDomain()},getCurrent:function(){return m},getAbsolutePath:function(){var a=this.curDir(),
b=f(this.curDir());return b.relative()?b.joinFrom(steal.root.path,true):a},add:function(a){if(typeof a.func=="function")j.unshift(a);else{var b=steal.cur(),c=steal.exists(a);if(c)b.dependencies.push(c);else{b&&b.dependencies.push(a);if(q)return a.runNow();b=a.absolute||a.path;for(c=0;c<i.length;c++)if(i[c].absolute==b){i.splice(c,1);break}j.unshift(a)}}},exists:function(a){a=a.absolute||a.path;var b;for(b=0;b<k.length;b++)if(k[b].absolute==a)return k[b];for(b=0;b<j.length;b++)if(j[b].absolute==a)return j[b]},
done:function(){typeof steal.options.done=="function"&&steal.options.done(k)},end:function(){clearTimeout(steal.timer);i=i.concat(j);if(i.length){var a=i.pop();if(a){k.push(a);j=[];a.run()}else{q=true;steal.done()}}},start:function(){steal.end()},css:function(){if(steal.options.env=="production"){if(!steal.loadedProductionCSS){var a=steal.File(steal.options.production.replace(".js",".css")).normalize();a=steal.root.join(a);steal.createLink(a);steal.loadedProductionCSS=true}return steal}for(var b=
0;b<arguments.length;b++){a=f(arguments[b]+".css").joinCurrent();steal.createLink(steal.root.join(a))}return this},createLink:function(a,b){b=b||{};var c=document.createElement("link");c.rel=b.rel||"stylesheet";c.href=a;c.type=b.type||"text/css";n().appendChild(c);return c},request:function(a,b){b=b||"application/x-www-form-urlencoded; charset="+steal.options.encoding;var c=v();c.open("GET",a,false);c.setRequestHeader("Content-type",b);c.overrideMimeType&&c.overrideMimeType(b);try{c.send(null)}catch(d){return null}if(c.status===
500||c.status===404||c.status===2||c.status===0&&c.responseText==="")return null;return c.responseText},insertHead:function(a,b,c,d,g){b=b||"UTF-8";var e=t();if(a)e.src=a;if(g)e.id=g;e.charset=b;e.type=c||"text/javascript";if(d)e.text=d;n().appendChild(e)},write:function(a){document.write('<script type="text/javascript" src="'+a+'" encode="+encode+"><\/script>')},resetApp:function(a){return function(b){var c=steal.getCurrent();steal.curDir("");if(b.path)b.path=a(b.path);else b=a(b);steal(b);steal.curDir(c);
return steal}},callOnArgs:function(a){return function(){for(var b=0;b<arguments.length;b++)a(arguments[b]);return steal}},applier:function(a){return function(){for(var b=[],c=0;c<arguments.length;c++)b[c]=typeof arguments[c]=="function"?arguments[c]:a(arguments[c]);steal.apply(null,b);return steal}},then:steal,total:k});steal.plugin=steal.resetApp(function(a){return a+"/"+u(a)});steal.packs=function(){for(var a=0;a<arguments.length;a++)typeof arguments[a]=="function"?steal(arguments[a]):steal({force:true,
path:"//packages/"+arguments[a]+".js"});return this};h(steal,{plugins:steal.callOnArgs(steal.plugin),controllers:steal.applier(function(a){if(a.match(/^\/\//))return a=steal.root.join(a.substr(2));return"controllers/"+a+"_controller"}),models:steal.applier(function(a){if(a.match(/^\/\//))return a=steal.root.join(a.substr(2));return"models/"+a}),resources:steal.applier(function(a){if(a.match(/^\/\//))return a=steal.root.join(a.substr(2));return"resources/"+a}),views:function(){if(l.rhino||steal.options.env==
"production")for(var a=0;a<arguments.length;a++)steal.view(arguments[a]);return steal},timerCount:0,view:function(a){var b=a.match(/\.\w+$/gi)[0].replace(".","");if(a.indexOf("//")!==0)a="views/"+a;steal({path:a,type:"text/"+b,compress:"false"});return steal},timers:{},ct:function(a){clearTimeout(steal.timers[a]);delete steal.timers[a]},loadErrorTimer:function(a){var b=++steal.timerCount;steal.timers[b]=setTimeout(function(){throw"steal.js Could not load "+a.src+". Are you sure you have the right path?";
},5E3);return"onLoad='steal.ct("+b+")' "},cleanId:function(a){return a.replace(/[\/\.]/g,"_")}});if(!steal.build)steal.build={types:{}};steal.loadedProductionCSS=false;steal.init()})();