@@ 7-223 (lines=217) @@ | ||
4 | * @param success |
|
5 | * @constructor |
|
6 | */ |
|
7 | var Router = function (include, error, success) { |
|
8 | ||
9 | this.cfg = {}; |
|
10 | this.cfg.target = 'body'; |
|
11 | this.include = include; |
|
12 | this.included = []; |
|
13 | ||
14 | ||
15 | if (typeof error !== 'function') { |
|
16 | error = function (data) { |
|
17 | console.log('error', "Page not found."); |
|
18 | // console.error(data); |
|
19 | // AddMessage(data.message.error); |
|
20 | } |
|
21 | } |
|
22 | ||
23 | if (typeof success !== 'function') { |
|
24 | success = function (data) { |
|
25 | console.log('success', "included"); |
|
26 | // console.table(data); |
|
27 | // AddMessage(data.message.info); |
|
28 | } |
|
29 | } |
|
30 | ||
31 | this.error = error; |
|
32 | this.success = success; |
|
33 | ||
34 | var router = this; |
|
35 | ||
36 | ||
37 | // var obj = this; |
|
38 | this.docs = function (obj) { |
|
39 | if (typeof obj !== 'object') { |
|
40 | console.error('apiunit.docs: is not object:', obj); |
|
41 | return this; |
|
42 | } |
|
43 | ||
44 | for (var i in obj) { |
|
45 | console.log('apiunit.docs: ', i, ' = ', obj[i]); |
|
46 | ||
47 | // for (var name in obj[i]) { |
|
48 | // console.log('apiunit.docs: ', name, obj[i][name]); |
|
49 | // } |
|
50 | } |
|
51 | return this; |
|
52 | }; |
|
53 | ||
54 | ||
55 | this.image = function (files) { |
|
56 | ||
57 | if (typeof files !== 'object') { |
|
58 | files = [files]; |
|
59 | } |
|
60 | ||
61 | for (var i in files) { |
|
62 | ||
63 | console.log('files[i] ', files[i]); |
|
64 | ||
65 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
66 | ||
67 | console.log('exist_in_apiunit ', exist_in_apiunit); |
|
68 | ||
69 | ||
70 | if (!exist_in_apiunit) { |
|
71 | router.include.includeImg(files[i], router.cfg.target, router.error, router.success); |
|
72 | router.included.push(files[i]); |
|
73 | ||
74 | } else { |
|
75 | console.error('!exist: ', files[i]); |
|
76 | } |
|
77 | } |
|
78 | ||
79 | return this; |
|
80 | }; |
|
81 | ||
82 | ||
83 | this.domain = function (domain) { |
|
84 | if (typeof domain !== 'object') { |
|
85 | router.cfg.domain = domain; |
|
86 | // router.included.push(domain); |
|
87 | } else { |
|
88 | console.error('apiunit.domain: is an object:', domain); |
|
89 | } |
|
90 | ||
91 | return this; |
|
92 | }; |
|
93 | ||
94 | // let img = new Image; |
|
95 | // |
|
96 | // img.onload = function() { |
|
97 | // console.log ("Bild geladen"); |
|
98 | // elem.appendChild (img); |
|
99 | // } |
|
100 | // img.src = "../img/apiunit.png"; // erst nach dem Event Listener! |
|
101 | // |
|
102 | // window.onunload = function() { |
|
103 | // alert('bye bye Honey') |
|
104 | // }; |
|
105 | // |
|
106 | // window.onload = function () { |
|
107 | // console.log('Dokument geladen'); |
|
108 | // } |
|
109 | // |
|
110 | ||
111 | this.target = function (target) { |
|
112 | router.cfg.target = target; |
|
113 | ||
114 | return this; |
|
115 | }; |
|
116 | ||
117 | this.html = function (files) { |
|
118 | ||
119 | if (typeof files !== 'object') { |
|
120 | files = [files]; |
|
121 | } |
|
122 | // console.log('files ', files); |
|
123 | ||
124 | if (typeof router.cfg.target !== 'string') { |
|
125 | console.error('!router html router.cfg.target ', router.cfg.target); |
|
126 | return this; |
|
127 | } |
|
128 | // var target = router.cfg.target |
|
129 | ||
130 | for (var i in files) { |
|
131 | ||
132 | console.log('files[i] ', files[i]); |
|
133 | ||
134 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
135 | ||
136 | console.log('exist_in_apiunit ', exist_in_apiunit); |
|
137 | ||
138 | ||
139 | if (!exist_in_apiunit) { |
|
140 | router.include.includeHtml(files[i], router.cfg.target, router.error, router.success); |
|
141 | router.included.push(files[i]); |
|
142 | } else { |
|
143 | console.error('!exist: ', files[i]); |
|
144 | } |
|
145 | } |
|
146 | ||
147 | return this; |
|
148 | }; |
|
149 | ||
150 | this.script = function (files) { |
|
151 | if (typeof files !== 'object') { |
|
152 | files = [files]; |
|
153 | } |
|
154 | ||
155 | for (var i in files) { |
|
156 | ||
157 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
158 | ||
159 | if (!exist_in_apiunit) { |
|
160 | // router.include.addScriptToHead(files[i], router.cfg.target, router.error, router.success); |
|
161 | router.include.addScriptToHead(files[i]); |
|
162 | router.included.push(files[i]); |
|
163 | } else { |
|
164 | console.error('!exist: ', files[i]); |
|
165 | } |
|
166 | } |
|
167 | ||
168 | return this; |
|
169 | }; |
|
170 | ||
171 | this.script_onload = function (files) { |
|
172 | // addScriptToHeadDelayed(file); |
|
173 | window.onload = function () { |
|
174 | router.include.addScriptToHead(file); |
|
175 | }; |
|
176 | //router.included.push(file); |
|
177 | // return this; |
|
178 | }; |
|
179 | this.script_delay = function (file) { |
|
180 | router.include.addScriptToHeadDelayed(file); |
|
181 | }; |
|
182 | ||
183 | ||
184 | this.style = function (files) { |
|
185 | if (typeof files !== 'object') { |
|
186 | files = [files]; |
|
187 | } |
|
188 | ||
189 | for (var i in files) { |
|
190 | ||
191 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
192 | ||
193 | if (!exist_in_apiunit) { |
|
194 | //router.include.addStyleToHead(files[i], router.cfg.target, this.error, this.success); |
|
195 | router.include.addStyleToHead(files[i]); |
|
196 | router.included.push(files[i]); |
|
197 | } else { |
|
198 | console.error('!exist: ', files[i]); |
|
199 | } |
|
200 | } |
|
201 | ||
202 | return this; |
|
203 | }; |
|
204 | ||
205 | this.style_string = function (file) { |
|
206 | // addStyleStringToHeadDelayed(file); |
|
207 | router.include.addStyleStringToHead(file); |
|
208 | //router.included.push(file); |
|
209 | ||
210 | // return this; |
|
211 | }; |
|
212 | ||
213 | this.style_onload = function (file) { |
|
214 | window.onload = function () { |
|
215 | console.log('style_onload', file); |
|
216 | router.include.addStyleToHead(file); |
|
217 | } |
|
218 | //router.included.push(file); |
|
219 | // return this; |
|
220 | }; |
|
221 | ||
222 | // return this; |
|
223 | }; |
|
224 |
@@ 1-204 (lines=204) @@ | ||
1 | var Router = function (target, error, success) { |
|
2 | // |
|
3 | this.cfg = {}; |
|
4 | this.cfg.target = target; |
|
5 | this.included = []; |
|
6 | ||
7 | if (typeof error !== 'function') { |
|
8 | error = function (data) { |
|
9 | console.log('error', "Page not found."); |
|
10 | // console.error(data); |
|
11 | // AddMessage(data.message.error); |
|
12 | } |
|
13 | } |
|
14 | ||
15 | if (typeof success !== 'function') { |
|
16 | success = function (data) { |
|
17 | console.log('success', "included"); |
|
18 | // console.table(data); |
|
19 | // AddMessage(data.message.info); |
|
20 | } |
|
21 | } |
|
22 | ||
23 | this.error = error; |
|
24 | this.success = success; |
|
25 | ||
26 | var router = this; |
|
27 | ||
28 | ||
29 | // var obj = this; |
|
30 | this.docs = function (obj) { |
|
31 | if (typeof obj !== 'object') { |
|
32 | console.error('apiunit.docs: is not object:', obj); |
|
33 | return this; |
|
34 | } |
|
35 | ||
36 | for (var i in obj) { |
|
37 | console.log('apiunit.docs: ', i, ' = ', obj[i]); |
|
38 | ||
39 | // for (var name in obj[i]) { |
|
40 | // console.log('apiunit.docs: ', name, obj[i][name]); |
|
41 | // } |
|
42 | } |
|
43 | return this; |
|
44 | }; |
|
45 | ||
46 | ||
47 | this.image = function (files) { |
|
48 | ||
49 | if (typeof files !== 'object') { |
|
50 | files = [files]; |
|
51 | } |
|
52 | ||
53 | for (var i in files) { |
|
54 | ||
55 | console.log('files[i] ', files[i]); |
|
56 | ||
57 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
58 | ||
59 | console.log('exist_in_apiunit ', exist_in_apiunit); |
|
60 | ||
61 | ||
62 | if (!exist_in_apiunit) { |
|
63 | includeImg(files[i], router.cfg.target, this.error, this.success); |
|
64 | router.included.push(files[i]); |
|
65 | ||
66 | } else { |
|
67 | console.error('!exist: ', files[i]); |
|
68 | } |
|
69 | } |
|
70 | ||
71 | return this; |
|
72 | }; |
|
73 | ||
74 | ||
75 | this.domain = function (domain) { |
|
76 | if (typeof domain !== 'object') { |
|
77 | router.cfg.domain = domain; |
|
78 | router.included.push(file); |
|
79 | }{ |
|
80 | console.error('apiunit.domain: is an object:', domain); |
|
81 | } |
|
82 | ||
83 | return this; |
|
84 | }; |
|
85 | ||
86 | // let img = new Image; |
|
87 | // |
|
88 | // img.onload = function() { |
|
89 | // console.log ("Bild geladen"); |
|
90 | // elem.appendChild (img); |
|
91 | // } |
|
92 | // img.src = "../img/apiunit.png"; // erst nach dem Event Listener! |
|
93 | // |
|
94 | // window.onunload = function() { |
|
95 | // alert('bye bye Honey') |
|
96 | // }; |
|
97 | // |
|
98 | // window.onload = function () { |
|
99 | // console.log('Dokument geladen'); |
|
100 | // } |
|
101 | // |
|
102 | this.target = function (target) { |
|
103 | router.cfg.target = target; |
|
104 | ||
105 | return this; |
|
106 | }; |
|
107 | ||
108 | this.html = function (files, target) { |
|
109 | ||
110 | if (typeof files !== 'object') { |
|
111 | files = [files]; |
|
112 | } |
|
113 | ||
114 | for (var i in files) { |
|
115 | ||
116 | console.log('files[i] ', files[i]); |
|
117 | ||
118 | ||
119 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
120 | ||
121 | console.log('exist_in_apiunit ', exist_in_apiunit); |
|
122 | ||
123 | ||
124 | if (!exist_in_apiunit) { |
|
125 | includeHtml(files[i], router.cfg.target, this.error, this.success); |
|
126 | router.included.push(files[i]); |
|
127 | } else { |
|
128 | console.error('!exist: ', files[i]); |
|
129 | } |
|
130 | } |
|
131 | ||
132 | return this; |
|
133 | }; |
|
134 | ||
135 | this.script = function (files, target) { |
|
136 | if (typeof files !== 'object') { |
|
137 | files = [files]; |
|
138 | } |
|
139 | ||
140 | for (var i in files) { |
|
141 | ||
142 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
143 | ||
144 | if (!exist_in_apiunit) { |
|
145 | addScriptToHead(files[i], target, this.error, this.success); |
|
146 | router.included.push(files[i]); |
|
147 | } else { |
|
148 | console.error('!exist: ', files[i]); |
|
149 | } |
|
150 | } |
|
151 | ||
152 | return this; |
|
153 | }; |
|
154 | ||
155 | this.script_onload = function (files) { |
|
156 | // addScriptToHeadDelayed(file); |
|
157 | window.onload = function () { |
|
158 | addScriptToHead(file); |
|
159 | }; |
|
160 | //router.included.push(file); |
|
161 | // return this; |
|
162 | }; |
|
163 | this.script_delay = function (file) { |
|
164 | addScriptToHeadDelayed(file); |
|
165 | }; |
|
166 | ||
167 | ||
168 | this.style = function (files, target) { |
|
169 | if (typeof files !== 'object') { |
|
170 | files = [files]; |
|
171 | } |
|
172 | ||
173 | for (var i in files) { |
|
174 | ||
175 | var exist_in_apiunit = router.included.indexOf(files[i]) !== -1; |
|
176 | ||
177 | if (!exist_in_apiunit) { |
|
178 | addStyleToHead(files[i], target, this.error, this.success); |
|
179 | router.included.push(files[i]); |
|
180 | } else { |
|
181 | console.error('!exist: ', files[i]); |
|
182 | } |
|
183 | } |
|
184 | ||
185 | return this; |
|
186 | }; |
|
187 | this.style_string = function (file) { |
|
188 | // addStyleStringToHeadDelayed(file); |
|
189 | addStyleStringToHead(file); |
|
190 | //router.included.push(file); |
|
191 | ||
192 | // return this; |
|
193 | }; |
|
194 | this.style_onload = function (file) { |
|
195 | window.onload = function () { |
|
196 | console.log('style_onload', file); |
|
197 | addStyleToHead(file); |
|
198 | } |
|
199 | //router.included.push(file); |
|
200 | // return this; |
|
201 | }; |
|
202 | ||
203 | // return this; |
|
204 | }; |
|
205 |