Last active
August 29, 2015 14:24
-
-
Save darkowlzz/d0ebcfe57f2b81d15ca4 to your computer and use it in GitHub Desktop.
This file contains 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
// 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