This repository has been archived by the owner on Jan 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemantics.min.js
1 lines (1 loc) · 9.34 KB
/
semantics.min.js
1
(function(){function a(){}function d(a){this.request=a;try{this.obj=JSON.parse(a.responseText)}catch(b){}}function e(a){this.req=new XMLHttpRequest,this.config={},this.url=a[0],this.ioData="";var b=["success","failure","serialize"],c,d,e=this,f=function(a){return function(b){return e.config[a]=b,this}};for(c=0,d;d=b[c];c++)this[d]=f(d)}function f(a){b.implement("DelayableQueue",this),this._node=a}function g(){}function h(a){function h(a){return function(){for(var b=0,c;c=g.nodes[b];b++)c[a].apply(c,arguments)}}var b=[];for(var c=0,d;d=a[c];c++)b.push(new f(d));this.nodes=b;var e=["remove","addClass","removeClass"],g=this;for(var c=0,i;i=e[c];c++)this[i]=h(i)}function j(){this.animClass="nwt-anim-on"}function l(a){this._e=a,this.target=new f(a.target)}function m(){}a.prototype={implement:function(a,b){var c={DelayableQueue:["wait",function(){var a=0;return function(b){a+=b*1e3;var c=this,d={},e=function(e){return d[e]=c[e],function(){var f=[],g,h=arguments.length;for(g=0;g<h;g++)f.push(arguments[g]);return a<=0?d[e].apply(c,f):(setTimeout(function(){a-=b*1e3,d[e].apply(c,f)},a),c)}};for(var f in c){if(typeof c[f]!="function"||f=="wait"||d[f])continue;c[f]=e(f)}return c}}]};b[c[a][0]]=c[a][1]()}};var b=new a;window.nwt=b;var c={};b.register=function(a){c[a.name]=a},b.plugin=function(a){var b=Array.prototype.slice.call(arguments),d,e=b.shift(),f=c[a],g=function(){},h;wrapPluginCall=function(a){var b;return f.extends&&(b=function(){c[f.extends].methods[a].apply(this,arguments)}),function(){return this._super=b,f.methods[a].apply(this,arguments)}};if(f.methods)for(d in f.methods)g.prototype[d]=wrapPluginCall(d);return h=new g,h.init.apply(h,b)},d.prototype={toString:function(){return this.request.responseText}},e.prototype={_run:function(){var a=this;return this.req.onreadystatechange=function(){var b;a.req.readyState==4&&a.req.status==200?b="success":a.req.readyState==4&&(b="failure");if(b&&a.config[b]){var c=new d(a.req);a.config[b](c)}},this.req.send(this.ioData?this.ioData:null),this},post:function(a,b){var c=!0;typeof a=="string"?this.ioData=a:typeof a=="object"&&a._node&&(a.getAttribute("enctype")&&(c=!1),this.ioData=new FormData(a._node));var d=this.req,b=b||"POST";return d.open(b,this.url),c&&d.setRequestHeader("Content-type","application/x-www-form-urlencoded"),this._run()},get:function(){return this.req.open("GET",this.url),this._run()},put:function(a){return this.post("?"+a,"PUT")},"delete":function(a){return this.post("?"+a,"DELETE")},abort:function(){return this.req.abort(),this}},b.io=function(){return new e(arguments)},f.prototype={ancestor:function(a){var c=b.all(a),d=this._node,e=null,f=0;if(c.size()==0)return null;for(;;){c.each(function(a){a._node==d&&(e=a)});var g=d.parentNode;if(e||!g)break;d=g}return e?e:null},parent:function(){var a=new f(this._node.parentNode);return a},hasClass:function(a){return this._node.className&&this._node.className.indexOf(a)!==-1},addClass:function(a){return this.hasClass(a)||(this._node.className=this._node.className+" "+a),this},removeClass:function(a){return this.swapClass(a,"")},swapClass:function(a,b){return this._node.className=this._node.className.replace(a,b),this},data:function(a){return this._node.getAttribute("data-"+a)},get:function(a){if(a==="parentNode"){var b=this._node[a];return b?new f(b):null}return this._node[a]},set:function(a,b){return this._node[a]=b,this},getAttribute:function(a){return this._node.getAttribute(a)},hasAttribute:function(a){return this._node.hasAttribute(a)},setAttribute:function(a,b){return this._node.setAttribute(a,b),this},_jsStyle:function(a){var b={"float":"cssFloat"};return b[a]&&(a=b[a]),a},getStyle:function(a){if(!this.getAttribute("style"))return"";a=this._jsStyle(a);var b=this._node.style[a];return b?b:null},removeStyle:function(a){return this.removeStyles(a)},removeStyles:function(a){typeof a=="string"&&(a=[a]);var b,c=a.length;for(b=0;b<c;b+=1)this._node.style[a[b]]="";return this},setStyle:function(a,b){var c={};return c[a]=b,this.setStyles(c)},setStyles:function(a){this.getAttribute("style")||this.setAttribute("style","");var b="",c={top:"px",left:"px",width:"px",height:"px"},d,e,f=[];for(d in a){var g=this._jsStyle(d);eachStyleVal=a[d],c[g]&&!isNaN(eachStyleVal)&&(eachStyleVal+=c[g]),this._node.style[g]=eachStyleVal}return this},on:function(a,b){this._node.addEventListener(a,function(a){b(new NWTEventWrapper(a))},!1)},serialize:function(){var a="",b=this._node.getElementsByTagName("*");for(var c=0,d;d=b[c];c++)if(!d.disabled&&d.name&&d.name.length>0)switch(d.tagName.toLowerCase()){case"input":switch(d.type){case"checkbox":case"radio":d.checked&&(a.length>0&&(a+="&"),a+=d.name+"="+encodeURIComponent(d.value));break;case"hidden":case"password":case"text":a.length>0&&(a+="&"),a+=d.name+"="+encodeURIComponent(d.value)}break;case"select":case"textarea":a.length>0&&(a+="&"),a+=d.name+"="+encodeURIComponent(d.value)}return a},getContent:function(a){return this._node.innerHTML},setContent:function(a){return this._node.innerHTML=a,this},next:function(){var a=this._node;do a=a.nextSibling;while(a&&a.nodeType!=1);return new f(a)},previous:function(){var a=this._node;do a=a.previousSibling;while(a&&a.nodeType!=1);return new f(a)},one:function(a){var b=this._node.querySelector(a);return new f(b)},all:function(a){var b=this._node.querySelectorAll(a);return new h(b)},append:function(a){return a instanceof f&&(a=a._node),this._node.appendChild(a),this},remove:function(){this._node.parentNode.removeChild(this._node)},insert:function(a,b){b=b||"before",b=="before"?this._node.parentNode.insertBefore(a._node,this._node):b=="after"&&this._node.parentNode.insertBefore(a._node,this.next()._node)},click:function(){var a=document.createEvent("MouseEvents");return a.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),!this._node.dispatchEvent(a)}},g.prototype={create:function(a){var b=document.createElement("div");return b.innerHTML=a,new f(b.childNodes[0])},one:function(a){if(typeof a=="string"){var b=document.querySelectorAll(a);return b.length==0?null:new f(b[0])}return new f(a)},all:function(a){var b=document.querySelectorAll(a);return new h(b)}},b.node=new g,b.one=b.node.one,h.prototype={each:function(a){for(var b=0,c;c=this.nodes[b];b++)a(c)},item:function(a){return this.nodes[a]},size:function(){return this.nodes.length}},b.all=b.node.all,j.prototype={init:function(a,c){b.one("#nwt-anim-styles")&&b.one("#nwt-anim-styles").remove();var d=b.node.create('<style type="text/css" id="nwt-anim-styles"></style>');c=c||"ease-in-out",a=a||1;var e=" "+a+"s "+c,f={"-webkit-transition":"all"+e,"-moz-transition":" all"+e,"-o-ransition":" all"+e,"ms-transition":" all"+e,transition:" all"+e},g=[],h="";for(i in f)g.push(i),h+=i+": "+f[i]+";";d.setContent("."+this.animClass+"{"+h+"}"),b.one("head").append(d)},anim:function(a,b,c,d){return k.init(c,d),a.addClass(k.animClass),a.setStyles(b),a}};var k=new j;b.anim=k.anim,f.prototype.anim=function(a,c,d){return b.anim(this,a,c,d)},l.prototype={stop:function(){return this.noBubble().noDefault()},noDefault:function(){return this._e.preventDefault(),this},noBubble:function(){return this._e.stopPropagation(),this}},m.prototype={live:function(a,c,d){var e=new RegExp(c);b.one("body").on("click",function(b){b.target.getAttribute(a).match(c)&&d(b.target),b.target.get("nodeName").toUpperCase()!=="INPUT"&&b.stop();return})},on:function(a,b,c,d,e){var f=function(d){var g=new l(d);c.call(a,g),e&&a.removeEventListener(b,f)};a.addEventListener(b,f)},off:function(a,b,c){implement.on.removeEventListener(b,c)},ready:function(a){var b=!1,c=!0,d=window,e=d.document,f=e.documentElement,g=e.addEventListener?"addEventListener":"attachEvent",h=e.addEventListener?"removeEventListener":"detachEvent",i=e.addEventListener?"":"on",j=function(c){if(c.type=="readystatechange"&&e.readyState!="complete")return;(c.type=="load"?d:e)[h](i+c.type,j,!1),!b&&(b=!0)&&a.call(d,c.type||c)},k=function(){try{f.doScroll("left")}catch(a){setTimeout(k,50);return}j("poll")};if(e.readyState=="complete")a.call(d,"lazy");else{if(e.createEventObject&&f.doScroll){try{c=!d.frameElement}catch(l){}c&&k()}e[g](i+"DOMContentLoaded",j,!1),e[g](i+"readystatechange",j,!1),d[g](i+"load",j,!1)}}},b.event=new m,b.ready=b.event.ready,f.prototype.addEventListener=function(a,b){return this._node.addEventListener(a,b)},f.prototype.removeEventListener=function(a,b){return this._node.removeEventListener(a,b)},f.prototype.on=function(a,c,d){return b.event.on(this,a,c,d)},f.prototype.once=function(a,c,d){return b.event.on(this,a,c,d,!0)},f.prototype.off=function(a,c){return b.event.off(this,a,c)}})();function c(){}function d(){this.CLICK_ATTR="js",this.MOUSE_ATTR="mouse",this.SCROLL_ATTR="scroll"}var a="nwt",b={};b.View=new c,d.prototype={enable:function(a,b,c){nwt.one("body").on(a,function(a){var d=a.target,e=a.target,f=1;for(;;){if(e.data(b)){Semantics.dispatch(d,e,b);break}e=e.parent();if(!e||f>c)break;f++}})},extend:function(a,c){c.extend=a,b[c.name]=c},dispatch:function(a,c,d){var e=c.data(d),f=e.split("."),g=f.length,h,i,j;for(h=0;h<g;h++){var k=f[h];h==0&&b[k]?(i=b[k].methods,j=b[k]):i[k]&&(i=i[k])}if(j.extend&&b[j.extend].methods){j._super=b[j.extend].methods;for(h=1;h<g;h++){var k=f[h];j._super[k]&&(j._super=j._super[k])}}i.apply(j,[Semantics.getNode(a),Semantics.getNode(c)])},getNode:function(b){var c=b;return a=="jquery"&&(c=$(c._node)),c},use:function(b){a=b.toLowerCase()}},nwt.ready(function(){Semantics.enable("click",Semantics.CLICK_ATTR),Semantics.enable("mousemove",Semantics.MOUSE_ATTR,1)}),window.Semantics=new d