diff --git a/README.md b/README.md index da748485..21fc6190 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,9 @@ var flky = new Flickity( '.gallery', { // sets the height of gallery // disable if gallery already has height set with CSS + sliderTagName: 'div', + // sets the HTML element tagname of the slider wrapper + watchCSS: false, // watches the content of :after of the element // activates if #element:after { content: 'flickity' } diff --git a/dist/flickity.pkgd.js b/dist/flickity.pkgd.js index d1f39fb9..f61a90f6 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 ); }; }; @@ -1224,6 +1227,7 @@ var GUID = 0; var instances = {}; function Flickity( element, options ) { + var queryElement = utils.getQueryElement( element ); if ( !queryElement ) { if ( console ) { @@ -1257,6 +1261,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 +1369,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 +2019,7 @@ return Flickity; })); /*! - * Unipointer v2.2.0 + * Unipointer v2.2.1 * base class for doing one thing with pointer event * MIT license */ @@ -2126,8 +2131,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 +4200,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 +4252,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 +4284,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 +4315,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 +4483,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