UnitApi /
js
| 1 | View Code Duplication | var Router = function (target, error, success) { |
|
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 2 | // |
||
| 3 | this.cfg = {}; |
||
| 4 | this.cfg.target = target; |
||
| 5 | this.included = []; |
||
| 6 | |||
| 7 | if (typeof error !== 'function') { |
||
| 8 | error = function (data) { |
||
|
0 ignored issues
–
show
|
|||
| 9 | console.log('error', "Page not found."); |
||
|
0 ignored issues
–
show
|
|||
| 10 | // console.error(data); |
||
| 11 | // AddMessage(data.message.error); |
||
| 12 | } |
||
| 13 | } |
||
| 14 | |||
| 15 | if (typeof success !== 'function') { |
||
| 16 | success = function (data) { |
||
|
0 ignored issues
–
show
|
|||
| 17 | console.log('success', "included"); |
||
|
0 ignored issues
–
show
|
|||
| 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) { |
||
|
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty.
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
Loading history...
|
|||
| 37 | console.log('apiunit.docs: ', i, ' = ', obj[i]); |
||
|
0 ignored issues
–
show
|
|||
| 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) { |
||
|
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty.
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
Loading history...
|
|||
| 54 | |||
| 55 | console.log('files[i] ', files[i]); |
||
|
0 ignored issues
–
show
|
|||
| 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); |
||
|
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...
|
|||
| 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) { |
||
|
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty.
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
Loading history...
|
|||
| 115 | |||
| 116 | console.log('files[i] ', files[i]); |
||
|
0 ignored issues
–
show
|
|||
| 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) { |
||
|
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty.
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
Loading history...
|
|||
| 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) { |
||
|
0 ignored issues
–
show
|
|||
| 156 | // addScriptToHeadDelayed(file); |
||
| 157 | window.onload = function () { |
||
| 158 | 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...
|
|||
| 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) { |
||
|
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty.
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
Loading history...
|
|||
| 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); |
||
|
0 ignored issues
–
show
|
|||
| 197 | addStyleToHead(file); |
||
| 198 | } |
||
| 199 | //router.included.push(file); |
||
| 200 | // return this; |
||
| 201 | }; |
||
| 202 | |||
| 203 | // return this; |
||
| 204 | }; |
||
| 205 |