// drag ( function( window, factory ) { // universal module definition /* jshint strict: false */ if ( typeof define == 'function' && define.amd ) { // AMD define( [ './flickity', 'unidragger/unidragger', 'fizzy-ui-utils/utils' ], function( Flickity, Unidragger, utils ) { return factory( window, Flickity, Unidragger, utils ); }); } else if ( typeof module == 'object' && module.exports ) { // CommonJS module.exports = factory( window, require('./flickity'), require('unidragger'), require('fizzy-ui-utils') ); } else { // browser global window.Flickity = factory( window, window.Flickity, window.Unidragger, window.fizzyUIUtils ); } }( window, function factory( window, Flickity, Unidragger, utils ) { 'use strict'; // ----- defaults ----- // utils.extend( Flickity.defaults, { draggable: true, dragThreshold: 3, }); // ----- create ----- // Flickity.createMethods.push('_createDrag'); // -------------------------- drag prototype -------------------------- // var proto = Flickity.prototype; utils.extend( proto, Unidragger.prototype ); // -------------------------- -------------------------- // var isTouch = 'createTouch' in document; var isTouchmoveScrollCanceled = false; proto._createDrag = function() { this.on( 'activate', this.bindDrag ); this.on( 'uiChange', this._uiChangeDrag ); this.on( 'childUIPointerDown', this._childUIPointerDownDrag ); this.on( 'deactivate', this.unbindDrag ); // HACK - add seemingly innocuous handler to fix iOS 10 scroll behavior // #457, RubaXa/Sortable#973 if ( isTouch && !isTouchmoveScrollCanceled ) { window.addEventListener( 'touchmove', function() {}); isTouchmoveScrollCanceled = true; } }; proto.bindDrag = function() { if ( !this.options.draggable || this.isDragBound ) { return; } this.element.classList.add('is-draggable'); this.handles = [ this.viewport ]; this.bindHandles(); this.isDragBound = true; }; proto.unbindDrag = function() { if ( !this.isDragBound ) { return; } this.element.classList.remove('is-draggable'); this.unbindHandles(); delete this.isDragBound; }; proto._uiChangeDrag = function() { delete this.isFreeScrolling; }; proto._childUIPointerDownDrag = function( event ) { event.preventDefault(); this.pointerDownFocus( event ); }; // -------------------------- pointer events -------------------------- // // nodes that have text fields var cursorNodes = { TEXTAREA: true, INPUT: true, OPTION: true, }; // input types that do not have text fields var clickTypes = { radio: true, checkbox: true, button: true, submit: true, image: true, file: true, }; proto.pointerDown = function( event, pointer ) { // dismiss inputs with text fields. #403, #404 var isCursorInput = cursorNodes[ event.target.nodeName ] && !clickTypes[ event.target.type ]; if ( isCursorInput ) { // reset pointerDown logic this.isPointerDown = false; delete this.pointerIdentifier; return; } this._dragPointerDown( event, pointer ); // kludge to blur focused inputs in dragger var focused = document.activeElement; if ( focused && focused.blur && focused != this.element && // do not blur body for IE9 & 10, #117 focused != document.body ) { focused.blur(); } this.pointerDownFocus( event ); // stop if it was moving this.dragX = this.x; this.viewport.classList.add('is-pointer-down'); // bind move and end events this._bindPostStartEvents( event ); // track scrolling this.pointerDownScroll = getScrollPosition(); window.addEventListener( 'scroll', this ); this.dispatchEvent( 'pointerDown', event, [ pointer ] ); }; var touchStartEvents = { touchstart: true, MSPointerDown: true }; var focusNodes = { INPUT: true, SELECT: true }; proto.pointerDownFocus = function( event ) { // focus element, if not touch, and its not an input or select if ( !this.options.accessibility || touchStartEvents[ event.type ] || focusNodes[ event.target.nodeName ] ) { return; } var prevScrollY = window.pageYOffset; this.element.focus(); // hack to fix scroll jump after focus, #76 if ( window.pageYOffset != prevScrollY ) { window.scrollTo( window.pageXOffset, prevScrollY ); } }; proto.canPreventDefaultOnPointerDown = function( event ) { // prevent default, unless touchstart or