This repository has been archived by the owner on Feb 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.min.js
8 lines (8 loc) · 3.92 KB
/
index.min.js
1
2
3
4
5
6
7
8
(function(n,e){e=e.bind(null,window,document);"object"===typeof exports?e(exports):"function"===typeof define&&define.amd?define([],e):n.byda=e()})(this,function(n,e){function s(a){var b=[],c=[];if(t(a)){a=a.querySelectorAll("[data-"+k+"]");for(var d=a.length-1;0<=d;d--)/\^$/.test(a[d].getAttribute("data-"+k))?b.push(a[d]):c.push(a[d]);return c.filter(function(a){return b.every(function(b){return!b.contains(a)})})}}function t(a){return"object"==typeof a&&!!a.nodeType}function f(a,b){if(a){if("function"==
typeof a)return a.apply(f.flash());"string"==typeof a&&(a={file:a});a.file=g?g+"/"+a.file:a.file;a.callback=b||m;a.imp=p[a.file];if(u&&A&&!a.imp){var c=g?g+"/"+a.file:a.file,d=e.querySelector('link[href="'+c+'"]');if(d)return a.imp=d["import"],v(a);var l=e.createElement("link");l.rel="import";l.href=c;l.onload=function(b){a.imp=l["import"];q(a)};l.onerror=function(b){w(a)};e.head.appendChild(l)}else v(a)}}function v(a){var b=a.file;if(!b||a.imp)return q(null,a);c&&4>c.readyState&&(c.onreadystatechange=
m,c.abort());var c=new XMLHttpRequest;c.open("GET",b,!0);c.setRequestHeader("X-BYDA","true");c.onreadystatechange=function(){if(4==c.readyState){if(200==c.status||0===c.status&&-1!=b.indexOf("file:///"))return q(c.responseText,a);w(a)}};c.send()}function q(a,b){var c=p[b.file]||f.flash({dom:a||b.imp});p[b.file]=c;setTimeout(function(){f.flash({dom:b.dom,transitions:b.transitions}).generate(c).run(function(){b.callback(this.update())},function(){x(b)})},0)}function w(a){throw Error("Could not get: "+
a.file);}function y(a,b,c){this.name=a;this.list=[];this.transition=c;this.value=b}function z(a){a||(a={});var b=a.dom;this.dom=("string"==typeof b?(new DOMParser).parseFromString(b,"text/html"):b)||e;this.list=s(this.dom);this.transitions=a.transitions||{};a.frozen&&(this.frozen=!0);this.organize()}var m=function(){},g,r={},p={},k="load",x=m,u=!0,A="import"in e.createElement("link");y.prototype={emit:function(){var a,b={detail:{name:this.name,value:this.value},bubbles:!0,cancelable:!0};"function"==
typeof CustomEvent?a=new CustomEvent("byda",b):e.createEvent&&(a=e.createEvent("CustomEvent"),a.initCustomEvent("byda",b.bubbles,b.cancelable,b.detail));n.dispatchEvent(a)},set:function(a,b){var c,d;"object"==typeof a&&(a=a[this.name]);a||(a="");for(c=this.list.length-1;0<=c;c--)d=this.list[c],"value"in d?d.value=a:d.innerHTML=a;this.value=a;this.emit();return this},get:function(){return this.value},compare:function(a){"object"==typeof a&&(this.to=a.list[0]);return this},commit:function(a){function b(){d&&
c.set(d);h&&h.parentNode&&h.parentNode.removeChild(h);return a&&a(c.name)}var c=this;if(!this.to)return b();var d=t(this.to)?this.to.value||this.to.innerHTML:this.to,e=this.list,h,f;d||(d="");if("function"==typeof this.transition)for(var g=e.length-1;0<=g;g--)h=e[g],f=h.cloneNode(!0),h.setAttribute("data-"+k,"^"),f.innerHTML=d,this.transition(h,f,b);else b()}};z.prototype={update:function(){return this.organize(s(this.dom))},count:function(){var a=0,b;for(b in this.stores)a++;return a},find:function(a){return this.stores[a]},
map:function(a,b){for(var c in a)this.stores[c]&&this.stores[c].set(a[c]);return this},condense:function(){var a={},b=this.stores,c;for(c in b)a[c]=b[c].get();return a},generate:function(a){for(var b in this.stores)this.stores[b].compare(a.stores[b]);return this},organize:function(a){var b,c,d=this.stores={};a&&(this.list=a);for(a=this.list.length-1;0<=a;a--)b=this.list[a],c=b.getAttribute("data-"+k),this.frozen&&(b=b.cloneNode(!0)),d[c]||(d[c]=new y(c,b.value||b.innerHTML,this.transitions[c]||r[c])),
d[c].list.push(b);return this},run:function(a,b){function c(a){e.push(a);if(d==e.length)return b&&b()}var d=this.count(),e=[],f;for(f in this.stores)this.stores[f].commit(c);"function"==typeof a&&a.apply(this)}};f.init=function(a){a&&(k="string"==typeof a?a:a.data||k,r=a.transitions||r,u=a.imports,g=a.base,x=a.complete||m)};f.base=function(a){"string"==typeof a&&(g=a);return g};f.flash=function(a){return new z(a)};return f});