targetj 1.0.74 → 1.0.76

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.
Files changed (44) hide show
  1. package/babel.config.json +17 -0
  2. package/build/$Dom.js +424 -0
  3. package/build/App.js +187 -0
  4. package/build/Bracket.js +157 -0
  5. package/build/BracketGenerator.js +86 -0
  6. package/build/Browser.js +105 -0
  7. package/build/ColorUtil.js +182 -0
  8. package/build/Dim.js +31 -0
  9. package/build/Easing.js +59 -0
  10. package/build/EventListener.js +664 -0
  11. package/build/LoadingManager.js +366 -0
  12. package/build/LocationManager.js +211 -0
  13. package/build/Moves.js +71 -0
  14. package/build/PageManager.js +113 -0
  15. package/build/SearchUtil.js +196 -0
  16. package/build/TModel.js +1000 -0
  17. package/build/TModelManager.js +605 -0
  18. package/build/TUtil.js +188 -0
  19. package/build/TargetExecutor.js +117 -0
  20. package/build/TargetManager.js +197 -0
  21. package/build/TargetUtil.js +299 -0
  22. package/build/Viewport.js +163 -0
  23. package/package.json +11 -4
  24. package/webpack.config.js +14 -1
  25. package/src/$Dom.js +0 -380
  26. package/src/App.js +0 -224
  27. package/src/Bracket.js +0 -212
  28. package/src/Browser.js +0 -122
  29. package/src/ColorUtil.js +0 -166
  30. package/src/Dim.js +0 -21
  31. package/src/Easing.js +0 -41
  32. package/src/EventListener.js +0 -570
  33. package/src/LoadingManager.js +0 -368
  34. package/src/LocationManager.js +0 -236
  35. package/src/Moves.js +0 -59
  36. package/src/PageManager.js +0 -87
  37. package/src/SearchUtil.js +0 -210
  38. package/src/TModel.js +0 -937
  39. package/src/TModelManager.js +0 -575
  40. package/src/TUtil.js +0 -162
  41. package/src/TargetExecutor.js +0 -113
  42. package/src/TargetManager.js +0 -191
  43. package/src/TargetUtil.js +0 -307
  44. package/src/Viewport.js +0 -180
package/src/$Dom.js DELETED
@@ -1,380 +0,0 @@
1
- import { browser } from "./Browser.js";
2
- import { TUtil } from "./TUtil.js";
3
- import { getManager } from "./App.js";
4
-
5
- function $Dom(elemSelector) {
6
- if (typeof elemSelector === 'string') {
7
- this.selector = elemSelector;
8
- this.element = $Dom.query(elemSelector);
9
- } else if (elemSelector) {
10
- this.element = elemSelector;
11
- }
12
-
13
- this.childrenCount = 0;
14
- this.$domParent = undefined;
15
- this.originalContent = undefined;
16
- this.textOnly = true;
17
- }
18
-
19
- $Dom.prototype.exists = function() {
20
- if (this.selector) {
21
- this.element = $Dom.query(this.selector);
22
- }
23
-
24
- return !!this.element;
25
- };
26
-
27
- $Dom.prototype.create = function(tag) {
28
- this.element = document.createElement(tag);
29
- };
30
-
31
- $Dom.prototype.setSelector = function(selector) {
32
- this.selector = selector;
33
- };
34
-
35
- $Dom.prototype.setId = function(id) {
36
- this.attr("id", id[0] === '#' ? id.slice(1) : id);
37
- };
38
-
39
- $Dom.prototype.focus = function() {
40
- this.element.focus();
41
- };
42
-
43
- $Dom.prototype.attr = function(name, value) {
44
- if (!this.element) {
45
- return;
46
- }
47
-
48
- if (TUtil.isDefined(value)) {
49
- this.element.setAttribute(name, value);
50
- } else {
51
- return this.element.getAttribute(name);
52
- }
53
- };
54
-
55
- $Dom.prototype.value = function(value) {
56
- if (!this.element) {
57
- return;
58
- }
59
-
60
- if (TUtil.isDefined(value)) {
61
- this.element.value = value;
62
- } else {
63
- return this.element.value;
64
- }
65
- };
66
-
67
- $Dom.prototype.select = function() {
68
- if (!this.element || typeof this.element.select !== 'function') {
69
- return;
70
- }
71
-
72
- this.element.select();
73
- };
74
-
75
- $Dom.prototype.width = function(width) {
76
- if (TUtil.isDefined(width)) {
77
- this.element.style.width = TUtil.isNumber(width) ? width + 'px' : width;
78
- } else {
79
- return this.element.offsetWidth;
80
- }
81
- };
82
-
83
- $Dom.prototype.height = function(height) {
84
- if (TUtil.isDefined(height)) {
85
- this.element.style.height = TUtil.isNumber(height) ? height + 'px' : height;
86
- } else {
87
- return this.element.offsetHeight;
88
- }
89
- };
90
-
91
- $Dom.prototype.css = function(css) {
92
- if (TUtil.isDefined(css)) {
93
- this.attr('class', css);
94
- } else {
95
- return this.attr('classs');
96
- }
97
- };
98
-
99
- $Dom.prototype.setStyleByMap = function(attrMap) {
100
- var self = this;
101
- Object.keys(attrMap).forEach(function(key) {
102
- var value = attrMap[key];
103
- switch(key) {
104
- case 'transform':
105
- self.transform.apply(self, value);
106
- break;
107
-
108
- case 'width':
109
- self.width(value);
110
- break;
111
-
112
- case 'height':
113
- self.height(value);
114
- break;
115
-
116
- default:
117
- self.style(key, value);
118
- }
119
- });
120
- };
121
-
122
- $Dom.prototype.style = function(name, value) {
123
- if (TUtil.isDefined(value)) {
124
- this.element.style[name] = value;
125
- } else {
126
- return this.element.style[name];
127
- }
128
- };
129
-
130
- $Dom.prototype.getStyleValue = function(name) {
131
- var styleValue = this.style(name);
132
- var numericValue = TUtil.isDefined(styleValue) ? styleValue.replace(/[^-\d.]/g, '') : 0;
133
- return parseFloat(numericValue);
134
- };
135
-
136
- $Dom.prototype.getBoundingClientRect = function() {
137
- return this.element.getBoundingClientRect();
138
- };
139
-
140
- $Dom.prototype.parent = function() {
141
- return this.element ? this.element.parentElement : null;
142
- };
143
-
144
- $Dom.prototype.detach = function() {
145
- $Dom.detach(this.element);
146
- if (this.$domParent && this.$domParent.childrenCount > 0) {
147
- this.$domParent.childrenCount--;
148
- }
149
- };
150
-
151
- $Dom.prototype.append$Dom = function($dom) {
152
- this.element.appendChild($dom.element);
153
- };
154
-
155
- $Dom.prototype.insertFirst$Dom = function($dom) {
156
- if (this.element.firstChild) {
157
- this.element.insertBefore($dom.element, this.element.firstChild);
158
- } else {
159
- this.append$Dom($dom);
160
- }
161
- };
162
-
163
- $Dom.prototype.appendTModel$Dom = function(tmodel) {
164
- if (this.childrenCount === 0 && this.element.children.length > 1 && tmodel.getDomParent() && tmodel.getDomParent().getHtml()
165
- && tmodel.getDomParent().getHtml() === this.originalContent) {
166
- this.element.innerHTML = "<div>" + this.html() + "</div>";
167
- }
168
-
169
- this.element.appendChild(tmodel.$dom.element);
170
- tmodel.$dom.$domParent = this;
171
- this.childrenCount++;
172
- };
173
-
174
- $Dom.prototype.html = function(html) {
175
- if (TUtil.isDefined(html)) {
176
- if (this.childrenCount > 0) {
177
-
178
- var element = document.createElement('div');
179
- element.innerHTML = html;
180
-
181
- if (TUtil.isDefined(this.originalContent)) {
182
- this.element.replaceChild(element, this.element.firstChild);
183
- } else {
184
- this.element.insertBefore(element, this.element.firstChild);
185
- }
186
-
187
- this.originalContent = html;
188
- this.textOnly = false;
189
-
190
- } else {
191
- this.element.innerHTML = html;
192
- this.originalContent = html;
193
- this.textOnly = false;
194
- }
195
- } else {
196
- return this.originalContent;
197
- }
198
- };
199
-
200
- $Dom.prototype.text = function(text) {
201
- if (TUtil.isDefined(text)) {
202
- if (this.childrenCount > 0) {
203
- var element = document.createTextNode(text);
204
- if (TUtil.isDefined(this.originalContent)) {
205
- this.element.replaceChild(element, this.element.firstChild);
206
- } else {
207
- this.element.insertBefore(element, this.element.firstChild);
208
- }
209
-
210
- this.originalContent = text;
211
- this.textOnly = true;
212
-
213
- } else {
214
- this.element.textContent = text;
215
- this.originalContent = text;
216
- this.textOnly = true;
217
- }
218
- } else {
219
- return this.originalContent;
220
- }
221
- };
222
-
223
- $Dom.prototype.outerHTML = function(html) {
224
- this.element.outerHTML = html;
225
- };
226
-
227
- $Dom.prototype.innerHTML = function(html) {
228
- if (TUtil.isDefined(html)) {
229
- this.element.innerHTML = html;
230
- } else {
231
- return this.element.innerHTML;
232
- }
233
- };
234
-
235
- $Dom.prototype.addClass = function(className) {
236
- var oldValue = this.attr('class');
237
- var newValue = !oldValue ? className : oldValue.indexOf(className) >= 0 ? oldValue : oldValue + ' ' + className;
238
-
239
- if (newValue !== oldValue) {
240
- this.attr('class', newValue);
241
- }
242
- };
243
-
244
- $Dom.prototype.addEvent = function (type, fn) {
245
- if (!this.element.addEventListener) {
246
- this.element.attachEvent("on" + type, fn);
247
- } else {
248
- this.element.addEventListener(type, fn, { capture: false, passive: false });
249
- }
250
- };
251
-
252
- $Dom.prototype.detachEvent = function (type, fn) {
253
- if (this.element.removeEventListener) {
254
- this.element.removeEventListener(type, fn, false);
255
- } else if (this.element.detachEvent) {
256
- this.element.detachEvent("on" + type, fn);
257
- } else {
258
- this.element["on" + type] = null;
259
- }
260
- };
261
-
262
- $Dom.prototype.transform = function(x, y, rotate, scale) {
263
- var tranformValue = this.createTrasformValue(x, y, rotate, scale);
264
- if (tranformValue !== this.element.style[browser.style.transform]) {
265
- this.element.style[browser.style.transform] = tranformValue;
266
- }
267
- };
268
-
269
- $Dom.prototype.createTrasformValue = function(x, y, rotate, scale) {
270
- var xy = TUtil.isDefined(x) && TUtil.isDefined(y) ? 'translate(' + (x !== 0 ? x + 'px' : '0') + ',' + (y !== 0 ? y + 'px' : '0') + ') ': '';
271
- rotate = TUtil.isDefined(rotate) ? 'rotate(' + rotate + 'deg) ' : '';
272
- scale = TUtil.isDefined(scale) ? 'scale(' + scale + ')' : '';
273
- return (xy + rotate + scale).trim();
274
- };
275
-
276
- $Dom.prototype.animate = function(keyFrames, options) {
277
- return this.element.animate(keyFrames, options);
278
- };
279
-
280
- $Dom.prototype.getContext = function(type, selector) {
281
- var element = TUtil.isDefined(selector) ? $Dom.query(selector) : this.query('canvas');
282
- return element ? element.getContext(type) : undefined;
283
- };
284
-
285
- $Dom.prototype.findFirstByClass = function(className) {
286
- return $Dom.findFirstByClass(className, this.element);
287
- };
288
-
289
- $Dom.prototype.findFirstByTag = function(tagName) {
290
- return $Dom.findFirstByTag(tagName, this.element);
291
- };
292
-
293
- $Dom.prototype.query = function(selector) {
294
- return selector[0] === '#' ? $Dom.findById(selector) : selector[0] === '.' ? this.findFirstByClass(selector) : this.findFirstByTag(selector);
295
- };
296
-
297
- $Dom.query = function(selector) {
298
- return selector[0] === '#' ? $Dom.findById(selector) : selector[0] === '.' ? $Dom.findFirstByClass(selector) : $Dom.findFirstByTag(selector);
299
- };
300
-
301
- $Dom.findById = function(id) {
302
- return document.getElementById(id[0] === '#' ? id.slice(1) : id);
303
- };
304
-
305
- $Dom.findFirstByClass = function(className, element) {
306
- var elements = $Dom.findByClass(className, element);
307
- return elements.length > 0 ? elements[0] : null;
308
- };
309
-
310
- $Dom.findFirstByTag = function(tagName, element) {
311
- var elements = $Dom.findByTag(tagName, element);
312
- return elements.length > 0 ? elements[0] : null;
313
- };
314
-
315
- $Dom.findByTag = function(tagName, element) {
316
- element = TUtil.isDefined(element) ? element : document;
317
- return element.getElementsByTagName(tagName);
318
- };
319
-
320
- $Dom.findByClass = function(className, element) {
321
- element = TUtil.isDefined(element) ? element : document;
322
- return element.getElementsByClassName(className[0] === '.' ? className.slice(1) : className);
323
- };
324
-
325
- $Dom.findNearestParentWithId = function(element) {
326
- while (element) {
327
- var oid = typeof element.getAttribute === 'function' && element.getAttribute("id") ? element.getAttribute("id") : null;
328
- if (oid && getManager().visibleOidMap[oid]) {
329
- return oid;
330
- }
331
-
332
- element = element.parentElement;
333
- }
334
- };
335
-
336
- $Dom.detach = function(element) {
337
- var parent = TUtil.isDefined(element) ? element.parentElement : null;
338
- if (parent) {
339
- parent.removeChild(element);
340
- }
341
- };
342
-
343
- $Dom.ready = function(callback) {
344
- var $doc = new $Dom(document);
345
- $doc.addEvent('DOMContentLoaded', callback);
346
- };
347
-
348
- $Dom.ajax = function(query) {
349
- var xhr = new XMLHttpRequest();
350
-
351
- var params = "";
352
- if (query.data) {
353
- params = Object.keys(query.data).map(function(key) {
354
- return key + "=" + encodeURIComponent(query.data[key]);
355
- }).join('&');
356
- }
357
-
358
- xhr.onreadystatechange = function () {
359
- if (xhr.readyState === 4) {
360
- if (xhr.status === 200) {
361
- var response = query.dataType === 'json' ? JSON.parse(this.responseText) : this.responseText;
362
- query.success(response);
363
- } else {
364
- query.error(xhr.status);
365
- }
366
- }
367
- };
368
-
369
- if (query.type === 'POST') {
370
- xhr.open(query.type, query.url, true);
371
- xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
372
- xhr.send(params);
373
- } else {
374
- query.url += !params ? "" : query.url > "" && query.url.indexOf("?") >= 0 ? "&" + params : "?" + params;
375
- xhr.open(query.type, query.url, true);
376
- xhr.send();
377
- }
378
- };
379
-
380
- export { $Dom };
package/src/App.js DELETED
@@ -1,224 +0,0 @@
1
- import { $Dom } from "./$Dom.js";
2
- import { TModel } from "./TModel.js";
3
- import { browser } from "./Browser.js";
4
- import { Dim } from "./Dim.js";
5
- import { EventListener } from "./EventListener.js";
6
- import { LoadingManager } from "./LoadingManager.js";
7
- import { LocationManager } from "./LocationManager.js";
8
- import { PageManager } from "./PageManager.js";
9
- import { SearchUtil } from "./SearchUtil.js";
10
- import { TModelManager } from "./TModelManager.js";
11
- import { TUtil } from "./TUtil.js";
12
- import { TargetManager } from "./TargetManager.js";
13
-
14
- var tapp;
15
-
16
- function AppFn(firstChild) {
17
-
18
- function my() {}
19
-
20
- my.throttle = 0;
21
- my.debugLevel = 0;
22
-
23
- my.runningFlag = false;
24
-
25
- my.init = function() {
26
- browser.setup();
27
-
28
- my.$window = new $Dom(window);
29
- my.$window.addEvent("popstate", function(event) {
30
- if (event.state) {
31
- tapp.pager.openLinkFromHistory(event.state);
32
- }
33
- });
34
-
35
- my.loader = new LoadingManager();
36
-
37
- my.pager = new PageManager();
38
-
39
- my.dim = Dim().measureScreen();
40
-
41
- my.events = new EventListener();
42
-
43
- my.locationManager = new LocationManager();
44
- my.targetManager = new TargetManager();
45
- my.manager = new TModelManager();
46
-
47
- my.trootFactory = function() {
48
-
49
- var troot = new TModel('targetj');
50
-
51
- troot.addChild = function(child, index) {
52
- if (!TUtil.isDefined(child.targets['domHolder'])) {
53
- child.addTarget('domHolder', {
54
- value: function() {
55
- var $dom;
56
- if (!$Dom.query('#tj-root')) {
57
- $dom = new $Dom();
58
- $dom.create('div');
59
- $dom.setSelector('#tj-root');
60
- $dom.setId('#tj-root');
61
- $dom.attr("tabindex", "0");
62
- new $Dom('body').insertFirst$Dom($dom);
63
- } else {
64
- $dom = new $Dom('#tj-root');
65
- }
66
- return $dom;
67
- }
68
- });
69
- }
70
-
71
- if (!TUtil.isDefined(child.targets['addEventHandler'])) {
72
- child.addTarget('addEventHandler', {
73
- value: function() {
74
- my.events.removeHandlers(this.$dom);
75
- my.events.addHandlers(this.$dom);
76
- if (this.hasDom) {
77
- this.$dom.focus();
78
- }
79
- },
80
- enabledOn: function() {
81
- return this.hasDom();
82
- }
83
- });
84
- }
85
-
86
- TModel.prototype.addChild.call(troot, child, index);
87
- };
88
-
89
- if (my.troot) {
90
- my.troot.getChildren().forEach(function(t, num) {
91
- var child = new TModel(t.type, t.targets);
92
- child.oidNum = num;
93
- child.oid = num > 0 ? t.type + num : t.type;
94
- troot.addChild(child);
95
- });
96
- }
97
-
98
- return troot;
99
- };
100
-
101
-
102
- my.troot = my.trootFactory();
103
-
104
- if (firstChild) {
105
- my.troot.addChild(firstChild);
106
- }
107
-
108
- window.history.pushState({ link: document.URL }, "", document.URL);
109
-
110
- return my;
111
- };
112
-
113
- my.start = function () {
114
- my.runningFlag = false;
115
-
116
- my.events.clearAll();
117
- my.troot.getChildren().forEach(function(child) {
118
- child.deleteTargetValue('addEventHandler');
119
- });
120
-
121
- my.events.removeWindowHandlers();
122
- my.events.addWindowHandlers();
123
-
124
- my.dim.measureScreen();
125
- my.manager.resetRuns();
126
-
127
- my.runningFlag = true;
128
-
129
- my.manager.scheduleRun(0, "appStart");
130
-
131
- return my;
132
- };
133
-
134
- my.stop = function() {
135
- my.runningFlag = false;
136
-
137
- my.events.removeWindowHandlers();
138
- my.troot.getChildren().forEach(function(child) {
139
- if (child.hasDom()) {
140
- my.events.removeHandlers(child.$dom);
141
- }
142
- });
143
-
144
- my.events.clearAll();
145
-
146
- my.manager.resetRuns();
147
-
148
- return my;
149
- };
150
-
151
- my.reset = function() {
152
- my.manager.lists.visible.forEach(function(tmodel) { tmodel.domValues = {}; });
153
- my.manager.clear();
154
- my.locationManager.hasLocationList.length = 0;
155
- my.locationManager.screenWidth = 0;
156
- my.locationManager.screenHeight = 0;
157
- SearchUtil.foundParentWithTarget = {};
158
- SearchUtil.foundTypeMap = {};
159
- SearchUtil.foundTargetMap = {};
160
- };
161
-
162
- my.isRunning = function() {
163
- return my.runningFlag;
164
- };
165
-
166
- my.find = function(oid) {
167
- return SearchUtil.find(oid);
168
- };
169
-
170
- return my;
171
- }
172
-
173
- function App(tmodel) {
174
- tapp = AppFn(tmodel);
175
- tapp.init().start();
176
-
177
- return tapp;
178
- }
179
-
180
- function isRunning() {
181
- return tapp ? tapp.runningFlag : false;
182
- }
183
-
184
- function troot() {
185
- return tapp ? tapp.troot : null;
186
- }
187
-
188
- function getEvents() {
189
- return tapp ? tapp.events : null;
190
- }
191
-
192
- function getPager() {
193
- return tapp ? tapp.pager : null;
194
- }
195
-
196
- function getLoader() {
197
- return tapp ? tapp.loader : null;
198
- }
199
-
200
- function getManager() {
201
- return tapp ? tapp.manager : null;
202
- }
203
-
204
- function getScreenWidth() {
205
- return tapp ? tapp.dim.screen.width : 0;
206
- }
207
-
208
- function getScreenHeight() {
209
- return tapp ? tapp.dim.screen.height : 0;
210
- }
211
-
212
- window.t = window.t || SearchUtil.find;
213
-
214
- App.oids = {};
215
- App.getOid = function(type) {
216
- if (!TUtil.isDefined(App.oids[type])) {
217
- App.oids[type] = 0;
218
- }
219
-
220
- var num = App.oids[type]++;
221
- return { oid: num > 0 ? type + num : type, num: num };
222
- };
223
-
224
- export { tapp, App, troot, isRunning, getEvents, getPager, getLoader, getManager, $Dom, getScreenWidth, getScreenHeight };