Created
December 19, 2017 14:12
-
-
Save salami-art/a8d36219840751b61a592a405ccd1794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare var $: any; | |
declare var application: Application; | |
class ApplicationModule { | |
} | |
class modalHandling extends ApplicationModule { | |
public get(action: string) { | |
application.html.get(`/modals/${ action }`, function(data: string) { | |
let container = this.getContainer(); | |
let modal = application.html.parse(data); | |
container.appendChild(modal); | |
$(`\#${ action }`).modal('show'); | |
}); | |
} | |
private getContainer() { | |
return document.getElementById('modals'); | |
} | |
} | |
class htmlHandling extends ApplicationModule { | |
public get(action: string, callback: Function) { | |
return application.getRequest(action, callback); | |
} | |
public parse(html: string) { | |
let parser = new DOMParser(); | |
return parser.parseFromString(html, 'text/xml'); | |
} | |
} | |
class Application { | |
public html: htmlHandling; | |
public modal: modalHandling; | |
init() { | |
console.log('BASE LOADED'); | |
this.initModules(); | |
} | |
public getRequest(action: string, callback: Function) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', action); | |
xhr.onload = function() { | |
if (xhr.status === 200) { | |
callback(xhr.responseText); | |
} | |
else { | |
this.handleErrors(xhr.status); | |
} | |
}; | |
xhr.send(); | |
} | |
public handleErrors(e: any) { | |
console.log(e); | |
} | |
private initModules() { | |
this.html = new htmlHandling(); | |
this.modal = new modalHandling(); | |
} | |
} | |
const application = new Application(); | |
application.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment