From f21d97251dcfc44fc88270592a1442a7c5844b65 Mon Sep 17 00:00:00 2001 From: Nick Piscitelli Date: Tue, 13 Nov 2018 21:36:11 -0500 Subject: [PATCH] Change event emitter function name from `event` to `emit` to save the space for a potential similarly named event bind function Fix inconsitent spacing --- docs/assets/js/glider.js | 114 +++++++++++++++++++-------------------- glider.js | 114 +++++++++++++++++++-------------------- glider.min.js | 10 ++-- 3 files changed, 119 insertions(+), 119 deletions(-) diff --git a/docs/assets/js/glider.js b/docs/assets/js/glider.js index 7e93b88..b83b8dc 100644 --- a/docs/assets/js/glider.js +++ b/docs/assets/js/glider.js @@ -5,13 +5,13 @@ \___//_//_/ \_,_/ \__//_/ (_)__/ //___/ |___/ - Version: 1.5 + Version: 1.5.1 Author: Nick Piscitelli (pickykneee) Website: https://nickpiscitelli.com Documentation: http://nickpiscitelli.github.io/Glider.js License: MIT License Release Date: October 25th, 2018 - Last Update: November 10th, 2018 + */ ;(function (factory) { typeof define === 'function' && define.amd ? define(factory) : @@ -24,64 +24,64 @@ function Glider(element, settings) { - var _ = this; + var _ = this; - if (element._glider) return element._glider; + if (element._glider) return element._glider; - _.ele = element - _.ele.classList.add('glider'); + _.ele = element + _.ele.classList.add('glider'); - // expose glider object to its DOM element - _.ele._glider = _ + // expose glider object to its DOM element + _.ele._glider = _ - // merge user setting with defaults - _.opt = Object.assign({}, { - slidesToScroll: 1, - slidesToShow: 1, - duration: .5, - // easeInQuad - easing: function (x, t, b, c, d) { - return c*(t/=d)*t + b; - } + // merge user setting with defaults + _.opt = Object.assign({}, { + slidesToScroll: 1, + slidesToShow: 1, + duration: .5, + // easeInQuad + easing: function (x, t, b, c, d) { + return c*(t/=d)*t + b; + } }, settings); - // set defaults - _.aIndex = _.page = _.slide = 0; - _.arrows = {}; + // set defaults + _.aIndex = _.page = _.slide = 0; + _.arrows = {}; - // preserve original options to - // extend breakpoint settings - _._opt = _.opt; + // preserve original options to + // extend breakpoint settings + _._opt = _.opt; - // create track and wrap slides - _.track = document.createElement('div'); - _.track.className = 'glider-track'; - _.ele.appendChild(_.track) - while (_.ele.children.length !== 1){ - _.track.appendChild(_.ele.children[0]) - } + // create track and wrap slides + _.track = document.createElement('div'); + _.track.className = 'glider-track'; + _.ele.appendChild(_.track) + while (_.ele.children.length !== 1){ + _.track.appendChild(_.ele.children[0]) + } + + // calculate list dimensions + _.init(); - // calculate list dimensions - _.init(); - - // set events - _.ele.classList.toggle('draggable', _.opt.draggable === true) - if (_.opt.draggable){ - _.mouseup = function(){ - _.mouseDown = undefined; - _.ele.classList.remove('drag'); - } - _.ele.addEventListener('mouseup', _.mouseup); - _.ele.addEventListener('mouseleave', _.mouseup); - _.ele.addEventListener('mousedown',function(e){ - _.mouseDown = e.clientX; - _.ele.classList.add('drag'); - }); - _.ele.addEventListener('mousemove', _.handleMouse.bind(_)); + // set events + _.ele.classList.toggle('draggable', _.opt.draggable === true) + if (_.opt.draggable){ + _.mouseup = function(){ + _.mouseDown = undefined; + _.ele.classList.remove('drag'); } - _.resize = _.init.bind(_, true); - _.ele.addEventListener('scroll', _.updateControls.bind(_)) - window.addEventListener('resize', _.resize); + _.ele.addEventListener('mouseup', _.mouseup); + _.ele.addEventListener('mouseleave', _.mouseup); + _.ele.addEventListener('mousedown',function(e){ + _.mouseDown = e.clientX; + _.ele.classList.add('drag'); + }); + _.ele.addEventListener('mousemove', _.handleMouse.bind(_)); + } + _.resize = _.init.bind(_, true); + _.ele.addEventListener('scroll', _.updateControls.bind(_)) + window.addEventListener('resize', _.resize); } return Glider; @@ -132,7 +132,7 @@ _.updateControls(); } - _.event(refresh ? 'refresh ' : 'loaded') + _.emit(refresh ? 'refresh ' : 'loaded') }; gliderPrototype.buildDots = function(){ @@ -226,7 +226,7 @@ var isVisible = itemStart >= start && itemEnd <= end; slideClasses.toggle('visible', isVisible); if (isVisible != wasVisible){ - _.event('slide-' +(isVisible ? 'visible' : 'hidden'), { + _.emit('slide-' +(isVisible ? 'visible' : 'hidden'), { slide: index }) } @@ -279,7 +279,7 @@ _.opt.duration * (Math.abs(_.ele.scrollLeft - slide)), function() { _.updateControls(); - _.event('animated',{ + _.emit('animated',{ value: originalSlide, type: typeof originalSlide === 'string' ? 'arrow' : dot ? 'dot' : 'slide' @@ -328,7 +328,7 @@ if (_.slides.length){ _.track.removeChild(_.slides[index]); _.init(true, true); - _.event('remove') + _.emit('remove') } } @@ -337,7 +337,7 @@ _.track.appendChild(ele); _.init(true, true); - _.event('add') + _.emit('add') } gliderPrototype.handleMouse = function(e){ @@ -376,10 +376,10 @@ [].forEach.call(replace.getElementsByTagName('*'),clear); _.ele.parentNode.replaceChild(replace, _.ele); window.removeEventListener('resize', _.resize); - _.event('destroy') + _.emit('destroy') } - gliderPrototype.event = function(name, arg){ + gliderPrototype.emit = function(name, arg){ var _ = this, e = new CustomEvent('glider-'+name, { bubbles: !_.opt.eventPropagate, detail: arg diff --git a/glider.js b/glider.js index 7e93b88..b83b8dc 100644 --- a/glider.js +++ b/glider.js @@ -5,13 +5,13 @@ \___//_//_/ \_,_/ \__//_/ (_)__/ //___/ |___/ - Version: 1.5 + Version: 1.5.1 Author: Nick Piscitelli (pickykneee) Website: https://nickpiscitelli.com Documentation: http://nickpiscitelli.github.io/Glider.js License: MIT License Release Date: October 25th, 2018 - Last Update: November 10th, 2018 + */ ;(function (factory) { typeof define === 'function' && define.amd ? define(factory) : @@ -24,64 +24,64 @@ function Glider(element, settings) { - var _ = this; + var _ = this; - if (element._glider) return element._glider; + if (element._glider) return element._glider; - _.ele = element - _.ele.classList.add('glider'); + _.ele = element + _.ele.classList.add('glider'); - // expose glider object to its DOM element - _.ele._glider = _ + // expose glider object to its DOM element + _.ele._glider = _ - // merge user setting with defaults - _.opt = Object.assign({}, { - slidesToScroll: 1, - slidesToShow: 1, - duration: .5, - // easeInQuad - easing: function (x, t, b, c, d) { - return c*(t/=d)*t + b; - } + // merge user setting with defaults + _.opt = Object.assign({}, { + slidesToScroll: 1, + slidesToShow: 1, + duration: .5, + // easeInQuad + easing: function (x, t, b, c, d) { + return c*(t/=d)*t + b; + } }, settings); - // set defaults - _.aIndex = _.page = _.slide = 0; - _.arrows = {}; + // set defaults + _.aIndex = _.page = _.slide = 0; + _.arrows = {}; - // preserve original options to - // extend breakpoint settings - _._opt = _.opt; + // preserve original options to + // extend breakpoint settings + _._opt = _.opt; - // create track and wrap slides - _.track = document.createElement('div'); - _.track.className = 'glider-track'; - _.ele.appendChild(_.track) - while (_.ele.children.length !== 1){ - _.track.appendChild(_.ele.children[0]) - } + // create track and wrap slides + _.track = document.createElement('div'); + _.track.className = 'glider-track'; + _.ele.appendChild(_.track) + while (_.ele.children.length !== 1){ + _.track.appendChild(_.ele.children[0]) + } + + // calculate list dimensions + _.init(); - // calculate list dimensions - _.init(); - - // set events - _.ele.classList.toggle('draggable', _.opt.draggable === true) - if (_.opt.draggable){ - _.mouseup = function(){ - _.mouseDown = undefined; - _.ele.classList.remove('drag'); - } - _.ele.addEventListener('mouseup', _.mouseup); - _.ele.addEventListener('mouseleave', _.mouseup); - _.ele.addEventListener('mousedown',function(e){ - _.mouseDown = e.clientX; - _.ele.classList.add('drag'); - }); - _.ele.addEventListener('mousemove', _.handleMouse.bind(_)); + // set events + _.ele.classList.toggle('draggable', _.opt.draggable === true) + if (_.opt.draggable){ + _.mouseup = function(){ + _.mouseDown = undefined; + _.ele.classList.remove('drag'); } - _.resize = _.init.bind(_, true); - _.ele.addEventListener('scroll', _.updateControls.bind(_)) - window.addEventListener('resize', _.resize); + _.ele.addEventListener('mouseup', _.mouseup); + _.ele.addEventListener('mouseleave', _.mouseup); + _.ele.addEventListener('mousedown',function(e){ + _.mouseDown = e.clientX; + _.ele.classList.add('drag'); + }); + _.ele.addEventListener('mousemove', _.handleMouse.bind(_)); + } + _.resize = _.init.bind(_, true); + _.ele.addEventListener('scroll', _.updateControls.bind(_)) + window.addEventListener('resize', _.resize); } return Glider; @@ -132,7 +132,7 @@ _.updateControls(); } - _.event(refresh ? 'refresh ' : 'loaded') + _.emit(refresh ? 'refresh ' : 'loaded') }; gliderPrototype.buildDots = function(){ @@ -226,7 +226,7 @@ var isVisible = itemStart >= start && itemEnd <= end; slideClasses.toggle('visible', isVisible); if (isVisible != wasVisible){ - _.event('slide-' +(isVisible ? 'visible' : 'hidden'), { + _.emit('slide-' +(isVisible ? 'visible' : 'hidden'), { slide: index }) } @@ -279,7 +279,7 @@ _.opt.duration * (Math.abs(_.ele.scrollLeft - slide)), function() { _.updateControls(); - _.event('animated',{ + _.emit('animated',{ value: originalSlide, type: typeof originalSlide === 'string' ? 'arrow' : dot ? 'dot' : 'slide' @@ -328,7 +328,7 @@ if (_.slides.length){ _.track.removeChild(_.slides[index]); _.init(true, true); - _.event('remove') + _.emit('remove') } } @@ -337,7 +337,7 @@ _.track.appendChild(ele); _.init(true, true); - _.event('add') + _.emit('add') } gliderPrototype.handleMouse = function(e){ @@ -376,10 +376,10 @@ [].forEach.call(replace.getElementsByTagName('*'),clear); _.ele.parentNode.replaceChild(replace, _.ele); window.removeEventListener('resize', _.resize); - _.event('destroy') + _.emit('destroy') } - gliderPrototype.event = function(name, arg){ + gliderPrototype.emit = function(name, arg){ var _ = this, e = new CustomEvent('glider-'+name, { bubbles: !_.opt.eventPropagate, detail: arg diff --git a/glider.min.js b/glider.min.js index 50bd88c..dd6a6e4 100644 --- a/glider.min.js +++ b/glider.min.js @@ -16,13 +16,13 @@ (function(e){"function"===typeof define&&define.amd?define(e):"object"===typeof exports?module.exports=e():e()})(function(){var e=(window.Glider=function(){return function(c,b){var a=this;if(c._glider)return c._glider;a.ele=c;a.ele.classList.add("glider");a.ele._glider=a;a.opt=Object.assign({},{slidesToScroll:1,slidesToShow:1,duration:.5,easing:function(a,b,c,e,f){return e*(b/=f)*b+c}},b);a.aIndex=a.page=a.slide=0;a.arrows={};a._opt=a.opt;a.track=document.createElement("div");a.track.className="glider-track"; for(a.ele.appendChild(a.track);1!==a.ele.children.length;)a.track.appendChild(a.ele.children[0]);a.init();a.ele.classList.toggle("draggable",!0===a.opt.draggable);a.opt.draggable&&(a.mouseup=function(){a.mouseDown=void 0;a.ele.classList.remove("drag")},a.ele.addEventListener("mouseup",a.mouseup),a.ele.addEventListener("mouseleave",a.mouseup),a.ele.addEventListener("mousedown",function(b){a.mouseDown=b.clientX;a.ele.classList.add("drag")}),a.ele.addEventListener("mousemove",a.handleMouse.bind(a))); a.resize=a.init.bind(a,!0);a.ele.addEventListener("scroll",a.updateControls.bind(a));window.addEventListener("resize",a.resize)}}()).prototype;e.init=function(c,b){var a=this,d=0;a.slides=a.track.children;[].forEach.call(a.slides,function(a){a.classList.add("glider-slide")});a.containerWidth=a.ele.clientWidth;var e=a.settingsBreakpoint();b||(b=e);"auto"===a.opt.slidesToShow&&(a.opt.slidesToShow=Math.floor(a.containerWidth/a.opt.itemWidth));"auto"===a.opt.slidesToScroll&&(a.opt.slidesToScroll=a.opt.slidesToShow); -a.itemWidth=a.containerWidth/a.opt.slidesToShow;[].forEach.call(a.slides,function(b){b.style.height="auto";b.style.width=a.itemWidth+"px";d+=a.itemWidth});a.track.style.width=d+"px";a.trackWidth=d;if(!c||b)a.bindArrows(),a.buildDots(),a.updateControls();a.event(c?"refresh ":"loaded")};e.buildDots=function(){if(this.opt.dots){if(this.dots="string"===typeof this.opt.dots?document.querySelector(this.opt.dots):this.opt.dots){this.dots.innerHTML="";this.dots.className="glider-dots";for(var c=0;c=b.trackWidth;b.arrows.prev&&b.arrows.prev.classList.toggle("disabled",0>=b.ele.scrollLeft||a);b.arrows.next&&b.arrows.next.classList.toggle("disabled",b.ele.scrollLeft+b.containerWidth>=Math.floor(b.trackWidth)||a);b.slide=Math.round(b.ele.scrollLeft/b.itemWidth);b.page=Math.round(b.ele.scrollLeft/b.containerWidth);var d=b.slide+ Math.floor(Math.floor(b.opt.slidesToShow)/2),e=Math.floor(b.opt.slidesToShow)%2?0:d+1;1==Math.floor(b.opt.slidesToShow)&&(e=0);b.ele.scrollLeft+b.containerWidth>=Math.floor(b.trackWidth)&&(b.page=b.dots?b.dots.children.length-1:0,b.slide=b.slides.length-b.opt.slidesToShow);[].forEach.call(b.slides,function(a,c){var f=a.classList,l=f.contains("visible"),g=b.ele.scrollLeft,k=b.ele.scrollLeft+b.containerWidth,h=b.itemWidth*c,m=h+b.itemWidth;f.forEach(function(a){/^left|right/.test(a)&&f.remove(a)}); -f.toggle("active",b.slide===c);d==c||e&&e==c?f.add("center"):(f.remove("center"),f.add([c=g&&m<=k;f.toggle("visible",g);g!=l&&b.event("slide-"+(g?"visible":"hidden"),{slide:c})});b.dots&&[].forEach.call(b.dots.children,function(a,c){a.classList.toggle("active",b.page===c)});c&&b.opt.scrollLock&&(clearTimeout(b.scrollLock),b.scrollLock=setTimeout(function(){clearTimeout(b.scrollLock);b.ele.scrollLeft/b.itemWidth%1&&b.scrollItem(b.round(b.ele.scrollLeft/ -b.itemWidth))},b.opt.scrollLockDelay||250))};e.scrollItem=function(c,b,a){a&&a.preventDefault();var d=this,e=c;d.aIndex++;!0===b?c*=d.containerWidth:("string"===typeof c&&(a="prev"===c,c=d.opt.slidesToScroll%1||d.opt.slidesToShow%1?d.round(d.ele.scrollLeft/d.itemWidth):d.slide,c=a?c-d.opt.slidesToScroll:c+d.opt.slidesToScroll),c=Math.max(Math.min(c,d.slides.length),0),d.slide=c,c*=d.itemWidth);d.scrollTo(c,d.opt.duration*Math.abs(d.ele.scrollLeft-c),function(){d.updateControls();d.event("animated", +f.toggle("active",b.slide===c);d==c||e&&e==c?f.add("center"):(f.remove("center"),f.add([c=g&&m<=k;f.toggle("visible",g);g!=l&&b.emit("slide-"+(g?"visible":"hidden"),{slide:c})});b.dots&&[].forEach.call(b.dots.children,function(a,c){a.classList.toggle("active",b.page===c)});c&&b.opt.scrollLock&&(clearTimeout(b.scrollLock),b.scrollLock=setTimeout(function(){clearTimeout(b.scrollLock);b.ele.scrollLeft/b.itemWidth%1&&b.scrollItem(b.round(b.ele.scrollLeft/ +b.itemWidth))},b.opt.scrollLockDelay||250))};e.scrollItem=function(c,b,a){a&&a.preventDefault();var d=this,e=c;d.aIndex++;!0===b?c*=d.containerWidth:("string"===typeof c&&(a="prev"===c,c=d.opt.slidesToScroll%1||d.opt.slidesToShow%1?d.round(d.ele.scrollLeft/d.itemWidth):d.slide,c=a?c-d.opt.slidesToScroll:c+d.opt.slidesToScroll),c=Math.max(Math.min(c,d.slides.length),0),d.slide=c,c*=d.itemWidth);d.scrollTo(c,d.opt.duration*Math.abs(d.ele.scrollLeft-c),function(){d.updateControls();d.emit("animated", {value:e,type:"string"===typeof e?"arrow":b?"dot":"slide"})});return!1};e.settingsBreakpoint=function(){var c=this._opt.responsive;if(c)for(var b=0;ba.breakpoint)return this.opt=Object.assign({},this._opt,a.settings),!0}return!1};e.scrollTo=function(c,b,a){var d=this,e=(new Date).getTime(),h=d.aIndex,k=function(){var f=(new Date).getTime()-e;d.ele.scrollLeft+=(c-d.ele.scrollLeft)*d.opt.easing(0,f,0,1,b);f