cdn-experiments/common/js/bss-min-1.2.6.js

2 lines
4.3 KiB
JavaScript

var BSS={_call:function(t,e,n,i){try{return t(e,n,i)}catch(r){console.error("While calling edi function",t,"with (e d i) parameters",e,n,i,"got: ",r)}},_get:function(t,e,n,i){return"function"==typeof t?this._call(t,e,n,i):t},_selectTarget:function(t,e,n,i){return"function"==typeof t?this._call(t,e,n,i):e.querySelector(t)},_selectTargets:function(t,e,n,i){return"function"==typeof t?this._call(t,e,n,i):e.querySelectorAll(t)},_hasTemplate:function(t){return void 0!==t.template&&null!=t.template},_getTemplate:function(t,e,n,i){var r=t.template,a="function"==typeof r?this._call(r,e,n,i):t.rootdocument.querySelector(r);if(null==a)throw"No template found "+r;return document.importNode(a.content,!0)},_setRootDocument:function(t,e){var n=e||this._get(t.rootdocument);return n=n||document,t.rootdocument=n,n},polyfill:function(){if(!("content"in document.createElement("template"))){var t=Array.prototype.slice.call(document.getElementsByTagName("template"));for(var e in t){var n=t[e],i=n.children,r=document.createDocumentFragment();n.style.display="none";var a=null;for(j=0;a=i[j];j++)r.appendChild(a);n.content=r}}},commit:function(t){this._bindingCache.commit(t)},clear:function(t){this._bindingCache.clear(t);var e=this._setRootDocument(t,t.rootdocument?t.rootdocument:document),n=this._selectTarget(t.target,e);n?n.innerHTML="":console.error("Target not found")},reapply:function(t){this._bindingCache.reapply(t)},apply:function(t,e){t.id||(t.id=1e12*Math.random()|0),this._bindingCache.clear(t);var n=this._setRootDocument(t,e);this._bind(t,t,t.rootdocument),this.reapply(t),null!=this._selectTarget(t.target,n)||console.error("Target not found",t.target)},_bindSingle:function(t,e,n,i,r,a){this._bindingCache.addApplyBinding(t,e,n,i,a),r&&this._bindingCache.addCommitBinding(t,e,n,r,a),this._registerEvents(t,n)},_bind:function(t,e,n,i,r,a){for(var o=this._selectTargets(t.target,n,i,a),c=0,s=o.length;c<s;c++){var l=o[c],u=this._getCurrentData(t,l,i,a),d=this._getCurrentDataOut(t,l,i,r,a),h=this._prepareRecurse(t,l,u,a);if(u instanceof Array){var p=this._replaceTargetWithReplicas(t,e,l,u,a);for(var f in p){var m=p[f];for(var _ in this._bindSingle(t,e,m,u,d,f),h)this._bind(h[_],e,m,u[f],d?d[f]:null,f)}}else for(var g in l=this._replaceTarget(t,l,u,null),this._bindSingle(t,e,l,u,d,null),h)this._bind(h[g],e,l,u,d,a)}},_registerEvents:function(t,e){for(var n in t)if("on"===n){var i=t[n];for(var r in i)(i[r]instanceof Array?i[r]:[i[r]]).forEach(function(t){e.addEventListener(r,t,!1)})}else 0===n.lastIndexOf("on_")&&(t[n]instanceof Array?t[n]:[t[n]]).forEach(function(t){e.addEventListener(n.substring(3),t,!1)})},_getCurrentData:function(t,e,n,i){var r=n;return t.inout&&(r=this._get(t.inout,e,n,i)),t.in&&(r=this._get(t.in,e,n,i)),r},_getCurrentDataOut:function(t,e,n,i,r){var a=i;return t.inout&&(a=this._get(t.inout,e,n,r)),t.out&&(a=this._get(t.out,e,n,r)),a},_prepareRecurse:function(t,e,n,i){var r=t.recurse?this._get(t.recurse,e,n,i):[];return(r=r||[])instanceof Array?r:[r]},_replaceTarget:function(t,e,n,i){var r=e;return this._hasTemplate(t)&&(r=this._getTemplate(t,e,n,i).firstElementChild,e.parentNode.replaceChild(r,e)),r},_replaceTargetWithReplicas:function(t,e,n,i,r){for(var a=[],o=0,c=i.length;o<c;o++){var s=null;s=this._hasTemplate(t)?this._getTemplate(e,n,i,r).firstElementChild:n.cloneNode(!0),a.push(s),n.parentNode.appendChild(s)}return n.parentNode.removeChild(n),a},_bindingCache:{applies:{},commits:{},clear:function(t){this.applies[t.id]=this.applies[t.id]?this.applies[t.id].splice():[],this.commits[t.id]=this.commits[t.id]?this.commits[t.id].splice():[]},addApplyBinding:function(t,e,n,i,r){var a={element:n,index:r,transfer:t.apply?t.apply:function(){},data:r?i[r]:i,container:r?i:null};n.bss_input=a,this.applies[e.id].push(a)},addCommitBinding:function(t,e,n,i,r){var a={element:n,index:r,transfer:t.commit?t.commit:function(){},data:r?i[r]:i,container:r?i:null,remove:r?function(){this.container.splice(this.index,1)}:function(){}};n.bss_output=a,n.bss_binding=a,this.commits[e.id].push(a)},reapply:function(t){this.applies[t.id]&&this.applies[t.id].forEach(function(t){try{t.transfer(t.element,t.data,t.index)}catch(e){console.error("Error in apply",t.transfer,t.element,t.data,t.index)}})},commit:function(t){this.commits[t.id]&&this.commits[t.id].forEach(function(t){try{t.transfer(t.element,t.data,t.index)}catch(e){console.error("Error in commit",t.transfer,t.element,t.data,t.index)}})}}};