From 17273f303cdf1a09b00e824f326364145f4bc24b Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 2 Feb 2018 14:23:35 -0600 Subject: [PATCH 1/7] Added sliderTagName option to allow a specific HTML element name to be used as the slider wrapper HTML (such as 'ul' for a slider of 'li's to maintain valid HTML) --- dist/flickity.pkgd.js | 90 ++++++++++++++++++++++----------------- dist/flickity.pkgd.min.js | 4 +- js/flickity.js | 4 +- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/dist/flickity.pkgd.js b/dist/flickity.pkgd.js index d1f39fb9..696bf23c 100644 --- a/dist/flickity.pkgd.js +++ b/dist/flickity.pkgd.js @@ -531,7 +531,7 @@ return getSize; })); /** - * Fizzy UI utils v2.0.5 + * Fizzy UI utils v2.0.7 * MIT license */ @@ -586,23 +586,27 @@ utils.modulo = function( num, div ) { // ----- makeArray ----- // +var arraySlice = Array.prototype.slice; + // turn element or nodeList into an array utils.makeArray = function( obj ) { - var ary = []; if ( Array.isArray( obj ) ) { // use object if already an array - ary = obj; - } else if ( obj && typeof obj == 'object' && - typeof obj.length == 'number' ) { + return obj; + } + // return empty array if undefined or null. #6 + if ( obj === null || obj === undefined ) { + return []; + } + + var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number'; + if ( isArrayLike ) { // convert nodeList to array - for ( var i=0; i < obj.length; i++ ) { - ary.push( obj[i] ); - } - } else { - // array of single index - ary.push( obj ); + return arraySlice.call( obj ); } - return ary; + + // array of single index + return [ obj ]; }; // ----- removeFrom ----- // @@ -681,22 +685,21 @@ utils.filterFindElements = function( elems, selector ) { // ----- debounceMethod ----- // utils.debounceMethod = function( _class, methodName, threshold ) { + threshold = threshold || 100; // original method var method = _class.prototype[ methodName ]; var timeoutName = methodName + 'Timeout'; _class.prototype[ methodName ] = function() { var timeout = this[ timeoutName ]; - if ( timeout ) { - clearTimeout( timeout ); - } - var args = arguments; + clearTimeout( timeout ); + var args = arguments; var _this = this; this[ timeoutName ] = setTimeout( function() { method.apply( _this, args ); delete _this[ timeoutName ]; - }, threshold || 100 ); + }, threshold ); }; }; @@ -1257,6 +1260,7 @@ Flickity.defaults = { cellAlign: 'center', // cellSelector: undefined, // contain: false, + sliderTagName: 'div', freeScrollFriction: 0.075, // friction when free-scrolling friction: 0.28, // friction when selecting namespaceJQueryEvents: true, @@ -1364,7 +1368,7 @@ proto.activate = function() { // slider positions the cells proto._createSlider = function() { // slider element does all the positioning - var slider = document.createElement('div'); + var slider = document.createElement(this.options.sliderTagName); slider.className = 'flickity-slider'; slider.style[ this.originSide ] = 0; this.slider = slider; @@ -2014,7 +2018,7 @@ return Flickity; })); /*! - * Unipointer v2.2.0 + * Unipointer v2.2.1 * base class for doing one thing with pointer event * MIT license */ @@ -2126,8 +2130,9 @@ proto.onpointerdown = function( event ) { * @param {Event or Touch} pointer */ proto._pointerDown = function( event, pointer ) { - // dismiss other pointers - if ( this.isPointerDown ) { + // dismiss right click and other pointers + // button = 0 is okay, 1-4 not + if ( event.button || this.isPointerDown ) { return; } @@ -4194,7 +4199,7 @@ return Flickity; })); /*! - * imagesLoaded v4.1.3 + * imagesLoaded v4.1.4 * JavaScript is all like "You images are done yet or what?" * MIT License */ @@ -4246,22 +4251,23 @@ function extend( a, b ) { return a; } +var arraySlice = Array.prototype.slice; + // turn element or nodeList into an array function makeArray( obj ) { - var ary = []; if ( Array.isArray( obj ) ) { // use object if already an array - ary = obj; - } else if ( typeof obj.length == 'number' ) { + return obj; + } + + var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number'; + if ( isArrayLike ) { // convert nodeList to array - for ( var i=0; i < obj.length; i++ ) { - ary.push( obj[i] ); - } - } else { - // array of single index - ary.push( obj ); + return arraySlice.call( obj ); } - return ary; + + // array of single index + return [ obj ]; } // -------------------------- imagesLoaded -------------------------- // @@ -4277,13 +4283,19 @@ function ImagesLoaded( elem, options, onAlways ) { return new ImagesLoaded( elem, options, onAlways ); } // use elem as selector string + var queryElem = elem; if ( typeof elem == 'string' ) { - elem = document.querySelectorAll( elem ); + queryElem = document.querySelectorAll( elem ); + } + // bail if bad element + if ( !queryElem ) { + console.error( 'Bad element for imagesLoaded ' + ( queryElem || elem ) ); + return; } - this.elements = makeArray( elem ); + this.elements = makeArray( queryElem ); this.options = extend( {}, this.options ); - + // shift arguments if no options set if ( typeof options == 'function' ) { onAlways = options; } else { @@ -4302,9 +4314,7 @@ function ImagesLoaded( elem, options, onAlways ) { } // HACK check async to allow time to bind listeners - setTimeout( function() { - this.check(); - }.bind( this )); + setTimeout( this.check.bind( this ) ); } ImagesLoaded.prototype = Object.create( EvEmitter.prototype ); @@ -4472,7 +4482,9 @@ LoadingImage.prototype.check = function() { }; LoadingImage.prototype.getIsImageComplete = function() { - return this.img.complete && this.img.naturalWidth !== undefined; + // check for non-zero, non-undefined naturalWidth + // fixes Safari+InfiniteScroll+Masonry bug infinite-scroll#671 + return this.img.complete && this.img.naturalWidth; }; LoadingImage.prototype.confirm = function( isLoaded, message ) { diff --git a/dist/flickity.pkgd.min.js b/dist/flickity.pkgd.min.js index 6af89945..a0ce641c 100644 --- a/dist/flickity.pkgd.min.js +++ b/dist/flickity.pkgd.min.js @@ -9,5 +9,5 @@ * Copyright 2017 Metafizzy */ -!function(t,e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("jquery")):t.jQueryBridget=e(t,t.jQuery)}(window,function(t,e){"use strict";function i(i,o,a){function h(t,e,n){var s,o="$()."+i+'("'+e+'")';return t.each(function(t,h){var l=a.data(h,i);if(!l)return void r(i+" not initialized. Cannot call methods, i.e. "+o);var c=l[e];if(!c||"_"==e.charAt(0))return void r(o+" is not a valid method");var d=c.apply(l,n);s=void 0===s?d:s}),void 0!==s?s:t}function l(t,e){t.each(function(t,n){var s=a.data(n,i);s?(s.option(e),s._init()):(s=new o(n,e),a.data(n,i,s))})}a=a||e||t.jQuery,a&&(o.prototype.option||(o.prototype.option=function(t){a.isPlainObject(t)&&(this.options=a.extend(!0,this.options,t))}),a.fn[i]=function(t){if("string"==typeof t){var e=s.call(arguments,1);return h(this,t,e)}return l(this,t),this},n(a))}function n(t){!t||t&&t.bridget||(t.bridget=i)}var s=Array.prototype.slice,o=t.console,r="undefined"==typeof o?function(){}:function(t){o.error(t)};return n(e||t.jQuery),i}),function(t,e){"function"==typeof define&&define.amd?define("ev-emitter/ev-emitter",e):"object"==typeof module&&module.exports?module.exports=e():t.EvEmitter=e()}("undefined"!=typeof window?window:this,function(){function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var i=this._events=this._events||{},n=i[t]=i[t]||[];return n.indexOf(e)==-1&&n.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var i=this._onceEvents=this._onceEvents||{},n=i[t]=i[t]||{};return n[e]=!0,this}},e.off=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){var n=i.indexOf(e);return n!=-1&&i.splice(n,1),this}},e.emitEvent=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){i=i.slice(0),e=e||[];for(var n=this._onceEvents&&this._onceEvents[t],s=0;s