-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwn.min.js
11 lines (11 loc) · 5.23 KB
/
wn.min.js
1
2
3
4
5
6
7
8
9
10
11
/*!*
* WebNicer (WN) JavaScript Library v1.0.4
* http://bitbucket.org/jciolek/webnicer
*
* @preserve
* @author Jacek Ciolek <j.ciolek@webnicer.com>
* @licence Copyright 2012-2013, Jacek Ciolek
* Dual licensed under the MIT or GPL Version 3 licenses.
* http://bitbucket.org/jciolek/webnicer/wiki/Licence
*/
(function(a){var d=a.wn,b;function f(){var i=function(k,j){return i.ns(k,j)};f.extend(i,f);i.nsObj={};i.loader=new e();return i}f.extend=function h(k,l,o,t){var v=typeof k,j=typeof l,n={object:true,"function":true},m=function(){},u,q,r;o=o||false;t=t||false;if(!(j in n&&v in n)){throw new TypeError("WN::extend(): Type mismatch. Trying to extend "+v+" with "+j+".")}if(k===null||l===null){throw new TypeError("WN::extend(): child and parent cannot be null.")}for(u in l){if(l.hasOwnProperty(u)){q=l[u];r=k[u];if(!o||q===null||!(typeof q in n)){k[u]=q;continue}if(t||!(typeof r in n)){if(typeof q==="function"){r=(function(){var p=q.__wnCloneOf||q,i=function(){return p.apply(this,arguments)};i.__wnCloneOf=p;return i})()}else{try{r=new q.constructor()}catch(s){m.prototype=q.constructor.prototype;r=new m()}}}k[u]=h(r,q,o,t)}}return k};f.extend(f,{nsObj:null,loader:null,sandbox:f,require:function(k,l){var j=new g(l),i;if(typeof k==="string"){k=[k]}if(!(k instanceof Array)){throw new TypeError("WN::require(): nsArr parameter is expected to be a String or an Array. "+typeof ns+" given.")}if(l!==undefined&&typeof l!=="function"){throw new TypeError("WN::require(): callback parameter is expected to be a Function. "+typeof l+" given.")}while(i=k.shift()){if(this.ns(i)==undefined){if(i.charAt(0)!=="."){i="."+i}j.add(i)}}if(!j.finish()){this.loader.request(j)}},ns:function(v,p){var u=[],q=0,w=0,x,s=this.nsObj,m=s,r=(p===undefined),o=true,k=false,n="",t="";if(typeof v!="string"||v.length===0){throw new TypeError("WN::ns(): nsStr parameter is expected to be a non-zero length String. "+typeof v+': "'+v+'" given.')}if(v.charAt(0)!=="."){v="."+v}if(r){return m[v]}if(v.charAt(v.length-1)=="."){o=false;v=v.substr(0,v.length-1)}if(!o&&(typeof p!="object"||p instanceof Array)){throw new TypeError("WN::ns(): obj parameter is expected to be a non-Array Object, "+typeof p+" given.")}u=v.split(".");for(w=0,q=u.length;w<q;w++){k=(q-1<=w);n=u[w]+(!k||!o?".":"");t+=n;if(m[n]===undefined){if(!k||!o){s[t]=m[n]={}}}if(k){if(!o){for(x in p){if(p.hasOwnProperty(x)&&p[x]!==undefined){m[n][x]=p[x];s[t+x]=p[x];this.loader.notify(t+x)}}}else{s[t]=m[n]=p}this.loader.notify(t)}m=m[n]}return m},inherit:(function(){var i=function(){};return function(n,k,l){var j,m;k=typeof k==="string"&&this.ns(k)||k;n=typeof n==="string"&&this.ns(n)||n;l=l||false;if(typeof n!=="function"){throw new TypeError("WN::inherit(): C parameter is expected to be a function, "+typeof n+" given.")}if(typeof k!=="function"){throw new TypeError("WN::inherit(): P parameter is expected to be a function, "+typeof k+" given.")}j=k.prototype,m=n.prototype;i.prototype=j;n.prototype=new i();this.extend(n.prototype,m);n.prototype.constructor=n;n.prototype.parent=j;if(l){this.extend(n,k)}n.parent=k}})()});function e(){this.required={};this.requested={};this.nsMapping={}}f.extend(e.prototype,{urlPrefix:"/js/",urlSuffix:".js",ns2url:function(i){return this.urlPrefix+i.replace(/^\./,"").replace(/\.$/,"_").replace(/\./g,"/")+this.urlSuffix},addMapping:function(j,k,i){if(typeof j!=="string"||j.length===0||j==="."){throw new TypeError("WN::addMapping(): ns parameter is expected to be a non-zero length string. "+typeof j+': "'+j+'" + given.')}if(j.charAt(0)!=="."){j="."+j}this.nsMapping[j]=new c(k,i)},request:function(m){var k=this,o,n,i=m.nsObj,j,l,p;for(j in i){l=this.nsMapping[j]||new c(this.ns2url(j));p=l.url;if(this.requested[p]===true){m.del(j);continue}if(this.required[j]===undefined){this.required[j]=[]}this.required[j].push(m);if(this.requested[p]===undefined){this.requested[p]=false;o=document.createElement("script");o.type="text/javascript";o.src=p;o.async=true;if(l.noNs){o.onload=(function(){var r=j,q=p;return function(s){k.requested[q]=true;k.notify.call(k,r)}})();o.onreadystatechange=(function(){var q=o;return function(){if(q.readyState==="loaded"||q.readyState==="complete"){q.onreadystatechange=null;q.onload()}}})()}n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(o,n)}}return m.finish()},notify:function(i){var j,k;j=this.required[i];if(j!==undefined){while(k=j.shift()){k.del(i);k.finish()}delete this.required[i]}}});function c(j,i){if(typeof j!=="string"||j.length===0){throw new TypeError("RequestURL(): url parameter is expected to be a non-zero length string. "+typeof j+': "'+j+'" given.')}this.url=j||"";this.noNs=Boolean(i||false)}function g(i){this.nsObj={};this.callback=i}f.extend(g.prototype,{nsObj:null,callback:null,finished:false,length:0,del:function(i){var j=false;if(this.nsObj.hasOwnProperty(i)){delete this.nsObj[i];this.length--;j=true}return j},add:function(i){var j=false;if(this.fihised){throw new Error("Request::add(): tried to add the namespace "+i+" to finished Request.")}if(!this.nsObj.hasOwnProperty(i)){this.nsObj[i]=null;this.length++;j=true}return j},finish:function(){if(!this.finished&&this.length===0){if(typeof this.callback==="function"){setTimeout(this.callback,0)}this.finished=true}return this.finished}});b=f.sandbox();b.noConflict=function(){a.wn=d;return b};a.wn=b})(window);