dragula.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. (function(f){
  2. if(typeof exports==="object"&&typeof module!=="undefined"){
  3. module.exports=f()
  4. }else if(typeof define==="function"&&define.amd){
  5. define([],f)
  6. }else{
  7. var g;
  8. if(typeof window!=="undefined")
  9. {
  10. g=window
  11. }else if(typeof global!=="undefined"){
  12. g=global
  13. }else if(typeof self!=="undefined"){
  14. g=self}else{
  15. g=this
  16. }
  17. g.dragula = f()
  18. }
  19. })
  20. (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){
  21. 'use strict';
  22. var cache = {};
  23. var start = '(?:^|\\s)';
  24. var end = '(?:\\s|$)';
  25. function lookupClass (className) {
  26. var cached = cache[className];
  27. if (cached) {
  28. cached.lastIndex = 0;
  29. } else {
  30. cache[className] = cached = new RegExp(start + className + end, 'g');
  31. }
  32. return cached;
  33. }
  34. function addClass (el, className) {
  35. var current = el.className;
  36. if (!current.length) {
  37. el.className = className;
  38. } else if (!lookupClass(className).test(current)) {
  39. el.className += ' ' + className;
  40. }
  41. }
  42. function rmClass (el, className) {
  43. el.className = el.className.replace(lookupClass(className), ' ').trim();
  44. }
  45. module.exports = {
  46. add: addClass,
  47. rm: rmClass
  48. };
  49. },{}],2:[function(require,module,exports){
  50. (function (global){
  51. 'use strict';
  52. var emitter = require('contra/emitter');
  53. var crossvent = require('crossvent');
  54. var classes = require('./classes');
  55. var doc = document;
  56. var documentElement = doc.documentElement;
  57. function dragula (initialContainers, options) {
  58. var len = arguments.length;
  59. if (len === 1 && Array.isArray(initialContainers) === false) {
  60. options = initialContainers;
  61. initialContainers = [];
  62. }
  63. var _mirror; // mirror image
  64. var _source; // source container
  65. var _item; // item being dragged
  66. var _offsetX; // reference x
  67. var _offsetY; // reference y
  68. var _moveX; // reference move x
  69. var _moveY; // reference move y
  70. var _initialSibling; // reference sibling when grabbed
  71. var _currentSibling; // reference sibling now
  72. var _copy; // item used for copying
  73. var _renderTimer; // timer for setTimeout renderMirrorImage
  74. var _lastDropTarget = null; // last container item was over
  75. var _grabbed; // holds mousedown context until first mousemove
  76. var o = options || {};
  77. if (o.moves === void 0) { o.moves = always; }
  78. if (o.accepts === void 0) { o.accepts = always; }
  79. if (o.invalid === void 0) { o.invalid = invalidTarget; }
  80. if (o.containers === void 0) { o.containers = initialContainers || []; }
  81. if (o.isContainer === void 0) { o.isContainer = never; }
  82. if (o.copy === void 0) { o.copy = false; }
  83. if (o.copySortSource === void 0) { o.copySortSource = false; }
  84. if (o.revertOnSpill === void 0) { o.revertOnSpill = false; }
  85. if (o.removeOnSpill === void 0) { o.removeOnSpill = false; }
  86. if (o.direction === void 0) { o.direction = 'vertical'; }
  87. if (o.ignoreInputTextSelection === void 0) { o.ignoreInputTextSelection = true; }
  88. if (o.mirrorContainer === void 0) { o.mirrorContainer = doc.body; }
  89. var drake = emitter({
  90. containers: o.containers,
  91. start: manualStart,
  92. end: end,
  93. cancel: cancel,
  94. remove: remove,
  95. destroy: destroy,
  96. canMove: canMove,
  97. dragging: false
  98. });
  99. if (o.removeOnSpill === true) {
  100. drake.on('over', spillOver).on('out', spillOut);
  101. }
  102. events();
  103. return drake;
  104. function isContainer (el) {
  105. return drake.containers.indexOf(el) !== -1 || o.isContainer(el);
  106. }
  107. function events (remove) {
  108. var op = remove ? 'remove' : 'add';
  109. touchy(documentElement, op, 'mousedown', grab);
  110. touchy(documentElement, op, 'mouseup', release);
  111. }
  112. function eventualMovements (remove) {
  113. var op = remove ? 'remove' : 'add';
  114. touchy(documentElement, op, 'mousemove', startBecauseMouseMoved);
  115. }
  116. function movements (remove) {
  117. var op = remove ? 'remove' : 'add';
  118. crossvent[op](documentElement, 'selectstart', preventGrabbed); // IE8
  119. crossvent[op](documentElement, 'click', preventGrabbed);
  120. }
  121. function destroy () {
  122. events(true);
  123. release({});
  124. }
  125. function preventGrabbed (e) {
  126. if (_grabbed) {
  127. e.preventDefault();
  128. }
  129. }
  130. function grab (e) {
  131. _moveX = e.clientX;
  132. _moveY = e.clientY;
  133. var ignore = whichMouseButton(e) !== 1 || e.metaKey || e.ctrlKey;
  134. if (ignore) {
  135. return; // we only care about honest-to-god left clicks and touch events
  136. }
  137. var item = e.target;
  138. var context = canStart(item);
  139. if (!context) {
  140. return;
  141. }
  142. _grabbed = context;
  143. eventualMovements();
  144. if (e.type === 'mousedown') {
  145. if (isInput(item)) { // see also: https://github.com/bevacqua/dragula/issues/208
  146. item.focus(); // fixes https://github.com/bevacqua/dragula/issues/176
  147. } else {
  148. e.preventDefault(); // fixes https://github.com/bevacqua/dragula/issues/155
  149. }
  150. }
  151. }
  152. function startBecauseMouseMoved (e) {
  153. if (!_grabbed) {
  154. return;
  155. }
  156. if (whichMouseButton(e) === 0) {
  157. release({});
  158. return; // when text is selected on an input and then dragged, mouseup doesn't fire. this is our only hope
  159. }
  160. // truthy check fixes #239, equality fixes #207
  161. if (e.clientX !== void 0 && e.clientX === _moveX && e.clientY !== void 0 && e.clientY === _moveY) {
  162. return;
  163. }
  164. if (o.ignoreInputTextSelection) {
  165. var clientX = getCoord('clientX', e);
  166. var clientY = getCoord('clientY', e);
  167. var elementBehindCursor = doc.elementFromPoint(clientX, clientY);
  168. if (isInput(elementBehindCursor)) {
  169. return;
  170. }
  171. }
  172. var grabbed = _grabbed; // call to end() unsets _grabbed
  173. eventualMovements(true);
  174. movements();
  175. end();
  176. start(grabbed);
  177. var offset = getOffset(_item);
  178. _offsetX = getCoord('pageX', e) - offset.left;
  179. _offsetY = getCoord('pageY', e) - offset.top;
  180. classes.add(_copy || _item, 'gu-transit');
  181. renderMirrorImage();
  182. drag(e);
  183. }
  184. function canStart (item) {
  185. if (drake.dragging && _mirror) {
  186. return;
  187. }
  188. if (isContainer(item)) {
  189. return; // don't drag container itself
  190. }
  191. var handle = item;
  192. while (getParent(item) && isContainer(getParent(item)) === false) {
  193. if (o.invalid(item, handle)) {
  194. return;
  195. }
  196. item = getParent(item); // drag target should be a top element
  197. if (!item) {
  198. return;
  199. }
  200. }
  201. var source = getParent(item);
  202. if (!source) {
  203. return;
  204. }
  205. if (o.invalid(item, handle)) {
  206. return;
  207. }
  208. var movable = o.moves(item, source, handle, nextEl(item));
  209. if (!movable) {
  210. return;
  211. }
  212. return {
  213. item: item,
  214. source: source
  215. };
  216. }
  217. function canMove (item) {
  218. return !!canStart(item);
  219. }
  220. function manualStart (item) {
  221. var context = canStart(item);
  222. if (context) {
  223. start(context);
  224. }
  225. }
  226. function start (context) {
  227. if (isCopy(context.item, context.source)) {
  228. _copy = context.item.cloneNode(true);
  229. drake.emit('cloned', _copy, context.item, 'copy');
  230. }
  231. _source = context.source;
  232. _item = context.item;
  233. _initialSibling = _currentSibling = nextEl(context.item);
  234. drake.dragging = true;
  235. drake.emit('drag', _item, _source);
  236. }
  237. function invalidTarget () {
  238. return false;
  239. }
  240. function end () {
  241. if (!drake.dragging) {
  242. return;
  243. }
  244. var item = _copy || _item;
  245. drop(item, getParent(item));
  246. }
  247. function ungrab () {
  248. _grabbed = false;
  249. eventualMovements(true);
  250. movements(true);
  251. }
  252. function release (e) {
  253. ungrab();
  254. if (!drake.dragging) {
  255. return;
  256. }
  257. var item = _copy || _item;
  258. var clientX = getCoord('clientX', e);
  259. var clientY = getCoord('clientY', e);
  260. var elementBehindCursor = getElementBehindPoint(_mirror, clientX, clientY);
  261. var dropTarget = findDropTarget(elementBehindCursor, clientX, clientY);
  262. if (dropTarget && ((_copy && o.copySortSource) || (!_copy || dropTarget !== _source))) {
  263. drop(item, dropTarget);
  264. } else if (o.removeOnSpill) {
  265. remove();
  266. } else {
  267. cancel();
  268. }
  269. }
  270. function drop (item, target) {
  271. var parent = getParent(item);
  272. if (_copy && o.copySortSource && target === _source) {
  273. parent.removeChild(_item);
  274. }
  275. if (isInitialPlacement(target)) {
  276. drake.emit('cancel', item, _source, _source);
  277. } else {
  278. drake.emit('drop', item, target, _source, _currentSibling);
  279. }
  280. cleanup();
  281. }
  282. function remove () {
  283. if (!drake.dragging) {
  284. return;
  285. }
  286. var item = _copy || _item;
  287. var parent = getParent(item);
  288. if (parent) {
  289. parent.removeChild(item);
  290. }
  291. drake.emit(_copy ? 'cancel' : 'remove', item, parent, _source);
  292. cleanup();
  293. }
  294. function cancel (revert) {
  295. if (!drake.dragging) {
  296. return;
  297. }
  298. var reverts = arguments.length > 0 ? revert : o.revertOnSpill;
  299. var item = _copy || _item;
  300. var parent = getParent(item);
  301. var initial = isInitialPlacement(parent);
  302. if (initial === false && reverts) {
  303. if (_copy) {
  304. if (parent) {
  305. parent.removeChild(_copy);
  306. }
  307. } else {
  308. _source.insertBefore(item, _initialSibling);
  309. }
  310. }
  311. if (initial || reverts) {
  312. drake.emit('cancel', item, _source, _source);
  313. } else {
  314. drake.emit('drop', item, parent, _source, _currentSibling);
  315. }
  316. cleanup();
  317. }
  318. function cleanup () {
  319. var item = _copy || _item;
  320. ungrab();
  321. removeMirrorImage();
  322. if (item) {
  323. classes.rm(item, 'gu-transit');
  324. }
  325. if (_renderTimer) {
  326. clearTimeout(_renderTimer);
  327. }
  328. drake.dragging = false;
  329. if (_lastDropTarget) {
  330. drake.emit('out', item, _lastDropTarget, _source);
  331. }
  332. drake.emit('dragend', item);
  333. _source = _item = _copy = _initialSibling = _currentSibling = _renderTimer = _lastDropTarget = null;
  334. }
  335. function isInitialPlacement (target, s) {
  336. var sibling;
  337. if (s !== void 0) {
  338. sibling = s;
  339. } else if (_mirror) {
  340. sibling = _currentSibling;
  341. } else {
  342. sibling = nextEl(_copy || _item);
  343. }
  344. return target === _source && sibling === _initialSibling;
  345. }
  346. function findDropTarget (elementBehindCursor, clientX, clientY) {
  347. var target = elementBehindCursor;
  348. while (target && !accepted()) {
  349. target = getParent(target);
  350. }
  351. return target;
  352. function accepted () {
  353. var droppable = isContainer(target);
  354. if (droppable === false) {
  355. return false;
  356. }
  357. var immediate = getImmediateChild(target, elementBehindCursor);
  358. var reference = getReference(target, immediate, clientX, clientY);
  359. var initial = isInitialPlacement(target, reference);
  360. if (initial) {
  361. return true; // should always be able to drop it right back where it was
  362. }
  363. return o.accepts(_item, target, _source, reference);
  364. }
  365. }
  366. function drag (e) {
  367. if (!_mirror) {
  368. return;
  369. }
  370. e.preventDefault();
  371. var clientX = getCoord('clientX', e);
  372. var clientY = getCoord('clientY', e);
  373. var x = clientX - _offsetX;
  374. var y = clientY - _offsetY;
  375. _mirror.style.left = x + 'px';
  376. _mirror.style.top = y + 'px';
  377. var item = _copy || _item;
  378. var elementBehindCursor = getElementBehindPoint(_mirror, clientX, clientY);
  379. var dropTarget = findDropTarget(elementBehindCursor, clientX, clientY);
  380. var changed = dropTarget !== null && dropTarget !== _lastDropTarget;
  381. if (changed || dropTarget === null) {
  382. out();
  383. _lastDropTarget = dropTarget;
  384. over();
  385. }
  386. var parent = getParent(item);
  387. if (dropTarget === _source && _copy && !o.copySortSource) {
  388. if (parent) {
  389. parent.removeChild(item);
  390. }
  391. return;
  392. }
  393. var reference;
  394. var immediate = getImmediateChild(dropTarget, elementBehindCursor);
  395. if (immediate !== null) {
  396. reference = getReference(dropTarget, immediate, clientX, clientY);
  397. } else if (o.revertOnSpill === true && !_copy) {
  398. reference = _initialSibling;
  399. dropTarget = _source;
  400. } else {
  401. if (_copy && parent) {
  402. parent.removeChild(item);
  403. }
  404. return;
  405. }
  406. if (
  407. (reference === null && changed) ||
  408. reference !== item &&
  409. reference !== nextEl(item)
  410. ) {
  411. _currentSibling = reference;
  412. dropTarget.insertBefore(item, reference);
  413. drake.emit('shadow', item, dropTarget, _source);
  414. }
  415. function moved (type) { drake.emit(type, item, _lastDropTarget, _source); }
  416. function over () { if (changed) { moved('over'); } }
  417. function out () { if (_lastDropTarget) { moved('out'); } }
  418. }
  419. function spillOver (el) {
  420. classes.rm(el, 'gu-hide');
  421. }
  422. function spillOut (el) {
  423. if (drake.dragging) { classes.add(el, 'gu-hide'); }
  424. }
  425. function renderMirrorImage () {
  426. if (_mirror) {
  427. return;
  428. }
  429. var rect = _item.getBoundingClientRect();
  430. _mirror = _item.cloneNode(true);
  431. _mirror.style.width = getRectWidth(rect) + 'px';
  432. _mirror.style.height = getRectHeight(rect) + 'px';
  433. classes.rm(_mirror, 'gu-transit');
  434. classes.add(_mirror, 'gu-mirror');
  435. o.mirrorContainer.appendChild(_mirror);
  436. touchy(documentElement, 'add', 'mousemove', drag);
  437. classes.add(o.mirrorContainer, 'gu-unselectable');
  438. drake.emit('cloned', _mirror, _item, 'mirror');
  439. }
  440. function removeMirrorImage () {
  441. if (_mirror) {
  442. classes.rm(o.mirrorContainer, 'gu-unselectable');
  443. touchy(documentElement, 'remove', 'mousemove', drag);
  444. getParent(_mirror).removeChild(_mirror);
  445. _mirror = null;
  446. }
  447. }
  448. function getImmediateChild (dropTarget, target) {
  449. var immediate = target;
  450. while (immediate !== dropTarget && getParent(immediate) !== dropTarget) {
  451. immediate = getParent(immediate);
  452. }
  453. if (immediate === documentElement) {
  454. return null;
  455. }
  456. return immediate;
  457. }
  458. function getReference (dropTarget, target, x, y) {
  459. var horizontal = o.direction === 'horizontal';
  460. var reference = target !== dropTarget ? inside() : outside();
  461. return reference;
  462. function outside () { // slower, but able to figure out any position
  463. var len = dropTarget.children.length;
  464. var i;
  465. var el;
  466. var rect;
  467. for (i = 0; i < len; i++) {
  468. el = dropTarget.children[i];
  469. rect = el.getBoundingClientRect();
  470. if (horizontal && (rect.left + rect.width / 2) > x) { return el; }
  471. if (!horizontal && (rect.top + rect.height / 2) > y) { return el; }
  472. }
  473. return null;
  474. }
  475. function inside () { // faster, but only available if dropped inside a child element
  476. var rect = target.getBoundingClientRect();
  477. if (horizontal) {
  478. return resolve(x > rect.left + getRectWidth(rect) / 2);
  479. }
  480. return resolve(y > rect.top + getRectHeight(rect) / 2);
  481. }
  482. function resolve (after) {
  483. return after ? nextEl(target) : target;
  484. }
  485. }
  486. function isCopy (item, container) {
  487. return typeof o.copy === 'boolean' ? o.copy : o.copy(item, container);
  488. }
  489. }
  490. function touchy (el, op, type, fn) {
  491. var touch = {
  492. mouseup: 'touchend',
  493. mousedown: 'touchstart',
  494. mousemove: 'touchmove'
  495. };
  496. var pointers = {
  497. mouseup: 'pointerup',
  498. mousedown: 'pointerdown',
  499. mousemove: 'pointermove'
  500. };
  501. var microsoft = {
  502. mouseup: 'MSPointerUp',
  503. mousedown: 'MSPointerDown',
  504. mousemove: 'MSPointerMove'
  505. };
  506. if (global.navigator.pointerEnabled) {
  507. crossvent[op](el, pointers[type], fn);
  508. } else if (global.navigator.msPointerEnabled) {
  509. crossvent[op](el, microsoft[type], fn);
  510. } else {
  511. crossvent[op](el, touch[type], fn);
  512. crossvent[op](el, type, fn);
  513. }
  514. }
  515. function whichMouseButton (e) {
  516. if (e.touches !== void 0) { return e.touches.length; }
  517. if (e.which !== void 0 && e.which !== 0) { return e.which; } // see https://github.com/bevacqua/dragula/issues/261
  518. if (e.buttons !== void 0) { return e.buttons; }
  519. var button = e.button;
  520. if (button !== void 0) { // see https://github.com/jquery/jquery/blob/99e8ff1baa7ae341e94bb89c3e84570c7c3ad9ea/src/event.js#L573-L575
  521. return button & 1 ? 1 : button & 2 ? 3 : (button & 4 ? 2 : 0);
  522. }
  523. }
  524. function getOffset (el) {
  525. var rect = el.getBoundingClientRect();
  526. return {
  527. left: rect.left + getScroll('scrollLeft', 'pageXOffset'),
  528. top: rect.top + getScroll('scrollTop', 'pageYOffset')
  529. };
  530. }
  531. function getScroll (scrollProp, offsetProp) {
  532. if (typeof global[offsetProp] !== 'undefined') {
  533. return global[offsetProp];
  534. }
  535. if (documentElement.clientHeight) {
  536. return documentElement[scrollProp];
  537. }
  538. return doc.body[scrollProp];
  539. }
  540. function getElementBehindPoint (point, x, y) {
  541. var p = point || {};
  542. var state = p.className;
  543. var el;
  544. p.className += ' gu-hide';
  545. el = doc.elementFromPoint(x, y);
  546. p.className = state;
  547. return el;
  548. }
  549. function never () { return false; }
  550. function always () { return true; }
  551. function getRectWidth (rect) { return rect.width || (rect.right - rect.left); }
  552. function getRectHeight (rect) { return rect.height || (rect.bottom - rect.top); }
  553. function getParent (el) { return el.parentNode === doc ? null : el.parentNode; }
  554. function isInput (el) { return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT' || isEditable(el); }
  555. function isEditable (el) {
  556. if (!el) { return false; } // no parents were editable
  557. if (el.contentEditable === 'false') { return false; } // stop the lookup
  558. if (el.contentEditable === 'true') { return true; } // found a contentEditable element in the chain
  559. return isEditable(getParent(el)); // contentEditable is set to 'inherit'
  560. }
  561. function nextEl (el) {
  562. return el.nextElementSibling || manually();
  563. function manually () {
  564. var sibling = el;
  565. do {
  566. sibling = sibling.nextSibling;
  567. } while (sibling && sibling.nodeType !== 1);
  568. return sibling;
  569. }
  570. }
  571. function getEventHost (e) {
  572. // on touchend event, we have to use `e.changedTouches`
  573. // see http://stackoverflow.com/questions/7192563/touchend-event-properties
  574. // see https://github.com/bevacqua/dragula/issues/34
  575. if (e.targetTouches && e.targetTouches.length) {
  576. return e.targetTouches[0];
  577. }
  578. if (e.changedTouches && e.changedTouches.length) {
  579. return e.changedTouches[0];
  580. }
  581. return e;
  582. }
  583. function getCoord (coord, e) {
  584. var host = getEventHost(e);
  585. var missMap = {
  586. pageX: 'clientX', // IE8
  587. pageY: 'clientY' // IE8
  588. };
  589. if (coord in missMap && !(coord in host) && missMap[coord] in host) {
  590. coord = missMap[coord];
  591. }
  592. return host[coord];
  593. }
  594. module.exports = dragula;
  595. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  596. },{"./classes":1,"contra/emitter":5,"crossvent":6}],3:[function(require,module,exports){
  597. module.exports = function atoa (a, n) { return Array.prototype.slice.call(a, n); }
  598. },{}],4:[function(require,module,exports){
  599. 'use strict';
  600. var ticky = require('ticky');
  601. module.exports = function debounce (fn, args, ctx) {
  602. if (!fn) { return; }
  603. ticky(function run () {
  604. fn.apply(ctx || null, args || []);
  605. });
  606. };
  607. },{"ticky":9}],5:[function(require,module,exports){
  608. 'use strict';
  609. var atoa = require('atoa');
  610. var debounce = require('./debounce');
  611. module.exports = function emitter (thing, options) {
  612. var opts = options || {};
  613. var evt = {};
  614. if (thing === undefined) { thing = {}; }
  615. thing.on = function (type, fn) {
  616. if (!evt[type]) {
  617. evt[type] = [fn];
  618. } else {
  619. evt[type].push(fn);
  620. }
  621. return thing;
  622. };
  623. thing.once = function (type, fn) {
  624. fn._once = true; // thing.off(fn) still works!
  625. thing.on(type, fn);
  626. return thing;
  627. };
  628. thing.off = function (type, fn) {
  629. var c = arguments.length;
  630. if (c === 1) {
  631. delete evt[type];
  632. } else if (c === 0) {
  633. evt = {};
  634. } else {
  635. var et = evt[type];
  636. if (!et) { return thing; }
  637. et.splice(et.indexOf(fn), 1);
  638. }
  639. return thing;
  640. };
  641. thing.emit = function () {
  642. var args = atoa(arguments);
  643. return thing.emitterSnapshot(args.shift()).apply(this, args);
  644. };
  645. thing.emitterSnapshot = function (type) {
  646. var et = (evt[type] || []).slice(0);
  647. return function () {
  648. var args = atoa(arguments);
  649. var ctx = this || thing;
  650. if (type === 'error' && opts.throws !== false && !et.length) { throw args.length === 1 ? args[0] : args; }
  651. et.forEach(function emitter (listen) {
  652. if (opts.async) { debounce(listen, args, ctx); } else { listen.apply(ctx, args); }
  653. if (listen._once) { thing.off(type, listen); }
  654. });
  655. return thing;
  656. };
  657. };
  658. return thing;
  659. };
  660. },{"./debounce":4,"atoa":3}],6:[function(require,module,exports){
  661. (function (global){
  662. 'use strict';
  663. var customEvent = require('custom-event');
  664. var eventmap = require('./eventmap');
  665. var doc = global.document;
  666. var addEvent = addEventEasy;
  667. var removeEvent = removeEventEasy;
  668. var hardCache = [];
  669. if (!global.addEventListener) {
  670. addEvent = addEventHard;
  671. removeEvent = removeEventHard;
  672. }
  673. module.exports = {
  674. add: addEvent,
  675. remove: removeEvent,
  676. fabricate: fabricateEvent
  677. };
  678. function addEventEasy (el, type, fn, capturing) {
  679. return el.addEventListener(type, fn, capturing);
  680. }
  681. function addEventHard (el, type, fn) {
  682. return el.attachEvent('on' + type, wrap(el, type, fn));
  683. }
  684. function removeEventEasy (el, type, fn, capturing) {
  685. return el.removeEventListener(type, fn, capturing);
  686. }
  687. function removeEventHard (el, type, fn) {
  688. var listener = unwrap(el, type, fn);
  689. if (listener) {
  690. return el.detachEvent('on' + type, listener);
  691. }
  692. }
  693. function fabricateEvent (el, type, model) {
  694. var e = eventmap.indexOf(type) === -1 ? makeCustomEvent() : makeClassicEvent();
  695. if (el.dispatchEvent) {
  696. el.dispatchEvent(e);
  697. } else {
  698. el.fireEvent('on' + type, e);
  699. }
  700. function makeClassicEvent () {
  701. var e;
  702. if (doc.createEvent) {
  703. e = doc.createEvent('Event');
  704. e.initEvent(type, true, true);
  705. } else if (doc.createEventObject) {
  706. e = doc.createEventObject();
  707. }
  708. return e;
  709. }
  710. function makeCustomEvent () {
  711. return new customEvent(type, { detail: model });
  712. }
  713. }
  714. function wrapperFactory (el, type, fn) {
  715. return function wrapper (originalEvent) {
  716. var e = originalEvent || global.event;
  717. e.target = e.target || e.srcElement;
  718. e.preventDefault = e.preventDefault || function preventDefault () { e.returnValue = false; };
  719. e.stopPropagation = e.stopPropagation || function stopPropagation () { e.cancelBubble = true; };
  720. e.which = e.which || e.keyCode;
  721. fn.call(el, e);
  722. };
  723. }
  724. function wrap (el, type, fn) {
  725. var wrapper = unwrap(el, type, fn) || wrapperFactory(el, type, fn);
  726. hardCache.push({
  727. wrapper: wrapper,
  728. element: el,
  729. type: type,
  730. fn: fn
  731. });
  732. return wrapper;
  733. }
  734. function unwrap (el, type, fn) {
  735. var i = find(el, type, fn);
  736. if (i) {
  737. var wrapper = hardCache[i].wrapper;
  738. hardCache.splice(i, 1); // free up a tad of memory
  739. return wrapper;
  740. }
  741. }
  742. function find (el, type, fn) {
  743. var i, item;
  744. for (i = 0; i < hardCache.length; i++) {
  745. item = hardCache[i];
  746. if (item.element === el && item.type === type && item.fn === fn) {
  747. return i;
  748. }
  749. }
  750. }
  751. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  752. },{"./eventmap":7,"custom-event":8}],7:[function(require,module,exports){
  753. (function (global){
  754. 'use strict';
  755. var eventmap = [];
  756. var eventname = '';
  757. var ron = /^on/;
  758. for (eventname in global) {
  759. if (ron.test(eventname)) {
  760. eventmap.push(eventname.slice(2));
  761. }
  762. }
  763. module.exports = eventmap;
  764. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  765. },{}],8:[function(require,module,exports){
  766. (function (global){
  767. var NativeCustomEvent = global.CustomEvent;
  768. function useNative () {
  769. try {
  770. var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } });
  771. return 'cat' === p.type && 'bar' === p.detail.foo;
  772. } catch (e) {
  773. }
  774. return false;
  775. }
  776. /**
  777. * Cross-browser `CustomEvent` constructor.
  778. *
  779. * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent
  780. *
  781. * @public
  782. */
  783. module.exports = useNative() ? NativeCustomEvent :
  784. // IE >= 9
  785. 'function' === typeof document.createEvent ? function CustomEvent (type, params) {
  786. var e = document.createEvent('CustomEvent');
  787. if (params) {
  788. e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail);
  789. } else {
  790. e.initCustomEvent(type, false, false, void 0);
  791. }
  792. return e;
  793. } :
  794. // IE <= 8
  795. function CustomEvent (type, params) {
  796. var e = document.createEventObject();
  797. e.type = type;
  798. if (params) {
  799. e.bubbles = Boolean(params.bubbles);
  800. e.cancelable = Boolean(params.cancelable);
  801. e.detail = params.detail;
  802. } else {
  803. e.bubbles = false;
  804. e.cancelable = false;
  805. e.detail = void 0;
  806. }
  807. return e;
  808. }
  809. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  810. },{}],9:[function(require,module,exports){
  811. var si = typeof setImmediate === 'function', tick;
  812. if (si) {
  813. tick = function (fn) { setImmediate(fn); };
  814. } else {
  815. tick = function (fn) { setTimeout(fn, 0); };
  816. }
  817. module.exports = tick;
  818. },{}]},{},[2])(2)
  819. });
  820. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJjbGFzc2VzLmpzIiwiZHJhZ3VsYS5qcyIsIm5vZGVfbW9kdWxlcy9hdG9hL2F0b2EuanMiLCJub2RlX21vZHVsZXMvY29udHJhL2RlYm91bmNlLmpzIiwibm9kZV9tb2R1bGVzL2NvbnRyYS9lbWl0dGVyLmpzIiwibm9kZV9tb2R1bGVzL2Nyb3NzdmVudC9zcmMvY3Jvc3N2ZW50LmpzIiwibm9kZV9tb2R1bGVzL2Nyb3NzdmVudC9zcmMvZXZlbnRtYXAuanMiLCJub2RlX21vZHVsZXMvY3VzdG9tLWV2ZW50L2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL3RpY2t5L3RpY2t5LWJyb3dzZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7O0FDakNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FB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