From 7d0208f046940f7d6e2d6eaa92d364de7baf3c98 Mon Sep 17 00:00:00 2001 From: displaynone Date: Wed, 3 May 2017 00:06:29 +0200 Subject: [PATCH] New tests: scrollTo and autoslide --- package.json | 9 +++- static/js/webslides.js | 85 +++++++++++++++++++----------------- static/js/webslides.min.js | 4 +- test/utils/autoslide.test.js | 43 ++++++++++++++++++ test/utils/scroll-to.test.js | 23 ++++++++++ 5 files changed, 120 insertions(+), 44 deletions(-) create mode 100644 test/utils/autoslide.test.js create mode 100644 test/utils/scroll-to.test.js diff --git a/package.json b/package.json index dc34f64..e091fc2 100644 --- a/package.json +++ b/package.json @@ -30,14 +30,16 @@ "devDependencies": { "babel-cli": "^6.24.1", "babel-core": "^6.24.1", - "babel-loader": "^7.0.0", "babel-jest": "^19.0.0", + "babel-loader": "^7.0.0", "babel-preset-env": "^1.4.0", "babel-preset-es2015": "^6.24.1", "eslint": "^3.19.0", "eslint-loader": "^1.7.1", "eslint-plugin-jest": "^19.0.1", "jest": "^19.0.2", + "jest-css-modules": "^1.1.0", + "jsdom": "^10.1.0", "npm-run-all": "^4.0.2", "rimraf": "^2.6.1", "simulant": "^0.2.2", @@ -62,5 +64,10 @@ } ] ] + }, + "jest": { + "moduleNameMapper": { + "\\.(css)$": "/node_modules/jest-css-modules" + } } } diff --git a/static/js/webslides.js b/static/js/webslides.js index 9028c73..bfcfc4b 100644 --- a/static/js/webslides.js +++ b/static/js/webslides.js @@ -1,7 +1,7 @@ /*! * Name: WebSlides * Version: 1.3.1 - * Date: 2017-04-29 + * Date: 2017-05-01 * Description: Making HTML presentations easy * URL: https://github.com/webslides/webslides#readme * Credits: @jlantunez, @LuisSacristan, @Belelros @@ -238,8 +238,7 @@ var DOM = function () { } /** - * Checks if the element is visible.This is only intended - * to be used in conjunction with DOM.hide and DOM.show + * Checks if the element is visible. * @param {Element} el Element to check. * @return {boolean} */ @@ -247,7 +246,7 @@ var DOM = function () { }, { key: 'isVisible', value: function isVisible(el) { - return el.style.display == ''; + return el.offsetParent !== null; } /** @@ -304,9 +303,9 @@ var DOM = function () { } /** - * Gets the integer value of a style property - * @param {string} prop CSS property value - * @return {integer} The property without the units + * Gets the integer value of a style property. + * @param {string} prop CSS property value. + * @return {Number} The property without the units. */ }, { @@ -316,10 +315,10 @@ var DOM = function () { } /** - * Wraps a HTML structure arrond a element - * @param {Element} elem the element to be wrapped - * @param {string} tag the new element tag - * @return {Element} the new element + * Wraps a HTML structure around an element. + * @param {Element} elem the element to be wrapped. + * @param {string} tag the new element tag. + * @return {Element} the new element. */ }, { @@ -333,9 +332,9 @@ var DOM = function () { } /** - * Inserts and element after another element - * @param {Element} elem the element to be inserted - * @param {Element} target the element to be inserted after + * Inserts and element after another element. + * @param {Element} elem the element to be inserted. + * @param {Element} target the element to be inserted after. */ }, { @@ -343,7 +342,7 @@ var DOM = function () { value: function after(elem, target) { var parent = target.parentNode; - if (parent.lastChild == target) { + if (parent.lastChild === target) { parent.appendChild(elem); } else { parent.insertBefore(elem, target.nextSibling); @@ -2122,13 +2121,13 @@ var Touch = function () { var info = Touch.normalizeEventInfo(event); - if (event.touches.length == 1) { + if (event.touches.length === 1) { this.startX_ = info.x; this.startY_ = info.y; this.endX_ = info.x; this.endY_ = info.y; } else if (event.touches.length > 1) { - this.startTouches = this.getTouchCoorinates(event); + this.startTouches = Touch.getTouchCoordinates(event); this.endTouches = this.startTouches; this.isGesture = true; } @@ -2150,7 +2149,7 @@ var Touch = function () { var info = Touch.normalizeEventInfo(event); if (this.isGesture) { - this.endTouches = this.getTouchCoorinates(event); + this.endTouches = Touch.getTouchCoordinates(event); } else { this.endX_ = info.x; this.endY_ = info.y; @@ -2193,15 +2192,21 @@ var Touch = function () { } /** - * Get X,Y coordinates from touchs pointers + * Get X,Y coordinates from touch pointers. * @param {Event} event - * @return {array} + * @return {Object} */ - }, { - key: 'getTouchCoorinates', - value: function getTouchCoorinates(event) { - return [{ x: event.touches[0].clientX, y: event.touches[0].clientY }, { x: event.touches[1].clientX, y: event.touches[1].clientY }]; + }], [{ + key: 'getTouchCoordinates', + value: function getTouchCoordinates(event) { + return [{ + x: event.touches[0].clientX, + y: event.touches[0].clientY + }, { + x: event.touches[1].clientX, + y: event.touches[1].clientY + }]; } /** @@ -2211,7 +2216,7 @@ var Touch = function () { * @return {Object} Normalised touch points. */ - }], [{ + }, { key: 'normalizeEventInfo', value: function normalizeEventInfo(event) { var touchEvent = { pageX: 0, pageY: 0 }; @@ -2718,7 +2723,7 @@ var Zoom = function () { /** * On key down handler. Will decide if Zoom in or out - * @param {Event} event Key down event + * @param {Event} event Key down event. */ @@ -2727,14 +2732,14 @@ var Zoom = function () { value: function onKeyDown(event) { if (!this.isZoomed_ && __WEBPACK_IMPORTED_MODULE_1__utils_keys__["a" /* default */].MINUS.includes(event.which)) { this.zoomIn(); - } else if (this.isZoomed_ && (__WEBPACK_IMPORTED_MODULE_1__utils_keys__["a" /* default */].PLUS.includes(event.which) || event.which == __WEBPACK_IMPORTED_MODULE_1__utils_keys__["a" /* default */].ESCAPE)) { + } else if (this.isZoomed_ && (__WEBPACK_IMPORTED_MODULE_1__utils_keys__["a" /* default */].PLUS.includes(event.which) || event.which === __WEBPACK_IMPORTED_MODULE_1__utils_keys__["a" /* default */].ESCAPE)) { this.zoomOut(); } } /** * Prepare zoom structure, scales the slides and uses a grid layout - * to show them + * to show them. */ }, { @@ -2767,8 +2772,8 @@ var Zoom = function () { } /** - * Creates a block structure around the slide - * @param {Element} elem slide element + * Creates a block structure around the slide. + * @param {Element} elem slide element. */ }, { @@ -2783,7 +2788,7 @@ var Zoom = function () { var div = __WEBPACK_IMPORTED_MODULE_0__utils_dom__["a" /* default */].wrap(wrap, 'div'); div.className = CLASSES.DIV; // Adding some layer for controling click events - var divLayer = document.createElement('div'); + var divLayer = __WEBPACK_IMPORTED_MODULE_0__utils_dom__["a" /* default */].createNode('div'); divLayer.className = 'zoom-layer'; divLayer.addEventListener('click', function (e) { e.stopPropagation(); @@ -2792,9 +2797,8 @@ var Zoom = function () { }); wrap.appendChild(divLayer); // Slide number - var slideNumber = document.createElement('p'); + var slideNumber = __WEBPACK_IMPORTED_MODULE_0__utils_dom__["a" /* default */].createNode('p', '', '' + (elem.i + 1)); slideNumber.className = 'text-slide-number'; - slideNumber.textContent = '' + (elem.i + 1); div.appendChild(slideNumber); this.setSizes_(div, wrap, elem); @@ -2817,12 +2821,12 @@ var Zoom = function () { // Sets element size: window size - relative margins var scale = divCSS.width.includes('%') ? 100 / __WEBPACK_IMPORTED_MODULE_0__utils_dom__["a" /* default */].parseSize(divCSS.width) : window.innerWidth / __WEBPACK_IMPORTED_MODULE_0__utils_dom__["a" /* default */].parseSize(divCSS.width); - if (scale == 1) { + if (scale === 1) { // If the scale is 100% means it is mobile var wsW = this.ws_.el.clientWidth; elem.el.style.width = (wsW - marginW) * 2 + 'px'; elem.el.style.height = (wsW - marginH) * 1.5 + 'px'; - elem.el.style.minHeight = scale == 1 ? 'auto' : ''; + elem.el.style.minHeight = scale === 1 ? 'auto' : ''; // Because of flexbox, wrap height is required wrap.style.height = (wsW - marginH) * 1.5 / 2 + 'px'; } else { @@ -2834,7 +2838,7 @@ var Zoom = function () { } /** - * Toggles zoom + * Toggles zoom. */ }, { @@ -2848,7 +2852,7 @@ var Zoom = function () { } /** - * Zoom In the slider, scales the slides and uses a grid layout to show them + * Zoom In the slider, scales the slides and uses a grid layout to show them. */ }, { @@ -2869,7 +2873,7 @@ var Zoom = function () { } /** - * Zoom Out the slider, remove scale from the slides + * Zoom Out the slider, remove scale from the slides. */ }, { @@ -2890,13 +2894,12 @@ var Zoom = function () { } /** - * When windows resize it is necessary to recalculate layers sizes - * @param {Event} ev + * When windows resize it is necessary to recalculate layers sizes. */ }, { key: 'onWindowResize', - value: function onWindowResize(ev) { + value: function onWindowResize() { var _this5 = this; if (this.isZoomed_) this.zoomOut(); diff --git a/static/js/webslides.min.js b/static/js/webslides.min.js index a808806..fd33cc0 100644 --- a/static/js/webslides.min.js +++ b/static/js/webslides.min.js @@ -1,9 +1,9 @@ /*! * Name: WebSlides * Version: 1.3.1 - * Date: 2017-04-29 + * Date: 2017-05-01 * Description: Making HTML presentations easy * URL: https://github.com/webslides/webslides#readme * Credits: @jlantunez, @LuisSacristan, @Belelros */ -!function(e){function t(n){if(i[n])return i[n].exports;var s=i[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var i={};t.m=e,t.c=i,t.i=function(e){return e},t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/static/js/",t(t.s=5)}([function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(18),o=function(){function e(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=document.createElement(e);return n.id=t,i&&(n.textContent=i),n}},{key:"once",value:function(e,t,i){var n=function n(s){s.target===e&&(e.removeEventListener(t,n),i(s))};e.addEventListener(t,n,!1)}},{key:"getTransitionEvent",value:function(e){if(a&&!e)return a;a="";for(var t=e||document.createElement("ws"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"},n=Object.keys(i),s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:{},n=new s.a(t,{detail:i});e.dispatchEvent(n)}},{key:"toArray",value:function(e){return[].slice.call(e)}},{key:"isFocusableElement",value:function(){var e=!1;if(document.activeElement){var t="inherit"!==document.activeElement.contentEditable&&void 0!==document.activeElement.contentEditable;e=["INPUT","SELECT","OPTION","TEXTAREA"].indexOf(document.activeElement.tagName)>-1||t}return e}},{key:"parseSize",value:function(e){return Number(e.replace(/[^\d\.]/g,""))}},{key:"wrap",value:function(e,t){var i=document.createElement(t);return e.parentElement.insertBefore(i,e),i.appendChild(e),i}},{key:"after",value:function(e,t){var i=t.parentNode;i.lastChild==t?i.appendChild(e):i.insertBefore(e,t.nextSibling)}}]),e}();t.a=l},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(0);i.d(t,"a",function(){return l}),i.d(t,"b",function(){return r});var o=function(){function e(e,t){for(var i=0;i0&&void 0!==arguments[0]?arguments[0]:{},i=t.autoslide,s=void 0!==i&&i,o=t.changeOnClick,a=void 0!==o&&o,r=t.loop,l=void 0===r||r,c=t.minWheelDelta,h=void 0===c?40:c,d=t.navigateOnScroll,f=void 0===d||d,v=t.scrollWait,y=void 0===v?450:v,p=t.slideOffset,m=void 0===p?50:p;if(n(this,e),this.el=document.getElementById("webslides"),!this.el)throw new Error("Couldn't find the webslides container!");this.isMoving=!1,this.slides=null,this.currentSlideI_=-1,this.currentSlide_=null,this.maxSlide_=0,this.isVertical=this.el.classList.contains(u.VERTICAL),this.plugins={},this.options={autoslide:s,changeOnClick:a,loop:l,minWheelDelta:h,navigateOnScroll:f,scrollWait:y,slideOffset:m},this.initialised=!1,this.removeChildren_(),this.grabSlides_(),this.createPlugins_(),this.initSlides_(),this.onInit_()}return l(e,[{key:"removeChildren_",value:function(){for(var e=this.el.childNodes,t=e.length;t--;){var i=e[t];o.a.isCandidate(i)||this.el.removeChild(i)}}},{key:"createPlugins_",value:function(){var e=this;Object.keys(c).forEach(function(t){var i=c[t];e.plugins[t]=new i(e)})}},{key:"onInit_",value:function(){this.initialised=!0,a.a.fireEvent(this.el,"ws:init"),document.documentElement.classList.add(u.READY)}},{key:"grabSlides_",value:function(){this.slides=a.a.toArray(this.el.childNodes).map(function(e,t){return new o.a(e,t)}),this.maxSlide_=this.slides.length}},{key:"goToSlide",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this.isValidIndexSlide_(e)&&!this.isMoving&&this.currentSlideI_!==e){this.isMoving=!0;var i=!1;null!==t?i=t:this.currentSlideI_>=0&&(i=e>this.currentSlideI_);var n=this.slides[e];null===this.currentSlide_||!this.isVertical||this.plugins.touch&&this.plugins.touch.isEnabled?this.transitionToSlide_(i,n,this.onSlideChange_):this.scrollTransitionToSlide_(i,n,this.onSlideChange_)}}},{key:"scrollTransitionToSlide_",value:function(e,t,n){var s=this;this.el.style.overflow="hidden",e?t.show():(t.moveBeforeFirst(),t.show(),i.i(r.a)(this.currentSlide_.el.offsetTop,0)),i.i(r.a)(t.el.offsetTop,500,function(){s.currentSlide_.hide(),e&&s.currentSlide_.moveAfterLast(),s.el.style.overflow="auto",setTimeout(function(){n.call(s,t)},150)})}},{key:"transitionToSlide_",value:function(e,t,n){var s=this;i.i(r.a)(0,0);var o="slideInRight";e||(t.moveBeforeFirst(),o="slideInLeft"),this.currentSlide_&&(e&&this.currentSlide_.moveAfterLast(),this.currentSlide_.hide()),t.show(),this.initialised&&this.plugins.touch&&this.plugins.touch.isEnabled?(a.a.once(t.el,a.a.getAnimationEvent(),function(){t.el.classList.remove(o),n.call(s,t)}),t.el.classList.add(o)):n.call(this,t)}},{key:"onSlideChange_",value:function(e){this.currentSlide_&&this.currentSlide_.disable(),this.currentSlide_=e,this.currentSlideI_=e.i,this.currentSlide_.enable(),this.isMoving=!1,a.a.fireEvent(this.el,"ws:slide-change",{slides:this.maxSlide_,currentSlide0:this.currentSlideI_,currentSlide:this.currentSlideI_+1})}},{key:"goNext",value:function(){var e=this.currentSlideI_+1;if(e>=this.maxSlide_){if(!this.options.loop)return;e=0}this.goToSlide(e,!0)}},{key:"goPrev",value:function(){var e=this.currentSlideI_-1;if(e<0){if(!this.options.loop)return;e=this.maxSlide_-1}this.goToSlide(e,!1)}},{key:"isValidIndexSlide_",value:function(e){return e>=0&&e=this.maxSlide_)&&(e=0),0!==e)for(var t=0;t0&&(this.interval_=setInterval(this.ws_.goNext.bind(this.ws_),e))}},{key:"stop",value:function(){this.interval_&&(clearInterval(this.interval_),this.interval_=null)}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var i=0;iMath.abs(t);if(this.isGoingUp_=t<0,this.isGoingLeft_=i<0,s){if(n)return;e.preventDefault()}(Math.abs(t)>=this.ws_.options.minWheelDelta||Math.abs(i)>=this.ws_.options.minWheelDelta)&&(s&&this.isGoingLeft_||!s&&this.isGoingUp_?this.ws_.goPrev():this.ws_.goNext(),e.preventDefault())}}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(3),o=function(){function e(e,t){for(var i=0;i1&&(this.startTouches=this.getTouchCoorinates(t),this.endTouches=this.startTouches,this.isGesture=!0)}}},{key:"onMove_",value:function(t){if(!this.ws_.isDisabled()){var i=e.normalizeEventInfo(t);this.isGesture?this.endTouches=this.getTouchCoorinates(t):(this.endX_=i.x,this.endY_=i.y)}}},{key:"onStop_",value:function(){if(!this.ws_.isDisabled())if(this.isGesture){var e=Math.sqrt(Math.pow(this.startTouches[0].x-this.startTouches[1].x,2)+Math.pow(this.startTouches[0].y-this.startTouches[1].y,2)),t=Math.sqrt(Math.pow(this.endTouches[0].x-this.endTouches[1].x,2)+Math.pow(this.endTouches[0].y-this.endTouches[1].y,2));e>t&&this.ws_.toggleZoom(),this.isGesture=!1}else{var i=this.startX_-this.endX_,n=this.startY_-this.endY_;Math.abs(i)>Math.abs(n)&&(i<-this.ws_.options.slideOffset?this.ws_.goPrev():i>this.ws_.options.slideOffset&&this.ws_.goNext())}}},{key:"getTouchCoorinates",value:function(e){return[{x:e.touches[0].clientX,y:e.touches[0].clientY},{x:e.touches[1].clientX,y:e.touches[1].clientY}]}}],[{key:"normalizeEventInfo",value:function(e){var t={pageX:0,pageY:0};return void 0!==e.changedTouches?t=e.changedTouches[0]:void 0!==e.originalEvent&&void 0!==e.originalEvent.changedTouches&&(t=e.originalEvent.changedTouches[0]),{x:e.offsetX||e.layerX||t.pageX,y:e.offsetY||e.layerY||t.pageY}}}]),e}();t.a=r},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(0),o=i(1),a=function(){function e(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:500,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},n=e-o.scrollTop,a=o.scrollTop;if(!t)return o.scrollTop=e,void i();!function r(l){l+=16;var u=Math.min(1,l/t),c=s.a.swing(u,l*u,e,n,t);o.scrollTop=Math.floor(a+c*n),l1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=document.createElement(e);return n.id=t,i&&(n.textContent=i),n}},{key:"once",value:function(e,t,i){var n=function n(s){s.target===e&&(e.removeEventListener(t,n),i(s))};e.addEventListener(t,n,!1)}},{key:"getTransitionEvent",value:function(e){if(a&&!e)return a;a="";for(var t=e||document.createElement("ws"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"},n=Object.keys(i),s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:{},n=new s.a(t,{detail:i});e.dispatchEvent(n)}},{key:"toArray",value:function(e){return[].slice.call(e)}},{key:"isFocusableElement",value:function(){var e=!1;if(document.activeElement){var t="inherit"!==document.activeElement.contentEditable&&void 0!==document.activeElement.contentEditable;e=["INPUT","SELECT","OPTION","TEXTAREA"].indexOf(document.activeElement.tagName)>-1||t}return e}},{key:"parseSize",value:function(e){return Number(e.replace(/[^\d\.]/g,""))}},{key:"wrap",value:function(e,t){var i=document.createElement(t);return e.parentElement.insertBefore(i,e),i.appendChild(e),i}},{key:"after",value:function(e,t){var i=t.parentNode;i.lastChild===t?i.appendChild(e):i.insertBefore(e,t.nextSibling)}}]),e}();t.a=l},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(0);i.d(t,"a",function(){return l}),i.d(t,"b",function(){return r});var o=function(){function e(e,t){for(var i=0;i0&&void 0!==arguments[0]?arguments[0]:{},i=t.autoslide,s=void 0!==i&&i,o=t.changeOnClick,a=void 0!==o&&o,r=t.loop,l=void 0===r||r,c=t.minWheelDelta,h=void 0===c?40:c,d=t.navigateOnScroll,f=void 0===d||d,v=t.scrollWait,y=void 0===v?450:v,p=t.slideOffset,m=void 0===p?50:p;if(n(this,e),this.el=document.getElementById("webslides"),!this.el)throw new Error("Couldn't find the webslides container!");this.isMoving=!1,this.slides=null,this.currentSlideI_=-1,this.currentSlide_=null,this.maxSlide_=0,this.isVertical=this.el.classList.contains(u.VERTICAL),this.plugins={},this.options={autoslide:s,changeOnClick:a,loop:l,minWheelDelta:h,navigateOnScroll:f,scrollWait:y,slideOffset:m},this.initialised=!1,this.removeChildren_(),this.grabSlides_(),this.createPlugins_(),this.initSlides_(),this.onInit_()}return l(e,[{key:"removeChildren_",value:function(){for(var e=this.el.childNodes,t=e.length;t--;){var i=e[t];o.a.isCandidate(i)||this.el.removeChild(i)}}},{key:"createPlugins_",value:function(){var e=this;Object.keys(c).forEach(function(t){var i=c[t];e.plugins[t]=new i(e)})}},{key:"onInit_",value:function(){this.initialised=!0,a.a.fireEvent(this.el,"ws:init"),document.documentElement.classList.add(u.READY)}},{key:"grabSlides_",value:function(){this.slides=a.a.toArray(this.el.childNodes).map(function(e,t){return new o.a(e,t)}),this.maxSlide_=this.slides.length}},{key:"goToSlide",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this.isValidIndexSlide_(e)&&!this.isMoving&&this.currentSlideI_!==e){this.isMoving=!0;var i=!1;null!==t?i=t:this.currentSlideI_>=0&&(i=e>this.currentSlideI_);var n=this.slides[e];null===this.currentSlide_||!this.isVertical||this.plugins.touch&&this.plugins.touch.isEnabled?this.transitionToSlide_(i,n,this.onSlideChange_):this.scrollTransitionToSlide_(i,n,this.onSlideChange_)}}},{key:"scrollTransitionToSlide_",value:function(e,t,n){var s=this;this.el.style.overflow="hidden",e?t.show():(t.moveBeforeFirst(),t.show(),i.i(r.a)(this.currentSlide_.el.offsetTop,0)),i.i(r.a)(t.el.offsetTop,500,function(){s.currentSlide_.hide(),e&&s.currentSlide_.moveAfterLast(),s.el.style.overflow="auto",setTimeout(function(){n.call(s,t)},150)})}},{key:"transitionToSlide_",value:function(e,t,n){var s=this;i.i(r.a)(0,0);var o="slideInRight";e||(t.moveBeforeFirst(),o="slideInLeft"),this.currentSlide_&&(e&&this.currentSlide_.moveAfterLast(),this.currentSlide_.hide()),t.show(),this.initialised&&this.plugins.touch&&this.plugins.touch.isEnabled?(a.a.once(t.el,a.a.getAnimationEvent(),function(){t.el.classList.remove(o),n.call(s,t)}),t.el.classList.add(o)):n.call(this,t)}},{key:"onSlideChange_",value:function(e){this.currentSlide_&&this.currentSlide_.disable(),this.currentSlide_=e,this.currentSlideI_=e.i,this.currentSlide_.enable(),this.isMoving=!1,a.a.fireEvent(this.el,"ws:slide-change",{slides:this.maxSlide_,currentSlide0:this.currentSlideI_,currentSlide:this.currentSlideI_+1})}},{key:"goNext",value:function(){var e=this.currentSlideI_+1;if(e>=this.maxSlide_){if(!this.options.loop)return;e=0}this.goToSlide(e,!0)}},{key:"goPrev",value:function(){var e=this.currentSlideI_-1;if(e<0){if(!this.options.loop)return;e=this.maxSlide_-1}this.goToSlide(e,!1)}},{key:"isValidIndexSlide_",value:function(e){return e>=0&&e=this.maxSlide_)&&(e=0),0!==e)for(var t=0;t0&&(this.interval_=setInterval(this.ws_.goNext.bind(this.ws_),e))}},{key:"stop",value:function(){this.interval_&&(clearInterval(this.interval_),this.interval_=null)}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var i=0;iMath.abs(t);if(this.isGoingUp_=t<0,this.isGoingLeft_=i<0,s){if(n)return;e.preventDefault()}(Math.abs(t)>=this.ws_.options.minWheelDelta||Math.abs(i)>=this.ws_.options.minWheelDelta)&&(s&&this.isGoingLeft_||!s&&this.isGoingUp_?this.ws_.goPrev():this.ws_.goNext(),e.preventDefault())}}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(3),o=function(){function e(e,t){for(var i=0;i1&&(this.startTouches=e.getTouchCoordinates(t),this.endTouches=this.startTouches,this.isGesture=!0)}}},{key:"onMove_",value:function(t){if(!this.ws_.isDisabled()){var i=e.normalizeEventInfo(t);this.isGesture?this.endTouches=e.getTouchCoordinates(t):(this.endX_=i.x,this.endY_=i.y)}}},{key:"onStop_",value:function(){if(!this.ws_.isDisabled())if(this.isGesture){var e=Math.sqrt(Math.pow(this.startTouches[0].x-this.startTouches[1].x,2)+Math.pow(this.startTouches[0].y-this.startTouches[1].y,2)),t=Math.sqrt(Math.pow(this.endTouches[0].x-this.endTouches[1].x,2)+Math.pow(this.endTouches[0].y-this.endTouches[1].y,2));e>t&&this.ws_.toggleZoom(),this.isGesture=!1}else{var i=this.startX_-this.endX_,n=this.startY_-this.endY_;Math.abs(i)>Math.abs(n)&&(i<-this.ws_.options.slideOffset?this.ws_.goPrev():i>this.ws_.options.slideOffset&&this.ws_.goNext())}}}],[{key:"getTouchCoordinates",value:function(e){return[{x:e.touches[0].clientX,y:e.touches[0].clientY},{x:e.touches[1].clientX,y:e.touches[1].clientY}]}},{key:"normalizeEventInfo",value:function(e){var t={pageX:0,pageY:0};return void 0!==e.changedTouches?t=e.changedTouches[0]:void 0!==e.originalEvent&&void 0!==e.originalEvent.changedTouches&&(t=e.originalEvent.changedTouches[0]),{x:e.offsetX||e.layerX||t.pageX,y:e.offsetY||e.layerY||t.pageY}}}]),e}();t.a=r},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(0),o=i(1),a=function(){function e(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:500,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},n=e-o.scrollTop,a=o.scrollTop;if(!t)return o.scrollTop=e,void i();!function r(l){l+=16;var u=Math.min(1,l/t),c=s.a.swing(u,l*u,e,n,t);o.scrollTop=Math.floor(a+c*n),l { + document.body.innerHTML = `
`; +}); + +test('AutoSlide plugin', () => { + const next = jest.fn(); + const ws = document.getElementById('webslides'); + const webslides = { + options: { + autoslide: 100 + }, + goNext: next, + el: ws + }; + + expect(next).not.toBeCalled(); + + const autoslide = new AutoSlide(webslides); + DOM.fireEvent(ws, 'ws:init'); + + // Wait until next execution + jest.runTimersToTime(101); + + expect(next.mock.calls.length).toBe(1); + + // Wait until next execution + jest.runTimersToTime(101); + + expect(next.mock.calls.length).toBe(2); + + // Pause on focus + document.getElementById('focusable').focus(); + DOM.fireEvent(document.body, 'focus'); + jest.runTimersToTime(101); + + expect(next.mock.calls.length).toBe(2); + +}); diff --git a/test/utils/scroll-to.test.js b/test/utils/scroll-to.test.js new file mode 100644 index 0000000..6b16218 --- /dev/null +++ b/test/utils/scroll-to.test.js @@ -0,0 +1,23 @@ +jest.useFakeTimers(); + +beforeAll(() => { + const brs = '
'.repeat(20); + document.body.innerHTML = `
${brs}
`; +}); + +test('ScrollTo utility', () => { + const ws = document.getElementById('webslides'); + // Needs to be required and not imported because const defined in top level + const scrollTo = require('../../src/js/utils/scroll-to'); + const cb = jest.fn(); + + scrollTo.default(100, 500, cb); + + expect(cb).not.toBeCalled(); + expect(ws.scrollTop).toBe(0); + + jest.runAllTimers(); + + expect(cb).toBeCalled(); + expect(ws.scrollTop).toBe(100); +});