2018-07-13 15:56:09 +00:00
|
|
|
function Main()
|
|
|
|
{
|
2018-07-16 02:58:03 +00:00
|
|
|
// REFERENCE
|
2018-07-17 13:08:20 +00:00
|
|
|
this.db = null;
|
2018-07-17 13:41:00 +00:00
|
|
|
this.view = null;
|
2018-07-13 15:56:09 +00:00
|
|
|
|
2018-07-15 14:23:07 +00:00
|
|
|
this.install = function()
|
|
|
|
{
|
2018-07-17 13:08:20 +00:00
|
|
|
this.db = new DataWrap(DATABASE);
|
|
|
|
this.db.install();
|
2018-07-15 15:47:40 +00:00
|
|
|
|
2018-07-17 13:41:00 +00:00
|
|
|
this.view = new ViewMasonry();
|
|
|
|
this.view.install();
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.start = function()
|
|
|
|
{
|
2018-07-15 16:21:20 +00:00
|
|
|
this.load(window.document.location.hash == "" ? 'home' : window.document.location.hash);
|
2018-07-17 13:41:00 +00:00
|
|
|
this.view.doStats(this.db.getStats());
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-15 16:21:20 +00:00
|
|
|
this.load = function(target = "home")
|
2018-07-15 14:23:07 +00:00
|
|
|
{
|
|
|
|
target = target.substr(0,1) == "#" ? target.substr(1,target.length-1) : target
|
|
|
|
target = target.trim() == "" ? "home" : target
|
|
|
|
|
2018-07-17 13:08:20 +00:00
|
|
|
if (target === '')
|
2018-07-15 14:23:07 +00:00
|
|
|
{
|
2018-07-15 15:47:40 +00:00
|
|
|
window.history.replaceState(undefined, undefined, "#" + target)
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-15 15:47:40 +00:00
|
|
|
window.location.hash = target;
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 13:08:20 +00:00
|
|
|
var entries = this.db.filter(target);
|
2018-07-17 13:41:00 +00:00
|
|
|
this.view.doEntries(entries);
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
2018-07-13 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 13:41:00 +00:00
|
|
|
window.addEventListener("hashchange", navigate);
|
2018-07-16 02:58:03 +00:00
|
|
|
|
|
|
|
function navigate()
|
|
|
|
{
|
2018-07-17 13:41:00 +00:00
|
|
|
main.load(window.document.location.hash);
|
2018-07-16 02:58:03 +00:00
|
|
|
}
|