-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstances.js
74 lines (66 loc) · 2.72 KB
/
instances.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
// Instances needed for the reactive drops control.
// They store only calculated data needed to rendering.
Drop.instances = new Mongo.Collection(null, { ref: 'templ:drop/instances' });
Drop.instances.attachSchema(new SimpleSchema({
// templating settings
template: {
type: String, optional: true,
autoValue: function() { if (!this.value) return Drop._template; }
},
theme: {
type: String, optional: true,
autoValue: function() { if (!this.value) return Drop._theme; }
},
placement: { type: String, optional: true, defaultValue: 'global' },
location: { type: String, optional: true, defaultValue: 'outside', allowedValues: ['outside', 'inside'] },
direction: { type: String, optional: true, defaultValue: 'top', allowedValues: ['top', 'right', 'bottom', 'left'] },
layer: { type: Number, optional: true, defaultValue: 9999 },
// prepare fields
directionKey: { type: String, optional: true, allowedValues: ['top', 'right', 'bottom', 'left'] },
directionValue: { type: Number, decimal: true, optional: true },
additionalKey: { type: String, optional: true, allowedValues: ['top', 'right', 'bottom', 'left'] },
additionalValue: { type: Number, decimal: true, optional: true },
// unprepare fields
positionValue: { type: Number, decimal: true, optional: true },
alignmentValue: { type: Number, decimal: true, optional: true },
width: { type: Number, decimal: true, optional: true },
height: { type: Number, decimal: true, optional: true },
// prepare state
prepare: {
type: Boolean, optional: true,
autoValue: function() {
if (this.isInsert) return true;
}
},
arrow: { type: Boolean, optional: true, defaultValue: true }
}));
Drop.instances.helpers({
drop: function() {
return Drop._instances[this._id];
},
arrowDirection: function() {
if (this.drop().data.location == 'outside')
return this.direction;
else
return Drop.invert(this.direction);
},
arrowValue: function() {
return this.alignmentValue * this[Drop.insize(this.additionalKey)];
}
});
Drop.instances.before.update(function(userId, doc, fieldNames, modifier, options) {
if(!('$set' in modifier)) modifier.$set = {};
if (!lodash.includes(fieldNames, 'prepare')) {
modifier.$set.prepare = false;
}
});
Drop.instances.after.update(function(userId, doc, fieldNames, modifier, options) {
for (var k in Drop._reinit) {
if (this.previous[Drop._reinit[k]] != doc[Drop._reinit[k]]) {
Drop.instances._transform(doc).drop().hide().show();
break;
}
}
});
// Drops storage by instances id.
Drop._instances = {};