unidragger
Advanced tools
Comparing version 2.2.3 to 2.3.0
@@ -5,3 +5,3 @@ { | ||
"dependencies": { | ||
"unipointer": "^2.2.0" | ||
"unipointer": "^2.3.0" | ||
}, | ||
@@ -8,0 +8,0 @@ "authors": [ |
{ | ||
"name": "unidragger", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"description": "Base draggable class", | ||
"main": "unidragger.js", | ||
"dependencies": { | ||
"unipointer": "^2.2.0" | ||
"unipointer": "^2.3.0" | ||
}, | ||
@@ -9,0 +9,0 @@ "scripts": { |
@@ -57,2 +57,2 @@ # Unidragger | ||
By [Metafizzy](http://metafizzy.co) | ||
By [Metafizzy 🌈🐻](https://metafizzy.co) |
/*! | ||
* Unidragger v2.2.3 | ||
* Unidragger v2.3.0 | ||
* Draggable base class | ||
@@ -56,18 +56,18 @@ * MIT license | ||
/** | ||
* 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; | ||
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 ); | ||
this._bindStartEvent( handle, isAdd ); | ||
handle[ bindMethod ]( 'click', this ); | ||
// touch-action: none to override browser touch gestures | ||
// metafizzy/flickity#540 | ||
// touch-action: none to override browser touch gestures. metafizzy/flickity#540 | ||
if ( window.PointerEvent ) { | ||
handle.style.touchAction = isBind ? this._touchActionValue : ''; | ||
handle.style.touchAction = touchAction; | ||
} | ||
@@ -88,16 +88,11 @@ } | ||
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 | ||
@@ -108,17 +103,39 @@ this._bindPostStartEvents( event ); | ||
// 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(); | ||
} | ||
}; | ||
@@ -141,6 +158,5 @@ | ||
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 | ||
}; | ||
@@ -159,3 +175,2 @@ // start drag if pointer has moved far enough to start drag | ||
// ----- end event ----- // | ||
@@ -187,6 +202,4 @@ | ||
this.isDragging = true; | ||
this.dragStartPoint = Unipointer.getPointerPoint( pointer ); | ||
// prevent clicks | ||
this.isPreventingClicks = true; | ||
this.dragStart( event, pointer ); | ||
@@ -248,7 +261,2 @@ }; | ||
// 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 ); | ||
@@ -255,0 +263,0 @@ |
261
9167
4
Updatedunipointer@^2.3.0