memex/docs/logic/main.js

78 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-07-13 15:56:09 +00:00
function Main()
{
this.db = null;
this.view = null;
this.add = null;
this.write = null;
2018-10-30 14:05:23 +00:00
this.lightbox = null;
2018-07-23 13:20:03 +00:00
this.queryCur = '';
2018-09-14 02:57:15 +00:00
this.queryPrev = '';
this.queryPrevAdd = '';
2018-10-30 14:05:23 +00:00
var parent = this;
2018-07-13 15:56:09 +00:00
2018-07-15 14:23:07 +00:00
this.install = function()
{
this.db = new Wrap();
this.db.install(DATABASE);
this.view = new View();
this.view.install();
this.lightbox = new Lightbox;
this.lightbox.install();
2018-07-24 11:50:04 +00:00
2018-10-30 03:01:22 +00:00
if (window.showAdd !== undefined && window.showAdd)
2018-07-24 11:50:04 +00:00
{
this.add = new Add();
this.add.install();
2018-09-14 02:57:15 +00:00
// var escape = document.getElementById("escape");
// escape.onclick = function()
// {
// main.add.close();
// }
2018-07-24 11:50:04 +00:00
}
2018-07-15 14:23:07 +00:00
}
this.start = function()
{
2018-07-22 19:45:04 +00:00
this.load(window.document.location.hash);
this.view.stats(this.db.stats());
2018-07-15 14:23:07 +00:00
}
2018-07-22 19:45:04 +00:00
this.load = function(target)
2018-07-15 14:23:07 +00:00
{
2018-10-30 14:05:23 +00:00
this.lightbox.close();
2018-07-24 11:50:04 +00:00
document.activeElement.blur();
2018-10-30 03:01:22 +00:00
if (this.queryCur !== 'add')
2018-07-24 11:50:04 +00:00
{
this.queryPrev = this.queryCur;
}
2018-10-30 03:01:22 +00:00
target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
2018-07-23 13:20:03 +00:00
this.queryCur = target.trim();
if (window.location.hash != this.queryCur)
{
window.location.hash = this.queryCur;
}
2018-10-30 03:01:22 +00:00
if (this.queryCur === 'add')
2018-07-23 13:20:03 +00:00
{
if (window.showAdd != undefined && window.showAdd)
{
this.add.show();
}
else
{
window.location.hash = this.queryPrev;
}
2018-07-23 13:20:03 +00:00
}
else
{
this.view.display(this.db.filter(this.queryCur));
}
2018-07-15 14:23:07 +00:00
}
2018-07-13 15:56:09 +00:00
}
window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });