1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.directive = undefined;
|
7 |
|
8 | var _vue = require('vue');
|
9 |
|
10 | var directive = exports.directive = {
|
11 | bind: function bind() {
|
12 | var _this = this;
|
13 |
|
14 | this.preLoading = false;
|
15 | this.tmp = null;
|
16 | this.clickToPreload = false;
|
17 | this.handleMouseOver = function (e) {
|
18 | if (_this.preLoading) {
|
19 | return;
|
20 | }
|
21 | _this.preLoading = true;
|
22 | _this.vm[_this.expression].call(null, _this, e);
|
23 | };
|
24 | this.handleMouseLeave = function (e) {};
|
25 | this.handleClick = function (e) {
|
26 | e.preventDefault();
|
27 | if (!_this.tmp && !_this.preLoading) {
|
28 | _this.clickToPreload = true;
|
29 | return _this.handleMouseOver(e);
|
30 | }
|
31 | _this.setState(_this.tmp);
|
32 | };
|
33 | _vue.util.on(this.el, 'mouseover', this.handleMouseOver);
|
34 | _vue.util.on(this.el, 'mouseleave', this.handleMouseLeave);
|
35 | _vue.util.on(this.el, 'click', this.handleClick);
|
36 | },
|
37 | set: function set(obj) {
|
38 | this.tmp = obj;
|
39 | },
|
40 | setState: function setState(state) {
|
41 | for (var key in state) {
|
42 | this.vm.$set(key, state[key]);
|
43 | }
|
44 | this.tmp = null;
|
45 | },
|
46 | end: function end() {
|
47 | this.preLoading = false;
|
48 | if (this.clickToPreload) {
|
49 | this.setState(this.tmp);
|
50 | this.clickToPreload = false;
|
51 | }
|
52 | },
|
53 | reset: function reset() {
|
54 | _vue.util.off(this.el, 'mouseover', this.handleMouseOver);
|
55 | _vue.util.off(this.el, 'mouseleave', this.handleMouseLeave);
|
56 | _vue.util.off(this.el, 'click', this.handleClick);
|
57 | },
|
58 | unbind: function unbind() {
|
59 | this.reset();
|
60 | }
|
61 | }; |
\ | No newline at end of file |