2018-07-13 15:56:09 +00:00
|
|
|
function Main()
|
|
|
|
{
|
2018-11-03 12:30:26 +00:00
|
|
|
this.util = null;
|
2018-11-06 12:34:55 +00:00
|
|
|
this.wrap = null;
|
|
|
|
this.articles = null;
|
2018-11-03 12:30:26 +00:00
|
|
|
this.grid = null;
|
|
|
|
this.nav = null;
|
2018-07-25 15:45:24 +00:00
|
|
|
this.add = null;
|
2018-08-05 15:05:18 +00:00
|
|
|
this.write = null;
|
2018-10-30 14:05:23 +00:00
|
|
|
|
2018-07-23 13:20:03 +00:00
|
|
|
this.queryCur = '';
|
2018-09-14 02:57:15 +00:00
|
|
|
this.queryPrev = '';
|
|
|
|
this.queryPrevAdd = '';
|
2018-11-07 01:49:36 +00:00
|
|
|
this.articlesDisplayed = 0;
|
2018-08-08 15:49:00 +00:00
|
|
|
var parent = this;
|
2018-07-13 15:56:09 +00:00
|
|
|
|
2018-07-15 14:23:07 +00:00
|
|
|
this.install = function()
|
|
|
|
{
|
2018-11-06 11:12:54 +00:00
|
|
|
seer.note('load all js files');
|
2018-11-06 10:27:32 +00:00
|
|
|
|
2018-11-03 12:30:26 +00:00
|
|
|
this.util = new Util();
|
2018-11-06 12:34:55 +00:00
|
|
|
this.wrap = new Wrap();
|
2018-11-03 12:30:26 +00:00
|
|
|
this.grid = new Grid();
|
|
|
|
this.grid.install(
|
2018-11-02 12:50:25 +00:00
|
|
|
document.querySelector('main'),
|
2018-11-03 12:30:26 +00:00
|
|
|
document.querySelector('.page-overlay'),
|
|
|
|
'main',
|
|
|
|
'article');
|
|
|
|
this.nav = new Nav();
|
|
|
|
this.nav.install(document.querySelector('nav'));
|
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
|
|
|
{
|
2018-08-09 15:18:32 +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
|
|
|
|
2018-11-06 11:12:54 +00:00
|
|
|
seer.note('install main');
|
2018-11-05 23:39:57 +00:00
|
|
|
}
|
2018-11-05 23:29:55 +00:00
|
|
|
|
2018-11-06 12:34:55 +00:00
|
|
|
this.start = function()
|
2018-11-06 09:28:12 +00:00
|
|
|
{
|
2018-11-06 12:51:05 +00:00
|
|
|
this.articles = this.wrap.start(DATABASE);
|
|
|
|
seer.note('process db');
|
2018-11-06 09:28:12 +00:00
|
|
|
|
2018-11-06 12:51:05 +00:00
|
|
|
let stats = this.wrap.stats(this.articles);
|
|
|
|
seer.note('calc stats');
|
|
|
|
this.nav.display(stats);
|
|
|
|
seer.note('render stats');
|
2018-11-06 12:34:55 +00:00
|
|
|
|
2018-11-06 12:51:05 +00:00
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
2018-11-06 11:45:52 +00:00
|
|
|
this.load = function()
|
|
|
|
{
|
2018-11-07 01:14:49 +00:00
|
|
|
// RESET
|
2018-11-06 12:34:55 +00:00
|
|
|
lightbox.close();
|
|
|
|
document.activeElement.blur();
|
|
|
|
|
2018-11-07 01:14:49 +00:00
|
|
|
// UPDATE QUERY
|
2018-11-06 12:34:55 +00:00
|
|
|
let target = window.document.location.hash;
|
|
|
|
if (this.queryCur !== 'add')
|
|
|
|
{
|
|
|
|
this.queryPrev = this.queryCur;
|
|
|
|
}
|
|
|
|
target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
|
|
|
|
this.queryCur = target.trim();
|
|
|
|
if (window.location.hash != this.queryCur)
|
|
|
|
{
|
|
|
|
window.location.hash = this.queryCur;
|
|
|
|
}
|
2018-11-07 01:14:49 +00:00
|
|
|
|
|
|
|
// DISPLAY
|
|
|
|
let filtered = main.wrap.filter(main.queryCur, main.articles);
|
|
|
|
let filteredLength = Object.keys(filtered).length;
|
|
|
|
seer.note('filter db');
|
|
|
|
|
|
|
|
let delay = 0;
|
2018-11-07 01:49:36 +00:00
|
|
|
if (filteredLength > SETTINGS.LOADANIMNUM || this.articlesDisplayed > SETTINGS.LOADANIMNUM)
|
2018-11-07 01:14:49 +00:00
|
|
|
{
|
|
|
|
// adding or removing a large number of articles can take time, so show loader
|
|
|
|
this.grid.clear();
|
|
|
|
document.querySelector('.loading-wave').style.display = 'inline-block';
|
|
|
|
delay = 10; // Small delay gives the preloader time to display
|
|
|
|
}
|
|
|
|
this.articlesDisplayed = filteredLength;
|
|
|
|
|
|
|
|
setTimeout(function() { main.build(filtered) }, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build = function(filtered)
|
|
|
|
{
|
|
|
|
let html = main.grid.buildAllArticles(filtered)
|
|
|
|
seer.note('build html');
|
|
|
|
|
|
|
|
main.grid.display(html);
|
|
|
|
seer.report();
|
|
|
|
|
|
|
|
document.querySelector('.loading-wave').style.display = 'none';
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
2018-07-13 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 01:14:49 +00:00
|
|
|
window.addEventListener("hashchange", function() { main.load(); });
|