diff --git a/docs/logic/view.js b/docs/logic/view.js index ee300cf..7516e12 100644 --- a/docs/logic/view.js +++ b/docs/logic/view.js @@ -80,11 +80,6 @@ function View() imgLoad.on( 'always', function() { parent.msnry.layout(); } ); } - this.isDefined = function(value) - { - return (typeof value !== 'undefined'); - } - this.buildEntry = function(db, key) { let value = db[key]; @@ -95,7 +90,7 @@ function View() { itemClass += " griditem-wide"; } - else if (typeof value.QOTE !== 'undefined') + else if (this.isDefined(value.QOTE)) { if (Array.isArray(value.QOTE) && value.QOTE.length > 4) { @@ -104,10 +99,7 @@ function View() } } - if ( - SETTINGS.SHOWIMAG - && typeof value.TYPE !== 'undefined' && value.TYPE === 'image' - ) + if (SETTINGS.SHOWIMAG && this.isDefined(value.TYP) && value.TYPE === 'image') { itemClass += " griditem-image"; } @@ -119,19 +111,16 @@ function View() if (this.isDefined(value.LINK)) { var idUrl = "url"; - if (typeof value.SEEN !== 'undefined' && value.SEEN === "true") + if (this.isDefined(value.SEEN) && value.SEEN === "true") { idUrl = "urlseen"; } // LINK START - if (SETTINGS.SHOWLINK) + if (SETTINGS.SHOWLINK && !this.isObject(value.LINK)) { - if (typeof value.LINK != 'object') - { - // If this item has only one link then make the whole title the link - entry += ``; - } + // If this item has only one link then make the whole title the link + entry += ``; } } @@ -147,9 +136,9 @@ function View() } // LINK END - if (SETTINGS.SHOWLINK && typeof value.LINK !== 'undefined') + if (SETTINGS.SHOWLINK && this.isDefined(value.LINK)) { - if (typeof value.LINK == 'object') + if (this.isObject(value.LINK)) { for (let l = 0; l < value.LINK.length; l++) { @@ -164,7 +153,7 @@ function View() } // TYPE - if (SETTINGS.SHOWTYPE && typeof value.TYPE !== 'undefined') + if (SETTINGS.SHOWTYPE && this.isDefined(value.TYPE)) { entry += `
`; @@ -188,13 +177,13 @@ function View() entry += `
`; // AUTHOR - if (SETTINGS.SHOWAUTH && typeof value.AUTH !== 'undefined') + if (SETTINGS.SHOWAUTH && this.isDefined(value.AUTH)) { entry += `
${value.AUTH}
`; } // TAGS - if (SETTINGS.SHOWTAGS && typeof value.TAGS !== 'undefined') + if (SETTINGS.SHOWTAGS && this.isDefined(value.TAGS)) { entry += `
`; for (var i = 0; i < value.TAGS.length; i++) @@ -209,74 +198,65 @@ function View() } // PROJECT - if (SETTINGS.SHOWPROJ) + if (SETTINGS.SHOWPROJ && this.isDefined(value.PROJ)) { - if (this.isDefined(value.PROJ)) + entry += `
`; + for (var i = 0; i < value.PROJ.length; i++) { - entry += `
`; - for (var i = 0; i < value.PROJ.length; i++) + entry += `${value.PROJ[i].to_properCase()}`; + if (i + 1 != value.PROJ.length) { - entry += `${value.PROJ[i]}`; - if (i + 1 != value.PROJ.length) - { - entry += `, `; - } - }; - entry += `
`; + entry += `, `; + } } + entry += `
`; } // TERM - if (SETTINGS.SHOWTERM) + if (SETTINGS.SHOWTERM && this.isDefined(value.TERM)) { - if (this.isDefined(value.TERM)) - { - entry += this.buildArrayElement(value.TERM, "griditem-term", "fas fa-ribbon textIcon"); - } + entry += this.doMultilineFormatting(value.TERM, "griditem-term", "fas fa-ribbon textIcon"); } // NOTE - if (SETTINGS.SHOWNOTE && typeof value.NOTE !== 'undefined') + if (SETTINGS.SHOWNOTE && this.isDefined(value.NOTE)) { - entry += this.buildArrayElement(value.NOTE, "griditem-note", "fas fa-sticky-note textIcon"); + entry += this.doMultilineFormatting(value.NOTE, "griditem-note", "fas fa-sticky-note textIcon"); } // QUOTE - if (SETTINGS.SHOWQOTE && typeof value.QOTE !== 'undefined') + if (SETTINGS.SHOWQOTE && this.isDefined(value.QOTE)) { - entry += this.buildArrayElement(value.QOTE, "griditem-quote", "fas fa-comment textIcon"); + entry += this.doMultilineFormatting(value.QOTE, "griditem-quote", "fas fa-comment textIcon"); } // TERM - if (SETTINGS.SHOWTERM && typeof value.TERM !== 'undefined') + if (SETTINGS.SHOWTERM && this.isDefined(value.TERM)) { - entry += this.buildArrayElement(value.TERM, "griditem-term", "fas fa-ribbon textIcon"); + entry += this.doMultilineFormatting(value.TERM, "griditem-term", "fas fa-ribbon textIcon"); } // PROGRESS - if (SETTINGS.SHOWPROG && typeof value.PROG !== 'undefined') + if (SETTINGS.SHOWPROG && this.isDefined(value.PROG)) { entry += `
${value.PROG}
`; } // FILE - if (SETTINGS.SHOWFILE) + if (SETTINGS.SHOWFILE && this.isDefined(value.FILE)) { - if (this.isDefined(value.FILE)) + if (this.isObject(value.FILE)) { - if (typeof value.FILE == 'object') + for (var i = 0; i < value.FILE.length; i++) { - for (var i = 0; i < value.FILE.length; i++) - { - entry += ``; - } - } - else - { - // single - entry += ``; + entry += ``; } } + else + { + // single + entry += ``; + } } // LOWER CONTENT END @@ -284,11 +264,8 @@ function View() } // IMAGE - if ( - SETTINGS.SHOWIMAG - && typeof value.TYPE !== 'undefined' && value.TYPE === 'image' - && typeof value.FILE !== 'undefined' - ) + if (SETTINGS.SHOWIMAG && this.isDefined(value.TYPE) + && value.TYPE === 'image' && this.isDefined(value.FILE)) { entry += `
`; if (SETTINGS.SHOWOVERLAY) @@ -306,7 +283,6 @@ function View() this.stats = function(value) { let menuContent = ``; - if (window.showAdd !== undefined && window.showAdd) { // ADD @@ -327,20 +303,17 @@ function View() // DONE menuContent += ``; + menuContent += ``; // TAGS @@ -383,12 +355,10 @@ function View() menuContent += `
`; } menuContent += `
`; - - this.menu.innerHTML = ``; - this.menu.innerHTML += menuContent; + this.menu.innerHTML = menuContent; } - this.buildArrayElement = function(data, className, iconName) + this.doMultilineFormatting = function(data, className, iconName) { let result = ''; if (Array.isArray(data)) @@ -437,7 +407,6 @@ function View() return result; } - // HELPER getTypeIconName = function(type) { let icon = ''; @@ -461,6 +430,17 @@ function View() return icon; } + // GENERAL HELPER + this.isDefined = function(value) + { + return (typeof value !== 'undefined'); + } + + this.isObject = function(value) + { + return (typeof value == 'object'); + } + String.prototype.to_properCase = function() { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); @@ -500,8 +480,6 @@ function View() } else { - console.log('calling extract on: ' + url); - hostname = url.split('/')[0]; }