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, 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 += `
`; // 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 += `
${value.NOTE}
`; } } // QUOTE if (SETTINGS.SHOWQOTE) { if (typeof value.QOTE !== 'undefined') { entry += `
${value.QOTE}
`; } } // TERM if (SETTINGS.SHOWTERM) { if (typeof value.TERM !== 'undefined') { for (var i = 0; i < value.TERM.length; i++) { entry += `
${value.TERM[i][0]}: ${value.TERM[i][1]}
`; } } } // 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 = ``; // 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; } // 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; } }