From 986313ac9581f813f495f17f288680f5b560c679 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Sat, 16 May 2020 12:27:23 -0400 Subject: [PATCH] 2.3.0 --- README.md | 2 +- dist/draggabilly.pkgd.js | 86 ++++++++++++++++++++++-------------- dist/draggabilly.pkgd.min.js | 30 +++++++++++-- draggabilly.js | 2 +- package-lock.json | 2 +- package.json | 2 +- 6 files changed, 84 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 2ea4ae7..d35852f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Rad because it supports IE10+ and touch devices. -Draggabilly v2.2.0 +Draggabilly v2.3.0 ## Install diff --git a/dist/draggabilly.pkgd.js b/dist/draggabilly.pkgd.js index d7f7548..66ddb51 100644 --- a/dist/draggabilly.pkgd.js +++ b/dist/draggabilly.pkgd.js @@ -1,5 +1,5 @@ /*! - * Draggabilly PACKAGED v2.2.0 + * Draggabilly PACKAGED v2.3.0 * Make that shiz draggable * https://draggabilly.desandro.com * MIT license @@ -1055,46 +1055,44 @@ return Unidragger; })); /*! - * Draggabilly v2.2.0 + * Draggabilly v2.3.0 * Make that shiz draggable * https://draggabilly.desandro.com * MIT license */ -/*jshint browser: true, strict: true, undef: true, unused: true */ +/* jshint browser: true, strict: true, undef: true, unused: true */ ( function( window, factory ) { // universal module definition - /* jshint strict: false */ /*globals define, module, require */ + /* jshint strict: false */ /* globals define */ if ( typeof define == 'function' && define.amd ) { // AMD define( [ - 'get-size/get-size', - 'unidragger/unidragger' - ], - function( getSize, Unidragger ) { + 'get-size/get-size', + 'unidragger/unidragger', + ], + function( getSize, Unidragger ) { return factory( window, getSize, Unidragger ); - }); + } ); } else if ( typeof module == 'object' && module.exports ) { // CommonJS module.exports = factory( - window, - require('get-size'), - require('unidragger') + window, + require('get-size'), + require('unidragger') ); } else { // browser global window.Draggabilly = factory( - window, - window.getSize, - window.Unidragger + window, + window.getSize, + window.Unidragger ); } }( window, function factory( window, getSize, Unidragger ) { - - // -------------------------- helpers & variables -------------------------- // // extend objects @@ -1145,7 +1143,7 @@ proto.option = function( opts ) { var positionValues = { relative: true, absolute: true, - fixed: true + fixed: true, }; proto._create = function() { @@ -1165,7 +1163,6 @@ proto._create = function() { } // events, bridge jQuery events from vanilla - this.on( 'pointerDown', this.onPointerDown ); this.on( 'pointerMove', this.onPointerMove ); this.on( 'pointerUp', this.onPointerUp ); @@ -1196,13 +1193,14 @@ proto.dispatchEvent = function( type, event, args ) { }; proto.dispatchJQueryEvent = function( type, event, args ) { - var jQuery = window.jQuery; + var jquery = window.jQuery; // trigger jQuery event - if ( !jQuery || !this.$element ) { + if ( !jquery || !this.$element ) { return; } // create jQuery event - var $event = jQuery.Event( event ); + /* eslint-disable-next-line new-cap */ + var $event = jquery.Event( event ); $event.type = type; this.$element.trigger( $event, args ); }; @@ -1257,10 +1255,31 @@ proto.onPointerDown = function( event, pointer ) { this.dispatchJQueryEvent( 'pointerDown', event, [ pointer ] ); }; +proto.pointerDown = function( event, pointer ) { + var isOkay = this.okayPointerDown( event ); + if ( !isOkay || !this.isEnabled ) { + this._pointerReset(); + return; + } + // track start event position + // Safari 9 overrides pageX and pageY. These values needs to be copied. flickity#842 + this.pointerDownPointer = { + pageX: pointer.pageX, + pageY: pointer.pageY, + }; + + event.preventDefault(); + this.pointerDownBlur(); + // bind move and end events + this._bindPostStartEvents( event ); + this.element.classList.add('is-pointer-down'); + this.dispatchEvent( 'pointerDown', event, [ pointer ] ); +}; + /** * drag start * @param {Event} event - * @param {Event or Touch} pointer + * @param {[Event, Touch]} pointer */ proto.dragStart = function( event, pointer ) { if ( !this.isEnabled ) { @@ -1299,12 +1318,12 @@ proto.measureContainment = function() { var position = this.relativeStartPosition = { x: elemRect.left - ( containerRect.left + containerSize.borderLeftWidth ), - y: elemRect.top - ( containerRect.top + containerSize.borderTopWidth ) + y: elemRect.top - ( containerRect.top + containerSize.borderTopWidth ), }; this.containSize = { width: ( containerSize.width - borderSizeX ) - position.x - elemSize.width, - height: ( containerSize.height - borderSizeY ) - position.y - elemSize.height + height: ( containerSize.height - borderSizeY ) - position.y - elemSize.height, }; }; @@ -1335,7 +1354,8 @@ proto.onPointerMove = function( event, pointer, moveVector ) { /** * drag move * @param {Event} event - * @param {Event or Touch} pointer + * @param {[Event, Touch]} pointer + * @param {Object} moveVector - x and y coordinates */ proto.dragMove = function( event, pointer, moveVector ) { if ( !this.isEnabled ) { @@ -1369,7 +1389,7 @@ proto.dragMove = function( event, pointer, moveVector ) { function applyGrid( value, grid, method ) { method = method || 'round'; - return grid ? Math[ method ]( value / grid ) * grid : value; + return grid ? Math[ method ]( value/grid ) * grid : value; } proto.containDrag = function( axis, drag, grid ) { @@ -1382,7 +1402,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.max( min, Math.min( max, drag ) ); + return Math.max( min, Math.min( max, drag ) ); }; // ----- end event ----- // @@ -1390,7 +1410,7 @@ proto.containDrag = function( axis, drag, grid ) { /** * pointer up * @param {Event} event - * @param {Event or Touch} pointer + * @param {[Event, Touch]} pointer */ proto.onPointerUp = function( event, pointer ) { this.element.classList.remove('is-pointer-down'); @@ -1400,7 +1420,7 @@ proto.onPointerUp = function( event, pointer ) { /** * drag end * @param {Event} event - * @param {Event or Touch} pointer + * @param {[Event, Touch]} pointer */ proto.dragEnd = function( event, pointer ) { if ( !this.isEnabled ) { @@ -1426,14 +1446,14 @@ proto.animate = function() { var _this = this; requestAnimationFrame( function animateFrame() { _this.animate(); - }); + } ); }; // left/top positioning proto.setLeftTop = function() { this.element.style.left = this.position.x + 'px'; - this.element.style.top = this.position.y + 'px'; + this.element.style.top = this.position.y + 'px'; }; proto.positionDrag = function() { @@ -1498,5 +1518,5 @@ if ( jQuery && jQuery.bridget ) { return Draggabilly; -})); +} ) ); diff --git a/dist/draggabilly.pkgd.min.js b/dist/draggabilly.pkgd.min.js index 276a7ab..e3ec5e1 100644 --- a/dist/draggabilly.pkgd.min.js +++ b/dist/draggabilly.pkgd.min.js @@ -1,8 +1,32 @@ /*! - * Draggabilly PACKAGED v2.2.0 + * Draggabilly PACKAGED v2.3.0 * Make that shiz draggable * https://draggabilly.desandro.com * MIT license */ - -!function(i,e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(t){return e(i,t)}):"object"==typeof module&&module.exports?module.exports=e(i,require("jquery")):i.jQueryBridget=e(i,i.jQuery)}(window,function(t,i){"use strict";var c=Array.prototype.slice,e=t.console,p=void 0===e?function(){}:function(t){e.error(t)};function n(d,o,u){(u=u||i||t.jQuery)&&(o.prototype.option||(o.prototype.option=function(t){u.isPlainObject(t)&&(this.options=u.extend(!0,this.options,t))}),u.fn[d]=function(t){if("string"==typeof t){var i=c.call(arguments,1);return s=i,a="$()."+d+'("'+(r=t)+'")',(e=this).each(function(t,i){var e=u.data(i,d);if(e){var n=e[r];if(n&&"_"!=r.charAt(0)){var o=n.apply(e,s);h=void 0===h?o:h}else p(a+" is not a valid method")}else p(d+" not initialized. Cannot call methods, i.e. "+a)}),void 0!==h?h:e}var e,r,s,h,a,n;return n=t,this.each(function(t,i){var e=u.data(i,d);e?(e.option(n),e._init()):(e=new o(i,n),u.data(i,d,e))}),this},r(u))}function r(t){!t||t&&t.bridget||(t.bridget=n)}return r(i||t.jQuery),n}),function(t,i){"use strict";"function"==typeof define&&define.amd?define("get-size/get-size",[],function(){return i()}):"object"==typeof module&&module.exports?module.exports=i():t.getSize=i()}(window,function(){"use strict";function m(t){var i=parseFloat(t);return-1==t.indexOf("%")&&!isNaN(i)&&i}var e="undefined"==typeof console?function(){}:function(t){console.error(t)},y=["paddingLeft","paddingRight","paddingTop","paddingBottom","marginLeft","marginRight","marginTop","marginBottom","borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth"],b=y.length;function E(t){var i=getComputedStyle(t);return i||e("Style returned "+i+". Are you running this code in a hidden iframe on Firefox? See http://bit.ly/getsizebug1"),i}var _,x=!1;function P(t){if(function(){if(!x){x=!0;var t=document.createElement("div");t.style.width="200px",t.style.padding="1px 2px 3px 4px",t.style.borderStyle="solid",t.style.borderWidth="1px 2px 3px 4px",t.style.boxSizing="border-box";var i=document.body||document.documentElement;i.appendChild(t);var e=E(t);P.isBoxSizeOuter=_=200==m(e.width),i.removeChild(t)}}(),"string"==typeof t&&(t=document.querySelector(t)),t&&"object"==typeof t&&t.nodeType){var i=E(t);if("none"==i.display)return function(){for(var t={width:0,height:0,innerWidth:0,innerHeight:0,outerWidth:0,outerHeight:0},i=0;i