forked from jakiestfu/Snap.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snap.min.js
executable file
·2 lines (2 loc) · 11.3 KB
/
snap.min.js
1
2
(function(n,t){"use strict";function e(n){document.addEventListener(n,o)}function o(n){n=n||window.event,$(document.body).removeClass(r+" "+u).addClass(n&&n.type in s?s[n.type]:this[i]?u:r)}var f=f||function(i){var f={element:null,element2:null,dragger:null,disable:"none",addBodyClasses:!0,hyperextensible:!0,resistance:.5,flickThreshold:50,transitionSpeed:.3,easing:"ease",maxPosition:266,minPosition:-266,tapToClose:!0,touchToDrag:!0,clickToDrag:!0,slideIntent:40,minDragDistance:5},r={simpleStates:{opening:null,towards:null,hyperExtending:null,halfway:null,flick:null,translation:{absolute:0,relative:0,sinceDirectionChange:0,percentage:0}}},o={},u={hasTouch:t.ontouchstart===null,eventType:function(n){var t={down:u.hasTouch?"touchstart":f.clickToDrag?"mousedown":"",move:u.hasTouch?"touchmove":f.clickToDrag?"mousemove":"",up:u.hasTouch?"touchend":f.clickToDrag?"mouseup":"",out:u.hasTouch?"touchcancel":f.clickToDrag?"mouseout":""};return t[n]},page:function(n,t){return u.hasTouch&&t.touches.length&&t.touches[0]?t.touches[0]["page"+n]:t["page"+n]},klass:{has:function(n,t){return n.className.indexOf(t)!==-1},add:function(n,t){!u.klass.has(n,t)&&f.addBodyClasses&&(n.className+=" "+t)},remove:function(n,t){f.addBodyClasses&&(n.className=n.className.replace(t,"").replace(/^\s+|\s+$/g,""))}},dispatchEvent:function(n){if(typeof o[n]=="function")return o[n].call(this)},vendor:function(){var r=t.createElement("div"),n="webkit Moz O ms".split(" "),i;for(i in n)if(typeof r.style[n[i]+"Transition"]!="undefined")return n[i]},transitionCallback:function(){return r.vendor==="Moz"||r.vendor==="ms"?"transitionend":r.vendor+"TransitionEnd"},canTransform:function(){return Modernizr.csstransforms3d||typeof f.element.style[r.vendor+"Transform"]!="undefined"},deepExtend:function(n,t){var i;for(i in t)t[i]&&t[i].constructor&&t[i].constructor===Object?(n[i]=n[i]||{},u.deepExtend(n[i],t[i])):n[i]=t[i];return n},angleOfDrag:function(n,t){var i,u;return u=Math.atan2(-(r.startDragY-t),r.startDragX-n),u<0&&(u+=2*Math.PI),i=Math.floor(u*(180/Math.PI)-180),i<0&&i>-180&&(i=360-Math.abs(i)),Math.abs(i)},events:{addEvent:function(n,t,i){return n.addEventListener?n.addEventListener(t,i,!1):n.attachEvent?n.attachEvent("on"+t,i):void 0},removeEvent:function(n,t,i){return n.addEventListener?n.removeEventListener(t,i,!1):n.attachEvent?n.detachEvent("on"+t,i):void 0},prevent:function(n){n.preventDefault?n.preventDefault():n.returnValue=!1}},parentUntil:function(n,t){for(var i=typeof t=="string";n.parentNode;){if(i&&n.getAttribute&&n.getAttribute(t)||!i&&n===t)return n;n=n.parentNode}return null}},e={translate:{get:{matrix:function(t){if(r.canTransform){var i=n.getComputedStyle(f.element)[r.vendor+"Transform"].match(/\((.*)\)/);return i?(i=i[1].split(","),i.length===16&&(t+=8),parseInt(i[t],10)):0}return parseInt(f.element.style.left,10)}},easeCallback:function(){var n=r.vendor+"Transition";f.element.style[n]="",$(".snap-fixed, .snap-drag-me-too").css(n,""),r.translation=e.translate.get.matrix(4),r.easing=!1,clearInterval(r.animatingInterval),r.easingTo===0&&(u.klass.remove(t.body,"snapjs-right"),u.klass.remove(t.body,"snapjs-left")),u.klass.remove(t.body,"snapjs-animating"),u.dispatchEvent("animated"),u.events.removeEvent(f.element,u.transitionCallback(),e.translate.easeCallback),f.element2&&u.events.removeEvent(f.element2,u.transitionCallback(),e.translate.easeCallback)},easeTo:function(n){var o,i;r.canTransform?(r.easing=!0,r.easingTo=n,i=r.vendor+"Transition",o="all "+f.transitionSpeed+"s "+f.easing,f.element.style[i]=o,$(".snap-fixed, .snap-drag-me-too").css(i,o),u.klass.add(t.body,"snapjs-animating"),r.animatingInterval=setInterval(function(){u.dispatchEvent("animating")},1),u.events.addEvent(f.element,u.transitionCallback(),e.translate.easeCallback),f.element2&&u.events.addEvent(f.element2,u.transitionCallback(),e.translate.easeCallback),e.translate.x(n),n===0&&(i=r.vendor+"Transform",f.element.style[i]="",$(".snap-fixed, .snap-drag-me-too").css(i,""))):(r.translation=n,e.translate.x(n))},x:function(i){var e,o,u,s;f.disable==="left"&&i>0||f.disable==="right"&&i<0||(f.hyperextensible||(i===f.maxPosition||i>f.maxPosition?i=f.maxPosition:(i===f.minPosition||i<f.minPosition)&&(i=f.minPosition)),i=parseInt(i,10),isNaN(i)&&(i=0),r.canTransform?(e="translate3d("+i+"px, 0,0)",o=r.vendor+"Transform",f.element.style[o]=e,$(".snap-fixed, .snap-drag-me-too").css(o,e)):(u=element.style,s={width:u.width=(n.innerWidth||t.documentElement.clientWidth)+"px",left:u.left=i+"px",right:u.right=""},$(".snap-fixed, .snap-drag-me-too").css(s)))}},drag:{listen:function(){r.translation=0,r.easing=!1,u.events.addEvent(f.element,u.eventType("down"),e.drag.startDrag),f.element2&&u.events.addEvent(f.element2,u.eventType("down"),e.drag.startDrag),u.hasTouch&&(u.events.addEvent(f.element,u.eventType("move"),e.drag.dragging),f.element2&&u.events.addEvent(f.element2,u.eventType("move"),e.drag.dragging)),u.events.addEvent(f.element,u.eventType("up"),e.drag.endDrag),f.element2&&u.events.addEvent(f.element2,u.eventType("up"),e.drag.endDrag)},stopListening:function(){u.events.removeEvent(f.element,u.eventType("down"),e.drag.startDrag),f.element2&&u.events.removeEvent(f.element2,u.eventType("down"),e.drag.startDrag),u.hasTouch&&(u.events.removeEvent(f.element,u.eventType("move"),e.drag.dragging),f.element2&&u.events.removeEvent(f.element2,u.eventType("move"),e.drag.dragging)),u.events.removeEvent(f.element,u.eventType("up"),e.drag.endDrag),f.element2&&u.events.removeEvent(f.element2,u.eventType("up"),e.drag.endDrag)},startDrag:function(n){var i=n.target?n.target:n.srcElement,s=u.parentUntil(i,"data-snap-ignore"),o,t;if(s){u.dispatchEvent("ignore");return}(u.hasTouch||(u.events.addEvent(f.element,u.eventType("move"),e.drag.dragging),f.element2&&u.events.addEvent(f.element2,u.eventType("move"),e.drag.dragging)),!f.dragger||(o=u.parentUntil(i,f.dragger),o||r.translation===f.minPosition||r.translation===f.maxPosition))&&(u.dispatchEvent("start"),r.canTransform&&(t=r.vendor+"Transition",f.element.style[t]="",$(".snap-fixed, .snap-drag-me-too").css(t,"")),r.isDragging=!0,r.hasIntent=null,r.intentChecked=!1,r.startDragX=u.page("X",n),r.startDragY=u.page("Y",n),r.dragWatchers={current:0,last:0,hold:0,state:""},r.simpleStates={opening:null,towards:null,hyperExtending:null,halfway:null,flick:null,translation:{absolute:0,relative:0,sinceDirectionChange:0,percentage:0}})},dragging:function(n){if(r.isDragging&&f.touchToDrag){var o=u.page("X",n),a=u.page("Y",n),v=r.translation,i=e.translate.get.matrix(4),h=o-r.startDragX,y=i>0,l=h,c;if(r.intentChecked&&!r.hasIntent)return;if(f.addBodyClasses&&(i>0?(u.klass.add(t.body,"snapjs-left"),u.klass.remove(t.body,"snapjs-right")):i<0&&(u.klass.add(t.body,"snapjs-right"),u.klass.remove(t.body,"snapjs-left"))),r.hasIntent===!1||r.hasIntent===null){var s=u.angleOfDrag(o,a),p=s>=0&&s<=f.slideIntent||s<=360&&s>360-f.slideIntent,w=s>=180&&s<=180+f.slideIntent||s<=180&&s>=180-f.slideIntent;r.hasIntent=w||p?!0:!1,r.intentChecked=!0}if(f.minDragDistance>=Math.abs(o-r.startDragX)||r.hasIntent===!1)return;u.events.prevent(n),u.dispatchEvent("drag"),r.dragWatchers.current=o,r.dragWatchers.last>o?(r.dragWatchers.state!=="left"&&(r.dragWatchers.state="left",r.dragWatchers.hold=o),r.dragWatchers.last=o):r.dragWatchers.last<o&&(r.dragWatchers.state!=="right"&&(r.dragWatchers.state="right",r.dragWatchers.hold=o),r.dragWatchers.last=o),y?(f.maxPosition<i&&(c=(i-f.maxPosition)*f.resistance,l=h-c),r.simpleStates={opening:"left",towards:r.dragWatchers.state,hyperExtending:f.maxPosition<i,halfway:i>f.maxPosition/2,flick:Math.abs(r.dragWatchers.current-r.dragWatchers.hold)>f.flickThreshold,translation:{absolute:i,relative:h,sinceDirectionChange:r.dragWatchers.current-r.dragWatchers.hold,percentage:i/f.maxPosition*100}}):(f.minPosition>i&&(c=(i-f.minPosition)*f.resistance,l=h-c),r.simpleStates={opening:"right",towards:r.dragWatchers.state,hyperExtending:f.minPosition>i,halfway:i<f.minPosition/2,flick:Math.abs(r.dragWatchers.current-r.dragWatchers.hold)>f.flickThreshold,translation:{absolute:i,relative:h,sinceDirectionChange:r.dragWatchers.current-r.dragWatchers.hold,percentage:i/f.minPosition*100}}),e.translate.x(l+v)}},endDrag:function(n){if(u.hasTouch||(u.events.removeEvent(f.element,u.eventType("move"),e.drag.dragging),f.element2&&u.events.removeEvent(f.element2,u.eventType("move"),e.drag.dragging)),r.isDragging){u.dispatchEvent("end");var t=e.translate.get.matrix(4);if(r.dragWatchers.current===0&&t!==0&&f.tapToClose){u.dispatchEvent("close"),u.events.prevent(n),e.translate.easeTo(0),r.isDragging=!1,r.startDragX=0;return}r.simpleStates.opening==="left"?r.simpleStates.halfway||r.simpleStates.hyperExtending||r.simpleStates.flick?r.simpleStates.flick&&r.simpleStates.towards==="left"?e.translate.easeTo(0):(r.simpleStates.flick&&r.simpleStates.towards==="right"||r.simpleStates.halfway||r.simpleStates.hyperExtending)&&e.translate.easeTo(f.maxPosition):e.translate.easeTo(0):r.simpleStates.opening==="right"&&(r.simpleStates.halfway||r.simpleStates.hyperExtending||r.simpleStates.flick?r.simpleStates.flick&&r.simpleStates.towards==="right"?e.translate.easeTo(0):(r.simpleStates.flick&&r.simpleStates.towards==="left"||r.simpleStates.halfway||r.simpleStates.hyperExtending)&&e.translate.easeTo(f.minPosition):e.translate.easeTo(0)),r.isDragging=!1,r.startDragX=u.page("X",n)}}}},s=function(n){n.element&&(u.deepExtend(f,n),r.vendor=u.vendor(),r.canTransform=u.canTransform(),e.drag.listen())};this.open=function(n){u.dispatchEvent("open"),u.klass.remove(t.body,"snapjs-expand-left"),u.klass.remove(t.body,"snapjs-expand-right"),n==="left"?(r.simpleStates.opening="left",r.simpleStates.towards="right",u.klass.add(t.body,"snapjs-left"),u.klass.remove(t.body,"snapjs-right"),e.translate.easeTo(f.maxPosition)):n==="right"&&(r.simpleStates.opening="right",r.simpleStates.towards="left",u.klass.remove(t.body,"snapjs-left"),u.klass.add(t.body,"snapjs-right"),e.translate.easeTo(f.minPosition))},this.close=function(){u.dispatchEvent("close"),e.translate.easeTo(0)},this.expand=function(i){var r=n.innerWidth||t.documentElement.clientWidth;i==="left"?(u.dispatchEvent("expandLeft"),u.klass.add(t.body,"snapjs-expand-left"),u.klass.remove(t.body,"snapjs-expand-right")):(u.dispatchEvent("expandRight"),u.klass.add(t.body,"snapjs-expand-right"),u.klass.remove(t.body,"snapjs-expand-left"),r*=-1),e.translate.easeTo(r)},this.on=function(n,t){return o[n]=t,this},this.off=function(n){o[n]&&(o[n]=!1)},this.enable=function(){u.dispatchEvent("enable"),e.drag.listen()},this.disable=function(){u.dispatchEvent("disable"),e.drag.stopListening()},this.settings=function(n){u.deepExtend(f,n)},this.state=function(){var n,t=e.translate.get.matrix(4);return n=t===f.maxPosition?"left":t===f.minPosition?"right":"closed",{state:n,info:r.simpleStates}},this.toggle=function(n){var n=n||"left";this.state().state=="closed"?this.open(n):this.close()},s(i)},i;typeof module!="undefined"&&module.exports&&(module.exports=f),typeof ender=="undefined"&&(this.Snap=f),typeof define=="function"&&define.amd&&define("snap",[],function(){return f}),i="hidden",i in document?e("visibilitychange"):(i="mozHidden")in document?e("mozvisibilitychange"):(i="webkitHidden")in document?e("webkitvisibilitychange"):(i="msHidden")in document?e("msvisibilitychange"):"onfocusin"in document?document.onfocusin=document.onfocusout=o:window.onpageshow=window.onpagehide=window.onfocus=window.onblur=o;var r="tab-visible",u="tab-hidden",s={focus:r,focusin:r,pageshow:r,blur:u,focusout:u,pagehide:u}}).call(this,window,document);
//@ sourceMappingURL=snap.min.js.map