This repository was archived by the owner on Mar 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdejavu.min.js
11 lines (11 loc) · 6.32 KB
/
dejavu.min.js
1
2
3
4
5
6
7
8
9
10
11
/*!
* dejavu.js v 0.2.0
* http://github.com/composite/Dejavu.js/
*
*
* Copyright 2016 Ukjin 'Composite' Yang.
* Released under the MIT license
* http://github.com/composite/Dejavu.js/LICENSE
*
*/
!function(){"use strict";var e=function(e){return"function"==typeof e};e(window.CustomEvent)&&(window.CustomEvent=function(t,n){n=n||{bubbles:!1,cancelable:!1,detail:void 0};var i,o=!!n.bubbles,r=!!n.cancelable,u=n.detail;return e(document.createEvent)?(i=document.createEvent("CustomEvent"),i.initCustomEvent(t,o,r,u)):(i=document.createEventObject(),i.bubbles=o,i.cancelable=r,i.detail=u),i});var t=void 0,n="addEventListener",i="",o=function(e){return e.length===[].slice.call(e,0).length},r=function(t,n){var i=document.createElement(t);return e(n)&&n.call(i,t),i},u={ev:"DEJAVU_SCROLLEV",ch:"DEJAVU_CHILDREN",op:"DEJAVU_OPTION",po:"DEJAVU_POSITION",on:"DEJAVU_EVENT"},d=[],a=function(e,t,n){for(var i=0,o=e.length;o>e;e++)if(n?e[i]===t:e[i]==t)return i;return-1},s=function(e){return"string"==typeof e||e instanceof String},h=function(){return{x:window.scrollX||window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft,y:window.scrollY||window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop}},c=function(e){window.Dejavu.debug&&console.debug(e)},l=function(){var e=document.documentElement;return{x:Math.max(e.clientWidth,window.innerWidth||0),y:Math.max(e.clientHeight,window.innerHeight||0)}},E=l(),p=function(t,n,i){return e(t.dispatchEvent)?t.dispatchEvent(i):t.fireEvent(n,i)},v={enable:function(e){return c(this[u.po].ENABLE=!!e),this.dejavu},random:function(e){return e!==t?c(this[u.po].RANDOM=!!e):this.dejavu.render(~~(Math.random()*this[u.po].LENGTH)),this.dejavu},next:function(){return c(this[u.po].CURRENT++),this[u.po].CURRENT==this[u.po].LENGTH&&(this[u.po].CURRENT=0),this.dejavu.render()},prev:function(){return c(this[u.po].CURRENT--),this[u.po].CURRENT<0&&(this[u.po].CURRENT=this[u.po].LENGTH-1),this.dejavu.render()},render:function(e){e=isNaN(e)?this[u.po].CURRENT:~~e;for(var t=0,n=this[u.ch],i=n.length;i>t;t++){if(n[t].parentNode!=this)return c("[DEJAVU] has been removed from parent. updating..."),this.dejavu.update(),this.dejavu.prev();t!=e?n[t].setAttribute("hidden","hidden"):n[t].removeAttribute("hidden","hidden")}return this.dejavu},shuffle:function(){return this[u.ch].sort(function(){return~~(3*Math.random())-1}),this.dejavu},sort:function(e){return this[u.ch].sort(e),this.dejavu},destroy:function(){return window.Dejavu.destroy(this)},update:function(e){e!==t&&(this[u.po].UPDATE=!!e),this[u.ch].length=0;for(var n=0,i=0,o=this.childNodes,r=o.length;r>n;n++)1==o[n].nodeType&&(i!=this[u.po].CURRENT?o[n].setAttribute("hidden","hidden"):o[n].removeAttribute("hidden"),this[u.ch].push(o[n]),i++);this[u.po].LENGTH=this[u.ch].length,c("[DEJAVU] updated");var d=this;return setTimeout(function(){E=l();var e=d.getBoundingClientRect(),t=h();d[u.po].MODEL=d[u.po].MODEL||{},d[u.po].MODEL.top=e.top+t.y,d[u.po].MODEL.bottom=e.bottom+t.y,d[u.po].MODEL.left=e.left+t.x,d[u.po].MODEL.right=e.right+t.x,c(d[u.po].MODEL)},0),this.dejavu.emit("update"),this.dejavu},on:function(t,n){return t in this[u.po].EVENT&&e(n)&&this[u.po].EVENT[t].push(n),this.dejavu},off:function(e,t){var n;return e in this[u.po].EVENT&&~(n=a(this[u.po].EVENT[e],t))&&this[u.po].EVENT[e].splice(n,1),this.dejavu},emit:function(e){if(e in this[u.po].EVENT){[].shift.call(arguments);var t=arguments,n=window.CustomEvent(u.on,{detail:{args:t,type:e,position:this[u.po].MODEL,current:this[u.po].CURRENT,length:this[u.po].LENGTH,inside:this[u.po].STATUS,enable:this[u.po].ENABLED}});p(this,i+u.on,n)}return this.dejavu}};void 0===document.hidden&&document.getElementsByTagName("head")[0].appendChild(r("style",function(){this.innerHTML="*[hidden]{display:none;}"}));var f=function(t,r){if(!t)throw Error("dejavu element(s) are not defined.");r=r||window.Dejavu.options,s(t)&&(t=document.querySelectorAll(t)||document.getElementById(t));var h=t,l=function(e,t,n){e.dejavu[n]=function(){return t[n].apply(e,arguments)}};o(t)||(t=[t]),c("[DEJAVU] Dejavu initialize"),c(t),c(r);for(var p=0,f=t.length;f>p;p++)if(t[p]&&!~a(d,t[p])&&1==t[p].nodeType){t[p][u.ch]=[],t[p][u.op]=r,t[p][u.ev]=function(e,t){var n=this[u.po];t+E.y-n.MARGIN>n.MODEL.top&&t+n.MARGIN<n.MODEL.bottom&&e+E.x-n.MARGIN>n.MODEL.left&&e+n.MARGIN<n.MODEL.right?n.STATUS||(n.STATUS=!0,c("[DEJAVU] in your eye side."),c([e,t,E.x,E.y,n.MARGIN,n.STATUS]),c(n.MODEL),this.dejavu.emit("inside",e,t)):n.STATUS&&(n.STATUS=!1,c("[DEJAVU] out of your eye side."),c([e,t,E.x,E.y,n.MARGIN,n.STATUS]),c(n.MODEL),n.RANDOM?this.dejavu.random():this.dejavu.next(),this.dejavu.emit("outside",e,t))},t[p].dejavu={};for(var m in v)l(t[p],v,m);for(var m in window.Dejavu.fn)l(t[p],window.Dejavu.fn,m);t[p][u.po]={CURRENT:0,LENGTH:0,STATUS:!1,ENABLED:"enable"in r?!!r.enable:window.Dejavu.options.enable,RANDOM:"random"in r?!!r.random:window.Dejavu.options.random,MARGIN:isNaN(r.margin)?window.Dejavu.options.margin:r.margin,MODEL:{top:0,bottom:0,right:0,left:0},UPDATE:"update"in r?!!r.update:window.Dejavu.options.update,EVENT:{inside:[],outside:[],update:[]}};for(var T in t[p][u.po].EVENT)e(r["on"+T])&&t[p][u.po].EVENT[T].push(r["on"+T]);t[p].dejavu.update(),t[p].dejavu.render(),!function(o){t[p][n](i+u.on,function(t){if(t||(t=window.event,t.currentTarget=o,t.preventDefault=function(){event.returnValue=!1},t.stopPropagation=function(){event.cancelBubble=!0},t.target=event.srcElement||o),t.detail.type in o[u.po].EVENT)for(var n=0,i=o[u.po].EVENT[t.detail.type],r=i.length;r>n;n++)!function(n,i){e(i)&&i.apply(o,t)}(n,i[n])})}(t[p]),d.push(t[p]),e(r.oninit)&&r.oninit.call(t[p],r)}return h};return f.destroy=function(e){var n=e;o(e)||(e=[e]),c("[DEJAVU] Dejavu destroying"),c(e);for(var i=0,r=e.length;r>i;i++)if(~a(d,e[i])){for(var s=0,h=e[i].childNodes,l=h.length;l>s;s++)1==h.nodeType&&h[s].removeAttribute("hidden");e[i].dejavu=t;for(var E in u)e[i][u[E]]=t;d.splice(a(e[i]),1)}return n},f.options={enable:!0,random:!1,shuffle:!1,update:!1,oninit:null,onoutside:null,oninside:null,onupdate:null,sort:null,margin:10},f.debug=!1,f.fn={},window[n](i+"scroll",function(e){e=e||window.event;for(var t=h(),n=0,i=d,o=i.length;o>n;n++)i[n][u.ev].call(i[n],t.x,t.y)}),window[n](i+"resize",function(){f.DEJAVU_RESIZE&&clearTimeout(f.DEJAVU_RESIZE),f.DEJAVU_RESIZE=setTimeout(function(){for(var e=0,t=d,n=t.length;n>e;e++)t[e].dejavu.update()},100)}),window.Dejavu=f}();