Comparing version 3.5.3 to 3.5.4
{ | ||
"name": "dragula.js", | ||
"version": "3.5.3", | ||
"version": "3.5.4", | ||
"description": "Drag and drop so simple it hurts", | ||
@@ -5,0 +5,0 @@ "main": [ |
@@ -43,2 +43,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.dragula = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var classes = require('./classes'); | ||
var doc = document; | ||
var documentElement = doc.documentElement; | ||
var body = doc.body; | ||
@@ -51,4 +54,2 @@ function dragula (initialContainers, options) { | ||
} | ||
var body = document.body; | ||
var documentElement = document.documentElement; | ||
var _mirror; // mirror image | ||
@@ -171,3 +172,3 @@ var _source; // source container | ||
var clientY = getCoord('clientY', e); | ||
var elementBehindCursor = document.elementFromPoint(clientX, clientY); | ||
var elementBehindCursor = doc.elementFromPoint(clientX, clientY); | ||
if (isInput(elementBehindCursor)) { | ||
@@ -201,7 +202,7 @@ return; | ||
var handle = item; | ||
while (item.parentElement && isContainer(item.parentElement) === false) { | ||
while (getParent(item) && isContainer(getParent(item)) === false) { | ||
if (o.invalid(item, handle)) { | ||
return; | ||
} | ||
item = item.parentElement; // drag target should be a top element | ||
item = getParent(item); // drag target should be a top element | ||
if (!item) { | ||
@@ -211,3 +212,3 @@ return; | ||
} | ||
var source = item.parentElement; | ||
var source = getParent(item); | ||
if (!source) { | ||
@@ -261,3 +262,3 @@ return; | ||
var item = _copy || _item; | ||
drop(item, item.parentElement); | ||
drop(item, getParent(item)); | ||
} | ||
@@ -292,3 +293,3 @@ | ||
function drop (item, target) { | ||
var parent = item.parentElement; | ||
var parent = getParent(item); | ||
if (_copy && o.copySortSource && target === _source) { | ||
@@ -310,3 +311,3 @@ parent.removeChild(_item); | ||
var item = _copy || _item; | ||
var parent = item.parentElement; | ||
var parent = getParent(item); | ||
if (parent) { | ||
@@ -325,3 +326,3 @@ parent.removeChild(item); | ||
var item = _copy || _item; | ||
var parent = item.parentElement; | ||
var parent = getParent(item); | ||
if (parent === _source && _copy) { | ||
@@ -375,3 +376,3 @@ parent.removeChild(_copy); | ||
while (target && !accepted()) { | ||
target = target.parentElement; | ||
target = getParent(target); | ||
} | ||
@@ -419,5 +420,6 @@ return target; | ||
} | ||
var parent = getParent(item); | ||
if (dropTarget === _source && _copy && !o.copySortSource) { | ||
if (item.parentElement) { | ||
item.parentElement.removeChild(item); | ||
if (parent) { | ||
parent.removeChild(item); | ||
} | ||
@@ -434,4 +436,4 @@ return; | ||
} else { | ||
if (_copy && item.parentElement) { | ||
item.parentElement.removeChild(item); | ||
if (_copy && parent) { | ||
parent.removeChild(item); | ||
} | ||
@@ -483,3 +485,3 @@ return; | ||
touchy(documentElement, 'remove', 'mousemove', drag); | ||
_mirror.parentElement.removeChild(_mirror); | ||
getParent(_mirror).removeChild(_mirror); | ||
_mirror = null; | ||
@@ -491,4 +493,4 @@ } | ||
var immediate = target; | ||
while (immediate !== dropTarget && immediate.parentElement !== dropTarget) { | ||
immediate = immediate.parentElement; | ||
while (immediate !== dropTarget && getParent(immediate) !== dropTarget) { | ||
immediate = getParent(immediate); | ||
} | ||
@@ -578,7 +580,5 @@ if (immediate === documentElement) { | ||
} | ||
var documentElement = document.documentElement; | ||
if (documentElement.clientHeight) { | ||
return documentElement[scrollProp]; | ||
} | ||
var body = document.body; | ||
return body[scrollProp]; | ||
@@ -592,3 +592,3 @@ } | ||
p.className += ' gu-hide'; | ||
el = document.elementFromPoint(x, y); | ||
el = doc.elementFromPoint(x, y); | ||
p.className = state; | ||
@@ -602,2 +602,3 @@ return el; | ||
function getRectHeight (rect) { return rect.height || (rect.bottom - rect.top); } | ||
function getParent (el) { return el.parentNode === doc ? null : el.parentNode; } | ||
function isInput (el) { return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT'; } | ||
@@ -904,2 +905,2 @@ | ||
}); | ||
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJjbGFzc2VzLmpzIiwiZHJhZ3VsYS5qcyIsIm5vZGVfbW9kdWxlcy9jb250cmEvZGVib3VuY2UuanMiLCJub2RlX21vZHVsZXMvY29udHJhL2VtaXR0ZXIuanMiLCJub2RlX21vZHVsZXMvY29udHJhL25vZGVfbW9kdWxlcy9hdG9hL2F0b2EuanMiLCJub2RlX21vZHVsZXMvY29udHJhL25vZGVfbW9kdWxlcy90aWNreS90aWNreS1icm93c2VyLmpzIiwibm9kZV9tb2R1bGVzL2Nyb3NzdmVudC9ub2RlX21vZHVsZXMvY3VzdG9tLWV2ZW50L2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2Nyb3NzdmVudC9zcmMvY3Jvc3N2ZW50LmpzIiwibm9kZV9tb2R1bGVzL2Nyb3NzdmVudC9zcmMvZXZlbnRtYXAuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQT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wpIHtcbiAgaWYgKHJvbi50ZXN0KGV2ZW50bmFtZSkpIHtcbiAgICBldmVudG1hcC5wdXNoKGV2ZW50bmFtZS5zbGljZSgyKSk7XG4gIH1cbn1cblxubW9kdWxlLmV4cG9ydHMgPSBldmVudG1hcDtcbiJdfQ== |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.dragula=e()}}(function(){return function e(n,t,r){function o(u,c){if(!t[u]){if(!n[u]){var a="function"==typeof require&&require;if(!c&&a)return a(u,!0);if(i)return i(u,!0);var l=new Error("Cannot find module '"+u+"'");throw l.code="MODULE_NOT_FOUND",l}var f=t[u]={exports:{}};n[u][0].call(f.exports,function(e){var t=n[u][1][e];return o(t?t:e)},f,f.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,n,t){"use strict";function r(e){var n=u[e];return n?n.lastIndex=0:u[e]=n=new RegExp(c+e+a,"g"),n}function o(e,n){var t=e.className;t.length?r(n).test(t)||(e.className+=" "+n):e.className=n}function i(e,n){e.className=e.className.replace(r(n)," ").trim()}var u={},c="(?:^|\\s)",a="(?:\\s|$)";n.exports={add:o,rm:i}},{}],2:[function(e,n,t){(function(t){"use strict";function r(e,n){function t(e){return-1!==ce.containers.indexOf(e)||ue.isContainer(e)}function r(e){var n=e?"remove":"add";o(oe,n,"mousedown",w),o(oe,n,"mouseup",Y)}function c(e){var n=e?"remove":"add";o(oe,n,"mousemove",x)}function p(e){var n=e?"remove":"add";o(oe,n,"selectstart",b),o(oe,n,"click",b)}function y(){r(!0),Y({})}function b(e){te&&e.preventDefault()}function w(e){J=e.clientX,Q=e.clientY;var n=1!==i(e)||e.metaKey||e.ctrlKey;if(!n){var t=e.target,r=S(t);r&&(te=r,c(),"mousedown"===e.type&&(v(t)?t.focus():e.preventDefault()))}}function x(e){if(te){if(0===i(e))return void Y({});if(void 0===e.clientX||e.clientX!==J||void 0===e.clientY||e.clientY!==Q){if(ue.ignoreInputTextSelection){var n=g("clientX",e),t=g("clientY",e),r=document.elementFromPoint(n,t);if(v(r))return}var o=te;c(!0),p(),N(),O(o);var a=u(V);$=g("pageX",e)-a.left,G=g("pageY",e)-a.top,E.add(ee||V,"gu-transit"),k(),A(e)}}}function S(e){if(!(ce.dragging&&z||t(e))){for(var n=e;e.parentElement&&t(e.parentElement)===!1;){if(ue.invalid(e,n))return;if(e=e.parentElement,!e)return}var r=e.parentElement;if(r&&!ue.invalid(e,n)){var o=ue.moves(e,r,n,m(e));if(o)return{item:e,source:r}}}}function C(e){var n=S(e);n&&O(n)}function O(e){F(e.item,e.source)&&(ee=e.item.cloneNode(!0),ce.emit("cloned",ee,e.item,"copy")),H=e.source,V=e.item,W=Z=m(e.item),ce.dragging=!0,ce.emit("drag",V,H)}function T(){return!1}function N(){if(ce.dragging){var e=ee||V;B(e,e.parentElement)}}function X(){te=!1,c(!0),p(!0)}function Y(e){if(X(),ce.dragging){var n=ee||V,t=g("clientX",e),r=g("clientY",e),o=a(z,t,r),i=R(o,t,r);i&&(ee&&ue.copySortSource||!ee||i!==H)?B(n,i):ue.removeOnSpill?P():D()}}function B(e,n){var t=e.parentElement;ee&&ue.copySortSource&&n===H&&t.removeChild(V),L(n)?ce.emit("cancel",e,H,H):ce.emit("drop",e,n,H,Z),I()}function P(){if(ce.dragging){var e=ee||V,n=e.parentElement;n&&n.removeChild(e),ce.emit(ee?"cancel":"remove",e,n,H),I()}}function D(e){if(ce.dragging){var n=arguments.length>0?e:ue.revertOnSpill,t=ee||V,r=t.parentElement;r===H&&ee&&r.removeChild(ee);var o=L(r);o===!1&&!ee&&n&&H.insertBefore(t,W),o||n?ce.emit("cancel",t,H,H):ce.emit("drop",t,r,H,Z),I()}}function I(){var e=ee||V;X(),q(),e&&E.rm(e,"gu-transit"),ne&&clearTimeout(ne),ce.dragging=!1,ie&&ce.emit("out",e,ie,H),ce.emit("dragend",e),H=V=ee=W=Z=ne=ie=null}function L(e,n){var t;return t=void 0!==n?n:z?Z:m(ee||V),e===H&&t===W}function R(e,n,r){function o(){var o=t(i);if(o===!1)return!1;var u=U(i,e),c=_(i,u,n,r),a=L(i,c);return a?!0:ue.accepts(V,i,H,c)}for(var i=e;i&&!o();)i=i.parentElement;return i}function A(e){function n(e){ce.emit(e,l,ie,H)}function t(){s&&n("over")}function r(){ie&&n("out")}if(z){e.preventDefault();var o=g("clientX",e),i=g("clientY",e),u=o-$,c=i-G;z.style.left=u+"px",z.style.top=c+"px";var l=ee||V,f=a(z,o,i),d=R(f,o,i),s=null!==d&&d!==ie;if((s||null===d)&&(r(),ie=d,t()),d===H&&ee&&!ue.copySortSource)return void(l.parentElement&&l.parentElement.removeChild(l));var v,p=U(d,f);if(null!==p)v=_(d,p,o,i);else{if(ue.revertOnSpill!==!0||ee)return void(ee&&l.parentElement&&l.parentElement.removeChild(l));v=W,d=H}(null===v||v!==l&&v!==m(l)&&v!==Z)&&(Z=v,d.insertBefore(l,v),ce.emit("shadow",l,d,H))}}function M(e){E.rm(e,"gu-hide")}function j(e){ce.dragging&&E.add(e,"gu-hide")}function k(){if(!z){var e=V.getBoundingClientRect();z=V.cloneNode(!0),z.style.width=d(e)+"px",z.style.height=s(e)+"px",E.rm(z,"gu-transit"),E.add(z,"gu-mirror"),ue.mirrorContainer.appendChild(z),o(oe,"add","mousemove",A),E.add(ue.mirrorContainer,"gu-unselectable"),ce.emit("cloned",z,V,"mirror")}}function q(){z&&(E.rm(ue.mirrorContainer,"gu-unselectable"),o(oe,"remove","mousemove",A),z.parentElement.removeChild(z),z=null)}function U(e,n){for(var t=n;t!==e&&t.parentElement!==e;)t=t.parentElement;return t===oe?null:t}function _(e,n,t,r){function o(){var n,o,i,u=e.children.length;for(n=0;u>n;n++){if(o=e.children[n],i=o.getBoundingClientRect(),c&&i.left>t)return o;if(!c&&i.top>r)return o}return null}function i(){var e=n.getBoundingClientRect();return u(c?t>e.left+d(e)/2:r>e.top+s(e)/2)}function u(e){return e?m(n):n}var c="horizontal"===ue.direction,a=n!==e?i():o();return a}function F(e,n){return"boolean"==typeof ue.copy?ue.copy:ue.copy(e,n)}var K=arguments.length;1===K&&Array.isArray(e)===!1&&(n=e,e=[]);var z,H,V,$,G,J,Q,W,Z,ee,ne,te,re=document.body,oe=document.documentElement,ie=null,ue=n||{};void 0===ue.moves&&(ue.moves=f),void 0===ue.accepts&&(ue.accepts=f),void 0===ue.invalid&&(ue.invalid=T),void 0===ue.containers&&(ue.containers=e||[]),void 0===ue.isContainer&&(ue.isContainer=l),void 0===ue.copy&&(ue.copy=!1),void 0===ue.copySortSource&&(ue.copySortSource=!1),void 0===ue.revertOnSpill&&(ue.revertOnSpill=!1),void 0===ue.removeOnSpill&&(ue.removeOnSpill=!1),void 0===ue.direction&&(ue.direction="vertical"),void 0===ue.ignoreInputTextSelection&&(ue.ignoreInputTextSelection=!0),void 0===ue.mirrorContainer&&(ue.mirrorContainer=re);var ce=h({containers:ue.containers,start:C,end:N,cancel:D,remove:P,destroy:y,dragging:!1});return ue.removeOnSpill===!0&&ce.on("over",M).on("out",j),r(),ce}function o(e,n,r,o){var i={mouseup:"touchend",mousedown:"touchstart",mousemove:"touchmove"},u={mouseup:"MSPointerUp",mousedown:"MSPointerDown",mousemove:"MSPointerMove"};t.navigator.msPointerEnabled&&y[n](e,u[r],o),y[n](e,i[r],o),y[n](e,r,o)}function i(e){if(void 0!==e.touches)return e.touches.length;if(void 0!==e.buttons)return e.buttons;if(void 0!==e.which)return e.which;var n=e.button;return void 0!==n?1&n?1:2&n?3:4&n?2:0:void 0}function u(e){var n=e.getBoundingClientRect();return{left:n.left+c("scrollLeft","pageXOffset"),top:n.top+c("scrollTop","pageYOffset")}}function c(e,n){if("undefined"!=typeof t[n])return t[n];var r=document.documentElement;if(r.clientHeight)return r[e];var o=document.body;return o[e]}function a(e,n,t){var r,o=e||{},i=o.className;return o.className+=" gu-hide",r=document.elementFromPoint(n,t),o.className=i,r}function l(){return!1}function f(){return!0}function d(e){return e.width||e.right-e.left}function s(e){return e.height||e.bottom-e.top}function v(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName||"SELECT"===e.tagName}function m(e){function n(){var n=e;do n=n.nextSibling;while(n&&1!==n.nodeType);return n}return e.nextElementSibling||n()}function p(e){return e.targetTouches&&e.targetTouches.length?e.targetTouches[0]:e.changedTouches&&e.changedTouches.length?e.changedTouches[0]:e}function g(e,n){var t=p(n),r={pageX:"clientX",pageY:"clientY"};return e in r&&!(e in t)&&r[e]in t&&(e=r[e]),t[e]}var h=e("contra/emitter"),y=e("crossvent"),E=e("./classes");n.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./classes":1,"contra/emitter":4,crossvent:8}],3:[function(e,n,t){"use strict";var r=e("ticky");n.exports=function(e,n,t){e&&r(function(){e.apply(t||null,n||[])})}},{ticky:6}],4:[function(e,n,t){"use strict";var r=e("atoa"),o=e("./debounce");n.exports=function(e,n){var t=n||{},i={};return void 0===e&&(e={}),e.on=function(n,t){return i[n]?i[n].push(t):i[n]=[t],e},e.once=function(n,t){return t._once=!0,e.on(n,t),e},e.off=function(n,t){var r=arguments.length;if(1===r)delete i[n];else if(0===r)i={};else{var o=i[n];if(!o)return e;o.splice(o.indexOf(t),1)}return e},e.emit=function(){var n=r(arguments);return e.emitterSnapshot(n.shift()).apply(this,n)},e.emitterSnapshot=function(n){var u=(i[n]||[]).slice(0);return function(){var i=r(arguments),c=this||e;if("error"===n&&t["throws"]!==!1&&!u.length)throw 1===i.length?i[0]:i;return u.forEach(function(r){t.async?o(r,i,c):r.apply(c,i),r._once&&e.off(n,r)}),e}},e}},{"./debounce":3,atoa:5}],5:[function(e,n,t){n.exports=function(e,n){return Array.prototype.slice.call(e,n)}},{}],6:[function(e,n,t){var r,o="function"==typeof setImmediate;r=o?function(e){setImmediate(e)}:function(e){setTimeout(e,0)},n.exports=r},{}],7:[function(e,n,t){(function(e){function t(){try{var e=new r("cat",{detail:{foo:"bar"}});return"cat"===e.type&&"bar"===e.detail.foo}catch(n){}return!1}var r=e.CustomEvent;n.exports=t()?r:"function"==typeof document.createEvent?function(e,n){var t=document.createEvent("CustomEvent");return n?t.initCustomEvent(e,n.bubbles,n.cancelable,n.detail):t.initCustomEvent(e,!1,!1,void 0),t}:function(e,n){var t=document.createEventObject();return t.type=e,n?(t.bubbles=Boolean(n.bubbles),t.cancelable=Boolean(n.cancelable),t.detail=n.detail):(t.bubbles=!1,t.cancelable=!1,t.detail=void 0),t}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],8:[function(e,n,t){(function(t){"use strict";function r(e,n,t,r){return e.addEventListener(n,t,r)}function o(e,n,t){return e.attachEvent("on"+n,l(e,n,t))}function i(e,n,t,r){return e.removeEventListener(n,t,r)}function u(e,n,t){var r=f(e,n,t);return r?e.detachEvent("on"+n,r):void 0}function c(e,n,t){function r(){var e;return m.createEvent?(e=m.createEvent("Event"),e.initEvent(n,!0,!0)):m.createEventObject&&(e=m.createEventObject()),e}function o(){return new s(n,{detail:t})}var i=-1===v.indexOf(n)?o():r();e.dispatchEvent?e.dispatchEvent(i):e.fireEvent("on"+n,i)}function a(e,n,r){return function(n){var o=n||t.event;o.target=o.target||o.srcElement,o.preventDefault=o.preventDefault||function(){o.returnValue=!1},o.stopPropagation=o.stopPropagation||function(){o.cancelBubble=!0},o.which=o.which||o.keyCode,r.call(e,o)}}function l(e,n,t){var r=f(e,n,t)||a(e,n,t);return h.push({wrapper:r,element:e,type:n,fn:t}),r}function f(e,n,t){var r=d(e,n,t);if(r){var o=h[r].wrapper;return h.splice(r,1),o}}function d(e,n,t){var r,o;for(r=0;r<h.length;r++)if(o=h[r],o.element===e&&o.type===n&&o.fn===t)return r}var s=e("custom-event"),v=e("./eventmap"),m=t.document,p=r,g=i,h=[];t.addEventListener||(p=o,g=u),n.exports={add:p,remove:g,fabricate:c}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./eventmap":9,"custom-event":7}],9:[function(e,n,t){(function(e){"use strict";var t=[],r="",o=/^on/;for(r in e)o.test(r)&&t.push(r.slice(2));n.exports=t}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[2])(2)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.dragula=e()}}(function(){return function e(n,t,r){function o(u,c){if(!t[u]){if(!n[u]){var a="function"==typeof require&&require;if(!c&&a)return a(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var l=t[u]={exports:{}};n[u][0].call(l.exports,function(e){var t=n[u][1][e];return o(t?t:e)},l,l.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,n,t){"use strict";function r(e){var n=u[e];return n?n.lastIndex=0:u[e]=n=new RegExp(c+e+a,"g"),n}function o(e,n){var t=e.className;t.length?r(n).test(t)||(e.className+=" "+n):e.className=n}function i(e,n){e.className=e.className.replace(r(n)," ").trim()}var u={},c="(?:^|\\s)",a="(?:\\s|$)";n.exports={add:o,rm:i}},{}],2:[function(e,n,t){(function(t){"use strict";function r(e,n){function t(e){return-1!==fe.containers.indexOf(e)||ae.isContainer(e)}function r(e){var n=e?"remove":"add";o(x,n,"mousedown",O),o(x,n,"mouseup",I)}function c(e){var n=e?"remove":"add";o(x,n,"mousemove",N)}function g(e){var n=e?"remove":"add";o(x,n,"selectstart",C),o(x,n,"click",C)}function b(){r(!0),I({})}function C(e){ue&&e.preventDefault()}function O(e){ee=e.clientX,ne=e.clientY;var n=1!==i(e)||e.metaKey||e.ctrlKey;if(!n){var t=e.target,r=T(t);r&&(ue=r,c(),"mousedown"===e.type&&(p(t)?t.focus():e.preventDefault()))}}function N(e){if(ue){if(0===i(e))return void I({});if(void 0===e.clientX||e.clientX!==ee||void 0===e.clientY||e.clientY!==ne){if(ae.ignoreInputTextSelection){var n=h("clientX",e),t=h("clientY",e),r=E.elementFromPoint(n,t);if(p(r))return}var o=ue;c(!0),g(),P(),Y(o);var a=u(Q);W=h("pageX",e)-a.left,Z=h("pageY",e)-a.top,w.add(oe||Q,"gu-transit"),F(),q(e)}}}function T(e){if(!(fe.dragging&&G||t(e))){for(var n=e;v(e)&&t(v(e))===!1;){if(ae.invalid(e,n))return;if(e=v(e),!e)return}var r=v(e);if(r&&!ae.invalid(e,n)){var o=ae.moves(e,r,n,m(e));if(o)return{item:e,source:r}}}}function X(e){var n=T(e);n&&Y(n)}function Y(e){V(e.item,e.source)&&(oe=e.item.cloneNode(!0),fe.emit("cloned",oe,e.item,"copy")),J=e.source,Q=e.item,te=re=m(e.item),fe.dragging=!0,fe.emit("drag",Q,J)}function B(){return!1}function P(){if(fe.dragging){var e=oe||Q;L(e,v(e))}}function D(){ue=!1,c(!0),g(!0)}function I(e){if(D(),fe.dragging){var n=oe||Q,t=h("clientX",e),r=h("clientY",e),o=a(G,t,r),i=k(o,t,r);i&&(oe&&ae.copySortSource||!oe||i!==J)?L(n,i):ae.removeOnSpill?R():A()}}function L(e,n){var t=v(e);oe&&ae.copySortSource&&n===J&&t.removeChild(Q),j(n)?fe.emit("cancel",e,J,J):fe.emit("drop",e,n,J,re),M()}function R(){if(fe.dragging){var e=oe||Q,n=v(e);n&&n.removeChild(e),fe.emit(oe?"cancel":"remove",e,n,J),M()}}function A(e){if(fe.dragging){var n=arguments.length>0?e:ae.revertOnSpill,t=oe||Q,r=v(t);r===J&&oe&&r.removeChild(oe);var o=j(r);o===!1&&!oe&&n&&J.insertBefore(t,te),o||n?fe.emit("cancel",t,J,J):fe.emit("drop",t,r,J,re),M()}}function M(){var e=oe||Q;D(),K(),e&&w.rm(e,"gu-transit"),ie&&clearTimeout(ie),fe.dragging=!1,ce&&fe.emit("out",e,ce,J),fe.emit("dragend",e),J=Q=oe=te=re=ie=ce=null}function j(e,n){var t;return t=void 0!==n?n:G?re:m(oe||Q),e===J&&t===te}function k(e,n,r){function o(){var o=t(i);if(o===!1)return!1;var u=z(i,e),c=H(i,u,n,r),a=j(i,c);return a?!0:ae.accepts(Q,i,J,c)}for(var i=e;i&&!o();)i=v(i);return i}function q(e){function n(e){fe.emit(e,f,ce,J)}function t(){s&&n("over")}function r(){ce&&n("out")}if(G){e.preventDefault();var o=h("clientX",e),i=h("clientY",e),u=o-W,c=i-Z;G.style.left=u+"px",G.style.top=c+"px";var f=oe||Q,l=a(G,o,i),d=k(l,o,i),s=null!==d&&d!==ce;(s||null===d)&&(r(),ce=d,t());var p=v(f);if(d===J&&oe&&!ae.copySortSource)return void(p&&p.removeChild(f));var g,y=z(d,l);if(null!==y)g=H(d,y,o,i);else{if(ae.revertOnSpill!==!0||oe)return void(oe&&p&&p.removeChild(f));g=te,d=J}(null===g||g!==f&&g!==m(f)&&g!==re)&&(re=g,d.insertBefore(f,g),fe.emit("shadow",f,d,J))}}function U(e){w.rm(e,"gu-hide")}function _(e){fe.dragging&&w.add(e,"gu-hide")}function F(){if(!G){var e=Q.getBoundingClientRect();G=Q.cloneNode(!0),G.style.width=d(e)+"px",G.style.height=s(e)+"px",w.rm(G,"gu-transit"),w.add(G,"gu-mirror"),ae.mirrorContainer.appendChild(G),o(x,"add","mousemove",q),w.add(ae.mirrorContainer,"gu-unselectable"),fe.emit("cloned",G,Q,"mirror")}}function K(){G&&(w.rm(ae.mirrorContainer,"gu-unselectable"),o(x,"remove","mousemove",q),v(G).removeChild(G),G=null)}function z(e,n){for(var t=n;t!==e&&v(t)!==e;)t=v(t);return t===x?null:t}function H(e,n,t,r){function o(){var n,o,i,u=e.children.length;for(n=0;u>n;n++){if(o=e.children[n],i=o.getBoundingClientRect(),c&&i.left>t)return o;if(!c&&i.top>r)return o}return null}function i(){var e=n.getBoundingClientRect();return u(c?t>e.left+d(e)/2:r>e.top+s(e)/2)}function u(e){return e?m(n):n}var c="horizontal"===ae.direction,a=n!==e?i():o();return a}function V(e,n){return"boolean"==typeof ae.copy?ae.copy:ae.copy(e,n)}var $=arguments.length;1===$&&Array.isArray(e)===!1&&(n=e,e=[]);var G,J,Q,W,Z,ee,ne,te,re,oe,ie,ue,ce=null,ae=n||{};void 0===ae.moves&&(ae.moves=l),void 0===ae.accepts&&(ae.accepts=l),void 0===ae.invalid&&(ae.invalid=B),void 0===ae.containers&&(ae.containers=e||[]),void 0===ae.isContainer&&(ae.isContainer=f),void 0===ae.copy&&(ae.copy=!1),void 0===ae.copySortSource&&(ae.copySortSource=!1),void 0===ae.revertOnSpill&&(ae.revertOnSpill=!1),void 0===ae.removeOnSpill&&(ae.removeOnSpill=!1),void 0===ae.direction&&(ae.direction="vertical"),void 0===ae.ignoreInputTextSelection&&(ae.ignoreInputTextSelection=!0),void 0===ae.mirrorContainer&&(ae.mirrorContainer=S);var fe=y({containers:ae.containers,start:X,end:P,cancel:A,remove:R,destroy:b,dragging:!1});return ae.removeOnSpill===!0&&fe.on("over",U).on("out",_),r(),fe}function o(e,n,r,o){var i={mouseup:"touchend",mousedown:"touchstart",mousemove:"touchmove"},u={mouseup:"MSPointerUp",mousedown:"MSPointerDown",mousemove:"MSPointerMove"};t.navigator.msPointerEnabled&&b[n](e,u[r],o),b[n](e,i[r],o),b[n](e,r,o)}function i(e){if(void 0!==e.touches)return e.touches.length;if(void 0!==e.buttons)return e.buttons;if(void 0!==e.which)return e.which;var n=e.button;return void 0!==n?1&n?1:2&n?3:4&n?2:0:void 0}function u(e){var n=e.getBoundingClientRect();return{left:n.left+c("scrollLeft","pageXOffset"),top:n.top+c("scrollTop","pageYOffset")}}function c(e,n){return"undefined"!=typeof t[n]?t[n]:x.clientHeight?x[e]:S[e]}function a(e,n,t){var r,o=e||{},i=o.className;return o.className+=" gu-hide",r=E.elementFromPoint(n,t),o.className=i,r}function f(){return!1}function l(){return!0}function d(e){return e.width||e.right-e.left}function s(e){return e.height||e.bottom-e.top}function v(e){return e.parentNode===E?null:e.parentNode}function p(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName||"SELECT"===e.tagName}function m(e){function n(){var n=e;do n=n.nextSibling;while(n&&1!==n.nodeType);return n}return e.nextElementSibling||n()}function g(e){return e.targetTouches&&e.targetTouches.length?e.targetTouches[0]:e.changedTouches&&e.changedTouches.length?e.changedTouches[0]:e}function h(e,n){var t=g(n),r={pageX:"clientX",pageY:"clientY"};return e in r&&!(e in t)&&r[e]in t&&(e=r[e]),t[e]}var y=e("contra/emitter"),b=e("crossvent"),w=e("./classes"),E=document,x=E.documentElement,S=E.body;n.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./classes":1,"contra/emitter":4,crossvent:8}],3:[function(e,n,t){"use strict";var r=e("ticky");n.exports=function(e,n,t){e&&r(function(){e.apply(t||null,n||[])})}},{ticky:6}],4:[function(e,n,t){"use strict";var r=e("atoa"),o=e("./debounce");n.exports=function(e,n){var t=n||{},i={};return void 0===e&&(e={}),e.on=function(n,t){return i[n]?i[n].push(t):i[n]=[t],e},e.once=function(n,t){return t._once=!0,e.on(n,t),e},e.off=function(n,t){var r=arguments.length;if(1===r)delete i[n];else if(0===r)i={};else{var o=i[n];if(!o)return e;o.splice(o.indexOf(t),1)}return e},e.emit=function(){var n=r(arguments);return e.emitterSnapshot(n.shift()).apply(this,n)},e.emitterSnapshot=function(n){var u=(i[n]||[]).slice(0);return function(){var i=r(arguments),c=this||e;if("error"===n&&t["throws"]!==!1&&!u.length)throw 1===i.length?i[0]:i;return u.forEach(function(r){t.async?o(r,i,c):r.apply(c,i),r._once&&e.off(n,r)}),e}},e}},{"./debounce":3,atoa:5}],5:[function(e,n,t){n.exports=function(e,n){return Array.prototype.slice.call(e,n)}},{}],6:[function(e,n,t){var r,o="function"==typeof setImmediate;r=o?function(e){setImmediate(e)}:function(e){setTimeout(e,0)},n.exports=r},{}],7:[function(e,n,t){(function(e){function t(){try{var e=new r("cat",{detail:{foo:"bar"}});return"cat"===e.type&&"bar"===e.detail.foo}catch(n){}return!1}var r=e.CustomEvent;n.exports=t()?r:"function"==typeof document.createEvent?function(e,n){var t=document.createEvent("CustomEvent");return n?t.initCustomEvent(e,n.bubbles,n.cancelable,n.detail):t.initCustomEvent(e,!1,!1,void 0),t}:function(e,n){var t=document.createEventObject();return t.type=e,n?(t.bubbles=Boolean(n.bubbles),t.cancelable=Boolean(n.cancelable),t.detail=n.detail):(t.bubbles=!1,t.cancelable=!1,t.detail=void 0),t}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],8:[function(e,n,t){(function(t){"use strict";function r(e,n,t,r){return e.addEventListener(n,t,r)}function o(e,n,t){return e.attachEvent("on"+n,f(e,n,t))}function i(e,n,t,r){return e.removeEventListener(n,t,r)}function u(e,n,t){var r=l(e,n,t);return r?e.detachEvent("on"+n,r):void 0}function c(e,n,t){function r(){var e;return p.createEvent?(e=p.createEvent("Event"),e.initEvent(n,!0,!0)):p.createEventObject&&(e=p.createEventObject()),e}function o(){return new s(n,{detail:t})}var i=-1===v.indexOf(n)?o():r();e.dispatchEvent?e.dispatchEvent(i):e.fireEvent("on"+n,i)}function a(e,n,r){return function(n){var o=n||t.event;o.target=o.target||o.srcElement,o.preventDefault=o.preventDefault||function(){o.returnValue=!1},o.stopPropagation=o.stopPropagation||function(){o.cancelBubble=!0},o.which=o.which||o.keyCode,r.call(e,o)}}function f(e,n,t){var r=l(e,n,t)||a(e,n,t);return h.push({wrapper:r,element:e,type:n,fn:t}),r}function l(e,n,t){var r=d(e,n,t);if(r){var o=h[r].wrapper;return h.splice(r,1),o}}function d(e,n,t){var r,o;for(r=0;r<h.length;r++)if(o=h[r],o.element===e&&o.type===n&&o.fn===t)return r}var s=e("custom-event"),v=e("./eventmap"),p=t.document,m=r,g=i,h=[];t.addEventListener||(m=o,g=u),n.exports={add:m,remove:g,fabricate:c}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./eventmap":9,"custom-event":7}],9:[function(e,n,t){(function(e){"use strict";var t=[],r="",o=/^on/;for(r in e)o.test(r)&&t.push(r.slice(2));n.exports=t}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[2])(2)}); |
@@ -6,2 +6,5 @@ 'use strict'; | ||
var classes = require('./classes'); | ||
var doc = document; | ||
var documentElement = doc.documentElement; | ||
var body = doc.body; | ||
@@ -14,4 +17,2 @@ function dragula (initialContainers, options) { | ||
} | ||
var body = document.body; | ||
var documentElement = document.documentElement; | ||
var _mirror; // mirror image | ||
@@ -134,3 +135,3 @@ var _source; // source container | ||
var clientY = getCoord('clientY', e); | ||
var elementBehindCursor = document.elementFromPoint(clientX, clientY); | ||
var elementBehindCursor = doc.elementFromPoint(clientX, clientY); | ||
if (isInput(elementBehindCursor)) { | ||
@@ -164,7 +165,7 @@ return; | ||
var handle = item; | ||
while (item.parentElement && isContainer(item.parentElement) === false) { | ||
while (getParent(item) && isContainer(getParent(item)) === false) { | ||
if (o.invalid(item, handle)) { | ||
return; | ||
} | ||
item = item.parentElement; // drag target should be a top element | ||
item = getParent(item); // drag target should be a top element | ||
if (!item) { | ||
@@ -174,3 +175,3 @@ return; | ||
} | ||
var source = item.parentElement; | ||
var source = getParent(item); | ||
if (!source) { | ||
@@ -224,3 +225,3 @@ return; | ||
var item = _copy || _item; | ||
drop(item, item.parentElement); | ||
drop(item, getParent(item)); | ||
} | ||
@@ -255,3 +256,3 @@ | ||
function drop (item, target) { | ||
var parent = item.parentElement; | ||
var parent = getParent(item); | ||
if (_copy && o.copySortSource && target === _source) { | ||
@@ -273,3 +274,3 @@ parent.removeChild(_item); | ||
var item = _copy || _item; | ||
var parent = item.parentElement; | ||
var parent = getParent(item); | ||
if (parent) { | ||
@@ -288,3 +289,3 @@ parent.removeChild(item); | ||
var item = _copy || _item; | ||
var parent = item.parentElement; | ||
var parent = getParent(item); | ||
if (parent === _source && _copy) { | ||
@@ -338,3 +339,3 @@ parent.removeChild(_copy); | ||
while (target && !accepted()) { | ||
target = target.parentElement; | ||
target = getParent(target); | ||
} | ||
@@ -382,5 +383,6 @@ return target; | ||
} | ||
var parent = getParent(item); | ||
if (dropTarget === _source && _copy && !o.copySortSource) { | ||
if (item.parentElement) { | ||
item.parentElement.removeChild(item); | ||
if (parent) { | ||
parent.removeChild(item); | ||
} | ||
@@ -397,4 +399,4 @@ return; | ||
} else { | ||
if (_copy && item.parentElement) { | ||
item.parentElement.removeChild(item); | ||
if (_copy && parent) { | ||
parent.removeChild(item); | ||
} | ||
@@ -446,3 +448,3 @@ return; | ||
touchy(documentElement, 'remove', 'mousemove', drag); | ||
_mirror.parentElement.removeChild(_mirror); | ||
getParent(_mirror).removeChild(_mirror); | ||
_mirror = null; | ||
@@ -454,4 +456,4 @@ } | ||
var immediate = target; | ||
while (immediate !== dropTarget && immediate.parentElement !== dropTarget) { | ||
immediate = immediate.parentElement; | ||
while (immediate !== dropTarget && getParent(immediate) !== dropTarget) { | ||
immediate = getParent(immediate); | ||
} | ||
@@ -541,7 +543,5 @@ if (immediate === documentElement) { | ||
} | ||
var documentElement = document.documentElement; | ||
if (documentElement.clientHeight) { | ||
return documentElement[scrollProp]; | ||
} | ||
var body = document.body; | ||
return body[scrollProp]; | ||
@@ -555,3 +555,3 @@ } | ||
p.className += ' gu-hide'; | ||
el = document.elementFromPoint(x, y); | ||
el = doc.elementFromPoint(x, y); | ||
p.className = state; | ||
@@ -565,2 +565,3 @@ return el; | ||
function getRectHeight (rect) { return rect.height || (rect.bottom - rect.top); } | ||
function getParent (el) { return el.parentNode === doc ? null : el.parentNode; } | ||
function isInput (el) { return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT'; } | ||
@@ -567,0 +568,0 @@ |
{ | ||
"name": "dragula", | ||
"version": "3.5.3", | ||
"version": "3.5.4", | ||
"description": "Drag and drop so simple it hurts", | ||
@@ -10,4 +10,4 @@ "main": "dragula.js", | ||
"deploy-plugins": "npm run deploy-react ; npm run deploy-angular ; cd ../dragula", | ||
"deploy-react": "cd ../react-dragula ; npm i -S dragula@* ; git commit package.json -m 'bumped dragula version'; npm run deploy", | ||
"deploy-angular": "cd ../angular-dragula ; npm i -S dragula@* ; git commit package.json -m 'bumped dragula version'; npm run deploy", | ||
"deploy-react": "cd ../react-dragula ; git pull ; npm i -S dragula@* ; git commit package.json -m 'bumped dragula version'; npm run deploy", | ||
"deploy-angular": "cd ../angular-dragula ; git pull ; npm i -S dragula@* ; git commit package.json -m 'bumped dragula version'; npm run deploy", | ||
"deployment": "git add dist && npm version ${BUMP:-\"patch\"} --no-git-tag-version && git add package.json && git commit -am \"Autogenerated pre-deployment commit\" && bower version ${BUMP:-\"patch\"} && git reset HEAD~2 && git add . && git commit -am \"Release $(cat package.json | jq -r .version)\" && git push --tags && npm publish && git push", | ||
@@ -14,0 +14,0 @@ "scripts": "jshint . && browserify -s dragula -do dist/dragula.js dragula.js && uglifyjs -m -c -o dist/dragula.min.js dist/dragula.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3034
843544