Skip to content

Instantly share code, notes, and snippets.

@darkowlzz
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkowlzz/d0ebcfe57f2b81d15ca4 to your computer and use it in GitHub Desktop.
Save darkowlzz/d0ebcfe57f2b81d15ca4 to your computer and use it in GitHub Desktop.
// main div which contains all contents except nav
var contentDiv = document.getElementById('content');
//Constructor for different views
function View(viewName){
var self = this;
console.log(this+ viewName);
//view name
this.viewName = viewName;
//file that has to be loaded
this.file = viewName + ".html";
}
View.prototype = {
//initalizing the buttons and other elements.
init : function(){},
//fetch and load the body content
show: function(){
/* function reqListener(){
console.log('reqListener called');
//new division to append
var div = document.createElement('div');
div.id = View.viewName;
div.innerHTML = this.responseText;
console.log(this);
removeOtherNodes();
contentDiv.appendChild(div);
}*/
console.log('show called');
var xReq = new XMLHttpRequest();
xReq.onload = this.reqListener(this.viewName);
xReq.open('GET','main.html');
xReq.send();
},
reqListener: function(viewName){
console.log('reqListener called');
//new division to append
var div = document.createElement('div');
div.id = viewName;
console.log(div.id)
div.innerHTML = this.responseText;
this.removeOtherNodes();
contentDiv.appendChild(div);
},
//remove al other nodes in content div :P
removeOtherNodes: function(){
if(contentDiv.children.length)
contentDiv.children[0].remove();
}
}
var main = new View('main');
main.show();
console.log('hello');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment