repeat-click.js 729 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _dom = require('element-ui/lib/utils/dom');
  4. exports.default = {
  5. bind: function bind(el, binding, vnode) {
  6. var interval = null;
  7. var startTime = void 0;
  8. var handler = function handler() {
  9. return vnode.context[binding.expression].apply();
  10. };
  11. var clear = function clear() {
  12. if (Date.now() - startTime < 100) {
  13. handler();
  14. }
  15. clearInterval(interval);
  16. interval = null;
  17. };
  18. (0, _dom.on)(el, 'mousedown', function (e) {
  19. if (e.button !== 0) return;
  20. startTime = Date.now();
  21. (0, _dom.once)(document, 'mouseup', clear);
  22. clearInterval(interval);
  23. interval = setInterval(handler, 100);
  24. });
  25. }
  26. };