2018-07-13 15:56:09 +00:00
|
|
|
function Main()
|
|
|
|
{
|
2018-11-03 12:30:26 +00:00
|
|
|
this.util = null;
|
2018-11-05 15:00:16 +00:00
|
|
|
this.database = 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-10-30 14:05:23 +00:00
|
|
|
|
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-03 12:30:26 +00:00
|
|
|
this.util = new Util();
|
2018-11-05 15:00:16 +00:00
|
|
|
this.database = new Wrap();
|
|
|
|
// this.database.install(DATABASE);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
this.start = function()
|
|
|
|
{
|
2018-11-05 15:00:16 +00:00
|
|
|
console.log(Date.now() + ' - start');
|
|
|
|
let dbPromise = this.database.start(new Indental(DATABASE).parse());
|
|
|
|
dbPromise.then((db) => {
|
|
|
|
console.log(Date.now() + ' - db ready');
|
|
|
|
// console.log(db);
|
|
|
|
|
2018-11-05 15:38:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-11-05 15:00:16 +00:00
|
|
|
let dbKeys = Object.keys(db);
|
|
|
|
let i = 0;
|
2018-11-05 15:38:56 +00:00
|
|
|
|
|
|
|
console.log(Date.now() + ' - start render');
|
|
|
|
|
|
|
|
while (i < 200)//dbKeys.length)
|
2018-11-05 15:00:16 +00:00
|
|
|
{
|
2018-11-05 15:38:56 +00:00
|
|
|
document.querySelector('main').innerHTML += this.grid.buildArticle(db[dbKeys[i]], dbKeys[i]);
|
|
|
|
console.log(Date.now() + ' - did one! LAAAAAAG while reflowing');
|
2018-11-05 15:00:16 +00:00
|
|
|
i++;
|
|
|
|
}
|
2018-11-05 15:38:56 +00:00
|
|
|
|
|
|
|
console.log('COMPLETED ALL ARTICLES - lag stops')
|
|
|
|
return 'done';
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-05 15:00:16 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log('ERROR:', error);
|
|
|
|
})
|
|
|
|
// this.load(window.document.location.hash);
|
|
|
|
// this.nav.display(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-11-02 12:57:28 +00:00
|
|
|
lightbox.close();
|
2018-10-30 14:05:23 +00:00
|
|
|
|
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
|
|
|
{
|
2018-08-09 15:26:29 +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
|
|
|
|
{
|
2018-11-03 06:42:45 +00:00
|
|
|
// this.db.filter(this.queryCur)
|
|
|
|
// .then(function(results){
|
|
|
|
// // Map our array of entries to
|
|
|
|
// // an array of template promises.
|
|
|
|
// // This makes sure they all template in parallel.
|
2018-11-03 12:30:26 +00:00
|
|
|
// return results.map(this.grid.templateEntry)
|
2018-11-03 06:42:45 +00:00
|
|
|
// .reduce(function(sequence, chapterPromise) {
|
|
|
|
// // Use reduce to chain the promises together,
|
|
|
|
// // adding content to the page for each entry
|
|
|
|
// return sequence.then(function() {
|
|
|
|
// // Wait for everything in the sequence so far,
|
|
|
|
// // then wait for this template to arrive.
|
|
|
|
// return chapterPromise;
|
|
|
|
// }).then(function(article) {
|
2018-11-03 12:30:26 +00:00
|
|
|
// this.grid.addHtmlToPage(article.html);
|
2018-11-03 06:42:45 +00:00
|
|
|
// });
|
|
|
|
// }, Promise.resolve());
|
|
|
|
// })
|
|
|
|
// .then(function() { console.log("done"); })
|
|
|
|
// .catch(function(err) { console.log("error: " + err.message); });
|
|
|
|
// .then(function() { console.log("stop loading anim"); })
|
|
|
|
|
|
|
|
// see: https://developers.google.com/web/fundamentals/primers/promises#whats-all-the-fuss-about
|
|
|
|
|
|
|
|
// this.db.filter(this.queryCur)
|
|
|
|
// .then(function(results){
|
2018-11-03 12:30:26 +00:00
|
|
|
// return this.grid.templateEntry(results[0]);
|
2018-11-03 06:42:45 +00:00
|
|
|
// }).then(function(article) {
|
2018-11-03 12:30:26 +00:00
|
|
|
// this.grid.addHtmlToPage(article.html);
|
2018-11-03 06:42:45 +00:00
|
|
|
// }).catch(function() {
|
|
|
|
// console.log("error: " + err.message);
|
|
|
|
// }).then(function() {
|
|
|
|
// console.log("stop loading anim");
|
|
|
|
// })
|
|
|
|
|
|
|
|
// see: https://developers.google.com/web/fundamentals/primers/promises#whats-all-the-fuss-about
|
|
|
|
|
2018-11-03 12:30:26 +00:00
|
|
|
this.grid.display(this.db.filter(this.queryCur));
|
2018-07-23 13:20:03 +00:00
|
|
|
}
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
2018-07-13 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 15:45:24 +00:00
|
|
|
window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });
|