diff --git a/README.md b/README.md
index 96c91bdf..aa462922 100644
--- a/README.md
+++ b/README.md
@@ -9,26 +9,26 @@ See [flickity.metafizzy.co](http://flickity.metafizzy.co) for complete docs and
### Download
+ CSS:
- - [flickity.css](https://github.com/metafizzy/flickity/raw/master/dist/flickity.min.css) minified, or
- - [flickity.css](https://github.com/metafizzy/flickity/raw/master/dist/flickity.css) un-minified
+ - [flickity.min.css](https://npmcdn.com/flickity@2.0/dist/flickity.pkgd.min.css) minified, or
+ - [flickity.css](https://npmcdn.com/flickity@2.0/dist/flickity.pkgd.css) un-minified
+ JavaScript:
- - [flickity.pkgd.min.js](https://github.com/metafizzy/flickity/raw/master/dist/flickity.pkgd.min.js) minified, or
- - [flickity.pkgd.js](https://github.com/metafizzy/flickity/raw/master/dist/flickity.pkgd.js) un-minified
+ - [flickity.pkgd.min.js](https://npmcdn.com/flickity@2.0/dist/flickity.pkgd.min.js) minified, or
+ - [flickity.pkgd.js](https://npmcdn.com/flickity@2.0/dist/flickity.pkgd.js) un-minified
### CDN
Link directly to [Flickity files on cdnjs](https://cdnjs.com/libraries/flickity).
``` html
-
+
-
+
```
``` html
-
+
-
+
```
### Package managers
diff --git a/bower.json b/bower.json
index 51d81097..767ce812 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "flickity",
- "description": "Touch, responsive, flickable galleries",
+ "description": "Touch, responsive, flickable carousels",
"main": [
"js/index.js",
"css/flickity.css"
@@ -14,21 +14,17 @@
"unidragger": "^2.1.0"
},
"devDependencies": {
- "flickity-imagesloaded": "v2",
- "flickity-as-nav-for": "v2",
+ "flickity-imagesloaded": "^2.0.0",
+ "flickity-as-nav-for": "^2.0.0",
"jquery-bridget": "^2.0.0",
"qunit": "^2.0.0"
},
- "moduleType": [
- "amd",
- "globals",
- "node"
- ],
"keywords": [
"gallery",
"carousel",
"touch"
],
+ "homepage": "http://flickity.metafizzy.co",
"authors": [
"Metafizzy"
],
diff --git a/css/flickity.css b/css/flickity.css
index 7c8dc92c..21de3e97 100644
--- a/css/flickity.css
+++ b/css/flickity.css
@@ -1,4 +1,4 @@
-/*! Flickity v1.2.1
+/*! Flickity v2.0.0
http://flickity.metafizzy.co
---------------------------------------------- */
diff --git a/dist/flickity.css b/dist/flickity.css
index bb62af22..21de3e97 100644
--- a/dist/flickity.css
+++ b/dist/flickity.css
@@ -1,4 +1,4 @@
-/*! Flickity v1.2.1
+/*! Flickity v2.0.0
http://flickity.metafizzy.co
---------------------------------------------- */
@@ -56,7 +56,6 @@ http://flickity.metafizzy.co
cursor: pointer;
/* vertically center */
-webkit-transform: translateY(-50%);
- -ms-transform: translateY(-50%);
transform: translateY(-50%);
}
@@ -68,7 +67,6 @@ http://flickity.metafizzy.co
}
.flickity-prev-next-button:active {
- filter: alpha(opacity=60); /* IE8 */
opacity: 0.6;
}
@@ -85,7 +83,6 @@ http://flickity.metafizzy.co
}
.flickity-prev-next-button:disabled {
- filter: alpha(opacity=30); /* IE8 */
opacity: 0.3;
cursor: auto;
}
@@ -102,12 +99,6 @@ http://flickity.metafizzy.co
fill: #333;
}
-/* color & size if no SVG - IE8 and Android 2.3 */
-.flickity-prev-next-button.no-svg {
- color: #333;
- font-size: 26px;
-}
-
/* ---- page dots ---- */
.flickity-page-dots {
@@ -130,12 +121,10 @@ http://flickity.metafizzy.co
margin: 0 8px;
background: #333;
border-radius: 50%;
- filter: alpha(opacity=25); /* IE8 */
opacity: 0.25;
cursor: pointer;
}
.flickity-page-dots .dot.is-selected {
- filter: alpha(opacity=100); /* IE8 */
opacity: 1;
}
diff --git a/dist/flickity.min.css b/dist/flickity.min.css
index d1a164ca..c20b59e6 100644
--- a/dist/flickity.min.css
+++ b/dist/flickity.min.css
@@ -1,4 +1,4 @@
-/*! Flickity v1.2.1
+/*! Flickity v2.0.0
http://flickity.metafizzy.co
---------------------------------------------- */
-.flickity-enabled{position:relative}.flickity-enabled:focus{outline:0}.flickity-viewport{overflow:hidden;position:relative;height:100%}.flickity-slider{position:absolute;width:100%;height:100%}.flickity-enabled.is-draggable{-webkit-tap-highlight-color:transparent;tap-highlight-color:transparent;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.flickity-enabled.is-draggable .flickity-viewport{cursor:move;cursor:-webkit-grab;cursor:grab}.flickity-enabled.is-draggable .flickity-viewport.is-pointer-down{cursor:-webkit-grabbing;cursor:grabbing}.flickity-prev-next-button{position:absolute;top:50%;width:44px;height:44px;border:none;border-radius:50%;background:#fff;background:hsla(0,0%,100%,.75);cursor:pointer;-webkit-transform:translateY(-50%);-ms-transform:translateY(-50%);transform:translateY(-50%)}.flickity-prev-next-button:hover{background:#fff}.flickity-prev-next-button:focus{outline:0;box-shadow:0 0 0 5px #09F}.flickity-prev-next-button:active{filter:alpha(opacity=60);opacity:.6}.flickity-prev-next-button.previous{left:10px}.flickity-prev-next-button.next{right:10px}.flickity-rtl .flickity-prev-next-button.previous{left:auto;right:10px}.flickity-rtl .flickity-prev-next-button.next{right:auto;left:10px}.flickity-prev-next-button:disabled{filter:alpha(opacity=30);opacity:.3;cursor:auto}.flickity-prev-next-button svg{position:absolute;left:20%;top:20%;width:60%;height:60%}.flickity-prev-next-button .arrow{fill:#333}.flickity-prev-next-button.no-svg{color:#333;font-size:26px}.flickity-page-dots{position:absolute;width:100%;bottom:-25px;padding:0;margin:0;list-style:none;text-align:center;line-height:1}.flickity-rtl .flickity-page-dots{direction:rtl}.flickity-page-dots .dot{display:inline-block;width:10px;height:10px;margin:0 8px;background:#333;border-radius:50%;filter:alpha(opacity=25);opacity:.25;cursor:pointer}.flickity-page-dots .dot.is-selected{filter:alpha(opacity=100);opacity:1}
\ No newline at end of file
+.flickity-enabled{position:relative}.flickity-enabled:focus{outline:0}.flickity-viewport{overflow:hidden;position:relative;height:100%}.flickity-slider{position:absolute;width:100%;height:100%}.flickity-enabled.is-draggable{-webkit-tap-highlight-color:transparent;tap-highlight-color:transparent;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.flickity-enabled.is-draggable .flickity-viewport{cursor:move;cursor:-webkit-grab;cursor:grab}.flickity-enabled.is-draggable .flickity-viewport.is-pointer-down{cursor:-webkit-grabbing;cursor:grabbing}.flickity-prev-next-button{position:absolute;top:50%;width:44px;height:44px;border:none;border-radius:50%;background:#fff;background:hsla(0,0%,100%,.75);cursor:pointer;-webkit-transform:translateY(-50%);transform:translateY(-50%)}.flickity-prev-next-button:hover{background:#fff}.flickity-prev-next-button:focus{outline:0;box-shadow:0 0 0 5px #09F}.flickity-prev-next-button:active{opacity:.6}.flickity-prev-next-button.previous{left:10px}.flickity-prev-next-button.next{right:10px}.flickity-rtl .flickity-prev-next-button.previous{left:auto;right:10px}.flickity-rtl .flickity-prev-next-button.next{right:auto;left:10px}.flickity-prev-next-button:disabled{opacity:.3;cursor:auto}.flickity-prev-next-button svg{position:absolute;left:20%;top:20%;width:60%;height:60%}.flickity-prev-next-button .arrow{fill:#333}.flickity-page-dots{position:absolute;width:100%;bottom:-25px;padding:0;margin:0;list-style:none;text-align:center;line-height:1}.flickity-rtl .flickity-page-dots{direction:rtl}.flickity-page-dots .dot{display:inline-block;width:10px;height:10px;margin:0 8px;background:#333;border-radius:50%;opacity:.25;cursor:pointer}.flickity-page-dots .dot.is-selected{opacity:1}
\ No newline at end of file
diff --git a/dist/flickity.pkgd.js b/dist/flickity.pkgd.js
index 5ca955ca..c3266cce 100644
--- a/dist/flickity.pkgd.js
+++ b/dist/flickity.pkgd.js
@@ -1,864 +1,296 @@
/*!
- * Flickity PACKAGED v1.2.1
- * Touch, responsive, flickable galleries
+ * Flickity PACKAGED v2.0.0
+ * Touch, responsive, flickable carousels
*
* Licensed GPLv3 for open source use
* or Flickity Commercial License for commercial use
*
* http://flickity.metafizzy.co
- * Copyright 2015 Metafizzy
+ * Copyright 2016 Metafizzy
*/
/**
* Bridget makes jQuery widgets
- * v1.1.0
+ * v2.0.0
* MIT license
*/
-( function( window ) {
+/* jshint browser: true, strict: true, undef: true, unused: true */
+( function( window, factory ) {
+ 'use strict';
+ /* globals define: false, module: false, require: false */
-
-// -------------------------- utils -------------------------- //
-
-var slice = Array.prototype.slice;
-
-function noop() {}
-
-// -------------------------- definition -------------------------- //
-
-function defineBridget( $ ) {
-
-// bail if no jQuery
-if ( !$ ) {
- return;
-}
-
-// -------------------------- addOptionMethod -------------------------- //
-
-/**
- * adds option method -> $().plugin('option', {...})
- * @param {Function} PluginClass - constructor class
- */
-function addOptionMethod( PluginClass ) {
- // don't overwrite original option method
- if ( PluginClass.prototype.option ) {
- return;
+ if ( typeof define == 'function' && define.amd ) {
+ // AMD
+ define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
+ factory( window, jQuery );
+ });
+ } else if ( typeof module == 'object' && module.exports ) {
+ // CommonJS
+ module.exports = factory(
+ window,
+ require('jquery')
+ );
+ } else {
+ // browser global
+ window.jQueryBridget = factory(
+ window,
+ window.jQuery
+ );
}
- // option setter
- PluginClass.prototype.option = function( opts ) {
- // bail out if not an object
- if ( !$.isPlainObject( opts ) ){
- return;
- }
- this.options = $.extend( true, this.options, opts );
- };
-}
+}( window, function factory( window, jQuery ) {
+'use strict';
-// -------------------------- plugin bridge -------------------------- //
+// ----- utils ----- //
+
+var arraySlice = Array.prototype.slice;
// helper function for logging errors
// $.error breaks jQuery chaining
-var logError = typeof console === 'undefined' ? noop :
+var console = window.console;
+var logError = typeof console == 'undefined' ? function() {} :
function( message ) {
console.error( message );
};
-/**
- * jQuery plugin bridge, access methods like $elem.plugin('method')
- * @param {String} namespace - plugin name
- * @param {Function} PluginClass - constructor class
- */
-function bridge( namespace, PluginClass ) {
- // add to jQuery fn namespace
- $.fn[ namespace ] = function( options ) {
- if ( typeof options === 'string' ) {
- // call plugin method when first argument is a string
- // get arguments for method
- var args = slice.call( arguments, 1 );
-
- for ( var i=0, len = this.length; i < len; i++ ) {
- var elem = this[i];
- var instance = $.data( elem, namespace );
- if ( !instance ) {
- logError( "cannot call methods on " + namespace + " prior to initialization; " +
- "attempted to call '" + options + "'" );
- continue;
- }
- if ( !$.isFunction( instance[options] ) || options.charAt(0) === '_' ) {
- logError( "no such method '" + options + "' for " + namespace + " instance" );
- continue;
- }
+// ----- jQueryBridget ----- //
- // trigger method with arguments
- var returnValue = instance[ options ].apply( instance, args );
+function jQueryBridget( namespace, PluginClass, $ ) {
+ $ = $ || jQuery || window.jQuery;
+ if ( !$ ) {
+ return;
+ }
- // break look and return first value if provided
- if ( returnValue !== undefined ) {
- return returnValue;
- }
+ // add option method -> $().plugin('option', {...})
+ if ( !PluginClass.prototype.option ) {
+ // option setter
+ PluginClass.prototype.option = function( opts ) {
+ // bail out if not an object
+ if ( !$.isPlainObject( opts ) ){
+ return;
}
- // return this if no return value
- return this;
- } else {
- return this.each( function() {
- var instance = $.data( this, namespace );
- if ( instance ) {
- // apply options & init
- instance.option( options );
- instance._init();
- } else {
- // initialize new instance
- instance = new PluginClass( this, options );
- $.data( this, namespace, instance );
- }
- });
+ this.options = $.extend( true, this.options, opts );
+ };
+ }
+
+ // make jQuery plugin
+ $.fn[ namespace ] = function( arg0 /*, arg1 */ ) {
+ if ( typeof arg0 == 'string' ) {
+ // method call $().plugin( 'methodName', { options } )
+ // shift arguments by 1
+ var args = arraySlice.call( arguments, 1 );
+ return methodCall( this, arg0, args );
}
+ // just $().plugin({ options })
+ plainCall( this, arg0 );
+ return this;
};
-}
-
-// -------------------------- bridget -------------------------- //
-
-/**
- * converts a Prototypical class into a proper jQuery plugin
- * the class must have a ._init method
- * @param {String} namespace - plugin name, used in $().pluginName
- * @param {Function} PluginClass - constructor class
- */
-$.bridget = function( namespace, PluginClass ) {
- addOptionMethod( PluginClass );
- bridge( namespace, PluginClass );
-};
-
-return $.bridget;
-
-}
-
-// transport
-if ( typeof define === 'function' && define.amd ) {
- // AMD
- define( 'jquery-bridget/jquery.bridget',[ 'jquery' ], defineBridget );
-} else if ( typeof exports === 'object' ) {
- defineBridget( require('jquery') );
-} else {
- // get jquery from browser global
- defineBridget( window.jQuery );
-}
-
-})( window );
-
-/*!
- * classie v1.0.1
- * class helper functions
- * from bonzo https://github.com/ded/bonzo
- * MIT license
- *
- * classie.has( elem, 'my-class' ) -> true/false
- * classie.add( elem, 'my-new-class' )
- * classie.remove( elem, 'my-unwanted-class' )
- * classie.toggle( elem, 'my-class' )
- */
-
-/*jshint browser: true, strict: true, undef: true, unused: true */
-/*global define: false, module: false */
-
-( function( window ) {
+ // $().plugin('methodName')
+ function methodCall( $elems, methodName, args ) {
+ var returnValue;
+ var pluginMethodStr = '$().' + namespace + '("' + methodName + '")';
+
+ $elems.each( function( i, elem ) {
+ // get instance
+ var instance = $.data( elem, namespace );
+ if ( !instance ) {
+ logError( namespace + ' not initialized. Cannot call methods, i.e. ' +
+ pluginMethodStr );
+ return;
+ }
+ var method = instance[ methodName ];
+ if ( !method || methodName.charAt(0) == '_' ) {
+ logError( pluginMethodStr + ' is not a valid method' );
+ return;
+ }
+ // apply method, get return value
+ var value = method.apply( instance, args );
+ // set return value if value is returned, use only first value
+ returnValue = returnValue === undefined ? value : returnValue;
+ });
-// class helper functions from bonzo https://github.com/ded/bonzo
+ return returnValue !== undefined ? returnValue : $elems;
+ }
-function classReg( className ) {
- return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
-}
+ function plainCall( $elems, options ) {
+ $elems.each( function( i, elem ) {
+ var instance = $.data( elem, namespace );
+ if ( instance ) {
+ // set options & init
+ instance.option( options );
+ instance._init();
+ } else {
+ // initialize new instance
+ instance = new PluginClass( elem, options );
+ $.data( elem, namespace, instance );
+ }
+ });
+ }
-// classList support for class management
-// altho to be fair, the api sucks because it won't accept multiple classes at once
-var hasClass, addClass, removeClass;
+ updateJQuery( $ );
-if ( 'classList' in document.documentElement ) {
- hasClass = function( elem, c ) {
- return elem.classList.contains( c );
- };
- addClass = function( elem, c ) {
- elem.classList.add( c );
- };
- removeClass = function( elem, c ) {
- elem.classList.remove( c );
- };
-}
-else {
- hasClass = function( elem, c ) {
- return classReg( c ).test( elem.className );
- };
- addClass = function( elem, c ) {
- if ( !hasClass( elem, c ) ) {
- elem.className = elem.className + ' ' + c;
- }
- };
- removeClass = function( elem, c ) {
- elem.className = elem.className.replace( classReg( c ), ' ' );
- };
}
-function toggleClass( elem, c ) {
- var fn = hasClass( elem, c ) ? removeClass : addClass;
- fn( elem, c );
-}
+// ----- updateJQuery ----- //
-var classie = {
- // full names
- hasClass: hasClass,
- addClass: addClass,
- removeClass: removeClass,
- toggleClass: toggleClass,
- // short names
- has: hasClass,
- add: addClass,
- remove: removeClass,
- toggle: toggleClass
-};
-
-// transport
-if ( typeof define === 'function' && define.amd ) {
- // AMD
- define( 'classie/classie',classie );
-} else if ( typeof exports === 'object' ) {
- // CommonJS
- module.exports = classie;
-} else {
- // browser global
- window.classie = classie;
+// set $.bridget for v1 backwards compatibility
+function updateJQuery( $ ) {
+ if ( !$ || ( $ && $.bridget ) ) {
+ return;
+ }
+ $.bridget = jQueryBridget;
}
-})( window );
-
-/*!
- * EventEmitter v4.2.11 - git.io/ee
- * Unlicense - http://unlicense.org/
- * Oliver Caldwell - http://oli.me.uk/
- * @preserve
- */
-
-;(function () {
- 'use strict';
-
- /**
- * Class for managing events.
- * Can be extended to provide event functionality in other classes.
- *
- * @class EventEmitter Manages event registering and emitting.
- */
- function EventEmitter() {}
-
- // Shortcuts to improve speed and size
- var proto = EventEmitter.prototype;
- var exports = this;
- var originalGlobalValue = exports.EventEmitter;
-
- /**
- * Finds the index of the listener for the event in its storage array.
- *
- * @param {Function[]} listeners Array of listeners to search through.
- * @param {Function} listener Method to look for.
- * @return {Number} Index of the specified listener, -1 if not found
- * @api private
- */
- function indexOfListener(listeners, listener) {
- var i = listeners.length;
- while (i--) {
- if (listeners[i].listener === listener) {
- return i;
- }
- }
-
- return -1;
- }
-
- /**
- * Alias a method while keeping the context correct, to allow for overwriting of target method.
- *
- * @param {String} name The name of the target method.
- * @return {Function} The aliased method
- * @api private
- */
- function alias(name) {
- return function aliasClosure() {
- return this[name].apply(this, arguments);
- };
- }
-
- /**
- * Returns the listener array for the specified event.
- * Will initialise the event object and listener arrays if required.
- * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
- * Each property in the object response is an array of listener functions.
- *
- * @param {String|RegExp} evt Name of the event to return the listeners from.
- * @return {Function[]|Object} All listener functions for the event.
- */
- proto.getListeners = function getListeners(evt) {
- var events = this._getEvents();
- var response;
- var key;
-
- // Return a concatenated array of all matching events if
- // the selector is a regular expression.
- if (evt instanceof RegExp) {
- response = {};
- for (key in events) {
- if (events.hasOwnProperty(key) && evt.test(key)) {
- response[key] = events[key];
- }
- }
- }
- else {
- response = events[evt] || (events[evt] = []);
- }
-
- return response;
- };
-
- /**
- * Takes a list of listener objects and flattens it into a list of listener functions.
- *
- * @param {Object[]} listeners Raw listener objects.
- * @return {Function[]} Just the listener functions.
- */
- proto.flattenListeners = function flattenListeners(listeners) {
- var flatListeners = [];
- var i;
-
- for (i = 0; i < listeners.length; i += 1) {
- flatListeners.push(listeners[i].listener);
- }
-
- return flatListeners;
- };
-
- /**
- * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
- *
- * @param {String|RegExp} evt Name of the event to return the listeners from.
- * @return {Object} All listener functions for an event in an object.
- */
- proto.getListenersAsObject = function getListenersAsObject(evt) {
- var listeners = this.getListeners(evt);
- var response;
-
- if (listeners instanceof Array) {
- response = {};
- response[evt] = listeners;
- }
-
- return response || listeners;
- };
-
- /**
- * Adds a listener function to the specified event.
- * The listener will not be added if it is a duplicate.
- * If the listener returns true then it will be removed after it is called.
- * If you pass a regular expression as the event name then the listener will be added to all events that match it.
- *
- * @param {String|RegExp} evt Name of the event to attach the listener to.
- * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.addListener = function addListener(evt, listener) {
- var listeners = this.getListenersAsObject(evt);
- var listenerIsWrapped = typeof listener === 'object';
- var key;
-
- for (key in listeners) {
- if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
- listeners[key].push(listenerIsWrapped ? listener : {
- listener: listener,
- once: false
- });
- }
- }
-
- return this;
- };
-
- /**
- * Alias of addListener
- */
- proto.on = alias('addListener');
-
- /**
- * Semi-alias of addListener. It will add a listener that will be
- * automatically removed after its first execution.
- *
- * @param {String|RegExp} evt Name of the event to attach the listener to.
- * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.addOnceListener = function addOnceListener(evt, listener) {
- return this.addListener(evt, {
- listener: listener,
- once: true
- });
- };
-
- /**
- * Alias of addOnceListener.
- */
- proto.once = alias('addOnceListener');
-
- /**
- * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
- * You need to tell it what event names should be matched by a regex.
- *
- * @param {String} evt Name of the event to create.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.defineEvent = function defineEvent(evt) {
- this.getListeners(evt);
- return this;
- };
-
- /**
- * Uses defineEvent to define multiple events.
- *
- * @param {String[]} evts An array of event names to define.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.defineEvents = function defineEvents(evts) {
- for (var i = 0; i < evts.length; i += 1) {
- this.defineEvent(evts[i]);
- }
- return this;
- };
-
- /**
- * Removes a listener function from the specified event.
- * When passed a regular expression as the event name, it will remove the listener from all events that match it.
- *
- * @param {String|RegExp} evt Name of the event to remove the listener from.
- * @param {Function} listener Method to remove from the event.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.removeListener = function removeListener(evt, listener) {
- var listeners = this.getListenersAsObject(evt);
- var index;
- var key;
-
- for (key in listeners) {
- if (listeners.hasOwnProperty(key)) {
- index = indexOfListener(listeners[key], listener);
-
- if (index !== -1) {
- listeners[key].splice(index, 1);
- }
- }
- }
-
- return this;
- };
-
- /**
- * Alias of removeListener
- */
- proto.off = alias('removeListener');
-
- /**
- * Adds listeners in bulk using the manipulateListeners method.
- * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
- * You can also pass it a regular expression to add the array of listeners to all events that match it.
- * Yeah, this function does quite a bit. That's probably a bad thing.
- *
- * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
- * @param {Function[]} [listeners] An optional array of listener functions to add.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.addListeners = function addListeners(evt, listeners) {
- // Pass through to manipulateListeners
- return this.manipulateListeners(false, evt, listeners);
- };
-
- /**
- * Removes listeners in bulk using the manipulateListeners method.
- * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
- * You can also pass it an event name and an array of listeners to be removed.
- * You can also pass it a regular expression to remove the listeners from all events that match it.
- *
- * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
- * @param {Function[]} [listeners] An optional array of listener functions to remove.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.removeListeners = function removeListeners(evt, listeners) {
- // Pass through to manipulateListeners
- return this.manipulateListeners(true, evt, listeners);
- };
-
- /**
- * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
- * The first argument will determine if the listeners are removed (true) or added (false).
- * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
- * You can also pass it an event name and an array of listeners to be added/removed.
- * You can also pass it a regular expression to manipulate the listeners of all events that match it.
- *
- * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
- * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
- * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
- var i;
- var value;
- var single = remove ? this.removeListener : this.addListener;
- var multiple = remove ? this.removeListeners : this.addListeners;
-
- // If evt is an object then pass each of its properties to this method
- if (typeof evt === 'object' && !(evt instanceof RegExp)) {
- for (i in evt) {
- if (evt.hasOwnProperty(i) && (value = evt[i])) {
- // Pass the single listener straight through to the singular method
- if (typeof value === 'function') {
- single.call(this, i, value);
- }
- else {
- // Otherwise pass back to the multiple function
- multiple.call(this, i, value);
- }
- }
- }
- }
- else {
- // So evt must be a string
- // And listeners must be an array of listeners
- // Loop over it and pass each one to the multiple method
- i = listeners.length;
- while (i--) {
- single.call(this, evt, listeners[i]);
- }
- }
-
- return this;
- };
-
- /**
- * Removes all listeners from a specified event.
- * If you do not specify an event then all listeners will be removed.
- * That means every event will be emptied.
- * You can also pass a regex to remove all events that match it.
- *
- * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.removeEvent = function removeEvent(evt) {
- var type = typeof evt;
- var events = this._getEvents();
- var key;
-
- // Remove different things depending on the state of evt
- if (type === 'string') {
- // Remove all listeners for the specified event
- delete events[evt];
- }
- else if (evt instanceof RegExp) {
- // Remove all events matching the regex.
- for (key in events) {
- if (events.hasOwnProperty(key) && evt.test(key)) {
- delete events[key];
- }
- }
- }
- else {
- // Remove all listeners in all events
- delete this._events;
- }
-
- return this;
- };
-
- /**
- * Alias of removeEvent.
- *
- * Added to mirror the node API.
- */
- proto.removeAllListeners = alias('removeEvent');
-
- /**
- * Emits an event of your choice.
- * When emitted, every listener attached to that event will be executed.
- * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
- * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
- * So they will not arrive within the array on the other side, they will be separate.
- * You can also pass a regular expression to emit to all events that match it.
- *
- * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
- * @param {Array} [args] Optional array of arguments to be passed to each listener.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.emitEvent = function emitEvent(evt, args) {
- var listeners = this.getListenersAsObject(evt);
- var listener;
- var i;
- var key;
- var response;
-
- for (key in listeners) {
- if (listeners.hasOwnProperty(key)) {
- i = listeners[key].length;
-
- while (i--) {
- // If the listener returns true then it shall be removed from the event
- // The function is executed either with a basic call or an apply if there is an args array
- listener = listeners[key][i];
-
- if (listener.once === true) {
- this.removeListener(evt, listener.listener);
- }
-
- response = listener.listener.apply(this, args || []);
-
- if (response === this._getOnceReturnValue()) {
- this.removeListener(evt, listener.listener);
- }
- }
- }
- }
-
- return this;
- };
-
- /**
- * Alias of emitEvent
- */
- proto.trigger = alias('emitEvent');
-
- /**
- * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
- * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
- *
- * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
- * @param {...*} Optional additional arguments to be passed to each listener.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.emit = function emit(evt) {
- var args = Array.prototype.slice.call(arguments, 1);
- return this.emitEvent(evt, args);
- };
-
- /**
- * Sets the current value to check against when executing listeners. If a
- * listeners return value matches the one set here then it will be removed
- * after execution. This value defaults to true.
- *
- * @param {*} value The new value to check for when executing listeners.
- * @return {Object} Current instance of EventEmitter for chaining.
- */
- proto.setOnceReturnValue = function setOnceReturnValue(value) {
- this._onceReturnValue = value;
- return this;
- };
+updateJQuery( jQuery || window.jQuery );
- /**
- * Fetches the current value to check against when executing listeners. If
- * the listeners return value matches this one then it should be removed
- * automatically. It will return true by default.
- *
- * @return {*|Boolean} The current value to check for or the default, true.
- * @api private
- */
- proto._getOnceReturnValue = function _getOnceReturnValue() {
- if (this.hasOwnProperty('_onceReturnValue')) {
- return this._onceReturnValue;
- }
- else {
- return true;
- }
- };
-
- /**
- * Fetches the events object and creates one if required.
- *
- * @return {Object} The events storage object.
- * @api private
- */
- proto._getEvents = function _getEvents() {
- return this._events || (this._events = {});
- };
+// ----- ----- //
- /**
- * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
- *
- * @return {Function} Non conflicting EventEmitter class.
- */
- EventEmitter.noConflict = function noConflict() {
- exports.EventEmitter = originalGlobalValue;
- return EventEmitter;
- };
+return jQueryBridget;
- // Expose the class either via AMD, CommonJS or the global object
- if (typeof define === 'function' && define.amd) {
- define('eventEmitter/EventEmitter',[],function () {
- return EventEmitter;
- });
- }
- else if (typeof module === 'object' && module.exports){
- module.exports = EventEmitter;
- }
- else {
- exports.EventEmitter = EventEmitter;
- }
-}.call(this));
+}));
-/*!
- * eventie v1.0.6
- * event binding helper
- * eventie.bind( elem, 'click', myFn )
- * eventie.unbind( elem, 'click', myFn )
- * MIT license
+/**
+ * EvEmitter v1.0.3
+ * Lil' event emitter
+ * MIT License
*/
-/*jshint browser: true, undef: true, unused: true */
-/*global define: false, module: false */
-
-( function( window ) {
-
+/* jshint unused: true, undef: true, strict: true */
+( function( global, factory ) {
+ // universal module definition
+ /* jshint strict: false */ /* globals define, module, window */
+ if ( typeof define == 'function' && define.amd ) {
+ // AMD - RequireJS
+ define( 'ev-emitter/ev-emitter',factory );
+ } else if ( typeof module == 'object' && module.exports ) {
+ // CommonJS - Browserify, Webpack
+ module.exports = factory();
+ } else {
+ // Browser globals
+ global.EvEmitter = factory();
+ }
-var docElem = document.documentElement;
+}( typeof window != 'undefined' ? window : this, function() {
-var bind = function() {};
-function getIEEvent( obj ) {
- var event = window.event;
- // add event.target
- event.target = event.target || event.srcElement || obj;
- return event;
-}
-if ( docElem.addEventListener ) {
- bind = function( obj, type, fn ) {
- obj.addEventListener( type, fn, false );
- };
-} else if ( docElem.attachEvent ) {
- bind = function( obj, type, fn ) {
- obj[ type + fn ] = fn.handleEvent ?
- function() {
- var event = getIEEvent( obj );
- fn.handleEvent.call( fn, event );
- } :
- function() {
- var event = getIEEvent( obj );
- fn.call( obj, event );
- };
- obj.attachEvent( "on" + type, obj[ type + fn ] );
- };
-}
+function EvEmitter() {}
-var unbind = function() {};
+var proto = EvEmitter.prototype;
-if ( docElem.removeEventListener ) {
- unbind = function( obj, type, fn ) {
- obj.removeEventListener( type, fn, false );
- };
-} else if ( docElem.detachEvent ) {
- unbind = function( obj, type, fn ) {
- obj.detachEvent( "on" + type, obj[ type + fn ] );
- try {
- delete obj[ type + fn ];
- } catch ( err ) {
- // can't delete window object properties
- obj[ type + fn ] = undefined;
- }
- };
-}
+proto.on = function( eventName, listener ) {
+ if ( !eventName || !listener ) {
+ return;
+ }
+ // set events hash
+ var events = this._events = this._events || {};
+ // set listeners array
+ var listeners = events[ eventName ] = events[ eventName ] || [];
+ // only add once
+ if ( listeners.indexOf( listener ) == -1 ) {
+ listeners.push( listener );
+ }
-var eventie = {
- bind: bind,
- unbind: unbind
+ return this;
};
-// ----- module definition ----- //
-
-if ( typeof define === 'function' && define.amd ) {
- // AMD
- define( 'eventie/eventie',eventie );
-} else if ( typeof exports === 'object' ) {
- // CommonJS
- module.exports = eventie;
-} else {
- // browser global
- window.eventie = eventie;
-}
-
-})( window );
-
-/*!
- * getStyleProperty v1.0.4
- * original by kangax
- * http://perfectionkills.com/feature-testing-css-properties/
- * MIT license
- */
-
-/*jshint browser: true, strict: true, undef: true */
-/*global define: false, exports: false, module: false */
-
-( function( window ) {
-
-
+proto.once = function( eventName, listener ) {
+ if ( !eventName || !listener ) {
+ return;
+ }
+ // add event
+ this.on( eventName, listener );
+ // set once flag
+ // set onceEvents hash
+ var onceEvents = this._onceEvents = this._onceEvents || {};
+ // set onceListeners object
+ var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
+ // set flag
+ onceListeners[ listener ] = true;
-var prefixes = 'Webkit Moz ms Ms O'.split(' ');
-var docElemStyle = document.documentElement.style;
+ return this;
+};
-function getStyleProperty( propName ) {
- if ( !propName ) {
+proto.off = function( eventName, listener ) {
+ var listeners = this._events && this._events[ eventName ];
+ if ( !listeners || !listeners.length ) {
return;
}
-
- // test standard property first
- if ( typeof docElemStyle[ propName ] === 'string' ) {
- return propName;
+ var index = listeners.indexOf( listener );
+ if ( index != -1 ) {
+ listeners.splice( index, 1 );
}
- // capitalize
- propName = propName.charAt(0).toUpperCase() + propName.slice(1);
+ return this;
+};
- // test vendor specific properties
- var prefixed;
- for ( var i=0, len = prefixes.length; i < len; i++ ) {
- prefixed = prefixes[i] + propName;
- if ( typeof docElemStyle[ prefixed ] === 'string' ) {
- return prefixed;
+proto.emitEvent = function( eventName, args ) {
+ var listeners = this._events && this._events[ eventName ];
+ if ( !listeners || !listeners.length ) {
+ return;
+ }
+ var i = 0;
+ var listener = listeners[i];
+ args = args || [];
+ // once stuff
+ var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
+
+ while ( listener ) {
+ var isOnce = onceListeners && onceListeners[ listener ];
+ if ( isOnce ) {
+ // remove listener
+ // remove before trigger to prevent recursion
+ this.off( eventName, listener );
+ // unset once flag
+ delete onceListeners[ listener ];
}
+ // trigger listener
+ listener.apply( this, args );
+ // get next listener
+ i += isOnce ? 0 : 1;
+ listener = listeners[i];
}
-}
-// transport
-if ( typeof define === 'function' && define.amd ) {
- // AMD
- define( 'get-style-property/get-style-property',[],function() {
- return getStyleProperty;
- });
-} else if ( typeof exports === 'object' ) {
- // CommonJS for Component
- module.exports = getStyleProperty;
-} else {
- // browser global
- window.getStyleProperty = getStyleProperty;
-}
+ return this;
+};
+
+return EvEmitter;
-})( window );
+}));
/*!
- * getSize v1.2.2
+ * getSize v2.0.2
* measure size of elements
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
-/*global define: false, exports: false, require: false, module: false, console: false */
+/*global define: false, module: false, console: false */
-( function( window, undefined ) {
+( function( window, factory ) {
+ 'use strict';
+ if ( typeof define == 'function' && define.amd ) {
+ // AMD
+ define( 'get-size/get-size',[],function() {
+ return factory();
+ });
+ } else if ( typeof module == 'object' && module.exports ) {
+ // CommonJS
+ module.exports = factory();
+ } else {
+ // browser global
+ window.getSize = factory();
+ }
+})( window, function factory() {
+'use strict';
// -------------------------- helpers -------------------------- //
@@ -866,13 +298,13 @@ if ( typeof define === 'function' && define.amd ) {
function getStyleSize( value ) {
var num = parseFloat( value );
// not a percent like '100%', and a number
- var isValid = value.indexOf('%') === -1 && !isNaN( num );
+ var isValid = value.indexOf('%') == -1 && !isNaN( num );
return isValid && num;
}
function noop() {}
-var logError = typeof console === 'undefined' ? noop :
+var logError = typeof console == 'undefined' ? noop :
function( message ) {
console.error( message );
};
@@ -894,6 +326,8 @@ var measurements = [
'borderBottomWidth'
];
+var measurementsLength = measurements.length;
+
function getZeroSize() {
var size = {
width: 0,
@@ -903,27 +337,39 @@ function getZeroSize() {
outerWidth: 0,
outerHeight: 0
};
- for ( var i=0, len = measurements.length; i < len; i++ ) {
+ for ( var i=0; i < measurementsLength; i++ ) {
var measurement = measurements[i];
size[ measurement ] = 0;
}
return size;
}
+// -------------------------- getStyle -------------------------- //
-
-function defineGetSize( getStyleProperty ) {
+/**
+ * getStyle, get style of element, check for Firefox bug
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=548397
+ */
+function getStyle( elem ) {
+ var style = getComputedStyle( elem );
+ if ( !style ) {
+ logError( 'Style returned ' + style +
+ '. Are you running this code in a hidden iframe on Firefox? ' +
+ 'See http://bit.ly/getsizebug1' );
+ }
+ return style;
+}
// -------------------------- setup -------------------------- //
var isSetup = false;
-var getStyle, boxSizingProp, isBoxSizeOuter;
+var isBoxSizeOuter;
/**
- * setup vars and functions
- * do it on initial getSize(), rather than on script load
- * For Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=548397
+ * setup
+ * check isBoxSizerOuter
+ * do on first getSize() rather than on page load for Firefox bug
*/
function setup() {
// setup once
@@ -932,50 +378,25 @@ function setup() {
}
isSetup = true;
- var getComputedStyle = window.getComputedStyle;
- getStyle = ( function() {
- var getStyleFn = getComputedStyle ?
- function( elem ) {
- return getComputedStyle( elem, null );
- } :
- function( elem ) {
- return elem.currentStyle;
- };
-
- return function getStyle( elem ) {
- var style = getStyleFn( elem );
- if ( !style ) {
- logError( 'Style returned ' + style +
- '. Are you running this code in a hidden iframe on Firefox? ' +
- 'See http://bit.ly/getsizebug1' );
- }
- return style;
- };
- })();
-
// -------------------------- box sizing -------------------------- //
- boxSizingProp = getStyleProperty('boxSizing');
-
/**
* WebKit measures the outer-width on style.width on border-box elems
- * IE & Firefox measures the inner-width
+ * IE & Firefox<29 measures the inner-width
*/
- if ( boxSizingProp ) {
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.padding = '1px 2px 3px 4px';
- div.style.borderStyle = 'solid';
- div.style.borderWidth = '1px 2px 3px 4px';
- div.style[ boxSizingProp ] = 'border-box';
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.padding = '1px 2px 3px 4px';
+ div.style.borderStyle = 'solid';
+ div.style.borderWidth = '1px 2px 3px 4px';
+ div.style.boxSizing = 'border-box';
- var body = document.body || document.documentElement;
- body.appendChild( div );
- var style = getStyle( div );
+ var body = document.body || document.documentElement;
+ body.appendChild( div );
+ var style = getStyle( div );
- isBoxSizeOuter = getStyleSize( style.width ) === 200;
- body.removeChild( div );
- }
+ getSize.isBoxSizeOuter = isBoxSizeOuter = getStyleSize( style.width ) == 200;
+ body.removeChild( div );
}
@@ -985,19 +406,19 @@ function getSize( elem ) {
setup();
// use querySeletor if elem is string
- if ( typeof elem === 'string' ) {
+ if ( typeof elem == 'string' ) {
elem = document.querySelector( elem );
}
// do not proceed on non-objects
- if ( !elem || typeof elem !== 'object' || !elem.nodeType ) {
+ if ( !elem || typeof elem != 'object' || !elem.nodeType ) {
return;
}
var style = getStyle( elem );
// if hidden, everything is 0
- if ( style.display === 'none' ) {
+ if ( style.display == 'none' ) {
return getZeroSize();
}
@@ -1005,14 +426,12 @@ function getSize( elem ) {
size.width = elem.offsetWidth;
size.height = elem.offsetHeight;
- var isBorderBox = size.isBorderBox = !!( boxSizingProp &&
- style[ boxSizingProp ] && style[ boxSizingProp ] === 'border-box' );
+ var isBorderBox = size.isBorderBox = style.boxSizing == 'border-box';
// get all measurements
- for ( var i=0, len = measurements.length; i < len; i++ ) {
+ for ( var i=0; i < measurementsLength; i++ ) {
var measurement = measurements[i];
var value = style[ measurement ];
- value = mungeNonPixel( elem, value );
var num = parseFloat( value );
// any 'auto', 'medium' value will be 0
size[ measurement ] = !isNaN( num ) ? num : 0;
@@ -1051,148 +470,38 @@ function getSize( elem ) {
return size;
}
-// IE8 returns percent values, not pixels
-// taken from jQuery's curCSS
-function mungeNonPixel( elem, value ) {
- // IE8 and has percent value
- if ( window.getComputedStyle || value.indexOf('%') === -1 ) {
- return value;
- }
- var style = elem.style;
- // Remember the original values
- var left = style.left;
- var rs = elem.runtimeStyle;
- var rsLeft = rs && rs.left;
-
- // Put in the new values to get a computed value out
- if ( rsLeft ) {
- rs.left = elem.currentStyle.left;
- }
- style.left = value;
- value = style.pixelLeft;
-
- // Revert the changed values
- style.left = left;
- if ( rsLeft ) {
- rs.left = rsLeft;
- }
-
- return value;
-}
-
return getSize;
-}
-
-// transport
-if ( typeof define === 'function' && define.amd ) {
- // AMD for RequireJS
- define( 'get-size/get-size',[ 'get-style-property/get-style-property' ], defineGetSize );
-} else if ( typeof exports === 'object' ) {
- // CommonJS for Component
- module.exports = defineGetSize( require('desandro-get-style-property') );
-} else {
- // browser global
- window.getSize = defineGetSize( window.getStyleProperty );
-}
-
-})( window );
-
-/*!
- * docReady v1.0.4
- * Cross browser DOMContentLoaded event emitter
- * MIT license
- */
-
-/*jshint browser: true, strict: true, undef: true, unused: true*/
-/*global define: false, require: false, module: false */
-
-( function( window ) {
-
-
-
-var document = window.document;
-// collection of functions to be triggered on ready
-var queue = [];
-
-function docReady( fn ) {
- // throw out non-functions
- if ( typeof fn !== 'function' ) {
- return;
- }
-
- if ( docReady.isReady ) {
- // ready now, hit it
- fn();
- } else {
- // queue function when ready
- queue.push( fn );
- }
-}
-
-docReady.isReady = false;
-
-// triggered on various doc ready events
-function onReady( event ) {
- // bail if already triggered or IE8 document is not ready just yet
- var isIE8NotReady = event.type === 'readystatechange' && document.readyState !== 'complete';
- if ( docReady.isReady || isIE8NotReady ) {
- return;
- }
-
- trigger();
-}
-
-function trigger() {
- docReady.isReady = true;
- // process queue
- for ( var i=0, len = queue.length; i < len; i++ ) {
- var fn = queue[i];
- fn();
- }
-}
-
-function defineDocReady( eventie ) {
- // trigger ready if page is ready
- if ( document.readyState === 'complete' ) {
- trigger();
- } else {
- // listen for events
- eventie.bind( document, 'DOMContentLoaded', onReady );
- eventie.bind( document, 'readystatechange', onReady );
- eventie.bind( window, 'load', onReady );
- }
-
- return docReady;
-}
-
-// transport
-if ( typeof define === 'function' && define.amd ) {
- // AMD
- define( 'doc-ready/doc-ready',[ 'eventie/eventie' ], defineDocReady );
-} else if ( typeof exports === 'object' ) {
- module.exports = defineDocReady( require('eventie') );
-} else {
- // browser global
- window.docReady = defineDocReady( window.eventie );
-}
-
-})( window );
+});
/**
- * matchesSelector v1.0.3
+ * matchesSelector v2.0.1
* matchesSelector( element, '.selector' )
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
-/*global define: false, module: false */
-( function( ElemProto ) {
+( function( window, factory ) {
+ /*global define: false, module: false */
+ 'use strict';
+ // universal module definition
+ if ( typeof define == 'function' && define.amd ) {
+ // AMD
+ define( 'desandro-matches-selector/matches-selector',factory );
+ } else if ( typeof module == 'object' && module.exports ) {
+ // CommonJS
+ module.exports = factory();
+ } else {
+ // browser global
+ window.matchesSelector = factory();
+ }
+}( window, function factory() {
'use strict';
var matchesMethod = ( function() {
+ var ElemProto = Element.prototype;
// check for the standard method name first
if ( ElemProto.matches ) {
return 'matches';
@@ -1204,7 +513,7 @@ if ( typeof define === 'function' && define.amd ) {
// check vendor prefixes
var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
- for ( var i=0, len = prefixes.length; i < len; i++ ) {
+ for ( var i=0; i < prefixes.length; i++ ) {
var prefix = prefixes[i];
var method = prefix + 'MatchesSelector';
if ( ElemProto[ method ] ) {
@@ -1213,117 +522,45 @@ if ( typeof define === 'function' && define.amd ) {
}
})();
- // ----- match ----- //
-
- function match( elem, selector ) {
+ return function matchesSelector( elem, selector ) {
return elem[ matchesMethod ]( selector );
- }
-
- // ----- appendToFragment ----- //
-
- function checkParent( elem ) {
- // not needed if already has parent
- if ( elem.parentNode ) {
- return;
- }
- var fragment = document.createDocumentFragment();
- fragment.appendChild( elem );
- }
-
- // ----- query ----- //
-
- // fall back to using QSA
- // thx @jonathantneal https://gist.github.com/3062955
- function query( elem, selector ) {
- // append to fragment if no parent
- checkParent( elem );
-
- // match elem with all selected elems of parent
- var elems = elem.parentNode.querySelectorAll( selector );
- for ( var i=0, len = elems.length; i < len; i++ ) {
- // return true if match
- if ( elems[i] === elem ) {
- return true;
- }
- }
- // otherwise return false
- return false;
- }
-
- // ----- matchChild ----- //
-
- function matchChild( elem, selector ) {
- checkParent( elem );
- return match( elem, selector );
- }
-
- // ----- matchesSelector ----- //
-
- var matchesSelector;
-
- if ( matchesMethod ) {
- // IE9 supports matchesSelector, but doesn't work on orphaned elems
- // check for that
- var div = document.createElement('div');
- var supportsOrphans = match( div, 'div' );
- matchesSelector = supportsOrphans ? match : matchChild;
- } else {
- matchesSelector = query;
- }
-
- // transport
- if ( typeof define === 'function' && define.amd ) {
- // AMD
- define( 'matches-selector/matches-selector',[],function() {
- return matchesSelector;
- });
- } else if ( typeof exports === 'object' ) {
- module.exports = matchesSelector;
- }
- else {
- // browser global
- window.matchesSelector = matchesSelector;
- }
+ };
-})( Element.prototype );
+}));
/**
- * Fizzy UI utils v1.0.1
+ * Fizzy UI utils v2.0.2
* MIT license
*/
/*jshint browser: true, undef: true, unused: true, strict: true */
( function( window, factory ) {
- /*global define: false, module: false, require: false */
- 'use strict';
// universal module definition
+ /*jshint strict: false */ /*globals define, module, require */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'fizzy-ui-utils/utils',[
- 'doc-ready/doc-ready',
- 'matches-selector/matches-selector'
- ], function( docReady, matchesSelector ) {
- return factory( window, docReady, matchesSelector );
+ 'desandro-matches-selector/matches-selector'
+ ], function( matchesSelector ) {
+ return factory( window, matchesSelector );
});
- } else if ( typeof exports == 'object' ) {
+ } else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
- require('doc-ready'),
require('desandro-matches-selector')
);
} else {
// browser global
window.fizzyUIUtils = factory(
window,
- window.docReady,
window.matchesSelector
);
}
-}( window, function factory( window, docReady, matchesSelector ) {
+}( window, function factory( window, matchesSelector ) {
@@ -1345,24 +582,17 @@ utils.modulo = function( num, div ) {
return ( ( num % div ) + div ) % div;
};
-// ----- isArray ----- //
-
-var objToString = Object.prototype.toString;
-utils.isArray = function( obj ) {
- return objToString.call( obj ) == '[object Array]';
-};
-
// ----- makeArray ----- //
// turn element or nodeList into an array
utils.makeArray = function( obj ) {
var ary = [];
- if ( utils.isArray( obj ) ) {
+ if ( Array.isArray( obj ) ) {
// use object if already an array
ary = obj;
} else if ( obj && typeof obj.length == 'number' ) {
// convert nodeList to array
- for ( var i=0, len = obj.length; i < len; i++ ) {
+ for ( var i=0; i < obj.length; i++ ) {
ary.push( obj[i] );
}
} else {
@@ -1372,52 +602,14 @@ utils.makeArray = function( obj ) {
return ary;
};
-// ----- indexOf ----- //
-
-// index of helper cause IE8
-utils.indexOf = Array.prototype.indexOf ? function( ary, obj ) {
- return ary.indexOf( obj );
- } : function( ary, obj ) {
- for ( var i=0, len = ary.length; i < len; i++ ) {
- if ( ary[i] === obj ) {
- return i;
- }
- }
- return -1;
- };
-
// ----- removeFrom ----- //
utils.removeFrom = function( ary, obj ) {
- var index = utils.indexOf( ary, obj );
+ var index = ary.indexOf( obj );
if ( index != -1 ) {
ary.splice( index, 1 );
}
-};
-
-// ----- isElement ----- //
-
-// http://stackoverflow.com/a/384380/182183
-utils.isElement = ( typeof HTMLElement == 'function' || typeof HTMLElement == 'object' ) ?
- function isElementDOM2( obj ) {
- return obj instanceof HTMLElement;
- } :
- function isElementQuirky( obj ) {
- return obj && typeof obj == 'object' &&
- obj.nodeType == 1 && typeof obj.nodeName == 'string';
- };
-
-// ----- setText ----- //
-
-utils.setText = ( function() {
- var setTextProperty;
- function setText( elem, text ) {
- // only check setTextProperty once
- setTextProperty = setTextProperty || ( document.documentElement.textContent !== undefined ? 'textContent' : 'innerText' );
- elem[ setTextProperty ] = text;
- }
- return setText;
-})();
+};
// ----- getParent ----- //
@@ -1457,28 +649,28 @@ utils.filterFindElements = function( elems, selector ) {
elems = utils.makeArray( elems );
var ffElems = [];
- for ( var i=0, len = elems.length; i < len; i++ ) {
- var elem = elems[i];
+ elems.forEach( function( elem ) {
// check that elem is an actual element
- if ( !utils.isElement( elem ) ) {
- continue;
+ if ( !( elem instanceof HTMLElement ) ) {
+ return;
+ }
+ // add elem if no selector
+ if ( !selector ) {
+ ffElems.push( elem );
+ return;
}
// filter & find items if we have a selector
- if ( selector ) {
- // filter siblings
- if ( matchesSelector( elem, selector ) ) {
- ffElems.push( elem );
- }
- // find children
- var childElems = elem.querySelectorAll( selector );
- // concat childElems to filterFound array
- for ( var j=0, jLen = childElems.length; j < jLen; j++ ) {
- ffElems.push( childElems[j] );
- }
- } else {
+ // filter
+ if ( matchesSelector( elem, selector ) ) {
ffElems.push( elem );
}
- }
+ // find children
+ var childElems = elem.querySelectorAll( selector );
+ // concat childElems to filterFound array
+ for ( var i=0; i < childElems.length; i++ ) {
+ ffElems.push( childElems[i] );
+ }
+ });
return ffElems;
};
@@ -1505,6 +697,17 @@ utils.debounceMethod = function( _class, methodName, threshold ) {
};
};
+// ----- docReady ----- //
+
+utils.docReady = function( callback ) {
+ var readyState = document.readyState;
+ if ( readyState == 'complete' || readyState == 'interactive' ) {
+ callback();
+ } else {
+ document.addEventListener( 'DOMContentLoaded', callback );
+ }
+};
+
// ----- htmlInit ----- //
// http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
@@ -1516,39 +719,43 @@ utils.toDashed = function( str ) {
var console = window.console;
/**
- * allow user to initialize classes via .js-namespace class
+ * allow user to initialize classes via [data-namespace] or .js-namespace class
* htmlInit( Widget, 'widgetName' )
- * options are parsed from data-namespace-option attribute
+ * options are parsed from data-namespace-options
*/
utils.htmlInit = function( WidgetClass, namespace ) {
- docReady( function() {
+ utils.docReady( function() {
var dashedNamespace = utils.toDashed( namespace );
- var elems = document.querySelectorAll( '.js-' + dashedNamespace );
- var dataAttr = 'data-' + dashedNamespace + '-options';
-
- for ( var i=0, len = elems.length; i < len; i++ ) {
- var elem = elems[i];
- var attr = elem.getAttribute( dataAttr );
+ var dataAttr = 'data-' + dashedNamespace;
+ var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
+ var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
+ var elems = utils.makeArray( dataAttrElems )
+ .concat( utils.makeArray( jsDashElems ) );
+ var dataOptionsAttr = dataAttr + '-options';
+ var jQuery = window.jQuery;
+
+ elems.forEach( function( elem ) {
+ var attr = elem.getAttribute( dataAttr ) ||
+ elem.getAttribute( dataOptionsAttr );
var options;
try {
options = attr && JSON.parse( attr );
} catch ( error ) {
// log error, do not initialize
if ( console ) {
- console.error( 'Error parsing ' + dataAttr + ' on ' +
- elem.nodeName.toLowerCase() + ( elem.id ? '#' + elem.id : '' ) + ': ' +
- error );
+ console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
+ ': ' + error );
}
- continue;
+ return;
}
// initialize
var instance = new WidgetClass( elem, options );
// make available via $().data('layoutname')
- var jQuery = window.jQuery;
if ( jQuery ) {
jQuery.data( elem, namespace, instance );
}
- }
+ });
+
});
};
@@ -1558,10 +765,10 @@ return utils;
}));
+// Flickity.Cell
( function( window, factory ) {
- 'use strict';
// universal module definition
-
+ /* jshint strict: false */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'flickity/js/cell',[
@@ -1569,7 +776,7 @@ return utils;
], function( getSize ) {
return factory( window, getSize );
});
- } else if ( typeof exports == 'object' ) {
+ } else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
@@ -1595,42 +802,39 @@ function Cell( elem, parent ) {
this.create();
}
-var isIE8 = 'attachEvent' in window;
+var proto = Cell.prototype;
-Cell.prototype.create = function() {
+proto.create = function() {
this.element.style.position = 'absolute';
- // IE8 prevent child from changing focus http://stackoverflow.com/a/17525223/182183
- if ( isIE8 ) {
- this.element.setAttribute( 'unselectable', 'on' );
- }
this.x = 0;
this.shift = 0;
};
-Cell.prototype.destroy = function() {
+proto.destroy = function() {
// reset style
this.element.style.position = '';
var side = this.parent.originSide;
this.element.style[ side ] = '';
};
-Cell.prototype.getSize = function() {
+proto.getSize = function() {
this.size = getSize( this.element );
};
-Cell.prototype.setPosition = function( x ) {
+proto.setPosition = function( x ) {
this.x = x;
- this.setDefaultTarget();
+ this.updateTarget();
this.renderPosition( x );
};
-Cell.prototype.setDefaultTarget = function() {
+// setDefaultTarget v1 method, backwards compatibility, remove in v3
+proto.updateTarget = proto.setDefaultTarget = function() {
var marginProperty = this.parent.originSide == 'left' ? 'marginLeft' : 'marginRight';
this.target = this.x + this.size[ marginProperty ] +
this.size.width * this.parent.cellAlign;
};
-Cell.prototype.renderPosition = function( x ) {
+proto.renderPosition = function( x ) {
// render position of cell with in slider
var side = this.parent.originSide;
this.element.style[ side ] = this.parent.getPositionValue( x );
@@ -1639,12 +843,12 @@ Cell.prototype.renderPosition = function( x ) {
/**
* @param {Integer} factor - 0, 1, or -1
**/
-Cell.prototype.wrapShift = function( shift ) {
+proto.wrapShift = function( shift ) {
this.shift = shift;
this.renderPosition( this.x + this.parent.slideableWidth * shift );
};
-Cell.prototype.remove = function() {
+proto.remove = function() {
this.element.parentNode.removeChild( this.element );
};
@@ -1652,23 +856,98 @@ return Cell;
}));
+// slide
( function( window, factory ) {
- 'use strict';
// universal module definition
+ /* jshint strict: false */
+ if ( typeof define == 'function' && define.amd ) {
+ // AMD
+ define( 'flickity/js/slide',factory );
+ } else if ( typeof module == 'object' && module.exports ) {
+ // CommonJS
+ module.exports = factory();
+ } else {
+ // browser global
+ window.Flickity = window.Flickity || {};
+ window.Flickity.Slide = factory();
+ }
+
+}( window, function factory() {
+'use strict';
+
+function Slide( parent ) {
+ this.parent = parent;
+ this.isOriginLeft = parent.originSide == 'left';
+ this.cells = [];
+ this.outerWidth = 0;
+ this.height = 0;
+}
+
+var proto = Slide.prototype;
+
+proto.addCell = function( cell ) {
+ this.cells.push( cell );
+ this.outerWidth += cell.size.outerWidth;
+ this.height = Math.max( cell.size.outerHeight, this.height );
+ // first cell stuff
+ if ( this.cells.length == 1 ) {
+ this.x = cell.x; // x comes from first cell
+ var beginMargin = this.isOriginLeft ? 'marginLeft' : 'marginRight';
+ this.firstMargin = cell.size[ beginMargin ];
+ }
+};
+
+proto.updateTarget = function() {
+ var endMargin = this.isOriginLeft ? 'marginRight' : 'marginLeft';
+ var lastCell = this.getLastCell();
+ var lastMargin = lastCell ? lastCell.size[ endMargin ] : 0;
+ var slideWidth = this.outerWidth - ( this.firstMargin + lastMargin );
+ this.target = this.x + this.firstMargin + slideWidth * this.parent.cellAlign;
+};
+
+proto.getLastCell = function() {
+ return this.cells[ this.cells.length - 1 ];
+};
+
+proto.select = function() {
+ this.changeSelectedClass('add');
+};
+
+proto.unselect = function() {
+ this.changeSelectedClass('remove');
+};
+
+proto.changeSelectedClass = function( method ) {
+ this.cells.forEach( function( cell ) {
+ cell.element.classList[ method ]('is-selected');
+ });
+};
+
+proto.getCellElements = function() {
+ return this.cells.map( function( cell ) {
+ return cell.element;
+ });
+};
+
+return Slide;
+
+}));
+// animate
+( function( window, factory ) {
+ // universal module definition
+ /* jshint strict: false */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'flickity/js/animate',[
- 'get-style-property/get-style-property',
'fizzy-ui-utils/utils'
- ], function( getStyleProperty, utils ) {
- return factory( window, getStyleProperty, utils );
+ ], function( utils ) {
+ return factory( window, utils );
});
- } else if ( typeof exports == 'object' ) {
+ } else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
- require('desandro-get-style-property'),
require('fizzy-ui-utils')
);
} else {
@@ -1676,51 +955,30 @@ return Cell;
window.Flickity = window.Flickity || {};
window.Flickity.animatePrototype = factory(
window,
- window.getStyleProperty,
window.fizzyUIUtils
);
}
-}( window, function factory( window, getStyleProperty, utils ) {
+}( window, function factory( window, utils ) {
// -------------------------- requestAnimationFrame -------------------------- //
-// https://gist.github.com/1866474
+// get rAF, prefixed, if present
+var requestAnimationFrame = window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame;
+// fallback to setTimeout
var lastTime = 0;
-var prefixes = 'webkit moz ms o'.split(' ');
-// get unprefixed rAF and cAF, if present
-var requestAnimationFrame = window.requestAnimationFrame;
-var cancelAnimationFrame = window.cancelAnimationFrame;
-// loop through vendor prefixes and get prefixed rAF and cAF
-var prefix;
-for( var i = 0; i < prefixes.length; i++ ) {
- if ( requestAnimationFrame && cancelAnimationFrame ) {
- break;
- }
- prefix = prefixes[i];
- requestAnimationFrame = requestAnimationFrame || window[ prefix + 'RequestAnimationFrame' ];
- cancelAnimationFrame = cancelAnimationFrame || window[ prefix + 'CancelAnimationFrame' ] ||
- window[ prefix + 'CancelRequestAnimationFrame' ];
-}
-
-// fallback to setTimeout and clearTimeout if either request/cancel is not supported
-if ( !requestAnimationFrame || !cancelAnimationFrame ) {
+if ( !requestAnimationFrame ) {
requestAnimationFrame = function( callback ) {
var currTime = new Date().getTime();
var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
- var id = window.setTimeout( function() {
- callback( currTime + timeToCall );
- }, timeToCall );
+ var id = setTimeout( callback, timeToCall );
lastTime = currTime + timeToCall;
return id;
};
-
- cancelAnimationFrame = function( id ) {
- window.clearTimeout( id );
- };
}
// -------------------------- animate -------------------------- //
@@ -1753,20 +1011,16 @@ proto.animate = function() {
_this.animate();
});
}
-
- /** /
- // log animation frame rate
- var now = new Date();
- if ( this.then ) {
- console.log( ~~( 1000 / (now-this.then)) + 'fps' )
- }
- this.then = now;
- /**/
};
-var transformProperty = getStyleProperty('transform');
-var is3d = !!getStyleProperty('perspective');
+var transformProperty = ( function () {
+ var style = document.documentElement.style;
+ if ( typeof style.transform == 'string' ) {
+ return 'transform';
+ }
+ return 'WebkitTransform';
+})();
proto.positionSlider = function() {
var x = this.x;
@@ -1778,7 +1032,6 @@ proto.positionSlider = function() {
}
x = x + this.cursorPosition;
-
// reverse if right-to-left and using transform
x = this.options.rightToLeft && transformProperty ? -x : x;
@@ -1787,19 +1040,25 @@ proto.positionSlider = function() {
if ( transformProperty ) {
// use 3D tranforms for hardware acceleration on iOS
// but use 2D when settled, for better font-rendering
- this.slider.style[ transformProperty ] = is3d && this.isAnimating ?
+ this.slider.style[ transformProperty ] = this.isAnimating ?
'translate3d(' + value + ',0,0)' : 'translateX(' + value + ')';
} else {
this.slider.style[ this.originSide ] = value;
}
+ // scroll event
+ var firstSlide = this.slides[0];
+ if ( firstSlide ) {
+ var positionX = -this.x - firstSlide.target;
+ var progress = positionX / this.slidesWidth;
+ this.emitEvent( 'scroll', [ progress, positionX ] );
+ }
};
proto.positionSliderAtSelected = function() {
if ( !this.cells.length ) {
return;
}
- var selectedCell = this.cells[ this.selectedIndex ];
- this.x = -selectedCell.target;
+ this.x = -this.selectedSlide.target;
this.positionSlider();
};
@@ -1823,9 +1082,7 @@ proto.settle = function( previousX ) {
this.isAnimating = false;
delete this.isFreeScrolling;
// render position with translateX when settled
- if ( is3d ) {
- this.positionSlider();
- }
+ this.positionSlider();
this.dispatchEvent('settle');
}
};
@@ -1840,7 +1097,7 @@ proto.shiftWrapCells = function( x ) {
};
proto._shiftCells = function( cells, gap, shift ) {
- for ( var i=0, len = cells.length; i < len; i++ ) {
+ for ( var i=0; i < cells.length; i++ ) {
var cell = cells[i];
var cellShift = gap > 0 ? shift : 0;
cell.wrapShift( cellShift );
@@ -1852,7 +1109,7 @@ proto._unshiftCells = function( cells ) {
if ( !cells || !cells.length ) {
return;
}
- for ( var i=0, len = cells.length; i < len; i++ ) {
+ for ( var i=0; i < cells.length; i++ ) {
cells[i].wrapShift( 0 );
}
};
@@ -1860,22 +1117,18 @@ proto._unshiftCells = function( cells ) {
// -------------------------- physics -------------------------- //
proto.integratePhysics = function() {
- this.velocity += this.accel;
this.x += this.velocity;
this.velocity *= this.getFrictionFactor();
- // reset acceleration
- this.accel = 0;
};
proto.applyForce = function( force ) {
- this.accel += force;
+ this.velocity += force;
};
proto.getFrictionFactor = function() {
return 1 - this.options[ this.isFreeScrolling ? 'freeScrollFriction' : 'friction' ];
};
-
proto.getRestingPosition = function() {
// my thanks to Steven Wittens, who simplified this math greatly
return this.x + this.velocity / ( 1 - this.getFrictionFactor() );
@@ -1893,14 +1146,10 @@ proto.applyDragForce = function() {
proto.applySelectedAttraction = function() {
// do not attract if pointer down or no cells
- var len = this.cells.length;
- if ( this.isPointerDown || this.isFreeScrolling || !len ) {
+ if ( this.isPointerDown || this.isFreeScrolling || !this.cells.length ) {
return;
}
- var cell = this.cells[ this.selectedIndex ];
- var wrap = this.options.wrapAround && len > 1 ?
- this.slideableWidth * Math.floor( this.selectedIndex / len ) : 0;
- var distance = ( cell.target + wrap ) * -1 - this.x;
+ var distance = this.selectedSlide.target * -1 - this.x;
var force = distance * this.options.selectedAttraction;
this.applyForce( force );
};
@@ -1909,37 +1158,31 @@ return proto;
}));
-/**
- * Flickity main
- */
-
+// Flickity main
( function( window, factory ) {
- 'use strict';
// universal module definition
-
+ /* jshint strict: false */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'flickity/js/flickity',[
- 'classie/classie',
- 'eventEmitter/EventEmitter',
- 'eventie/eventie',
+ 'ev-emitter/ev-emitter',
'get-size/get-size',
'fizzy-ui-utils/utils',
'./cell',
+ './slide',
'./animate'
- ], function( classie, EventEmitter, eventie, getSize, utils, Cell, animatePrototype ) {
- return factory( window, classie, EventEmitter, eventie, getSize, utils, Cell, animatePrototype );
+ ], function( EvEmitter, getSize, utils, Cell, Slide, animatePrototype ) {
+ return factory( window, EvEmitter, getSize, utils, Cell, Slide, animatePrototype );
});
- } else if ( typeof exports == 'object' ) {
+ } else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
- require('desandro-classie'),
- require('wolfy87-eventemitter'),
- require('eventie'),
+ require('ev-emitter'),
require('get-size'),
require('fizzy-ui-utils'),
require('./cell'),
+ require('./slide'),
require('./animate')
);
} else {
@@ -1948,18 +1191,17 @@ return proto;
window.Flickity = factory(
window,
- window.classie,
- window.EventEmitter,
- window.eventie,
+ window.EvEmitter,
window.getSize,
window.fizzyUIUtils,
_Flickity.Cell,
+ _Flickity.Slide,
_Flickity.animatePrototype
);
}
-}( window, function factory( window, classie, EventEmitter, eventie, getSize,
- utils, Cell, animatePrototype ) {
+}( window, function factory( window, EvEmitter, getSize,
+ utils, Cell, Slide, animatePrototype ) {
@@ -2005,11 +1247,13 @@ function Flickity( element, options ) {
Flickity.defaults = {
accessibility: true,
+ // adaptiveHeight: false,
cellAlign: 'center',
// cellSelector: undefined,
// contain: false,
freeScrollFriction: 0.075, // friction when free-scrolling
friction: 0.28, // friction when selecting
+ namespaceJQueryEvents: true,
// initialIndex: 0,
percentPosition: true,
resize: true,
@@ -2022,10 +1266,11 @@ Flickity.defaults = {
// hash of methods triggered on _create()
Flickity.createMethods = [];
+var proto = Flickity.prototype;
// inherit EventEmitter
-utils.extend( Flickity.prototype, EventEmitter.prototype );
+utils.extend( proto, EvEmitter.prototype );
-Flickity.prototype._create = function() {
+proto._create = function() {
// add id for Flickity.data
var id = this.guid = ++GUID;
this.element.flickityGUID = id; // expando
@@ -2037,23 +1282,19 @@ Flickity.prototype._create = function() {
// initial physics properties
this.x = 0;
this.velocity = 0;
- this.accel = 0;
this.originSide = this.options.rightToLeft ? 'right' : 'left';
// create viewport & slider
this.viewport = document.createElement('div');
this.viewport.className = 'flickity-viewport';
- Flickity.setUnselectable( this.viewport );
this._createSlider();
if ( this.options.resize || this.options.watchCSS ) {
- eventie.bind( window, 'resize', this );
- this.isResizeBound = true;
+ window.addEventListener( 'resize', this );
}
- for ( var i=0, len = Flickity.createMethods.length; i < len; i++ ) {
- var method = Flickity.createMethods[i];
+ Flickity.createMethods.forEach( function( method ) {
this[ method ]();
- }
+ }, this );
if ( this.options.watchCSS ) {
this.watchCSS();
@@ -2067,18 +1308,18 @@ Flickity.prototype._create = function() {
* set options
* @param {Object} opts
*/
-Flickity.prototype.option = function( opts ) {
+proto.option = function( opts ) {
utils.extend( this.options, opts );
};
-Flickity.prototype.activate = function() {
+proto.activate = function() {
if ( this.isActive ) {
return;
}
this.isActive = true;
- classie.add( this.element, 'flickity-enabled' );
+ this.element.classList.add('flickity-enabled');
if ( this.options.rightToLeft ) {
- classie.add( this.element, 'flickity-rtl' );
+ this.element.classList.add('flickity-rtl');
}
this.getSize();
@@ -2094,10 +1335,10 @@ Flickity.prototype.activate = function() {
// allow element to focusable
this.element.tabIndex = 0;
// listen for key presses
- eventie.bind( this.element, 'keydown', this );
+ this.element.addEventListener( 'keydown', this );
}
- this.emit('activate');
+ this.emitEvent('activate');
var index;
var initialIndex = this.options.initialIndex;
@@ -2115,7 +1356,7 @@ Flickity.prototype.activate = function() {
};
// slider positions the cells
-Flickity.prototype._createSlider = function() {
+proto._createSlider = function() {
// slider element does all the positioning
var slider = document.createElement('div');
slider.className = 'flickity-slider';
@@ -2123,12 +1364,12 @@ Flickity.prototype._createSlider = function() {
this.slider = slider;
};
-Flickity.prototype._filterFindCellElements = function( elems ) {
+proto._filterFindCellElements = function( elems ) {
return utils.filterFindElements( elems, this.options.cellSelector );
};
// goes through all children
-Flickity.prototype.reloadCells = function() {
+proto.reloadCells = function() {
// collection of item elements
this.cells = this._makeCells( this.slider.children );
this.positionCells();
@@ -2141,26 +1382,27 @@ Flickity.prototype.reloadCells = function() {
* @param {Array or NodeList or HTMLElement} elems
* @returns {Array} items - collection of new Flickity Cells
*/
-Flickity.prototype._makeCells = function( elems ) {
+proto._makeCells = function( elems ) {
var cellElems = this._filterFindCellElements( elems );
// create new Flickity for collection
- var cells = [];
- for ( var i=0, len = cellElems.length; i < len; i++ ) {
- var elem = cellElems[i];
- var cell = new Cell( elem, this );
- cells.push( cell );
- }
+ var cells = cellElems.map( function( cellElem ) {
+ return new Cell( cellElem, this );
+ }, this );
return cells;
};
-Flickity.prototype.getLastCell = function() {
+proto.getLastCell = function() {
return this.cells[ this.cells.length - 1 ];
};
+proto.getLastSlide = function() {
+ return this.slides[ this.slides.length - 1 ];
+};
+
// positions all cells
-Flickity.prototype.positionCells = function() {
+proto.positionCells = function() {
// size all cells
this._sizeCells( this.cells );
// position all cells
@@ -2171,7 +1413,7 @@ Flickity.prototype.positionCells = function() {
* position certain cells
* @param {Integer} index - which cell to start with
*/
-Flickity.prototype._positionCells = function( index ) {
+proto._positionCells = function( index ) {
index = index || 0;
// also measure maxCellHeight
// start 0 if positioning all cells
@@ -2182,38 +1424,106 @@ Flickity.prototype._positionCells = function( index ) {
var startCell = this.cells[ index - 1 ];
cellX = startCell.x + startCell.size.outerWidth;
}
- var cell;
- for ( var len = this.cells.length, i=index; i < len; i++ ) {
- cell = this.cells[i];
+ var len = this.cells.length;
+ for ( var i=index; i < len; i++ ) {
+ var cell = this.cells[i];
cell.setPosition( cellX );
cellX += cell.size.outerWidth;
this.maxCellHeight = Math.max( cell.size.outerHeight, this.maxCellHeight );
}
// keep track of cellX for wrap-around
this.slideableWidth = cellX;
- // contain cell target
- this._containCells();
+ // slides
+ this.updateSlides();
+ // contain slides target
+ this._containSlides();
+ // update slidesWidth
+ this.slidesWidth = len ? this.getLastSlide().target - this.slides[0].target : 0;
};
/**
* cell.getSize() on multiple cells
* @param {Array} cells
*/
-Flickity.prototype._sizeCells = function( cells ) {
- for ( var i=0, len = cells.length; i < len; i++ ) {
- var cell = cells[i];
+proto._sizeCells = function( cells ) {
+ cells.forEach( function( cell ) {
cell.getSize();
+ });
+};
+
+// -------------------------- -------------------------- //
+
+proto.updateSlides = function() {
+ this.slides = [];
+ if ( !this.cells.length ) {
+ return;
+ }
+
+ var slide = new Slide( this );
+ this.slides.push( slide );
+ var isOriginLeft = this.originSide == 'left';
+ var nextMargin = isOriginLeft ? 'marginRight' : 'marginLeft';
+
+ var canCellFit = this._getCanCellFit();
+
+ this.cells.forEach( function( cell, i ) {
+ // just add cell if first cell in slide
+ if ( !slide.cells.length ) {
+ slide.addCell( cell );
+ return;
+ }
+
+ var slideWidth = ( slide.outerWidth - slide.firstMargin ) +
+ ( cell.size.outerWidth - cell.size[ nextMargin ] );
+
+ if ( canCellFit.call( this, i, slideWidth ) ) {
+ slide.addCell( cell );
+ } else {
+ // doesn't fit, new slide
+ slide.updateTarget();
+
+ slide = new Slide( this );
+ this.slides.push( slide );
+ slide.addCell( cell );
+ }
+ }, this );
+ // last slide
+ slide.updateTarget();
+ // update .selectedSlide
+ this.updateSelectedSlide();
+};
+
+proto._getCanCellFit = function() {
+ var groupCells = this.options.groupCells;
+ if ( !groupCells ) {
+ return function() {
+ return false;
+ };
+ } else if ( typeof groupCells == 'number' ) {
+ // group by number. 3 -> [0,1,2], [3,4,5], ...
+ var number = parseInt( groupCells, 10 );
+ return function( i ) {
+ return ( i % number ) !== 0;
+ };
}
+ // default, group by width of slide
+ // parse '75%
+ var percentMatch = typeof groupCells == 'string' &&
+ groupCells.match(/^(\d+)%$/);
+ var percent = percentMatch ? parseInt( percentMatch[1], 10 ) / 100 : 1;
+ return function( i, slideWidth ) {
+ return slideWidth <= ( this.size.innerWidth + 1 ) * percent;
+ };
};
// alias _init for jQuery plugin .flickity()
-Flickity.prototype._init =
-Flickity.prototype.reposition = function() {
+proto._init =
+proto.reposition = function() {
this.positionCells();
this.positionSliderAtSelected();
};
-Flickity.prototype.getSize = function() {
+proto.getSize = function() {
this.size = getSize( this.element );
this.setCellAlign();
this.cursorPosition = this.size.innerWidth * this.cellAlign;
@@ -2235,18 +1545,20 @@ var cellAlignShorthands = {
}
};
-Flickity.prototype.setCellAlign = function() {
+proto.setCellAlign = function() {
var shorthand = cellAlignShorthands[ this.options.cellAlign ];
this.cellAlign = shorthand ? shorthand[ this.originSide ] : this.options.cellAlign;
};
-Flickity.prototype.setGallerySize = function() {
+proto.setGallerySize = function() {
if ( this.options.setGallerySize ) {
- this.viewport.style.height = this.maxCellHeight + 'px';
+ var height = this.options.adaptiveHeight && this.selectedSlide ?
+ this.selectedSlide.height : this.maxCellHeight;
+ this.viewport.style.height = height + 'px';
}
};
-Flickity.prototype._getWrapShiftCells = function() {
+proto._getWrapShiftCells = function() {
// only for wrap-around
if ( !this.options.wrapAround ) {
return;
@@ -2266,7 +1578,7 @@ Flickity.prototype._getWrapShiftCells = function() {
this.afterShiftCells = this._getGapCells( gapX, 0, 1 );
};
-Flickity.prototype._getGapCells = function( gapX, cellIndex, increment ) {
+proto._getGapCells = function( gapX, cellIndex, increment ) {
// keep adding cells until the cover the initial gap
var cells = [];
while ( gapX > 0 ) {
@@ -2284,32 +1596,30 @@ Flickity.prototype._getGapCells = function( gapX, cellIndex, increment ) {
// ----- contain ----- //
// contain cell targets so no excess sliding
-Flickity.prototype._containCells = function() {
+proto._containSlides = function() {
if ( !this.options.contain || this.options.wrapAround || !this.cells.length ) {
return;
}
- var startMargin = this.options.rightToLeft ? 'marginRight' : 'marginLeft';
- var endMargin = this.options.rightToLeft ? 'marginLeft' : 'marginRight';
- var firstCellStartMargin = this.cells[0].size[ startMargin ];
- var lastCell = this.getLastCell();
- var contentWidth = this.slideableWidth - lastCell.size[ endMargin ];
- var endLimit = contentWidth - this.size.innerWidth * ( 1 - this.cellAlign );
+ var isRightToLeft = this.options.rightToLeft;
+ var beginMargin = isRightToLeft ? 'marginRight' : 'marginLeft';
+ var endMargin = isRightToLeft ? 'marginLeft' : 'marginRight';
+ var contentWidth = this.slideableWidth - this.getLastCell().size[ endMargin ];
// content is less than gallery size
var isContentSmaller = contentWidth < this.size.innerWidth;
+ // bounds
+ var beginBound = this.cursorPosition + this.cells[0].size[ beginMargin ];
+ var endBound = contentWidth - this.size.innerWidth * ( 1 - this.cellAlign );
// contain each cell target
- for ( var i=0, len = this.cells.length; i < len; i++ ) {
- var cell = this.cells[i];
- // reset default target
- cell.setDefaultTarget();
+ this.slides.forEach( function( slide ) {
if ( isContentSmaller ) {
// all cells fit inside gallery
- cell.target = contentWidth * this.cellAlign;
+ slide.target = contentWidth * this.cellAlign;
} else {
// contain to bounds
- cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin );
- cell.target = Math.min( cell.target, endLimit );
+ slide.target = Math.max( slide.target, beginBound );
+ slide.target = Math.min( slide.target, endBound );
}
- }
+ }, this );
};
// ----- ----- //
@@ -2320,80 +1630,144 @@ Flickity.prototype._containCells = function() {
* @param {Event} event - original event
* @param {Array} args - extra arguments
*/
-Flickity.prototype.dispatchEvent = function( type, event, args ) {
+proto.dispatchEvent = function( type, event, args ) {
var emitArgs = [ event ].concat( args );
this.emitEvent( type, emitArgs );
if ( jQuery && this.$element ) {
+ // default trigger with type if no event
+ type += this.options.namespaceJQueryEvents ? '.flickity' : '';
+ var $event = type;
if ( event ) {
// create jQuery event
- var $event = jQuery.Event( event );
- $event.type = type;
- this.$element.trigger( $event, args );
- } else {
- // just trigger with type if no event available
- this.$element.trigger( type, args );
+ var jQEvent = jQuery.Event( event );
+ jQEvent.type = type;
+ $event = jQEvent;
}
+ this.$element.trigger( $event, args );
}
};
// -------------------------- select -------------------------- //
/**
- * @param {Integer} index - index of the cell
+ * @param {Integer} index - index of the slide
* @param {Boolean} isWrap - will wrap-around to last/first if at the end
* @param {Boolean} isInstant - will immediately set position at selected cell
*/
-Flickity.prototype.select = function( index, isWrap, isInstant ) {
+proto.select = function( index, isWrap, isInstant ) {
if ( !this.isActive ) {
return;
}
index = parseInt( index, 10 );
- // wrap position so slider is within normal area
- var len = this.cells.length;
- if ( this.options.wrapAround && len > 1 ) {
- if ( index < 0 ) {
- this.x -= this.slideableWidth;
- } else if ( index >= len ) {
- this.x += this.slideableWidth;
- }
- }
+ this._wrapSelect( index );
if ( this.options.wrapAround || isWrap ) {
- index = utils.modulo( index, len );
+ index = utils.modulo( index, this.slides.length );
}
// bail if invalid index
- if ( !this.cells[ index ] ) {
+ if ( !this.slides[ index ] ) {
return;
}
this.selectedIndex = index;
- this.setSelectedCell();
+ this.updateSelectedSlide();
if ( isInstant ) {
this.positionSliderAtSelected();
} else {
this.startAnimation();
}
+ if ( this.options.adaptiveHeight ) {
+ this.setGallerySize();
+ }
+
+ this.dispatchEvent('select');
+ // old v1 event name, remove in v3
this.dispatchEvent('cellSelect');
};
-Flickity.prototype.previous = function( isWrap ) {
+// wraps position for wrapAround, to move to closest slide. #113
+proto._wrapSelect = function( index ) {
+ var len = this.slides.length;
+ var isWrapping = this.options.wrapAround && len > 1;
+ if ( !isWrapping ) {
+ return index;
+ }
+ var wrapIndex = utils.modulo( index, len );
+ // go to shortest
+ var delta = Math.abs( wrapIndex - this.selectedIndex );
+ var backWrapDelta = Math.abs( ( wrapIndex + len ) - this.selectedIndex );
+ var forewardWrapDelta = Math.abs( ( wrapIndex - len ) - this.selectedIndex );
+ if ( !this.isDragSelect && backWrapDelta < delta ) {
+ index += len;
+ } else if ( !this.isDragSelect && forewardWrapDelta < delta ) {
+ index -= len;
+ }
+ // wrap position so slider is within normal area
+ if ( index < 0 ) {
+ this.x -= this.slideableWidth;
+ } else if ( index >= len ) {
+ this.x += this.slideableWidth;
+ }
+};
+
+proto.previous = function( isWrap ) {
this.select( this.selectedIndex - 1, isWrap );
};
-Flickity.prototype.next = function( isWrap ) {
+proto.next = function( isWrap ) {
this.select( this.selectedIndex + 1, isWrap );
};
-Flickity.prototype.setSelectedCell = function() {
- this._removeSelectedCellClass();
- this.selectedCell = this.cells[ this.selectedIndex ];
- this.selectedElement = this.selectedCell.element;
- classie.add( this.selectedElement, 'is-selected' );
+proto.updateSelectedSlide = function() {
+ var slide = this.slides[ this.selectedIndex ];
+ // selectedIndex could be outside of slides, if triggered before resize()
+ if ( !slide ) {
+ return;
+ }
+ // unselect previous selected slide
+ this.unselectSelectedSlide();
+ // update new selected slide
+ this.selectedSlide = slide;
+ slide.select();
+ this.selectedCells = slide.cells;
+ this.selectedElements = slide.getCellElements();
+ // HACK: selectedCell & selectedElement is first cell in slide, backwards compatibility
+ // Remove in v3?
+ this.selectedCell = slide.cells[0];
+ this.selectedElement = this.selectedElements[0];
+};
+
+proto.unselectSelectedSlide = function() {
+ if ( this.selectedSlide ) {
+ this.selectedSlide.unselect();
+ }
};
-Flickity.prototype._removeSelectedCellClass = function() {
- if ( this.selectedCell ) {
- classie.remove( this.selectedCell.element, 'is-selected' );
+/**
+ * select slide from number or cell element
+ * @param {Element or Number} elem
+ */
+proto.selectCell = function( value, isWrap, isInstant ) {
+ // get cell
+ var cell;
+ if ( typeof value == 'number' ) {
+ cell = this.cells[ value ];
+ } else {
+ // use string as selector
+ if ( typeof value == 'string' ) {
+ value = this.element.querySelector( value );
+ }
+ // get cell from element
+ cell = this.getCell( value );
+ }
+ // select slide that has cell
+ for ( var i=0; cell && i < this.slides.length; i++ ) {
+ var slide = this.slides[i];
+ var index = slide.cells.indexOf( cell );
+ if ( index != -1 ) {
+ this.select( i, isWrap, isInstant );
+ return;
+ }
}
};
@@ -2404,9 +1778,9 @@ Flickity.prototype._removeSelectedCellClass = function() {
* @param {Element} elem
* @returns {Flickity.Cell} item
*/
-Flickity.prototype.getCell = function( elem ) {
+proto.getCell = function( elem ) {
// loop through cells to get the one that matches
- for ( var i=0, len = this.cells.length; i < len; i++ ) {
+ for ( var i=0; i < this.cells.length; i++ ) {
var cell = this.cells[i];
if ( cell.element == elem ) {
return cell;
@@ -2419,16 +1793,15 @@ Flickity.prototype.getCell = function( elem ) {
* @param {Element, Array, NodeList} elems
* @returns {Array} cells - Flickity.Cells
*/
-Flickity.prototype.getCells = function( elems ) {
+proto.getCells = function( elems ) {
elems = utils.makeArray( elems );
var cells = [];
- for ( var i=0, len = elems.length; i < len; i++ ) {
- var elem = elems[i];
+ elems.forEach( function( elem ) {
var cell = this.getCell( elem );
if ( cell ) {
cells.push( cell );
}
- }
+ }, this );
return cells;
};
@@ -2436,12 +1809,10 @@ Flickity.prototype.getCells = function( elems ) {
* get cell elements
* @returns {Array} cellElems
*/
-Flickity.prototype.getCellElements = function() {
- var cellElems = [];
- for ( var i=0, len = this.cells.length; i < len; i++ ) {
- cellElems.push( this.cells[i].element );
- }
- return cellElems;
+proto.getCellElements = function() {
+ return this.cells.map( function( cell ) {
+ return cell.element;
+ });
};
/**
@@ -2449,7 +1820,7 @@ Flickity.prototype.getCellElements = function() {
* @param {Element} elem
* @returns {Flickit.Cell} cell
*/
-Flickity.prototype.getParentCell = function( elem ) {
+proto.getParentCell = function( elem ) {
// first check if elem is cell
var cell = this.getCell( elem );
if ( cell ) {
@@ -2461,28 +1832,28 @@ Flickity.prototype.getParentCell = function( elem ) {
};
/**
- * get cells adjacent to a cell
- * @param {Integer} adjCount - number of adjacent cells
- * @param {Integer} index - index of cell to start
+ * get cells adjacent to a slide
+ * @param {Integer} adjCount - number of adjacent slides
+ * @param {Integer} index - index of slide to start
* @returns {Array} cells - array of Flickity.Cells
*/
-Flickity.prototype.getAdjacentCellElements = function( adjCount, index ) {
+proto.getAdjacentCellElements = function( adjCount, index ) {
if ( !adjCount ) {
- return [ this.selectedElement ];
+ return this.selectedSlide.getCellElements();
}
index = index === undefined ? this.selectedIndex : index;
- var len = this.cells.length;
+ var len = this.slides.length;
if ( 1 + ( adjCount * 2 ) >= len ) {
return this.getCellElements();
}
var cellElems = [];
for ( var i = index - adjCount; i <= index + adjCount ; i++ ) {
- var cellIndex = this.options.wrapAround ? utils.modulo( i, len ) : i;
- var cell = this.cells[ cellIndex ];
- if ( cell ) {
- cellElems.push( cell.element );
+ var slideIndex = this.options.wrapAround ? utils.modulo( i, len ) : i;
+ var slide = this.slides[ slideIndex ];
+ if ( slide ) {
+ cellElems = cellElems.concat( slide.getCellElements() );
}
}
return cellElems;
@@ -2490,24 +1861,24 @@ Flickity.prototype.getAdjacentCellElements = function( adjCount, index ) {
// -------------------------- events -------------------------- //
-Flickity.prototype.uiChange = function() {
- this.emit('uiChange');
+proto.uiChange = function() {
+ this.emitEvent('uiChange');
};
-Flickity.prototype.childUIPointerDown = function( event ) {
+proto.childUIPointerDown = function( event ) {
this.emitEvent( 'childUIPointerDown', [ event ] );
};
// ----- resize ----- //
-Flickity.prototype.onresize = function() {
+proto.onresize = function() {
this.watchCSS();
this.resize();
};
utils.debounceMethod( Flickity, 'onresize', 150 );
-Flickity.prototype.resize = function() {
+proto.resize = function() {
if ( !this.isActive ) {
return;
}
@@ -2519,45 +1890,19 @@ Flickity.prototype.resize = function() {
this.positionCells();
this._getWrapShiftCells();
this.setGallerySize();
- this.positionSliderAtSelected();
+ this.emitEvent('resize');
+ // update selected index for group slides, instant
+ // TODO: position can be lost between groups of various numbers
+ var selectedElement = this.selectedElements && this.selectedElements[0];
+ this.selectCell( selectedElement, false, true );
};
-var supportsConditionalCSS = Flickity.supportsConditionalCSS = ( function() {
- var supports;
- return function checkSupport() {
- if ( supports !== undefined ) {
- return supports;
- }
- if ( !getComputedStyle ) {
- supports = false;
- return;
- }
- // style body's :after and check that
- var style = document.createElement('style');
- var cssText = document.createTextNode('body:after { content: "foo"; display: none; }');
- style.appendChild( cssText );
- document.head.appendChild( style );
- var afterContent = getComputedStyle( document.body, ':after' ).content;
- // check if able to get :after content
- supports = afterContent.indexOf('foo') != -1;
- document.head.removeChild( style );
- return supports;
- };
-})();
-
// watches the :after property, activates/deactivates
-Flickity.prototype.watchCSS = function() {
+proto.watchCSS = function() {
var watchOption = this.options.watchCSS;
if ( !watchOption ) {
return;
}
- var supports = supportsConditionalCSS();
- if ( !supports ) {
- // activate if watch option is fallbackOn
- var method = watchOption == 'fallbackOn' ? 'activate' : 'deactivate';
- this[ method ]();
- return;
- }
var afterContent = getComputedStyle( this.element, ':after' ).content;
// activate if :after { content: 'flickity' }
@@ -2571,7 +1916,7 @@ Flickity.prototype.watchCSS = function() {
// ----- keydown ----- //
// go previous/next if left/right keys pressed
-Flickity.prototype.onkeydown = function( event ) {
+proto.onkeydown = function( event ) {
// only work if element is in focus
if ( !this.options.accessibility ||
( document.activeElement && document.activeElement != this.element ) ) {
@@ -2594,36 +1939,33 @@ Flickity.prototype.onkeydown = function( event ) {
// -------------------------- destroy -------------------------- //
// deactivate all Flickity functionality, but keep stuff available
-Flickity.prototype.deactivate = function() {
+proto.deactivate = function() {
if ( !this.isActive ) {
return;
}
- classie.remove( this.element, 'flickity-enabled' );
- classie.remove( this.element, 'flickity-rtl' );
+ this.element.classList.remove('flickity-enabled');
+ this.element.classList.remove('flickity-rtl');
// destroy cells
- for ( var i=0, len = this.cells.length; i < len; i++ ) {
- var cell = this.cells[i];
+ this.cells.forEach( function( cell ) {
cell.destroy();
- }
- this._removeSelectedCellClass();
+ });
+ this.unselectSelectedSlide();
this.element.removeChild( this.viewport );
// move child elements back into element
moveElements( this.slider.children, this.element );
if ( this.options.accessibility ) {
this.element.removeAttribute('tabIndex');
- eventie.unbind( this.element, 'keydown', this );
+ this.element.removeEventListener( 'keydown', this );
}
// set flags
this.isActive = false;
- this.emit('deactivate');
+ this.emitEvent('deactivate');
};
-Flickity.prototype.destroy = function() {
+proto.destroy = function() {
this.deactivate();
- if ( this.isResizeBound ) {
- eventie.unbind( window, 'resize', this );
- }
- this.emit('destroy');
+ window.removeEventListener( 'resize', this );
+ this.emitEvent('destroy');
if ( jQuery && this.$element ) {
jQuery.removeData( this.element, 'flickity' );
}
@@ -2633,21 +1975,10 @@ Flickity.prototype.destroy = function() {
// -------------------------- prototype -------------------------- //
-utils.extend( Flickity.prototype, animatePrototype );
+utils.extend( proto, animatePrototype );
// -------------------------- extras -------------------------- //
-// quick check for IE8
-var isIE8 = 'attachEvent' in window;
-
-Flickity.setUnselectable = function( elem ) {
- if ( !isIE8 ) {
- return;
- }
- // IE8 prevent child from changing focus http://stackoverflow.com/a/17525223/182183
- elem.setAttribute( 'unselectable', 'on' );
-};
-
/**
* get Flickity instance from element
* @param {Element} elem
@@ -2672,43 +2003,38 @@ return Flickity;
}));
/*!
- * Unipointer v1.1.0
+ * Unipointer v2.1.0
* base class for doing one thing with pointer event
* MIT license
*/
/*jshint browser: true, undef: true, unused: true, strict: true */
-/*global define: false, module: false, require: false */
( function( window, factory ) {
- 'use strict';
// universal module definition
-
+ /* jshint strict: false */ /*global define, module, require */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'unipointer/unipointer',[
- 'eventEmitter/EventEmitter',
- 'eventie/eventie'
- ], function( EventEmitter, eventie ) {
- return factory( window, EventEmitter, eventie );
+ 'ev-emitter/ev-emitter'
+ ], function( EvEmitter ) {
+ return factory( window, EvEmitter );
});
- } else if ( typeof exports == 'object' ) {
+ } else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
- require('wolfy87-eventemitter'),
- require('eventie')
+ require('ev-emitter')
);
} else {
// browser global
window.Unipointer = factory(
window,
- window.EventEmitter,
- window.eventie
+ window.EvEmitter
);
}
-}( window, function factory( window, EventEmitter, eventie ) {
+}( window, function factory( window, EvEmitter ) {
@@ -2716,14 +2042,14 @@ function noop() {}
function Unipointer() {}
-// inherit EventEmitter
-Unipointer.prototype = new EventEmitter();
+// inherit EvEmitter
+var proto = Unipointer.prototype = Object.create( EvEmitter.prototype );
-Unipointer.prototype.bindStartEvent = function( elem ) {
+proto.bindStartEvent = function( elem ) {
this._bindStartEvent( elem, true );
};
-Unipointer.prototype.unbindStartEvent = function( elem ) {
+proto.unbindStartEvent = function( elem ) {
this._bindStartEvent( elem, false );
};
@@ -2731,26 +2057,26 @@ Unipointer.prototype.unbindStartEvent = function( elem ) {
* works as unbinder, as you can ._bindStart( false ) to unbind
* @param {Boolean} isBind - will unbind if falsey
*/
-Unipointer.prototype._bindStartEvent = function( elem, isBind ) {
+proto._bindStartEvent = function( elem, isBind ) {
// munge isBind, default to true
isBind = isBind === undefined ? true : !!isBind;
- var bindMethod = isBind ? 'bind' : 'unbind';
+ var bindMethod = isBind ? 'addEventListener' : 'removeEventListener';
if ( window.navigator.pointerEnabled ) {
// W3C Pointer Events, IE11. See https://coderwall.com/p/mfreca
- eventie[ bindMethod ]( elem, 'pointerdown', this );
+ elem[ bindMethod ]( 'pointerdown', this );
} else if ( window.navigator.msPointerEnabled ) {
// IE10 Pointer Events
- eventie[ bindMethod ]( elem, 'MSPointerDown', this );
+ elem[ bindMethod ]( 'MSPointerDown', this );
} else {
// listen for both, for devices like Chrome Pixel
- eventie[ bindMethod ]( elem, 'mousedown', this );
- eventie[ bindMethod ]( elem, 'touchstart', this );
+ elem[ bindMethod ]( 'mousedown', this );
+ elem[ bindMethod ]( 'touchstart', this );
}
};
// trigger handler methods for events
-Unipointer.prototype.handleEvent = function( event ) {
+proto.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
@@ -2758,8 +2084,8 @@ Unipointer.prototype.handleEvent = function( event ) {
};
// returns the touch that we're keeping track of
-Unipointer.prototype.getTouch = function( touches ) {
- for ( var i=0, len = touches.length; i < len; i++ ) {
+proto.getTouch = function( touches ) {
+ for ( var i=0; i < touches.length; i++ ) {
var touch = touches[i];
if ( touch.identifier == this.pointerIdentifier ) {
return touch;
@@ -2769,7 +2095,7 @@ Unipointer.prototype.getTouch = function( touches ) {
// ----- start event ----- //
-Unipointer.prototype.onmousedown = function( event ) {
+proto.onmousedown = function( event ) {
// dismiss clicks from right or middle buttons
var button = event.button;
if ( button && ( button !== 0 && button !== 1 ) ) {
@@ -2778,12 +2104,12 @@ Unipointer.prototype.onmousedown = function( event ) {
this._pointerDown( event, event );
};
-Unipointer.prototype.ontouchstart = function( event ) {
+proto.ontouchstart = function( event ) {
this._pointerDown( event, event.changedTouches[0] );
};
-Unipointer.prototype.onMSPointerDown =
-Unipointer.prototype.onpointerdown = function( event ) {
+proto.onMSPointerDown =
+proto.onpointerdown = function( event ) {
this._pointerDown( event, event );
};
@@ -2792,7 +2118,7 @@ Unipointer.prototype.onpointerdown = function( event ) {
* @param {Event} event
* @param {Event or Touch} pointer
*/
-Unipointer.prototype._pointerDown = function( event, pointer ) {
+proto._pointerDown = function( event, pointer ) {
// dismiss other pointers
if ( this.isPointerDown ) {
return;
@@ -2807,7 +2133,7 @@ Unipointer.prototype._pointerDown = function( event, pointer ) {
this.pointerDown( event, pointer );
};
-Unipointer.prototype.pointerDown = function( event, pointer ) {
+proto.pointerDown = function( event, pointer ) {
this._bindPostStartEvents( event );
this.emitEvent( 'pointerDown', [ event, pointer ] );
};
@@ -2820,54 +2146,46 @@ var postStartEvents = {
MSPointerDown: [ 'MSPointerMove', 'MSPointerUp', 'MSPointerCancel' ]
};
-Unipointer.prototype._bindPostStartEvents = function( event ) {
+proto._bindPostStartEvents = function( event ) {
if ( !event ) {
return;
}
// get proper events to match start event
var events = postStartEvents[ event.type ];
- // IE8 needs to be bound to document
- var node = event.preventDefault ? window : document;
// bind events to node
- for ( var i=0, len = events.length; i < len; i++ ) {
- var evnt = events[i];
- eventie.bind( node, evnt, this );
- }
+ events.forEach( function( eventName ) {
+ window.addEventListener( eventName, this );
+ }, this );
// save these arguments
- this._boundPointerEvents = {
- events: events,
- node: node
- };
+ this._boundPointerEvents = events;
};
-Unipointer.prototype._unbindPostStartEvents = function() {
- var args = this._boundPointerEvents;
- // IE8 can trigger dragEnd twice, check for _boundEvents
- if ( !args || !args.events ) {
+proto._unbindPostStartEvents = function() {
+ // check for _boundEvents, in case dragEnd triggered twice (old IE8 bug)
+ if ( !this._boundPointerEvents ) {
return;
}
+ this._boundPointerEvents.forEach( function( eventName ) {
+ window.removeEventListener( eventName, this );
+ }, this );
- for ( var i=0, len = args.events.length; i < len; i++ ) {
- var event = args.events[i];
- eventie.unbind( args.node, event, this );
- }
delete this._boundPointerEvents;
};
// ----- move event ----- //
-Unipointer.prototype.onmousemove = function( event ) {
+proto.onmousemove = function( event ) {
this._pointerMove( event, event );
};
-Unipointer.prototype.onMSPointerMove =
-Unipointer.prototype.onpointermove = function( event ) {
+proto.onMSPointerMove =
+proto.onpointermove = function( event ) {
if ( event.pointerId == this.pointerIdentifier ) {
this._pointerMove( event, event );
}
};
-Unipointer.prototype.ontouchmove = function( event ) {
+proto.ontouchmove = function( event ) {
var touch = this.getTouch( event.changedTouches );
if ( touch ) {
this._pointerMove( event, touch );
@@ -2880,30 +2198,30 @@ Unipointer.prototype.ontouchmove = function( event ) {
* @param {Event or Touch} pointer
* @private
*/
-Unipointer.prototype._pointerMove = function( event, pointer ) {
+proto._pointerMove = function( event, pointer ) {
this.pointerMove( event, pointer );
};
// public
-Unipointer.prototype.pointerMove = function( event, pointer ) {
+proto.pointerMove = function( event, pointer ) {
this.emitEvent( 'pointerMove', [ event, pointer ] );
};
// ----- end event ----- //
-Unipointer.prototype.onmouseup = function( event ) {
+proto.onmouseup = function( event ) {
this._pointerUp( event, event );
};
-Unipointer.prototype.onMSPointerUp =
-Unipointer.prototype.onpointerup = function( event ) {
+proto.onMSPointerUp =
+proto.onpointerup = function( event ) {
if ( event.pointerId == this.pointerIdentifier ) {
this._pointerUp( event, event );
}
};
-Unipointer.prototype.ontouchend = function( event ) {
+proto.ontouchend = function( event ) {
var touch = this.getTouch( event.changedTouches );
if ( touch ) {
this._pointerUp( event, touch );
@@ -2916,20 +2234,20 @@ Unipointer.prototype.ontouchend = function( event ) {
* @param {Event or Touch} pointer
* @private
*/
-Unipointer.prototype._pointerUp = function( event, pointer ) {
+proto._pointerUp = function( event, pointer ) {
this._pointerDone();
this.pointerUp( event, pointer );
};
// public
-Unipointer.prototype.pointerUp = function( event, pointer ) {
+proto.pointerUp = function( event, pointer ) {
this.emitEvent( 'pointerUp', [ event, pointer ] );
};
// ----- pointer done ----- //
// triggered on pointer up & pointer cancel
-Unipointer.prototype._pointerDone = function() {
+proto._pointerDone = function() {
// reset properties
this.isPointerDown = false;
delete this.pointerIdentifier;
@@ -2938,18 +2256,18 @@ Unipointer.prototype._pointerDone = function() {
this.pointerDone();
};
-Unipointer.prototype.pointerDone = noop;
+proto.pointerDone = noop;
// ----- pointer cancel ----- //
-Unipointer.prototype.onMSPointerCancel =
-Unipointer.prototype.onpointercancel = function( event ) {
+proto.onMSPointerCancel =
+proto.onpointercancel = function( event ) {
if ( event.pointerId == this.pointerIdentifier ) {
this._pointerCancel( event, event );
}
};
-Unipointer.prototype.ontouchcancel = function( event ) {
+proto.ontouchcancel = function( event ) {
var touch = this.getTouch( event.changedTouches );
if ( touch ) {
this._pointerCancel( event, touch );
@@ -2962,23 +2280,23 @@ Unipointer.prototype.ontouchcancel = function( event ) {
* @param {Event or Touch} pointer
* @private
*/
-Unipointer.prototype._pointerCancel = function( event, pointer ) {
+proto._pointerCancel = function( event, pointer ) {
this._pointerDone();
this.pointerCancel( event, pointer );
};
// public
-Unipointer.prototype.pointerCancel = function( event, pointer ) {
+proto.pointerCancel = function( event, pointer ) {
this.emitEvent( 'pointerCancel', [ event, pointer ] );
};
// ----- ----- //
-// utility function for getting x/y cooridinates from event, because IE8
+// utility function for getting x/y coords from event
Unipointer.getPointerPoint = function( pointer ) {
return {
- x: pointer.pageX !== undefined ? pointer.pageX : pointer.clientX,
- y: pointer.pageY !== undefined ? pointer.pageY : pointer.clientY
+ x: pointer.pageX,
+ y: pointer.pageY
};
};
@@ -2989,7 +2307,7 @@ return Unipointer;
}));
/*!
- * Unidragger v1.1.6
+ * Unidragger v2.1.0
* Draggable base class
* MIT license
*/
@@ -2997,35 +2315,31 @@ return Unipointer;
/*jshint browser: true, unused: true, undef: true, strict: true */
( function( window, factory ) {
- /*global define: false, module: false, require: false */
- 'use strict';
// universal module definition
+ /*jshint strict: false */ /*globals define, module, require */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'unidragger/unidragger',[
- 'eventie/eventie',
'unipointer/unipointer'
- ], function( eventie, Unipointer ) {
- return factory( window, eventie, Unipointer );
+ ], function( Unipointer ) {
+ return factory( window, Unipointer );
});
- } else if ( typeof exports == 'object' ) {
+ } else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
- require('eventie'),
require('unipointer')
);
} else {
// browser global
window.Unidragger = factory(
window,
- window.eventie,
window.Unipointer
);
}
-}( window, function factory( window, eventie, Unipointer ) {
+}( window, function factory( window, Unipointer ) {
@@ -3033,29 +2347,20 @@ return Unipointer;
function noop() {}
-// handle IE8 prevent default
-function preventDefaultEvent( event ) {
- if ( event.preventDefault ) {
- event.preventDefault();
- } else {
- event.returnValue = false;
- }
-}
-
// -------------------------- Unidragger -------------------------- //
function Unidragger() {}
-// inherit Unipointer & EventEmitter
-Unidragger.prototype = new Unipointer();
+// inherit Unipointer & EvEmitter
+var proto = Unidragger.prototype = Object.create( Unipointer.prototype );
// ----- bind start ----- //
-Unidragger.prototype.bindHandles = function() {
+proto.bindHandles = function() {
this._bindHandles( true );
};
-Unidragger.prototype.unbindHandles = function() {
+proto.unbindHandles = function() {
this._bindHandles( false );
};
@@ -3064,7 +2369,7 @@ var navigator = window.navigator;
* works as unbinder, as you can .bindHandles( false ) to unbind
* @param {Boolean} isBind - will unbind if falsey
*/
-Unidragger.prototype._bindHandles = function( isBind ) {
+proto._bindHandles = function( isBind ) {
// munge isBind, default to true
isBind = isBind === undefined ? true : !!isBind;
// extra bind logic
@@ -3080,44 +2385,15 @@ Unidragger.prototype._bindHandles = function( isBind ) {
handle.style.msTouchAction = isBind ? 'none' : '';
};
} else {
- binderExtra = function() {
- // TODO re-enable img.ondragstart when unbinding
- if ( isBind ) {
- disableImgOndragstart( handle );
- }
- };
+ binderExtra = noop;
}
// bind each handle
- var bindMethod = isBind ? 'bind' : 'unbind';
- for ( var i=0, len = this.handles.length; i < len; i++ ) {
+ var bindMethod = isBind ? 'addEventListener' : 'removeEventListener';
+ for ( var i=0; i < this.handles.length; i++ ) {
var handle = this.handles[i];
this._bindStartEvent( handle, isBind );
binderExtra( handle );
- eventie[ bindMethod ]( handle, 'click', this );
- }
-};
-
-// remove default dragging interaction on all images in IE8
-// IE8 does its own drag thing on images, which messes stuff up
-
-function noDragStart() {
- return false;
-}
-
-// TODO replace this with a IE8 test
-var isIE8 = 'attachEvent' in document.documentElement;
-
-// IE8 only
-var disableImgOndragstart = !isIE8 ? noop : function( handle ) {
-
- if ( handle.nodeName == 'IMG' ) {
- handle.ondragstart = noDragStart;
- }
-
- var images = handle.querySelectorAll('img');
- for ( var i=0, len = images.length; i < len; i++ ) {
- var img = images[i];
- img.ondragstart = noDragStart;
+ handle[ bindMethod ]( 'click', this );
}
};
@@ -3128,7 +2404,7 @@ var disableImgOndragstart = !isIE8 ? noop : function( handle ) {
* @param {Event} event
* @param {Event or Touch} pointer
*/
-Unidragger.prototype.pointerDown = function( event, pointer ) {
+proto.pointerDown = function( event, pointer ) {
// dismiss range sliders
if ( event.target.nodeName == 'INPUT' && event.target.type == 'range' ) {
// reset pointerDown logic
@@ -3145,26 +2421,26 @@ Unidragger.prototype.pointerDown = function( event, pointer ) {
}
// bind move and end events
this._bindPostStartEvents( event );
- // track scrolling
- this.pointerDownScroll = Unidragger.getScrollPosition();
- eventie.bind( window, 'scroll', this );
-
this.emitEvent( 'pointerDown', [ event, pointer ] );
};
// base pointer down logic
-Unidragger.prototype._dragPointerDown = function( event, pointer ) {
+proto._dragPointerDown = function( event, pointer ) {
// track to see when dragging starts
this.pointerDownPoint = Unipointer.getPointerPoint( pointer );
- // prevent default, unless touchstart or