Issues (171)

1
/**
2
 * @param include
3
 * @param error
4
 * @param success
5
 * @constructor
6
 */
7 View Code Duplication
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);
0 ignored issues
show
The variable file seems to be never declared. If this is a global, consider adding a /** global: file */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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