function View() { this.msnry = null; this.overlay = null; this.container = null; this.grid = null; this.menu = null; var parent = this; const SETTINGS = { STATSNUMTAGS: 5, STATSNUMTYPE: 10, WIDEGRIDITEM: true, USEMASONRY: true, GRIDITEMIDBASE: 'item', SHOWUPPER: true, SHOWTITLE: true, SHOWAUTH: true, SHOWTYPE: true, SHOWLINK: true, SHOWLOWER: true, SHOWTAGS: true, SHOWNOTE: true, SHOWQOTE: true, SHOWTERM: true, SHOWPROG: true, SHOWIMAG: true, SHOWOVERLAY: true } this.install = function() { this.overlay = document.getElementById("overlay"); this.container = document.getElementById("container"); this.grid = document.getElementById("grid"); this.menu = document.getElementById("menu"); if (SETTINGS.USEMASONRY) { this.msnry = new Masonry('.grid', { itemSelector: '.grid-item', columnWidth: 350, gutter: 20, fitWidth: true, transitionDuration: 0, }); } } this.display = function(db) { if (window.showAdd != undefined && window.showAdd) { main.add.setOverlay(false); } // BUILD this.grid.innerHTML = ''; this.grid.innerHTML += "
"; var dbKeys = Object.keys(db); var i = 0; while (i < dbKeys.length) { this.buildEntry(db, dbKeys[i]); i++; } // LAYOUT if (SETTINGS.USEMASONRY) { this.msnry.reloadItems(); this.msnry.layout(); } var imgLoad = imagesLoaded( container ); // When all images finish: redo mansonry layout imgLoad.on( 'always', function() { parent.msnry.layout(); } ); } this.buildEntry = function(db, key) { let value = db[key]; let itemClass = "grid-item"; if (SETTINGS.WIDEGRIDITEM) { if (typeof value.WIDE !== 'undefined' && value.WIDE) { itemClass += " grid-item--width2"; } else if (typeof value.QOTE !== 'undefined') { if (Array.isArray(value.QOTE) && value.QOTE.length > 4) { itemClass += " grid-item--width2"; } } } if (SETTINGS.SHOWIMAG) { if (typeof value.TYPE !== 'undefined' && value.TYPE == 'image') { itemClass += " grid-item-image"; } } let entry = ``; // ITEM DIV entry += `
`; if (typeof value.LINK !== 'undefined') { var idUrl = "url"; if (typeof value.SEEN !== 'undefined') { if (value.SEEN == "true") { idUrl = "urlseen"; } } // LINK START if (SETTINGS.SHOWLINK) { entry += ``; } } // UPPER CONTENT START if (SETTINGS.SHOWUPPER) { entry += `
`; // TITLE if (SETTINGS.SHOWTITLE) { entry += `
${key.to_properCase()}
`; } // LINK END if (SETTINGS.SHOWLINK) { if (typeof value.LINK !== 'undefined') { entry += `
`; } } // TYPE if (SETTINGS.SHOWTYPE) { if (typeof value.TYPE !== 'undefined') { entry += ``; entry += `
`; if (value.TYPE == 'article') { entry += ``; } else if (value.TYPE == 'podcast') { entry += ``; } else if (value.TYPE == 'video') { entry += ``; } else if (value.TYPE == 'list') { entry += ``; } else if (value.TYPE == 'book') { entry += ``; } else if (value.TYPE == 'game') { entry += ``; } else if (value.TYPE == 'service') { entry += ``; } else if (value.TYPE == 'lecture') { entry += ``; } else if (value.TYPE == 'quote') { entry += ``; } else if (value.TYPE == 'tool') { entry += ``; } else if (value.TYPE == 'music') { entry += ``; } else if (value.TYPE == 'image') { entry += ``; } else if (value.TYPE == 'encyclopedia') { entry += ``; } entry += `
`; entry += `
`; } } // UPPER CONTENT END entry += `
`; } // LOWER CONTENT START if (SETTINGS.SHOWLOWER) { entry += `
`; // AUTHOR if (SETTINGS.SHOWAUTH) { if (typeof value.AUTH !== 'undefined') { entry += `
${value.AUTH}
`; } } // TAGS if (SETTINGS.SHOWTAGS) { if (typeof value.TAGS !== 'undefined') { entry += `
`; for (var i = 0; i < value.TAGS.length; i++) { entry += `${value.TAGS[i]}`; if (i+1 != value.TAGS.length) { entry += `, `; } }; entry += `
`; } } // NOTE if (SETTINGS.SHOWNOTE) { if (typeof value.NOTE !== 'undefined') { entry += this.buildArrayElement(value.NOTE, "note", "fas fa-sticky-note textIcon"); } } // QUOTE if (SETTINGS.SHOWQOTE) { if (typeof value.QOTE !== 'undefined') { entry += this.buildArrayElement(value.QOTE, "quote", "fas fa-comment textIcon"); } } // TERM if (SETTINGS.SHOWTERM) { if (typeof value.TERM !== 'undefined') { entry += this.buildArrayElement(value.TERM, "term", "fas fa-ribbon textIcon"); } } // PROGRESS if (SETTINGS.SHOWPROG) { if (typeof value.PROG !== 'undefined') { entry += `
${value.PROG}
`; } } // LOWER CONTENT END entry += `
`; } // IMAGE if (SETTINGS.SHOWIMAG) { if (typeof value.TYPE !== 'undefined' && value.TYPE == 'image') { if (typeof value.FILE !== 'undefined') { entry += `
`; if (SETTINGS.SHOWOVERLAY) { entry += `
`; } entry += ``; entry += `
`; } } } entry += `
`; this.grid.innerHTML += entry; } this.stats = function(value) { let menuContent = ``; if (window.showAdd != undefined && window.showAdd) { // ADD menuContent += ``; menuContent += ``; menuContent += ``; menuContent += ``; } // TYPE menuContent += ``; menuContent += ``; menuContent += ``; for (var ty = 0; ty < Math.min(value.types.length, SETTINGS.STATSNUMTYPE); ty++) { if (value.types[ty][0] == 'article') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'podcast') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'video') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'list') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'book') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'game') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'service') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'lecture') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'quote') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'tool') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'music') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'image') { menuContent += ``; menuContent += ``; menuContent += ``; } else if (value.types[ty][0] == 'encyclopedia') { menuContent += ``; menuContent += ``; menuContent += ``; } } menuContent += ``; // TERM if (value.terms > 0) { // menuContent += ``; menuContent += ``; menuContent += ``; menuContent += ``; } menuContent += ``; // TAGS if (value.tags.length > 0) { menuContent += ``; } this.menu.innerHTML = ``; this.menu.innerHTML += menuContent; } this.buildArrayElement = function(data, className, iconName) { let result = ''; if (Array.isArray(data)) { for (var i in data) { if (data[i] == "& ") { // blank line, do nothing } else if (data[i].substring(0, 2) == "> ") { // New item if (data[i].includes(": ")) { let titleSplit = data[i].substring(2).split(': '); // .substring(2) removes the "> " for (var e = 0; e < titleSplit.length; e++) { titleSplit[e] = titleSplit[e].trim(); } result += `
${titleSplit[0]}: ${titleSplit[1]}
`; } else { result += `
${data[i].substring(2)}
`; } } else if (data[i].substring(0, 2) == "& ") { // New line in current item result += `
${data[i].substring(2)}
`; } else { // Handle unformatted result += `
${data[i]}
`; } } } else { // Handle not array result += `
${data}
`; } return result; } // HELPER String.prototype.to_properCase = function() { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); } // Source: https://stackoverflow.com/questions/8498592/extract-hostname-name-from-string this.extractRootDomain = function(url) { var domain = this.extractHostname(url), splitArr = domain.split('.'), arrLen = splitArr.length; // extracting the root domain here // if there is a subdomain if (arrLen > 2) { domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1]; // check to see if it's using a Country Code Top Level Domain (ccTLD) (i.e. ".me.uk") if (splitArr[arrLen - 2].length == 2 && splitArr[arrLen - 1].length == 2) { // this is using a ccTLD domain = splitArr[arrLen - 3] + '.' + domain; } } return domain; } // Source: https://stackoverflow.com/questions/8498592/extract-hostname-name-from-string this.extractHostname = function(url) { var hostname; // find & remove protocol (http, ftp, etc.) and get hostname if (url.indexOf("://") > -1) { hostname = url.split('/')[2]; } else { hostname = url.split('/')[0]; } // find & remove port number hostname = hostname.split(':')[0]; // find & remove "?" hostname = hostname.split('?')[0]; return hostname; } }