| @@ 215-273 (lines=59) @@ | ||
| 212 | return target.appendChild(scriptTag); |
|
| 213 | } |
|
| 214 | ||
| 215 | function includeHtml(url, target, success, error) { |
|
| 216 | var xhttp; |
|
| 217 | ||
| 218 | var el = new E(target); |
|
| 219 | var elmnt = el.first(); |
|
| 220 | ||
| 221 | if (typeof success !== 'function') { |
|
| 222 | success = function () { |
|
| 223 | console.log('includeHtml success', "included"); |
|
| 224 | } |
|
| 225 | } |
|
| 226 | ||
| 227 | if (typeof error !== 'function') { |
|
| 228 | error = function () { |
|
| 229 | console.log('includeHtml error', "Page not found."); |
|
| 230 | } |
|
| 231 | } |
|
| 232 | console.log('includeHtml url', url); |
|
| 233 | ||
| 234 | if (url) { |
|
| 235 | /* Make an HTTP request using the attribute value as the url name: */ |
|
| 236 | xhttp = new XMLHttpRequest(); |
|
| 237 | xhttp.onreadystatechange = function () { |
|
| 238 | console.log('includeHtml el_id', target); |
|
| 239 | ||
| 240 | if (this.readyState == 4) { |
|
| 241 | if (this.status == 200) { |
|
| 242 | // console.log('elmnt', elmnt); |
|
| 243 | // console.log('responseText', this.responseText); |
|
| 244 | // elmnt.innerHTML = this.responseText; |
|
| 245 | // elmnt.appendChild(this.responseText); |
|
| 246 | // elmnt.insertAdjacentHTML('beforeend', this.responseText); |
|
| 247 | // var e = document.createElement('div'); |
|
| 248 | // e.innerHTML = this.responseText; |
|
| 249 | // while(e.firstChild) { |
|
| 250 | // elmnt.appendChild(e); |
|
| 251 | // } |
|
| 252 | ||
| 253 | // elmnt.insertAdjacentHTML('afterend', this.responseText); |
|
| 254 | elmnt.insertAdjacentHTML('beforeend', this.responseText); |
|
| 255 | ||
| 256 | success(this); |
|
| 257 | } |
|
| 258 | if (this.status == 404) { |
|
| 259 | elmnt.innerHTML = "includeHtml Page not found."; |
|
| 260 | error(this); |
|
| 261 | } |
|
| 262 | /* Remove the attribute, and call this function once more: */ |
|
| 263 | // includeHtml(url, success, error); |
|
| 264 | } |
|
| 265 | } |
|
| 266 | xhttp.open("GET", url, true); |
|
| 267 | xhttp.send(); |
|
| 268 | /* Exit the function: */ |
|
| 269 | return this; |
|
| 270 | } |
|
| 271 | return false; |
|
| 272 | ||
| 273 | } |
|
| 274 | ||
| 275 | function includeStyle(url, target, success, error) { |
|
| 276 | if (typeof target === 'undefined') { |
|
| @@ 1-57 (lines=57) @@ | ||
| 1 | function includeHtml(url, target, error, success) { |
|
| 2 | var xhttp; |
|
| 3 | ||
| 4 | var el = new E(target); |
|
| 5 | var elmnt = el.first(); |
|
| 6 | ||
| 7 | if (typeof success !== 'function') { |
|
| 8 | success = function () { |
|
| 9 | console.log('includeHtml success', "included"); |
|
| 10 | } |
|
| 11 | } |
|
| 12 | ||
| 13 | if (typeof error !== 'function') { |
|
| 14 | error = function () { |
|
| 15 | console.log('includeHtml error', "Page not found."); |
|
| 16 | } |
|
| 17 | } |
|
| 18 | console.log('includeHtml url', url); |
|
| 19 | ||
| 20 | if (url) { |
|
| 21 | /* Make an HTTP request using the attribute value as the url name: */ |
|
| 22 | xhttp = new XMLHttpRequest(); |
|
| 23 | xhttp.onreadystatechange = function () { |
|
| 24 | console.log('includeHtml el_id', target); |
|
| 25 | ||
| 26 | if (this.readyState == 4) { |
|
| 27 | if (this.status == 200) { |
|
| 28 | // console.log('elmnt', elmnt); |
|
| 29 | // console.log('responseText', this.responseText); |
|
| 30 | // elmnt.innerHTML = this.responseText; |
|
| 31 | // elmnt.appendChild(this.responseText); |
|
| 32 | // elmnt.insertAdjacentHTML('beforeend', this.responseText); |
|
| 33 | // var e = document.createElement('div'); |
|
| 34 | // e.innerHTML = this.responseText; |
|
| 35 | // while(e.firstChild) { |
|
| 36 | // elmnt.appendChild(e); |
|
| 37 | // } |
|
| 38 | ||
| 39 | // elmnt.insertAdjacentHTML('afterend', this.responseText); |
|
| 40 | elmnt.insertAdjacentHTML('beforeend', this.responseText); |
|
| 41 | ||
| 42 | success(this); |
|
| 43 | } |
|
| 44 | if (this.status == 404) { |
|
| 45 | elmnt.innerHTML = "includeHtml Page not found."; |
|
| 46 | error(this); |
|
| 47 | } |
|
| 48 | /* Remove the attribute, and call this function once more: */ |
|
| 49 | // includeHtml(url, success, error); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | xhttp.open("GET", url, true); |
|
| 53 | xhttp.send(); |
|
| 54 | /* Exit the function: */ |
|
| 55 | return this; |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||