|
@@ -1,26 +1,25 @@
|
|
|
/*!
|
|
|
- * Draggabilly PACKAGED v2.1.1
|
|
|
+ * Draggabilly PACKAGED v2.2.0
|
|
|
* Make that shiz draggable
|
|
|
- * http://draggabilly.desandro.com
|
|
|
+ * https://draggabilly.desandro.com
|
|
|
* MIT license
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
* Bridget makes jQuery widgets
|
|
|
- * v2.0.0
|
|
|
+ * v2.0.1
|
|
|
* MIT license
|
|
|
*/
|
|
|
|
|
|
/* jshint browser: true, strict: true, undef: true, unused: true */
|
|
|
|
|
|
( function( window, factory ) {
|
|
|
-
|
|
|
- /* globals define: false, module: false, require: false */
|
|
|
-
|
|
|
+ // universal module definition
|
|
|
+ /*jshint strict: false */ /* globals define, module, require */
|
|
|
if ( typeof define == 'function' && define.amd ) {
|
|
|
// AMD
|
|
|
define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
|
|
|
- factory( window, jQuery );
|
|
|
+ return factory( window, jQuery );
|
|
|
});
|
|
|
} else if ( typeof module == 'object' && module.exports ) {
|
|
|
// CommonJS
|
|
@@ -37,7 +36,7 @@
|
|
|
}
|
|
|
|
|
|
}( window, function factory( window, jQuery ) {
|
|
|
-
|
|
|
+'use strict';
|
|
|
|
|
|
// ----- utils ----- //
|
|
|
|
|
@@ -160,7 +159,7 @@ return jQueryBridget;
|
|
|
/*global define: false, module: false, console: false */
|
|
|
|
|
|
( function( window, factory ) {
|
|
|
-
|
|
|
+ 'use strict';
|
|
|
|
|
|
if ( typeof define == 'function' && define.amd ) {
|
|
|
// AMD
|
|
@@ -176,7 +175,7 @@ return jQueryBridget;
|
|
|
}
|
|
|
|
|
|
})( window, function factory() {
|
|
|
-
|
|
|
+'use strict';
|
|
|
|
|
|
// -------------------------- helpers -------------------------- //
|
|
|
|
|
@@ -361,7 +360,7 @@ return getSize;
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
- * EvEmitter v1.0.3
|
|
|
+ * EvEmitter v1.1.0
|
|
|
* Lil' event emitter
|
|
|
* MIT License
|
|
|
*/
|
|
@@ -441,13 +440,14 @@ proto.emitEvent = function( eventName, args ) {
|
|
|
if ( !listeners || !listeners.length ) {
|
|
|
return;
|
|
|
}
|
|
|
- var i = 0;
|
|
|
- var listener = listeners[i];
|
|
|
+ // copy over to avoid interference if .off() in listener
|
|
|
+ listeners = listeners.slice(0);
|
|
|
args = args || [];
|
|
|
// once stuff
|
|
|
var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
|
|
|
|
|
|
- while ( listener ) {
|
|
|
+ for ( var i=0; i < listeners.length; i++ ) {
|
|
|
+ var listener = listeners[i]
|
|
|
var isOnce = onceListeners && onceListeners[ listener ];
|
|
|
if ( isOnce ) {
|
|
|
// remove listener
|
|
@@ -458,20 +458,22 @@ proto.emitEvent = function( eventName, args ) {
|
|
|
}
|
|
|
// trigger listener
|
|
|
listener.apply( this, args );
|
|
|
- // get next listener
|
|
|
- i += isOnce ? 0 : 1;
|
|
|
- listener = listeners[i];
|
|
|
}
|
|
|
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
+proto.allOff = function() {
|
|
|
+ delete this._events;
|
|
|
+ delete this._onceEvents;
|
|
|
+};
|
|
|
+
|
|
|
return EvEmitter;
|
|
|
|
|
|
}));
|
|
|
|
|
|
/*!
|
|
|
- * Unipointer v2.1.0
|
|
|
+ * Unipointer v2.3.0
|
|
|
* base class for doing one thing with pointer event
|
|
|
* MIT license
|
|
|
*/
|
|
@@ -522,25 +524,24 @@ proto.unbindStartEvent = function( elem ) {
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * works as unbinder, as you can ._bindStart( false ) to unbind
|
|
|
- * @param {Boolean} isBind - will unbind if falsey
|
|
|
+ * Add or remove start event
|
|
|
+ * @param {Boolean} isAdd - remove if falsey
|
|
|
*/
|
|
|
-proto._bindStartEvent = function( elem, isBind ) {
|
|
|
- // munge isBind, default to true
|
|
|
- isBind = isBind === undefined ? true : !!isBind;
|
|
|
- var bindMethod = isBind ? 'addEventListener' : 'removeEventListener';
|
|
|
-
|
|
|
- if ( window.navigator.pointerEnabled ) {
|
|
|
- // W3C Pointer Events, IE11. See https://coderwall.com/p/mfreca
|
|
|
- elem[ bindMethod ]( 'pointerdown', this );
|
|
|
- } else if ( window.navigator.msPointerEnabled ) {
|
|
|
- // IE10 Pointer Events
|
|
|
- elem[ bindMethod ]( 'MSPointerDown', this );
|
|
|
- } else {
|
|
|
- // listen for both, for devices like Chrome Pixel
|
|
|
- elem[ bindMethod ]( 'mousedown', this );
|
|
|
- elem[ bindMethod ]( 'touchstart', this );
|
|
|
+proto._bindStartEvent = function( elem, isAdd ) {
|
|
|
+ // munge isAdd, default to true
|
|
|
+ isAdd = isAdd === undefined ? true : isAdd;
|
|
|
+ var bindMethod = isAdd ? 'addEventListener' : 'removeEventListener';
|
|
|
+
|
|
|
+ // default to mouse events
|
|
|
+ var startEvent = 'mousedown';
|
|
|
+ if ( window.PointerEvent ) {
|
|
|
+ // Pointer Events
|
|
|
+ startEvent = 'pointerdown';
|
|
|
+ } else if ( 'ontouchstart' in window ) {
|
|
|
+ // Touch Events. iOS Safari
|
|
|
+ startEvent = 'touchstart';
|
|
|
}
|
|
|
+ elem[ bindMethod ]( startEvent, this );
|
|
|
};
|
|
|
|
|
|
// trigger handler methods for events
|
|
@@ -576,7 +577,6 @@ proto.ontouchstart = function( event ) {
|
|
|
this._pointerDown( event, event.changedTouches[0] );
|
|
|
};
|
|
|
|
|
|
-proto.onMSPointerDown =
|
|
|
proto.onpointerdown = function( event ) {
|
|
|
this._pointerDown( event, event );
|
|
|
};
|
|
@@ -587,8 +587,9 @@ proto.onpointerdown = function( event ) {
|
|
|
* @param {Event or Touch} pointer
|
|
|
*/
|
|
|
proto._pointerDown = function( event, pointer ) {
|
|
|
- // dismiss other pointers
|
|
|
- if ( this.isPointerDown ) {
|
|
|
+ // dismiss right click and other pointers
|
|
|
+ // button = 0 is okay, 1-4 not
|
|
|
+ if ( event.button || this.isPointerDown ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -611,7 +612,6 @@ var postStartEvents = {
|
|
|
mousedown: [ 'mousemove', 'mouseup' ],
|
|
|
touchstart: [ 'touchmove', 'touchend', 'touchcancel' ],
|
|
|
pointerdown: [ 'pointermove', 'pointerup', 'pointercancel' ],
|
|
|
- MSPointerDown: [ 'MSPointerMove', 'MSPointerUp', 'MSPointerCancel' ]
|
|
|
};
|
|
|
|
|
|
proto._bindPostStartEvents = function( event ) {
|
|
@@ -646,7 +646,6 @@ proto.onmousemove = function( event ) {
|
|
|
this._pointerMove( event, event );
|
|
|
};
|
|
|
|
|
|
-proto.onMSPointerMove =
|
|
|
proto.onpointermove = function( event ) {
|
|
|
if ( event.pointerId == this.pointerIdentifier ) {
|
|
|
this._pointerMove( event, event );
|
|
@@ -682,7 +681,6 @@ proto.onmouseup = function( event ) {
|
|
|
this._pointerUp( event, event );
|
|
|
};
|
|
|
|
|
|
-proto.onMSPointerUp =
|
|
|
proto.onpointerup = function( event ) {
|
|
|
if ( event.pointerId == this.pointerIdentifier ) {
|
|
|
this._pointerUp( event, event );
|
|
@@ -716,19 +714,21 @@ proto.pointerUp = function( event, pointer ) {
|
|
|
|
|
|
// triggered on pointer up & pointer cancel
|
|
|
proto._pointerDone = function() {
|
|
|
+ this._pointerReset();
|
|
|
+ this._unbindPostStartEvents();
|
|
|
+ this.pointerDone();
|
|
|
+};
|
|
|
+
|
|
|
+proto._pointerReset = function() {
|
|
|
// reset properties
|
|
|
this.isPointerDown = false;
|
|
|
delete this.pointerIdentifier;
|
|
|
- // remove events
|
|
|
- this._unbindPostStartEvents();
|
|
|
- this.pointerDone();
|
|
|
};
|
|
|
|
|
|
proto.pointerDone = noop;
|
|
|
|
|
|
// ----- pointer cancel ----- //
|
|
|
|
|
|
-proto.onMSPointerCancel =
|
|
|
proto.onpointercancel = function( event ) {
|
|
|
if ( event.pointerId == this.pointerIdentifier ) {
|
|
|
this._pointerCancel( event, event );
|
|
@@ -775,7 +775,7 @@ return Unipointer;
|
|
|
}));
|
|
|
|
|
|
/*!
|
|
|
- * Unidragger v2.1.0
|
|
|
+ * Unidragger v2.3.0
|
|
|
* Draggable base class
|
|
|
* MIT license
|
|
|
*/
|
|
@@ -811,10 +811,6 @@ return Unipointer;
|
|
|
|
|
|
|
|
|
|
|
|
-// ----- ----- //
|
|
|
-
|
|
|
-function noop() {}
|
|
|
-
|
|
|
// -------------------------- Unidragger -------------------------- //
|
|
|
|
|
|
function Unidragger() {}
|
|
@@ -832,39 +828,30 @@ proto.unbindHandles = function() {
|
|
|
this._bindHandles( false );
|
|
|
};
|
|
|
|
|
|
-var navigator = window.navigator;
|
|
|
/**
|
|
|
- * works as unbinder, as you can .bindHandles( false ) to unbind
|
|
|
- * @param {Boolean} isBind - will unbind if falsey
|
|
|
+ * Add or remove start event
|
|
|
+ * @param {Boolean} isAdd
|
|
|
*/
|
|
|
-proto._bindHandles = function( isBind ) {
|
|
|
- // munge isBind, default to true
|
|
|
- isBind = isBind === undefined ? true : !!isBind;
|
|
|
- // extra bind logic
|
|
|
- var binderExtra;
|
|
|
- if ( navigator.pointerEnabled ) {
|
|
|
- binderExtra = function( handle ) {
|
|
|
- // disable scrolling on the element
|
|
|
- handle.style.touchAction = isBind ? 'none' : '';
|
|
|
- };
|
|
|
- } else if ( navigator.msPointerEnabled ) {
|
|
|
- binderExtra = function( handle ) {
|
|
|
- // disable scrolling on the element
|
|
|
- handle.style.msTouchAction = isBind ? 'none' : '';
|
|
|
- };
|
|
|
- } else {
|
|
|
- binderExtra = noop;
|
|
|
- }
|
|
|
+proto._bindHandles = function( isAdd ) {
|
|
|
+ // munge isAdd, default to true
|
|
|
+ isAdd = isAdd === undefined ? true : isAdd;
|
|
|
// bind each handle
|
|
|
- var bindMethod = isBind ? 'addEventListener' : 'removeEventListener';
|
|
|
+ var bindMethod = isAdd ? 'addEventListener' : 'removeEventListener';
|
|
|
+ var touchAction = isAdd ? this._touchActionValue : '';
|
|
|
for ( var i=0; i < this.handles.length; i++ ) {
|
|
|
var handle = this.handles[i];
|
|
|
- this._bindStartEvent( handle, isBind );
|
|
|
- binderExtra( handle );
|
|
|
+ this._bindStartEvent( handle, isAdd );
|
|
|
handle[ bindMethod ]( 'click', this );
|
|
|
+ // touch-action: none to override browser touch gestures. metafizzy/flickity#540
|
|
|
+ if ( window.PointerEvent ) {
|
|
|
+ handle.style.touchAction = touchAction;
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+// prototype so it can be overwriteable by Flickity
|
|
|
+proto._touchActionValue = 'none';
|
|
|
+
|
|
|
// ----- start event ----- //
|
|
|
|
|
|
/**
|
|
@@ -873,40 +860,57 @@ proto._bindHandles = function( isBind ) {
|
|
|
* @param {Event or Touch} pointer
|
|
|
*/
|
|
|
proto.pointerDown = function( event, pointer ) {
|
|
|
- // dismiss range sliders
|
|
|
- if ( event.target.nodeName == 'INPUT' && event.target.type == 'range' ) {
|
|
|
- // reset pointerDown logic
|
|
|
- this.isPointerDown = false;
|
|
|
- delete this.pointerIdentifier;
|
|
|
+ var isOkay = this.okayPointerDown( event );
|
|
|
+ if ( !isOkay ) {
|
|
|
return;
|
|
|
}
|
|
|
+ // track start event position
|
|
|
+ this.pointerDownPointer = pointer;
|
|
|
|
|
|
- this._dragPointerDown( event, pointer );
|
|
|
- // kludge to blur focused inputs in dragger
|
|
|
- var focused = document.activeElement;
|
|
|
- if ( focused && focused.blur ) {
|
|
|
- focused.blur();
|
|
|
- }
|
|
|
+ event.preventDefault();
|
|
|
+ this.pointerDownBlur();
|
|
|
// bind move and end events
|
|
|
this._bindPostStartEvents( event );
|
|
|
this.emitEvent( 'pointerDown', [ event, pointer ] );
|
|
|
};
|
|
|
|
|
|
-// base pointer down logic
|
|
|
-proto._dragPointerDown = function( event, pointer ) {
|
|
|
- // track to see when dragging starts
|
|
|
- this.pointerDownPoint = Unipointer.getPointerPoint( pointer );
|
|
|
+// nodes that have text fields
|
|
|
+var cursorNodes = {
|
|
|
+ TEXTAREA: true,
|
|
|
+ INPUT: true,
|
|
|
+ SELECT: true,
|
|
|
+ OPTION: true,
|
|
|
+};
|
|
|
|
|
|
- var canPreventDefault = this.canPreventDefaultOnPointerDown( event, pointer );
|
|
|
- if ( canPreventDefault ) {
|
|
|
- event.preventDefault();
|
|
|
+// input types that do not have text fields
|
|
|
+var clickTypes = {
|
|
|
+ radio: true,
|
|
|
+ checkbox: true,
|
|
|
+ button: true,
|
|
|
+ submit: true,
|
|
|
+ image: true,
|
|
|
+ file: true,
|
|
|
+};
|
|
|
+
|
|
|
+// dismiss inputs with text fields. flickity#403, flickity#404
|
|
|
+proto.okayPointerDown = function( event ) {
|
|
|
+ var isCursorNode = cursorNodes[ event.target.nodeName ];
|
|
|
+ var isClickType = clickTypes[ event.target.type ];
|
|
|
+ var isOkay = !isCursorNode || isClickType;
|
|
|
+ if ( !isOkay ) {
|
|
|
+ this._pointerReset();
|
|
|
}
|
|
|
+ return isOkay;
|
|
|
};
|
|
|
|
|
|
-// overwriteable method so Flickity can prevent for scrolling
|
|
|
-proto.canPreventDefaultOnPointerDown = function( event ) {
|
|
|
- // prevent default, unless touchstart or <select>
|
|
|
- return event.target.nodeName != 'SELECT';
|
|
|
+// kludge to blur previously focused input
|
|
|
+proto.pointerDownBlur = function() {
|
|
|
+ var focused = document.activeElement;
|
|
|
+ // do not blur body for IE10, metafizzy/flickity#117
|
|
|
+ var canBlur = focused && focused.blur && focused != document.body;
|
|
|
+ if ( canBlur ) {
|
|
|
+ focused.blur();
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
// ----- move event ----- //
|
|
@@ -924,10 +928,9 @@ proto.pointerMove = function( event, pointer ) {
|
|
|
|
|
|
// base pointer move logic
|
|
|
proto._dragPointerMove = function( event, pointer ) {
|
|
|
- var movePoint = Unipointer.getPointerPoint( pointer );
|
|
|
var moveVector = {
|
|
|
- x: movePoint.x - this.pointerDownPoint.x,
|
|
|
- y: movePoint.y - this.pointerDownPoint.y
|
|
|
+ x: pointer.pageX - this.pointerDownPointer.pageX,
|
|
|
+ y: pointer.pageY - this.pointerDownPointer.pageY
|
|
|
};
|
|
|
// start drag if pointer has moved far enough to start drag
|
|
|
if ( !this.isDragging && this.hasDragStarted( moveVector ) ) {
|
|
@@ -941,7 +944,6 @@ proto.hasDragStarted = function( moveVector ) {
|
|
|
return Math.abs( moveVector.x ) > 3 || Math.abs( moveVector.y ) > 3;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
// ----- end event ----- //
|
|
|
|
|
|
/**
|
|
@@ -968,10 +970,8 @@ proto._dragPointerUp = function( event, pointer ) {
|
|
|
// dragStart
|
|
|
proto._dragStart = function( event, pointer ) {
|
|
|
this.isDragging = true;
|
|
|
- this.dragStartPoint = Unipointer.getPointerPoint( pointer );
|
|
|
// prevent clicks
|
|
|
this.isPreventingClicks = true;
|
|
|
-
|
|
|
this.dragStart( event, pointer );
|
|
|
};
|
|
|
|
|
@@ -1028,11 +1028,6 @@ proto._staticClick = function( event, pointer ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // allow click in <input>s and <textarea>s
|
|
|
- var nodeName = event.target.nodeName;
|
|
|
- if ( nodeName == 'INPUT' || nodeName == 'TEXTAREA' ) {
|
|
|
- event.target.focus();
|
|
|
- }
|
|
|
this.staticClick( event, pointer );
|
|
|
|
|
|
// set flag for emulated clicks 300ms after touchend
|
|
@@ -1060,9 +1055,9 @@ return Unidragger;
|
|
|
}));
|
|
|
|
|
|
/*!
|
|
|
- * Draggabilly v2.1.1
|
|
|
+ * Draggabilly v2.2.0
|
|
|
* Make that shiz draggable
|
|
|
- * http://draggabilly.desandro.com
|
|
|
+ * https://draggabilly.desandro.com
|
|
|
* MIT license
|
|
|
*/
|
|
|
|
|
@@ -1100,12 +1095,7 @@ return Unidragger;
|
|
|
|
|
|
|
|
|
|
|
|
-// vars
|
|
|
-var document = window.document;
|
|
|
-
|
|
|
-function noop() {}
|
|
|
-
|
|
|
-// -------------------------- helpers -------------------------- //
|
|
|
+// -------------------------- helpers & variables -------------------------- //
|
|
|
|
|
|
// extend objects
|
|
|
function extend( a, b ) {
|
|
@@ -1115,33 +1105,7 @@ function extend( a, b ) {
|
|
|
return a;
|
|
|
}
|
|
|
|
|
|
-function isElement( obj ) {
|
|
|
- return obj instanceof HTMLElement;
|
|
|
-}
|
|
|
-
|
|
|
-// -------------------------- requestAnimationFrame -------------------------- //
|
|
|
-
|
|
|
-// get rAF, prefixed, if present
|
|
|
-var requestAnimationFrame = window.requestAnimationFrame ||
|
|
|
- window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
|
|
|
-
|
|
|
-// fallback to setTimeout
|
|
|
-var lastTime = 0;
|
|
|
-if ( !requestAnimationFrame ) {
|
|
|
- requestAnimationFrame = function( callback ) {
|
|
|
- var currTime = new Date().getTime();
|
|
|
- var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
|
|
|
- var id = setTimeout( callback, timeToCall );
|
|
|
- lastTime = currTime + timeToCall;
|
|
|
- return id;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-// -------------------------- support -------------------------- //
|
|
|
-
|
|
|
-var docElem = document.documentElement;
|
|
|
-var transformProperty = typeof docElem.style.transform == 'string' ?
|
|
|
- 'transform' : 'WebkitTransform';
|
|
|
+function noop() {}
|
|
|
|
|
|
var jQuery = window.jQuery;
|
|
|
|
|
@@ -1185,7 +1149,6 @@ var positionValues = {
|
|
|
};
|
|
|
|
|
|
proto._create = function() {
|
|
|
-
|
|
|
// properties
|
|
|
this.position = {};
|
|
|
this._getPosition();
|
|
@@ -1198,12 +1161,16 @@ proto._create = function() {
|
|
|
// set relative positioning
|
|
|
var style = getComputedStyle( this.element );
|
|
|
if ( !positionValues[ style.position ] ) {
|
|
|
- this.element.style.position = 'fixed';
|
|
|
+ this.element.style.position = 'relative';
|
|
|
}
|
|
|
|
|
|
+ // events, bridge jQuery events from vanilla
|
|
|
+ this.on( 'pointerDown', this.onPointerDown );
|
|
|
+ this.on( 'pointerMove', this.onPointerMove );
|
|
|
+ this.on( 'pointerUp', this.onPointerUp );
|
|
|
+
|
|
|
this.enable();
|
|
|
this.setHandles();
|
|
|
-
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -1225,19 +1192,19 @@ proto.setHandles = function() {
|
|
|
proto.dispatchEvent = function( type, event, args ) {
|
|
|
var emitArgs = [ event ].concat( args );
|
|
|
this.emitEvent( type, emitArgs );
|
|
|
+ this.dispatchJQueryEvent( type, event, args );
|
|
|
+};
|
|
|
+
|
|
|
+proto.dispatchJQueryEvent = function( type, event, args ) {
|
|
|
var jQuery = window.jQuery;
|
|
|
// trigger jQuery event
|
|
|
- if ( jQuery && this.$element ) {
|
|
|
- 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 );
|
|
|
- }
|
|
|
+ if ( !jQuery || !this.$element ) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ // create jQuery event
|
|
|
+ var $event = jQuery.Event( event );
|
|
|
+ $event.type = type;
|
|
|
+ this.$element.trigger( $event, args );
|
|
|
};
|
|
|
|
|
|
// -------------------------- position -------------------------- //
|
|
@@ -1267,7 +1234,7 @@ proto._getPositionCoord = function( styleSide, measure ) {
|
|
|
|
|
|
// add transform: translate( x, y ) to position
|
|
|
proto._addTransformPosition = function( style ) {
|
|
|
- var transform = style[ transformProperty ];
|
|
|
+ var transform = style.transform;
|
|
|
// bail out if value is 'none'
|
|
|
if ( transform.indexOf('matrix') !== 0 ) {
|
|
|
return;
|
|
@@ -1285,34 +1252,9 @@ proto._addTransformPosition = function( style ) {
|
|
|
|
|
|
// -------------------------- events -------------------------- //
|
|
|
|
|
|
-/**
|
|
|
- * pointer start
|
|
|
- * @param {Event} event
|
|
|
- * @param {Event or Touch} pointer
|
|
|
- */
|
|
|
-proto.pointerDown = function( event, pointer ) {
|
|
|
- this._dragPointerDown( event, pointer );
|
|
|
- // kludge to blur focused inputs in dragger
|
|
|
- var focused = document.activeElement;
|
|
|
- // do not blur body for IE10, metafizzy/flickity#117
|
|
|
- if ( focused && focused.blur && focused != document.body ) {
|
|
|
- focused.blur();
|
|
|
- }
|
|
|
- // bind move and end events
|
|
|
- this._bindPostStartEvents( event );
|
|
|
+proto.onPointerDown = function( event, pointer ) {
|
|
|
this.element.classList.add('is-pointer-down');
|
|
|
- this.dispatchEvent( 'pointerDown', event, [ pointer ] );
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * drag move
|
|
|
- * @param {Event} event
|
|
|
- * @param {Event or Touch} pointer
|
|
|
- */
|
|
|
-proto.pointerMove = function( event, pointer ) {
|
|
|
- var moveVector = this._dragPointerMove( event, pointer );
|
|
|
- this.dispatchEvent( 'pointerMove', event, [ pointer, moveVector ] );
|
|
|
- this._dragMove( event, pointer, moveVector );
|
|
|
+ this.dispatchJQueryEvent( 'pointerDown', event, [ pointer ] );
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -1342,18 +1284,11 @@ proto.dragStart = function( event, pointer ) {
|
|
|
};
|
|
|
|
|
|
proto.measureContainment = function() {
|
|
|
- var containment = this.options.containment;
|
|
|
- if ( !containment ) {
|
|
|
+ var container = this.getContainer();
|
|
|
+ if ( !container ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // use element if element
|
|
|
- var container = isElement( containment ) ? containment :
|
|
|
- // fallback to querySelector if string
|
|
|
- typeof containment == 'string' ? document.querySelector( containment ) :
|
|
|
- // otherwise just `true`, use the parent
|
|
|
- this.element.parentNode;
|
|
|
-
|
|
|
var elemSize = getSize( this.element );
|
|
|
var containerSize = getSize( container );
|
|
|
var elemRect = this.element.getBoundingClientRect();
|
|
@@ -1373,8 +1308,30 @@ proto.measureContainment = function() {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+proto.getContainer = function() {
|
|
|
+ var containment = this.options.containment;
|
|
|
+ if ( !containment ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var isElement = containment instanceof HTMLElement;
|
|
|
+ // use as element
|
|
|
+ if ( isElement ) {
|
|
|
+ return containment;
|
|
|
+ }
|
|
|
+ // querySelector if string
|
|
|
+ if ( typeof containment == 'string' ) {
|
|
|
+ return document.querySelector( containment );
|
|
|
+ }
|
|
|
+ // fallback to parent element
|
|
|
+ return this.element.parentNode;
|
|
|
+};
|
|
|
+
|
|
|
// ----- move event ----- //
|
|
|
|
|
|
+proto.onPointerMove = function( event, pointer, moveVector ) {
|
|
|
+ this.dispatchJQueryEvent( 'pointerMove', event, [ pointer, moveVector ] );
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* drag move
|
|
|
* @param {Event} event
|
|
@@ -1425,7 +1382,7 @@ proto.containDrag = function( axis, drag, grid ) {
|
|
|
var min = applyGrid( -rel, grid, 'ceil' );
|
|
|
var max = this.containSize[ measure ];
|
|
|
max = applyGrid( max, grid, 'floor' );
|
|
|
- return Math.min( max, Math.max( min, drag ) );
|
|
|
+ return Math.max( min, Math.min( max, drag ) );
|
|
|
};
|
|
|
|
|
|
// ----- end event ----- //
|
|
@@ -1435,10 +1392,9 @@ proto.containDrag = function( axis, drag, grid ) {
|
|
|
* @param {Event} event
|
|
|
* @param {Event or Touch} pointer
|
|
|
*/
|
|
|
-proto.pointerUp = function( event, pointer ) {
|
|
|
+proto.onPointerUp = function( event, pointer ) {
|
|
|
this.element.classList.remove('is-pointer-down');
|
|
|
- this.dispatchEvent( 'pointerUp', event, [ pointer ] );
|
|
|
- this._dragPointerUp( event, pointer );
|
|
|
+ this.dispatchJQueryEvent( 'pointerUp', event, [ pointer ] );
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -1451,10 +1407,8 @@ proto.dragEnd = function( event, pointer ) {
|
|
|
return;
|
|
|
}
|
|
|
// use top left position when complete
|
|
|
- if ( transformProperty ) {
|
|
|
- this.element.style[ transformProperty ] = '';
|
|
|
- this.setLeftTop();
|
|
|
- }
|
|
|
+ this.element.style.transform = '';
|
|
|
+ this.setLeftTop();
|
|
|
this.element.classList.remove('is-dragging');
|
|
|
this.dispatchEvent( 'dragEnd', event, [ pointer ] );
|
|
|
};
|
|
@@ -1483,7 +1437,7 @@ proto.setLeftTop = function() {
|
|
|
};
|
|
|
|
|
|
proto.positionDrag = function() {
|
|
|
- this.element.style[ transformProperty ] = 'translate3d( ' + this.dragPoint.x +
|
|
|
+ this.element.style.transform = 'translate3d( ' + this.dragPoint.x +
|
|
|
'px, ' + this.dragPoint.y + 'px, 0)';
|
|
|
};
|
|
|
|
|
@@ -1495,6 +1449,16 @@ proto.staticClick = function( event, pointer ) {
|
|
|
|
|
|
// ----- methods ----- //
|
|
|
|
|
|
+/**
|
|
|
+ * @param {Number} x
|
|
|
+ * @param {Number} y
|
|
|
+ */
|
|
|
+proto.setPosition = function( x, y ) {
|
|
|
+ this.position.x = x;
|
|
|
+ this.position.y = y;
|
|
|
+ this.setLeftTop();
|
|
|
+};
|
|
|
+
|
|
|
proto.enable = function() {
|
|
|
this.isEnabled = true;
|
|
|
};
|
|
@@ -1509,7 +1473,7 @@ proto.disable = function() {
|
|
|
proto.destroy = function() {
|
|
|
this.disable();
|
|
|
// reset styles
|
|
|
- this.element.style[ transformProperty ] = '';
|
|
|
+ this.element.style.transform = '';
|
|
|
this.element.style.left = '';
|
|
|
this.element.style.top = '';
|
|
|
this.element.style.position = '';
|