Skip to content

Commit

Permalink
Build for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Malone committed Feb 23, 2016
1 parent 9bd23d8 commit bc11802
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 183 deletions.
71 changes: 36 additions & 35 deletions dist/amd/dragula.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/class-call-check', 'aurelia-dependency-injection', './touchy', './options', './util', 'contra', 'crossvent', './classes'], function (exports, _babelRuntimeHelpersCreateClass, _babelRuntimeHelpersClassCallCheck, _aureliaDependencyInjection, _touchy, _options, _util, _contra, _crossvent, _classes) {
define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/class-call-check', 'aurelia-dependency-injection', './touchy', './options', './util', './emitter', './classes'], function (exports, _babelRuntimeHelpersCreateClass, _babelRuntimeHelpersClassCallCheck, _aureliaDependencyInjection, _touchy, _options, _util, _emitter, _classes) {
'use strict';

Object.defineProperty(exports, '__esModule', {
Expand All @@ -11,18 +11,20 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/

var len = arguments.length;
this.options = options || new _options.Options();
this.drake = (0, _contra.emitter)({
this.emitter = new _emitter.Emitter();
this.drake = {
containers: this.options.containers,
start: this.manualStart.bind(this),
end: this.end.bind(this),
cancel: this.cancel.bind(this),
remove: this.remove.bind(this),
destroy: this.destroy.bind(this),
dragging: false
});
};

if (this.options.removeOnSpill === true) {
this.drake.on('over', spillOver).on('out', spillOut);
this.emitter.on('over', this.spillOver.bind(this));
this.emitter.on('out', this.spillOut.bind(this));
}

this._events();
Expand All @@ -45,7 +47,7 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
(0, _babelRuntimeHelpersCreateClass['default'])(Dragula, [{
key: 'on',
value: function on(eventName, callback) {
this.drake.on(eventName, callback);
this.emitter.on(eventName, callback);
}
}, {
key: 'isContainer',
Expand All @@ -55,22 +57,21 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
}, {
key: '_events',
value: function _events(remove) {
var op = remove ? 'remove' : 'add';
var op = remove ? 'removeEventListener' : 'addEventListener';
(0, _touchy.touchy)(document.documentElement, op, 'mousedown', this._grab.bind(this));
(0, _touchy.touchy)(document.documentElement, op, 'mouseup', this._release.bind(this));
}
}, {
key: '_eventualMovements',
value: function _eventualMovements(remove) {
var op = remove ? 'remove' : 'add';
var op = remove ? 'removeEventListener' : 'addEventListener';
(0, _touchy.touchy)(document.documentElement, op, 'mousemove', this._startBecauseMouseMoved.bind(this));
}
}, {
key: '_movements',
value: function _movements(remove) {
var op = remove ? 'remove' : 'add';
_crossvent[op](document.documentElement, 'selectstart', this._preventGrabbed);
_crossvent[op](document.documentElement, 'click', this._preventGrabbed);
var op = remove ? 'removeEventListener' : 'addEventListener';
document.documentElement[op]('click', this._preventGrabbed);
}
}, {
key: 'destroy',
Expand Down Expand Up @@ -197,15 +198,15 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
value: function start(context) {
if (this._isCopy(context.item, context.source)) {
this._copy = context.item.cloneNode(true);
this.drake.emit('cloned', this._copy, context.item, 'copy');
this.emitter.emit('cloned', this._copy, context.item, 'copy');
}

this._source = context.source;
this._item = context.item;
this._initialSibling = this._currentSibling = _util.Util.nextEl(context.item);

this.drake.dragging = true;
this.drake.emit('drag', this._item, this._source);
this.emitter.emit('drag', this._item, this._source);
}
}, {
key: 'end',
Expand Down Expand Up @@ -252,9 +253,9 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
parent.removeChild(_item);
}
if (this._isInitialPlacement(target)) {
this.drake.emit('cancel', item, this._source, this._source);
this.emitter.emit('cancel', item, this._source, this._source);
} else {
this.drake.emit('drop', item, target, this._source, this._currentSibling);
this.emitter.emit('drop', item, target, this._source, this._currentSibling);
}
this._cleanup();
}
Expand All @@ -269,7 +270,7 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
if (parent) {
parent.removeChild(item);
}
this.drake.emit(this._copy ? 'cancel' : 'remove', item, parent, this._source);
this.emitter.emit(this._copy ? 'cancel' : 'remove', item, parent, this._source);
this._cleanup();
}
}, {
Expand All @@ -289,9 +290,9 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
this._source.insertBefore(item, this._initialSibling);
}
if (initial || reverts) {
this.drake.emit('cancel', item, this._source, this._source);
this.emitter.emit('cancel', item, this._source, this._source);
} else {
this.drake.emit('drop', item, parent, this._source, this._currentSibling);
this.emitter.emit('drop', item, parent, this._source, this._currentSibling);
}
this._cleanup();
}
Expand All @@ -309,9 +310,9 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
}
this.drake.dragging = false;
if (this._lastDropTarget) {
this.drake.emit('out', item, this._lastDropTarget, this._source);
this.emitter.emit('out', item, this._lastDropTarget, this._source);
}
this.drake.emit('dragend', item);
this.emitter.emit('dragend', item);
this._source = this._item = this._copy = this._initialSibling = this._currentSibling = this._renderTimer = this._lastDropTarget = null;
}
}, {
Expand Down Expand Up @@ -364,7 +365,7 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
e.preventDefault();

var moved = function moved(type) {
_this2.drake.emit(type, item, _this2._lastDropTarget, _this2._source);
_this2.emitter.emit(type, item, _this2._lastDropTarget, _this2._source);
};
var over = function over() {
if (changed) {
Expand Down Expand Up @@ -417,7 +418,7 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
if (reference === null && changed || reference !== item && reference !== _util.Util.nextEl(item)) {
this._currentSibling = reference;
dropTarget.insertBefore(item, reference);
this.drake.emit('shadow', item, dropTarget, this._source);
this.emitter.emit('shadow', item, dropTarget, this._source);
}
}
}, {
Expand Down Expand Up @@ -445,28 +446,24 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
_classes.rm(this._mirror, 'gu-transit');
_classes.add(this._mirror, 'gu-mirror');
this.options.mirrorContainer.appendChild(this._mirror);
(0, _touchy.touchy)(document.documentElement, 'add', 'mousemove', this.drag.bind(this));
(0, _touchy.touchy)(document.documentElement, 'addEventListener', 'mousemove', this.drag.bind(this));
_classes.add(this.options.mirrorContainer, 'gu-unselectable');
this.drake.emit('cloned', this._mirror, this._item, 'mirror');
this.emitter.emit('cloned', this._mirror, this._item, 'mirror');
}
}, {
key: 'removeMirrorImage',
value: function removeMirrorImage() {
if (this._mirror) {
_classes.rm(this.options.mirrorContainer, 'gu-unselectable');
(0, _touchy.touchy)(document.documentElement, 'remove', 'mousemove', this.drag.bind(this));
(0, _touchy.touchy)(document.documentElement, 'removeEventListener', 'mousemove', this.drag.bind(this));
_util.Util.getParent(this._mirror).removeChild(this._mirror);
this._mirror = null;
}
}
}, {
key: 'getReference',
value: function getReference(dropTarget, target, x, y) {
var horizontal = this.options.direction === 'horizontal';
var reference = target !== dropTarget ? inside() : outside();
return reference;

outside = function () {
var outside = function outside() {
var len = dropTarget.children.length;
var i = undefined;
var el = undefined;
Expand All @@ -484,17 +481,21 @@ define(['exports', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/
return null;
};

inside = function () {
var resolve = function resolve(after) {
return after ? _util.Util.nextEl(target) : target;
};

var inside = function inside() {
var rect = target.getBoundingClientRect();
if (horizontal) {
return resolve(x > rect.left + getRectWidth(rect) / 2);
return resolve(x > rect.left + _util.Util.getRectWidth(rect) / 2);
}
return resolve(y > rect.top + getRectHeight(rect) / 2);
return resolve(y > rect.top + _util.Util.getRectHeight(rect) / 2);
};

resolve = function (after) {
return after ? _util.Util.nextEl(target) : target;
};
var horizontal = this.options.direction === 'horizontal';
var reference = target !== dropTarget ? inside() : outside();
return reference;
}
}, {
key: '_isCopy',
Expand Down
91 changes: 91 additions & 0 deletions dist/amd/emitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
define(['exports', 'babel-runtime/helpers/class-call-check', 'babel-runtime/helpers/create-class', 'babel-runtime/helpers/slice', 'babel-runtime/helpers/to-consumable-array'], function (exports, _babelRuntimeHelpersClassCallCheck, _babelRuntimeHelpersCreateClass, _babelRuntimeHelpersSlice, _babelRuntimeHelpersToConsumableArray) {
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

var EventListener = function EventListener(func) {
var once = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
(0, _babelRuntimeHelpersClassCallCheck['default'])(this, EventListener);

this.func = func;
this.once = once;
};

var Emitter = (function () {
function Emitter(options) {
(0, _babelRuntimeHelpersClassCallCheck['default'])(this, Emitter);

this.options = options || {};
this.events = {};
}

(0, _babelRuntimeHelpersCreateClass['default'])(Emitter, [{
key: 'on',
value: function on(type, fn) {
var once = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];

var newEvent = new EventListener(fn, once);
if (this.events[type] === undefined) {
this.events[type] = [];
}
this.events[type].push(newEvent);
}
}, {
key: 'once',
value: function once(type, fn) {
this.on(type, fn, true);
}
}, {
key: 'off',
value: function off(type, fn) {
if (arguments.length === 1) {
delete this.events[type];
} else if (arguments.length === 0) {
this.events = {};
} else {
var eventList = this.events[type];
if (eventList) {
var index = eventList.findIndex(function (x) {
return x.func === fn;
});
if (index >= 0) eventList.splice(index, 1);
}
}
}
}, {
key: 'emit',
value: function emit() {
var args = [].concat(_babelRuntimeHelpersSlice['default'].call(arguments));
return this._emitterSnapshot(args.shift()).apply(this, args);
}
}, {
key: '_emitterSnapshot',
value: function _emitterSnapshot(type) {
var et = (this.events[type] || []).slice(0);
return function () {
var _this = this;

var args = arguments ? [].concat(_babelRuntimeHelpersSlice['default'].call(arguments)) : [];
if (type === 'error' && this.options.throws !== false && !et.length) {
throw args.length === 1 ? args[0] : args;
}
et.forEach(function (listener) {
if (_this.options.async) {
debounce.apply(undefined, [listener.func].concat((0, _babelRuntimeHelpersToConsumableArray['default'])(args)));
} else {
listener.func.apply(listener, (0, _babelRuntimeHelpersToConsumableArray['default'])(args));
}
if (listener.once) {
_this.off(type, listener);
}
});
};
}
}]);
return Emitter;
})();

exports.Emitter = Emitter;
});
1 change: 1 addition & 0 deletions dist/amd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(['exports', './options', './dragula'], function (exports, _options, _drag
});
exports.configure = configure;
exports.Dragula = _dragula.Dragula;
exports.Options = _options.Options;

function configure(config, callback) {
var defaults = new _options.Options();
Expand Down
11 changes: 5 additions & 6 deletions dist/amd/touchy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
define(['exports', 'crossvent'], function (exports, _crossvent) {
define(['exports'], function (exports) {
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});
exports.touchy = touchy;

var touch = {
mouseup: 'touchend',
mousedown: 'touchstart',
Expand All @@ -24,12 +23,12 @@ define(['exports', 'crossvent'], function (exports, _crossvent) {

function touchy(el, op, type, fn) {
if (window.navigator.pointerEnabled) {
_crossvent[op](el, pointers[type], fn);
el[op](pointers[type], fn);
} else if (window.navigator.msPointerEnabled) {
_crossvent[op](el, microsoft[type], fn);
el[op](microsoft[type], fn);
} else {
_crossvent[op](el, touch[type], fn);
_crossvent[op](el, type, fn);
el[op](touch[type], fn);
el[op](type, fn);
}
}
});
Loading

0 comments on commit bc11802

Please sign in to comment.