function View()
{
this.nav = null;
this.container = null;
this.grid = null;
this.overlay = null;
this.msnry = null;
var parent = this;
this.install = function(nav, container, grid, overlay)
{
this.nav = nav;
this.container = container;
this.grid = grid;
this.overlay = overlay;
if (SETTINGS.USEMASONRY)
{
this.msnry = new Masonry('main',
{
itemSelector: 'article',
columnWidth: 350,
gutter: 20,
fitWidth: true,
transitionDuration: 0,
});
}
}
this.display = function(db)
{
if (window.showAdd !== undefined && window.showAdd)
{
main.add.setOverlay(false);
}
// BUILD
let dbKeys = Object.keys(db);
let i = 0;
let contentHtml = '';
while (i < dbKeys.length)
{
contentHtml += this.buildEntry(db, dbKeys[i]);
i++;
}
this.grid.innerHTML = contentHtml;
// LAYOUT
if (SETTINGS.USEMASONRY)
{
this.msnry.reloadItems();
this.msnry.layout();
if (SETTINGS.MASONRYCOMPLETE || SETTINGS.MASONRYPROGRESS)
{
let imgLoad = imagesLoaded( this.container );
if (!SETTINGS.MASONRYPROGRESS)
{
// When all images finish: redo mansonry layout
imgLoad.on( 'always', function() { parent.msnry.layout(); } );
}
else
{
// As images load one by one: redo masonry layout
imgLoad.on( 'progress', function() { parent.msnry.layout(); } );
}
}
}
}
this.buildEntry = function(db, key)
{
let value = db[key];
let itemClass = "article";
if (SETTINGS.WIDEGRIDITEM)
{
if (this.isDefined(value.WIDE) && value.WIDE)
{
itemClass += " griditem-wide";
}
else if (this.isDefined(value.QOTE))
{
if (Array.isArray(value.QOTE) && value.QOTE.length > SETTINGS.AUTOWIDETRIGGER)
{
itemClass += " griditem-wide";
}
}
}
let onclickImage = ``;
let entryIsImageType = (SETTINGS.SHOWIMAG && this.isType(value.TYPE, 'image'));
if (entryIsImageType)
{
itemClass += " griditem-image";
onclickImage = `onclick="main.view.handleImageClick(event, this, '${value.FILE}');"
style="cursor: pointer;"`;
}
let entry = ``;
entry += `