-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathclusterize-cluster.js
166 lines (165 loc) · 4.74 KB
/
clusterize-cluster.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
module.exports = {
mixins: [require("vue-mixins/vue")],
props: {
"bindingName": {
type: String,
"default": "data"
},
"loading": {
type: Number,
"default": 0
},
"nr": {
type: Number
},
"index": {
type: Number
},
"height": {
type: Number
},
"data": {
type: Array,
"default": function() {
return [];
}
},
"rowWatchers": {
type: Object
},
"parentVm": {
type: Object
}
},
data: function() {
return {
isCluster: true,
factory: null,
Vue: null,
end: null,
frags: []
};
},
ready: function() {
var key, ref, results, val;
this.end = this.Vue.util.createAnchor('clusterize-cluster-end');
this.$el.appendChild(this.end);
ref = this.rowWatchers;
results = [];
for (key in ref) {
val = ref[key];
results.push(this.initRowWatchers(key, val));
}
return results;
},
methods: {
createFrag: function(i) {
var frag, key, parentScope, ref, scope, val;
parentScope = this.parentVm;
scope = Object.create(parentScope);
scope.$refs = Object.create(parentScope.$refs);
scope.$els = Object.create(parentScope.$els);
scope.$parent = parentScope;
scope.$forContext = this;
this.Vue.util.defineReactive(scope, this.bindingName, this.data[i]);
this.Vue.util.defineReactive(scope, "loading", this.loading);
this.Vue.util.defineReactive(scope, "index", this.index + i);
ref = this.rowWatchers;
for (key in ref) {
val = ref[key];
this.Vue.util.defineReactive(scope, key, val.vm[val.prop]);
scope[key] = val.vm[val.prop];
}
frag = this.factory.create(this, scope, this.$options._frag);
frag.before(this.end);
return this.frags[i] = frag;
},
updateIndex: function() {
var frag, i, j, len, ref, results;
ref = this.frags;
results = [];
for (i = j = 0, len = ref.length; j < len; i = ++j) {
frag = ref[i];
results.push(frag.scope.index = this.index + i);
}
return results;
},
destroyFrag: function(i) {
return this.frags[i].remove();
},
initRowWatchers: function(key, obj) {
var self;
self = this;
return obj.vm.$watch(obj.prop, function(val) {
var frag, j, len, ref, results;
ref = self.frags;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
frag = ref[j];
results.push(frag.scope[key] = val);
}
return results;
});
},
redraw: function() {
var i, j, ref, results;
if (this.frags.length > 0) {
results = [];
for (i = j = 0, ref = this.frags.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
this.destroyFrag(i);
results.push(this.createFrag(i));
}
return results;
}
}
},
watch: {
"index": "updateIndex",
"factory": "redraw",
"rowWatchers": function(newRW, oldRW) {
var key, results, val;
results = [];
for (key in newRW) {
val = newRW[key];
if (oldRW[key] == null) {
results.push(this.initRowWatchers(key, val));
} else {
results.push(void 0);
}
}
return results;
},
data: function(newData, oldData) {
var diff, frag, i, index, j, k, l, len, ref, ref1, ref2, results;
diff = newData.length - oldData.length;
if (diff > 0) {
for (i = j = 0, ref = diff; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
this.createFrag(oldData.length + i);
}
} else if (diff < 0) {
for (i = k = ref1 = diff; ref1 <= 0 ? k < 0 : k > 0; i = ref1 <= 0 ? ++k : --k) {
this.destroyFrag(oldData.length + i);
}
}
ref2 = this.frags;
results = [];
for (index = l = 0, len = ref2.length; l < len; index = ++l) {
frag = ref2[index];
results.push(frag.scope.data = newData[index]);
}
return results;
},
loading: function(newLoading) {
var frag, j, len, ref, results;
ref = this.frags;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
frag = ref[j];
results.push(frag.scope.loading = newLoading);
}
return results;
}
}
};
if (module.exports.__esModule) module.exports = module.exports.default
;(typeof module.exports === "function"? module.exports.options: module.exports).template = "<div class=clusterize-cluster :class={loading:loading} :style=\"{height:height+'px',overflow:'visible',position:'relative',margin:0,padding:0}\"><div class=clusterize-cluster-loading v-el:loading=v-el:loading v-show=loading><slot>loading...</slot></div></div>"