targetj 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jshintrc +3 -0
- package/Gruntfile.js +42 -0
- package/package.json +27 -0
- package/src/$Dom.js +358 -0
- package/src/App.js +142 -0
- package/src/Bracket.js +201 -0
- package/src/Browser.js +297 -0
- package/src/Dim.js +19 -0
- package/src/EventListener.js +454 -0
- package/src/LoadingManager.js +348 -0
- package/src/LocationManager.js +156 -0
- package/src/PageManager.js +104 -0
- package/src/SearchUtil.js +179 -0
- package/src/TModel.js +761 -0
- package/src/TModelManager.js +378 -0
- package/src/TUtil.js +202 -0
- package/src/TargetManager.js +228 -0
- package/src/TargetUtil.js +221 -0
- package/src/Viewport.js +184 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
function TargetManager() {
|
|
2
|
+
this.doneTargets = [];
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
TargetManager.prototype.setTargetValuesWithKeys = function(tmodel, keys, force) {
|
|
6
|
+
for (var i = 0; i < keys.length; i++) {
|
|
7
|
+
var key = keys[i];
|
|
8
|
+
if (tmodel.targetValues[key] && tmodel.getCallingTargetKey(key) === key) {
|
|
9
|
+
this.setTargetValue(tmodel, key, force);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
TargetManager.prototype.setTargetValues = function(tmodel) {
|
|
15
|
+
|
|
16
|
+
var activeKeys = Object.keys(tmodel.activeTargetKeyMap);
|
|
17
|
+
|
|
18
|
+
if (tmodel.targets !== tmodel.actualValues.targets) {
|
|
19
|
+
tmodel.actualValues.targets = tmodel.targets;
|
|
20
|
+
Object.keys(tmodel.targets).forEach(function(key) {
|
|
21
|
+
if (activeKeys.indexOf(key) === -1) {
|
|
22
|
+
activeKeys.push(key);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
tmodel.targetUpdatingMap = {};
|
|
28
|
+
tmodel.targetUpdatingList = [];
|
|
29
|
+
|
|
30
|
+
for (var i = 0; i < activeKeys.length; i++) {
|
|
31
|
+
|
|
32
|
+
var key = activeKeys[i];
|
|
33
|
+
|
|
34
|
+
if (tmodel.targetUpdatingMap[key]) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (tmodel.isTargetUpdating(key) && tmodel.getCallingTargetKey(key) !== key) {
|
|
39
|
+
tmodel.targetUpdatingMap[key] = true;
|
|
40
|
+
tmodel.targetUpdatingList.push(key);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var result = this.setTargetValue(tmodel, key);
|
|
45
|
+
|
|
46
|
+
if (result) {
|
|
47
|
+
tmodel.targetUpdatingMap[key] = true;
|
|
48
|
+
tmodel.targetUpdatingList.push(key);
|
|
49
|
+
} else if (tmodel.isTargetDone(key) && !tmodel.isTargetComplete(key)) {
|
|
50
|
+
this.doneTargets.push({ tmodel: tmodel, key: key });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (tmodel.getParent() && tmodel.targetUpdatingList.length === 0) {
|
|
55
|
+
tmodel.getParent().removeUpdatingChild(tmodel);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
TargetManager.prototype.setTargetValue = function(tmodel, key, force) {
|
|
60
|
+
var target = tmodel.targets[key];
|
|
61
|
+
|
|
62
|
+
if (!TUtil.isDefined(target)) {
|
|
63
|
+
delete tmodel.activeTargetKeyMap[key];
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (tmodel.isTargetUpdating(key) || !tmodel.targetValues[key] || tmodel.isTargetInLoop(key) || !tmodel.hasTargetGotExecuted(key) || force) {
|
|
68
|
+
|
|
69
|
+
if (tmodel.isTargetEnabled(key)) {
|
|
70
|
+
|
|
71
|
+
var valueOnly = target ? !!target.valueOnly : false;
|
|
72
|
+
|
|
73
|
+
if (!TUtil.isDefined(tmodel.getActualTimeStamp(key))) {
|
|
74
|
+
var cycle = tmodel.getTargetCycle(key);
|
|
75
|
+
var valueArray = TargetUtil.getValueStepsCycles(tmodel, target, cycle, valueOnly, key);
|
|
76
|
+
TargetUtil.assignValueArray(tmodel, key, valueArray);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (tmodel.isTargetInLoop(key)
|
|
80
|
+
|| !tmodel.isTargetDone(key)
|
|
81
|
+
|| !tmodel.isTargetComplete(key)
|
|
82
|
+
|| TUtil.isDefined(tmodel.getActualTimeStamp(key))
|
|
83
|
+
|| !tmodel.hasTargetGotExecuted(key)) {
|
|
84
|
+
tmodel.activeTargetKeyMap[key] = true;
|
|
85
|
+
} else if (tmodel.activeTargetKeyMap[key]) {
|
|
86
|
+
delete tmodel.activeTargetKeyMap[key];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (TUtil.isDefined(tmodel.getActualTimeStamp(key))) {
|
|
90
|
+
var schedulePeriod = TargetUtil.getActualSchedulePeriod(tmodel, key, tmodel.getTargetStepInterval(key));
|
|
91
|
+
if (schedulePeriod > 0) {
|
|
92
|
+
tapp.manager.scheduleRun(schedulePeriod, "actualInterval__" + tmodel.oid + "__" + key);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (!tmodel.isTargetDone(key) && !tmodel.isTargetComplete(key)) || !tmodel.doesTargetEqualActual(key);
|
|
97
|
+
} else {
|
|
98
|
+
tmodel.activeTargetKeyMap[key] = true;
|
|
99
|
+
}
|
|
100
|
+
} else if (tmodel.activeTargetKeyMap[key]) {
|
|
101
|
+
delete tmodel.activeTargetKeyMap[key];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
TargetManager.prototype.setActualValues = function(tmodel) {
|
|
107
|
+
var i;
|
|
108
|
+
var target;
|
|
109
|
+
var key, keys = [];
|
|
110
|
+
|
|
111
|
+
for (i = 0; i < tmodel.targetUpdatingList.length; i++) {
|
|
112
|
+
key = tmodel.targetUpdatingList[i];
|
|
113
|
+
|
|
114
|
+
target = tmodel.targets[key];
|
|
115
|
+
var status = tmodel.getTargetStatus(key);
|
|
116
|
+
|
|
117
|
+
if (tmodel.isTargetUpdating(key)) {
|
|
118
|
+
keys.push(key);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (status !== tmodel.getTargetStatus(key)) {
|
|
122
|
+
tapp.manager.scheduleRun(1, tmodel.oid + "-" + key + '-statusChange');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
for (i = 0; i < keys.length; i++) {
|
|
127
|
+
key = keys[i];
|
|
128
|
+
|
|
129
|
+
var schedulePeriod = TargetUtil.getActualSchedulePeriod(tmodel, key, tmodel.getTargetStepInterval(key));
|
|
130
|
+
if (schedulePeriod === 0 || !TUtil.isDefined(schedulePeriod)) {
|
|
131
|
+
this.setActualValue(tmodel, key);
|
|
132
|
+
} else {
|
|
133
|
+
tapp.manager.scheduleRun(schedulePeriod, "actualInterval__" + tmodel.oid + "__" + key);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
TargetManager.prototype.setJustActualValue = function(tmodel, key) {
|
|
140
|
+
|
|
141
|
+
var target = tmodel.targets[key];
|
|
142
|
+
|
|
143
|
+
if (!tmodel.targetValues[key] || (target && typeof target.enabledOn === 'function' && !target.enabledOn.call(tmodel, key))) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
var targetValue = tmodel.getTargetValue(key);
|
|
148
|
+
|
|
149
|
+
var step = tmodel.getTargetStep(key);
|
|
150
|
+
var easing = TUtil.isDefined(tmodel.getTargetEasing(key)) ? tmodel.getTargetEasing(key) : EasingEffects.linear;
|
|
151
|
+
var steps = tmodel.getTargetSteps(key);
|
|
152
|
+
var easingStep = easing(tmodel.getTargetStepPercent(key, step));
|
|
153
|
+
|
|
154
|
+
if (step < steps) {
|
|
155
|
+
if (!TUtil.isDefined(tmodel.getLastActualValue(key))) {
|
|
156
|
+
tmodel.setLastActualValue(key, tmodel.actualValues[key]);
|
|
157
|
+
}
|
|
158
|
+
tmodel.actualValues[key] = typeof targetValue === 'number' ? targetValue * easingStep + tmodel.getLastActualValue(key) * (1 - easingStep) : targetValue;
|
|
159
|
+
} else {
|
|
160
|
+
tmodel.actualValues[key] = targetValue;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
TargetManager.prototype.setActualValue = function(tmodel, key) {
|
|
165
|
+
|
|
166
|
+
if (!tmodel.targetValues[key]) return false;
|
|
167
|
+
|
|
168
|
+
var targetValue = tmodel.getTargetValue(key);
|
|
169
|
+
var step = tmodel.getTargetStep(key);
|
|
170
|
+
var steps = tmodel.getTargetSteps(key);
|
|
171
|
+
var easing = TUtil.isDefined(tmodel.getTargetEasing(key)) ? tmodel.getTargetEasing(key) : EasingEffects.linear;
|
|
172
|
+
var cycle = tmodel.getTargetCycle(key);
|
|
173
|
+
var easingStep = easing(tmodel.getTargetStepPercent(key, step));
|
|
174
|
+
var cycleUpdate = false;
|
|
175
|
+
var stepInterval = tmodel.getTargetStepInterval(key);
|
|
176
|
+
var lastUpdate = tmodel.getActualValueLastUpdate(key);
|
|
177
|
+
var oldValue = tmodel.actualValues[key], oldStep = step, oldCycle = cycle;
|
|
178
|
+
var now = browser.now();
|
|
179
|
+
|
|
180
|
+
if (step < steps) {
|
|
181
|
+
if (!TUtil.isDefined(tmodel.getLastActualValue(key))) {
|
|
182
|
+
tmodel.setLastActualValue(key, tmodel.actualValues[key]);
|
|
183
|
+
}
|
|
184
|
+
tmodel.actualValues[key] = typeof targetValue === 'number' ? targetValue * easingStep + tmodel.getLastActualValue(key) * (1 - easingStep) : targetValue;
|
|
185
|
+
|
|
186
|
+
tmodel.setActualValueLastUpdate(key);
|
|
187
|
+
tmodel.setActualValueLastUpdate(key);
|
|
188
|
+
|
|
189
|
+
var stepIncrease = 1;
|
|
190
|
+
if (!TUtil.isDefined(stepInterval) && false) {
|
|
191
|
+
var expectedStepInterval = 10;
|
|
192
|
+
stepIncrease = step > 0 && lastUpdate && tapp.throttle === 0 && expectedStepInterval > 0 ? Math.max(1, Math.floor((now - lastUpdate) / expectedStepInterval)) : 1;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
step = tmodel.setTargetStep(key, step + stepIncrease);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (step >= steps) {
|
|
199
|
+
tmodel.actualValues[key] = targetValue;
|
|
200
|
+
tmodel.setActualValueLastUpdate(key);
|
|
201
|
+
|
|
202
|
+
if (typeof tmodel.targets[key] === 'object' && typeof tmodel.targets[key].onStepsEnd === 'function') {
|
|
203
|
+
tmodel.targets[key].onStepsEnd.call(tmodel, key, cycle);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
tmodel.updateTargetStatus(key);
|
|
207
|
+
|
|
208
|
+
if (tmodel.getTargetCycle(key) < tmodel.getTargetCycles(key)) {
|
|
209
|
+
tmodel.setTargetCycle(key, tmodel.getTargetCycle(key) + 1);
|
|
210
|
+
|
|
211
|
+
cycleUpdate = true;
|
|
212
|
+
tmodel.resetTargetStep(key);
|
|
213
|
+
tmodel.resetLastActualValue(key);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
TargetUtil.handleValueChange(tmodel, key, tmodel.actualValues[key], oldValue, oldStep, oldCycle);
|
|
219
|
+
|
|
220
|
+
if (TUtil.isDefined(tmodel.getActualTimeStamp(key))) {
|
|
221
|
+
tmodel.resetActualTimeStamp(key);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (step < steps || cycleUpdate) {
|
|
225
|
+
tapp.manager.scheduleRun(step < steps ? stepInterval : 0, tmodel.oid + "---" + key + "-" + step + "/" + steps + "-" + cycle + "-" + stepInterval);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
function TargetUtil() {}
|
|
2
|
+
|
|
3
|
+
TargetUtil.extractInvisibles = function(tmodel, target, key) {
|
|
4
|
+
if (typeof target === 'object' && target) {
|
|
5
|
+
Object.keys(target).forEach(function(k) {
|
|
6
|
+
if (k === 'onInvisible') {
|
|
7
|
+
if (!tmodel.invisibleFunctions) {
|
|
8
|
+
tmodel.invisibleFunctions = [];
|
|
9
|
+
}
|
|
10
|
+
tmodel.invisibleFunctions.push({ fn: target[k], key: key });
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
TargetUtil.emptyValue = function() {
|
|
17
|
+
return {
|
|
18
|
+
value: undefined,
|
|
19
|
+
step: 0,
|
|
20
|
+
steps: 0,
|
|
21
|
+
cycle: 0,
|
|
22
|
+
cycles: 0,
|
|
23
|
+
stepInterval: 0,
|
|
24
|
+
lastActualValue: undefined,
|
|
25
|
+
actualTimeStamp: undefined,
|
|
26
|
+
actualValueLastUpdate: 0,
|
|
27
|
+
status: '',
|
|
28
|
+
executionCounter: 0,
|
|
29
|
+
callingTargetKey: undefined
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
TargetUtil.getValueStepsCycles = function(tmodel, _target, cycle, valueOnly, key) {
|
|
34
|
+
var value = 0, steps = 0, stepInterval = 0, cycles = 0;
|
|
35
|
+
var lastValue = tmodel.getValue(key);
|
|
36
|
+
|
|
37
|
+
function getValue(target) {
|
|
38
|
+
if (Array.isArray(target)) {
|
|
39
|
+
if (!target.valueOnly) {
|
|
40
|
+
if (typeof target[0] === 'function') {
|
|
41
|
+
value = target[0].call(tmodel, key, cycle, lastValue);
|
|
42
|
+
} else {
|
|
43
|
+
value = target[0];
|
|
44
|
+
}
|
|
45
|
+
steps = target.length >= 2 ? target[1] : steps;
|
|
46
|
+
stepInterval = target.length >= 3 ? target[2] : stepInterval;
|
|
47
|
+
cycles = target.length >= 4 ? target[3] : cycles;
|
|
48
|
+
|
|
49
|
+
return [value, steps, stepInterval, cycles];
|
|
50
|
+
} else {
|
|
51
|
+
return [target, steps, stepInterval, cycles];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
} else if (typeof target === 'object' && target && !(target instanceof TModel)) {
|
|
55
|
+
value = typeof target.value === 'function' ? target.value.call(tmodel, key, cycle, lastValue) : TUtil.isDefined(target.value) ? target.value : target;
|
|
56
|
+
steps = typeof target.steps === 'function' ? target.steps.call(tmodel, key, cycle) : TUtil.isDefined(target.steps) ? target.steps : 0;
|
|
57
|
+
stepInterval = typeof target.stepInterval === 'function' ? target.stepInterval.call(tmodel, key, cycle, tmodel.getTargetStepInterval(key), steps) : TUtil.isDefined(target.stepInterval) ? target.stepInterval : 0;
|
|
58
|
+
cycles = typeof target.cycles === 'function' ? target.cycles.call(tmodel, key, cycle, tmodel.getTargetCycles(key)) : TUtil.isDefined(target.cycles) ? target.cycles : 0;
|
|
59
|
+
|
|
60
|
+
if (Array.isArray(value) && valueOnly === false && !value.valueOnly) {
|
|
61
|
+
return getValue(value);
|
|
62
|
+
} else {
|
|
63
|
+
return [value, steps, stepInterval, cycles];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} else {
|
|
67
|
+
if (typeof target === 'function') {
|
|
68
|
+
return getValue(target.call(tmodel, key, cycle, lastValue));
|
|
69
|
+
} else if (typeof target === 'number'
|
|
70
|
+
|| typeof target === 'string'
|
|
71
|
+
|| typeof target === 'boolean'
|
|
72
|
+
|| (target instanceof TModel)
|
|
73
|
+
|| (typeof target === 'object')) {
|
|
74
|
+
|
|
75
|
+
return [target, steps, stepInterval, cycles];
|
|
76
|
+
} else {
|
|
77
|
+
return [value, steps, stepInterval, cycles];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var valueArray = getValue(_target);
|
|
83
|
+
|
|
84
|
+
return valueArray;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
TargetUtil.assignValueArray = function(tmodel, key, valueArray) {
|
|
88
|
+
|
|
89
|
+
if (Array.isArray(valueArray)) {
|
|
90
|
+
var newValue = valueArray[0];
|
|
91
|
+
var newSteps = valueArray[1];
|
|
92
|
+
var newStepInterval = valueArray[2];
|
|
93
|
+
var newCycles = valueArray[3];
|
|
94
|
+
var target = tmodel.targets[key];
|
|
95
|
+
|
|
96
|
+
var cycle = tmodel.getTargetCycle(key);
|
|
97
|
+
var targetValue = tmodel.targetValues[key];
|
|
98
|
+
var theValue = targetValue ? targetValue.value : undefined;
|
|
99
|
+
var newValueFlag = !TUtil.areEqual(theValue, newValue, target.deepEquality)
|
|
100
|
+
|| !TUtil.isDefined(targetValue)
|
|
101
|
+
|| (!tmodel.isTargetUpdating(key) && !tmodel.doesTargetEqualActual(key));
|
|
102
|
+
|
|
103
|
+
if (newValueFlag || targetValue.steps !== newSteps || targetValue.cycles !== newCycles || targetValue.stepInterval !== newStepInterval) {
|
|
104
|
+
|
|
105
|
+
tmodel.setTargetValue(key, newValue, newSteps, newStepInterval, newCycles, key);
|
|
106
|
+
tmodel.targetValues[key].executionCounter++;
|
|
107
|
+
|
|
108
|
+
if (newValueFlag) {
|
|
109
|
+
tmodel.resetTargetStep(key);
|
|
110
|
+
|
|
111
|
+
tmodel.resetLastActualValue(key);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
TargetUtil.getIntervalValue = function(tmodel, key, interval) {
|
|
118
|
+
var intervalValue = typeof interval === 'function' ? interval.call(tmodel, key) : interval;
|
|
119
|
+
|
|
120
|
+
return TUtil.isNumber(intervalValue) ? intervalValue : 0;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
TargetUtil.getActualSchedulePeriod = function(tmodel, key, intervalValue) {
|
|
124
|
+
|
|
125
|
+
var now = browser.now();
|
|
126
|
+
var pastPeriod;
|
|
127
|
+
var schedulePeriod = 0;
|
|
128
|
+
|
|
129
|
+
if (intervalValue > 0) {
|
|
130
|
+
if (TUtil.isDefined(tmodel.getActualTimeStamp(key))) {
|
|
131
|
+
pastPeriod = now - tmodel.getActualTimeStamp(key);
|
|
132
|
+
if (pastPeriod < intervalValue) {
|
|
133
|
+
schedulePeriod = intervalValue - pastPeriod;
|
|
134
|
+
} else {
|
|
135
|
+
schedulePeriod = 0;
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
tmodel.setActualTimeStamp(key, now);
|
|
139
|
+
schedulePeriod = intervalValue;
|
|
140
|
+
}
|
|
141
|
+
} else if (TUtil.isDefined(tmodel.getActualTimeStamp(key))) {
|
|
142
|
+
pastPeriod = now - tmodel.getActualTimeStamp(key);
|
|
143
|
+
if (pastPeriod < 0) {
|
|
144
|
+
schedulePeriod = -pastPeriod;
|
|
145
|
+
} else {
|
|
146
|
+
schedulePeriod = 0;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return schedulePeriod;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
TargetUtil.getTargetSchedulePeriod = function(tmodel, key, intervalValue) {
|
|
154
|
+
|
|
155
|
+
var now = browser.now();
|
|
156
|
+
var pastPeriod;
|
|
157
|
+
var schedulePeriod = 0;
|
|
158
|
+
|
|
159
|
+
if (intervalValue > 0) {
|
|
160
|
+
if (TUtil.isDefined(tmodel.getTargetTimeStamp(key))) {
|
|
161
|
+
pastPeriod = now - tmodel.getTargetTimeStamp(key);
|
|
162
|
+
if (pastPeriod < intervalValue) {
|
|
163
|
+
schedulePeriod = intervalValue - pastPeriod;
|
|
164
|
+
} else {
|
|
165
|
+
schedulePeriod = 0;
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
tmodel.setTargetTimeStamp(key, now);
|
|
169
|
+
schedulePeriod = intervalValue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
} else if (TUtil.isDefined(tmodel.getTargetTimeStamp(key))) {
|
|
173
|
+
pastPeriod = now - tmodel.getTargetTimeStamp(key);
|
|
174
|
+
if (pastPeriod < 0) {
|
|
175
|
+
schedulePeriod = -pastPeriod;
|
|
176
|
+
} else {
|
|
177
|
+
schedulePeriod = 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return schedulePeriod;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
TargetUtil.handleValueChange = function(tmodel, key, newValue, lastValue, step, cycle) {
|
|
185
|
+
if (typeof tmodel.targets[key] === 'object' && typeof tmodel.targets[key].onValueChange === 'function') {
|
|
186
|
+
var valueChanged = !TUtil.areEqual(newValue, lastValue, tmodel.targets[key].deepEquality);
|
|
187
|
+
if (valueChanged) {
|
|
188
|
+
tmodel.targets[key].onValueChange.call(tmodel, key, newValue, lastValue, cycle);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
TargetUtil.setWidthFromDom = function(child) {
|
|
194
|
+
var width = TUtil.isDefined(child.domWidth) ? child.domWidth.width : 10 ;
|
|
195
|
+
|
|
196
|
+
if (!TUtil.isDefined(child.domWidth)
|
|
197
|
+
|| child.domWidth.height !== child.getHeight()
|
|
198
|
+
|| child.hasTargetUpdatedAfter('width', 'width', child.getParent())) {
|
|
199
|
+
child.$dom.width('auto');
|
|
200
|
+
width = child.$dom.width();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
child.domWidth = { width: width, height: child.getHeight() };
|
|
204
|
+
child.setValue('width', width);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
TargetUtil.setHeightFromDom = function(child) {
|
|
209
|
+
var height = TUtil.isDefined(child.domHeight) ? child.domHeight.height : 10 ;
|
|
210
|
+
|
|
211
|
+
if (!TUtil.isDefined(child.domHeight)
|
|
212
|
+
|| child.domHeight.width !== child.getWidth()
|
|
213
|
+
|| child.hasTargetUpdatedAfter('height', 'height', child.getParent())) {
|
|
214
|
+
child.$dom.height('auto');
|
|
215
|
+
height = child.$dom.height();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
child.domHeight = { height: height, width: child.getWidth() };
|
|
219
|
+
|
|
220
|
+
child.setValue('height', height);
|
|
221
|
+
};
|
package/src/Viewport.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
function Viewport(tmodel) {
|
|
2
|
+
|
|
3
|
+
this.tmodel = tmodel;
|
|
4
|
+
this.xNext = 0;
|
|
5
|
+
this.xNorth = 0;
|
|
6
|
+
this.xWest = 0;
|
|
7
|
+
this.xEast = 0;
|
|
8
|
+
this.xSouth = 0;
|
|
9
|
+
|
|
10
|
+
this.xOverflow = 0;
|
|
11
|
+
|
|
12
|
+
this.xOffset = 0;
|
|
13
|
+
|
|
14
|
+
this.yNext = 0;
|
|
15
|
+
this.yNorth = 0;
|
|
16
|
+
this.yWest = 0;
|
|
17
|
+
this.yEast = 0;
|
|
18
|
+
this.ySouth = 0;
|
|
19
|
+
|
|
20
|
+
this.yOffset = 0;
|
|
21
|
+
|
|
22
|
+
this.reset();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Viewport.prototype.reset = function() {
|
|
26
|
+
var x, y;
|
|
27
|
+
if (this.tmodel.type === 'BI') {
|
|
28
|
+
x = this.tmodel.getX() + this.tmodel.getScrollLeft();
|
|
29
|
+
y = this.tmodel.getY() + this.tmodel.getScrollTop();
|
|
30
|
+
|
|
31
|
+
this.xNext = x;
|
|
32
|
+
this.xNorth = x;
|
|
33
|
+
this.xEast = x;
|
|
34
|
+
this.xSouth = x;
|
|
35
|
+
this.xWest = x;
|
|
36
|
+
|
|
37
|
+
this.xOverflow = TUtil.isDefined(this.tmodel.getValue('xOverflow')) ? this.tmodel.getValue('xOverflow') : x;
|
|
38
|
+
|
|
39
|
+
this.yNext = y;
|
|
40
|
+
this.yNorth = y;
|
|
41
|
+
this.yWest = y;
|
|
42
|
+
this.yEast = y;
|
|
43
|
+
this.ySouth = this.tmodel.getRealParent().viewport ? this.tmodel.getRealParent().viewport.ySouth : y;
|
|
44
|
+
|
|
45
|
+
} else {
|
|
46
|
+
x = this.tmodel.getX();
|
|
47
|
+
y = this.tmodel.getY();
|
|
48
|
+
|
|
49
|
+
this.xNext = x;
|
|
50
|
+
this.xNorth = x;
|
|
51
|
+
this.xEast = x;
|
|
52
|
+
this.xSouth = x;
|
|
53
|
+
this.xWest = x;
|
|
54
|
+
|
|
55
|
+
this.xOverflow = TUtil.isDefined(this.tmodel.getValue('xOverflow')) ? this.tmodel.getValue('xOverflow') : x;
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
this.yNext = y;
|
|
59
|
+
this.yNorth = y;
|
|
60
|
+
this.yWest = y;
|
|
61
|
+
this.yEast = y;
|
|
62
|
+
this.ySouth = y;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
Viewport.prototype.setCurrentChild = function(child) {
|
|
69
|
+
this.currentChild = child;
|
|
70
|
+
|
|
71
|
+
this.xOffset = child.getDomParent() ? -child.getDomParent().getX() : 0;
|
|
72
|
+
this.yOffset = child.getDomParent() ? -child.getDomParent().getY() : 0;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
Viewport.prototype.getXNext = function() {
|
|
76
|
+
return this.xNext + this.currentChild.getLeftMargin() + this.xOffset - this.tmodel.getScrollLeft();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
Viewport.prototype.getYNext = function() {
|
|
80
|
+
return this.yNext + this.currentChild.getTopMargin() + this.yOffset - this.tmodel.getScrollTop();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
Viewport.prototype.isXVisible = function(child, x1, x2, minX, maxX) {
|
|
84
|
+
return child.type === 'BI' ? true : x1 <= maxX && x2 >= minX;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
Viewport.prototype.isYVisible = function(child, y1, y2, minY, maxY) {
|
|
88
|
+
return y1 <= maxY && y2 >= minY;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
Viewport.prototype.isVisible = function(child) {
|
|
92
|
+
|
|
93
|
+
var parentScale = child.getDomParent() ? child.getDomParent().getScale() : 1;
|
|
94
|
+
|
|
95
|
+
var minX = tapp.dim.screen.x;
|
|
96
|
+
var minY = tapp.dim.screen.y;
|
|
97
|
+
var maxX = tapp.dim.screen.width;
|
|
98
|
+
var maxY = tapp.dim.screen.height;
|
|
99
|
+
|
|
100
|
+
var x = child.getX();
|
|
101
|
+
var y = child.getY();
|
|
102
|
+
|
|
103
|
+
if (child.getDomHolder() !== tapp.$dom) {
|
|
104
|
+
minX = child.getDomParent().isInFlow() ? child.getDomParent().absX : child.getDomParent().getX();
|
|
105
|
+
minY = child.getDomParent().isInFlow() ? child.getDomParent().absY : child.getDomParent().getY();
|
|
106
|
+
maxX = Math.min(maxX, minX + child.getDomParent().getWidth());
|
|
107
|
+
maxY = Math.min(maxY, minY + child.getDomParent().getHeight());
|
|
108
|
+
minX = Math.max(0, minX);
|
|
109
|
+
minY = Math.max(0, minY);
|
|
110
|
+
|
|
111
|
+
x = child.getDomParent().isInFlow() ? child.getDomParent().absX + child.getX() : child.getDomParent().getX() + child.getX();
|
|
112
|
+
y = child.getDomParent().isInFlow() ? child.getDomParent().absY + child.getY() : child.getDomParent().getY() + child.getY();
|
|
113
|
+
|
|
114
|
+
} else if (child.type === 'BI') {
|
|
115
|
+
maxX = child.getRealParent().getX() + child.getRealParent().getWidth();
|
|
116
|
+
maxY = child.getRealParent().getY() + child.getRealParent().getHeight();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var scale = parentScale * child.getTargetScale();
|
|
120
|
+
var maxWidth = scale * child.getTargetWidth();
|
|
121
|
+
var maxHeight = scale * child.getTargetHeight();
|
|
122
|
+
|
|
123
|
+
child.xVisible = this.isXVisible(child, x, x + maxWidth, minX, maxX);
|
|
124
|
+
child.yVisible = this.isYVisible(child, y, y + maxHeight, minY, maxY);
|
|
125
|
+
|
|
126
|
+
//browser.log(child.oid === 'desc')("oid: " + child.oid + " in " + this.tmodel.oid + " min-maxX:" + Math.round(minX) + "-" + Math.round(maxX) + " x:" + Math.round(x) + " w:" + Math.floor(maxWidth) + " sc:" + scale + " vx:" + child.xVisible);
|
|
127
|
+
//browser.log(child.oid === 'closeButton')("oid: " + child.oid + " in " + this.tmodel.oid + " min-maxY:" + Math.round(minY) + "-" + Math.round(maxY) + " y:" + Math.round(y) + " h:" + Math.floor(maxHeight) + " sc:" + scale + " vy:" + child.yVisible);
|
|
128
|
+
|
|
129
|
+
return child.isVisible();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
Viewport.prototype.isOverflow = function(outerXEast, innerXEast) {
|
|
133
|
+
if (TUtil.isNumber(outerXEast) && TUtil.isNumber(innerXEast)) {
|
|
134
|
+
return outerXEast > innerXEast;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
Viewport.prototype.overflow = function() {
|
|
139
|
+
this.xNext = this.xOverflow;
|
|
140
|
+
this.yNext = this.ySouth;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
Viewport.prototype.appendNewLine = function() {
|
|
144
|
+
|
|
145
|
+
var height = this.currentChild.getHeight() * this.currentChild.getScale();
|
|
146
|
+
|
|
147
|
+
this.xNext = this.xOverflow;
|
|
148
|
+
this.yNext = this.ySouth + height + this.currentChild.getTopMargin() + this.currentChild.getBottomMargin() + this.currentChild.getValue('appendNewLine');
|
|
149
|
+
|
|
150
|
+
this.yEast = this.yNext;
|
|
151
|
+
this.xSouth = this.xNext;
|
|
152
|
+
|
|
153
|
+
this.ySouth = Math.max(this.yNext, this.ySouth);
|
|
154
|
+
|
|
155
|
+
this.currentChild.getRealParent().viewport.xEast = Math.max(this.currentChild.getRealParent().viewport.xEast, this.xEast);
|
|
156
|
+
this.currentChild.getRealParent().viewport.ySouth = Math.max(this.currentChild.getRealParent().viewport.ySouth, this.ySouth);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
Viewport.prototype.nextLocation = function() {
|
|
160
|
+
|
|
161
|
+
var innerWidth = this.currentChild.getInnerWidth() * this.currentChild.getScale();
|
|
162
|
+
var innerHeight = this.currentChild.getInnerHeight() * this.currentChild.getScale();
|
|
163
|
+
var innerContentHeight = this.currentChild.getInnerContentHeight() * this.currentChild.getScale();
|
|
164
|
+
|
|
165
|
+
var ySouth = this.yNext + innerHeight + this.currentChild.getTopMargin() + this.currentChild.getBottomMargin();
|
|
166
|
+
this.xNext += innerWidth + this.currentChild.getLeftMargin() + this.currentChild.getRightMargin();
|
|
167
|
+
this.yNext += innerContentHeight;
|
|
168
|
+
|
|
169
|
+
this.xSouth = this.xNext;
|
|
170
|
+
this.yEast = this.yNext;
|
|
171
|
+
|
|
172
|
+
this.xEast = Math.max(this.xNext, this.xEast);
|
|
173
|
+
this.ySouth = Math.max(ySouth, this.ySouth);
|
|
174
|
+
|
|
175
|
+
this.currentChild.getRealParent().viewport.xEast = Math.max(this.currentChild.getRealParent().viewport.xEast, this.xEast);
|
|
176
|
+
this.currentChild.getRealParent().viewport.ySouth = Math.max(this.currentChild.getRealParent().viewport.ySouth, this.ySouth);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
Viewport.prototype.calcContentWidthHeight = function() {
|
|
180
|
+
this.tmodel.contentHeight = this.ySouth - this.yNorth;
|
|
181
|
+
this.tmodel.innerContentHeight = this.yEast - this.yNorth;
|
|
182
|
+
this.tmodel.innerContentWidth = this.xSouth - this.xWest;
|
|
183
|
+
this.tmodel.contentWidth = this.xEast - this.xWest;
|
|
184
|
+
};
|