function ViewMasonry() { // REFERENCE this.msnry = null; this.grid = null; this.menu = null; var parent = this; // SETTINGS this.statsNumTags = 5; this.statsNumTypes = 10; this.doDoubleWide = true; // SETTINGS this.useMasonry = true; this.divNamePre = 'item'; this.install = function() { this.grid = document.getElementById("grid"); this.menu = document.getElementById("menu"); if (this.useMasonry) { this.msnry = new Masonry('.grid', { itemSelector: '.grid-item', columnWidth: 350, gutter: 20, fitWidth: true, transitionDuration: 0, }); /////////////////////////// // Fix squashed image divs var imgLoad = imagesLoaded('.grid'); imgLoad.on( 'always', function (instance) { parent.msnry.layout(); } ); // Above imgLoad on always msnry.layout() should work but occassionally doesn't in Chrome and NEVER does in Firefox. window.onload = function () { parent.msnry.layout(); } // msnry.layout() called by window onload fixes things but not ideal. /////////////////////////// } } this.doEntries = function(db) { // BUILD this.grid.innerHTML = ''; var dbKeys = Object.keys(db); var i = 0; while (i < dbKeys.length) { this.buildEntry(db, dbKeys[i]); i++; } // LAYOUT if (this.useMasonry) { this.msnry.reloadItems(); this.msnry.layout(); } } this.buildEntry = function(db, key) { let value = db[key]; let itemClass = "grid-item"; if (this.doDoubleWide) { if (typeof value.QOTE !== 'undefined') { if (Array.isArray(value.QOTE) && value.QOTE.length > 4) { itemClass += " grid-item--width2"; } } } if (typeof value.TYPE !== 'undefined' && value.TYPE == 'image') { itemClass += " grid-item-image"; } let entry = ``; // DIV entry += `