-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSVGEventListener-0.2.3.min.js
1 lines (1 loc) · 3 KB
/
SVGEventListener-0.2.3.min.js
1
!function(e){"use strict";function t(e){return"string"==typeof e}function n(t){return t===e}function i(t){if(u[t]!==e)return u[t];u[t]=!1;var n=document.createElementNS(l,"svg"),i=document.createElementNS(l,"rect"),r=document.createElementNS(l,"animate");return r.setAttributeNS(null,"dur","1ms"),r.setAttributeNS(null,"attributeName","x"),i.appendChild(r),n.appendChild(i),a.addEventListener.call(r,t+"Event",function(){u[t]=!0},!1),n.setAttributeNS(null,"style","display:none"),document.body.appendChild(n),setTimeout(function(){document.body.removeChild(n)},50),u[t]}function r(e){var t,n=e.split(":");if(1===n.length)return t=n[0],-1!==t.lastIndexOf("ms")?+t:(-1!==t.lastIndexOf("min")?t=60*parseFloat(t):-1!==t.lastIndexOf("h")&&(t=3600*parseFloat(t)),1e3*parseFloat(t));n.reverse(),t=0;for(var i in n)t+=n[i]*Math.pow(60,i)*1e3;return t}function s(e){this.el=e,this._listeners={},this._init()}var a,l,o,u;a={addEventListener:Element.prototype.addEventListener,svgAnimateBeginElement:SVGAnimateElement.prototype.beginElement,svgAnimateTransformBeginElement:SVGAnimateTransformElement.prototype.beginElement},l="http://www.w3.org/2000/svg",o=Array.isArray||function(e){return"[object Array]"==={}.toString.call(e)},String.prototype.contains=function(e){return-1!==this.indexOf(e)},u={},s.prototype={constructor:s,_delayEvent:function(e,t){var n=this,i=r(t);return function(){window.setTimeout(function(){n.fire(e+"Event")},i)}},_attachEvent:function(e,t){var n=this,i=document.getElementById(t);null!=i&&i.addEventListener(e+"Event",function(){n.fire("beginEvent")})},_init:function(){var e=this.el.getAttribute("begin"),t=this.el.getAttribute("dur");this.add("beginEvent",this._delayEvent("end",t)),"indefinite"===e||e.contains(".end")||e.contains(".begin")?e.contains(".end")?this._attachEvent("end",e.replace(".end","")):e.contains(".begin")&&this._attachEvent("begin",e.replace(".begin","")):this._delayEvent("begin",e)},add:function(e,t){n(this._listeners[e])&&(this._listeners[e]=[]),this._listeners[e].push(t)},fire:function(e){var n;if(t(e)&&(e={type:e,bubbles:!1,cancelable:!1,defaultPrevented:!1,currentTarget:null}),n=e.type.substr(0,e.type.indexOf("Event")),!i(n)){if(e.target||(e.target=e.currentTarget=this.el),!e.type)throw new Error('Event object missing "type" property.');if(o(this._listeners[e.type])){var r=this._listeners[e.type];for(var s in r)r[s].call(this.el,e)}}}},Element.prototype.addEventListener=function(e,t,r){return(this instanceof SVGAnimateElement||this instanceof SVGAnimateTransformElement)&&(n(this.listeners)&&(this.listeners=new s(this)),"endEvent"!==e||i("end")||this.listeners.add(e,t),"beginEvent"!==e||i("begin")||this.listeners.add(e,t)),a.addEventListener.call(this,e,t,r)},SVGAnimateElement.prototype.beginElement=function(){return i("begin")||this.listeners===e||this.listeners.fire("beginEvent"),a.svgAnimateBeginElement.call(this)},SVGAnimateTransformElement.prototype.beginElement=function(){return i("begin")||this.listeners===e||this.listeners.fire("beginEvent"),a.svgAnimateTransformBeginElement.call(this)}}();