Merge pull request #7 from joshavanier/master

Refactoring by joshavanier
This commit is contained in:
Hamish MacDonald 2018-10-30 21:42:52 +13:00 committed by GitHub
commit f4d5f65773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 193 deletions

View File

@ -29,7 +29,7 @@ function Main()
this.view = new View(); this.view = new View();
this.view.install(); this.view.install();
if (window.showAdd != undefined && window.showAdd) if (window.showAdd !== undefined && window.showAdd)
{ {
this.add = new Add(); this.add = new Add();
this.add.install(); this.add.install();
@ -53,12 +53,12 @@ function Main()
this.load = function(target) this.load = function(target)
{ {
document.activeElement.blur(); document.activeElement.blur();
if (this.queryCur != 'add') if (this.queryCur !== 'add')
{ {
this.queryPrev = this.queryCur; this.queryPrev = this.queryCur;
} }
target = target.substr(0,1) == "#" ? target.substr(1,target.length-1) : target; target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
this.queryCur = target.trim(); this.queryCur = target.trim();
if (window.location.hash != this.queryCur) if (window.location.hash != this.queryCur)
@ -66,7 +66,7 @@ function Main()
window.location.hash = this.queryCur; window.location.hash = this.queryCur;
} }
if (this.queryCur == 'add') if (this.queryCur === 'add')
{ {
if (window.showAdd != undefined && window.showAdd) if (window.showAdd != undefined && window.showAdd)
{ {

View File

@ -52,7 +52,7 @@ function View()
this.display = function(db) this.display = function(db)
{ {
if (window.showAdd != undefined && window.showAdd) if (window.showAdd !== undefined && window.showAdd)
{ {
main.add.setOverlay(false); main.add.setOverlay(false);
} }
@ -104,12 +104,12 @@ function View()
} }
} }
if (SETTINGS.SHOWIMAG) if (
SETTINGS.SHOWIMAG
&& typeof value.TYPE !== 'undefined' && value.TYPE === 'image'
)
{ {
if (this.isDefined(value.TYPE) && value.TYPE == 'image') itemClass += " griditem-image";
{
itemClass += " griditem-image";
}
} }
let entry = ``; let entry = ``;
@ -119,12 +119,9 @@ function View()
if (this.isDefined(value.LINK)) if (this.isDefined(value.LINK))
{ {
var idUrl = "url"; var idUrl = "url";
if (this.isDefined(value.SEEN)) if (typeof value.SEEN !== 'undefined' && value.SEEN === "true")
{ {
if (value.SEEN == "true") idUrl = "urlseen";
{
idUrl = "urlseen";
}
} }
// LINK START // LINK START
@ -150,46 +147,34 @@ function View()
} }
// LINK END // LINK END
if (SETTINGS.SHOWLINK) if (SETTINGS.SHOWLINK && typeof value.LINK !== 'undefined')
{ {
if (this.isDefined(value.LINK)) entry += `<div class="griditem-linkcontainer"><i class="griditem-linkicon fas fa-link"></i><div class="griditem-linktitle">${this.extractRootDomain(value.LINK)}</div></div></a>`;
{
if (typeof value.LINK == 'object')
{
for (let l = 0; l < value.LINK.length; l++)
{
entry += `<a class="griditem-link" href="${String(value.LINK[l])}" id="${idUrl}">`;
entry += `<div class="griditem-linkcontainer"><i class="griditem-linkicon fas fa-link"></i><div class="griditem-linktitle">${this.extractRootDomain(value.LINK[l])}</div></div></a>`;
}
}
else
{
entry += `<div class="griditem-linkcontainer"><i class="griditem-linkicon fas fa-link"></i><div class="griditem-linktitle">${this.extractRootDomain(value.LINK)}</div></div></a>`;
}
}
} }
// TYPE // TYPE
if (SETTINGS.SHOWTYPE) if (SETTINGS.SHOWTYPE && typeof value.TYPE !== 'undefined')
{ {
entry += `<div class="griditem-typecontainer">`; let icon = '';
if (this.isDefined(value.TYPE)) switch (value.TYPE) {
{ case 'article': icon = 'far fa-newspaper'; break;
if (typeof value.TYPE == 'object') case 'podcast': icon = 'fas fa-podcast'; break;
{ case 'video': icon = 'fas fa-tv'; break;
// This entry has an array of types case 'list': icon = 'fas fa-file-alt'; break;
for (var i = 0; i < value.TYPE.length; i++) case 'book': icon = 'fas fa-book-open'; break;
{ case 'game': icon = 'fas fa-gamepad'; break;
entry += this.doTypeIcon(value.TYPE[i]); case 'service': icon = 'fas fa-server'; break;
} case 'lecture': icon = 'fas fa-chalkboard-teacher'; break;
} case 'quote': icon = 'fas fa-comment'; break;
else case 'tool': icon = 'fas fa-wrench'; break;
{ case 'music': icon = 'fas fa-music'; break;
// This entry has a single type case 'image': icon = 'fas fa-image'; break;
entry += this.doTypeIcon(value.TYPE[i]); case 'encyclopedia': icon = 'fas fa-globe'; break;
}
} }
entry += `</div>`; //griditem-typecontainer
entry += `<a class="griditem-type" href='#type-${value.TYPE}'>`;
entry += `<i class="griditem-typeicon ${icon}"></i>`;
entry += `</a>`;
} }
// UPPER CONTENT END // UPPER CONTENT END
@ -202,30 +187,24 @@ function View()
entry += `<div class="griditem-containerlower">`; entry += `<div class="griditem-containerlower">`;
// AUTHOR // AUTHOR
if (SETTINGS.SHOWAUTH) if (SETTINGS.SHOWAUTH && typeof value.AUTH !== 'undefined')
{ {
if (this.isDefined(value.AUTH)) entry += `<div class="griditem-auth"><i class="fas fa-user textIcon"></i>${value.AUTH}</div>`;
{
entry += `<div class="griditem-auth"><i class="fas fa-user textIcon"></i>${value.AUTH}</div>`;
}
} }
// TAGS // TAGS
if (SETTINGS.SHOWTAGS) if (SETTINGS.SHOWTAGS && typeof value.TAGS !== 'undefined')
{ {
if (this.isDefined(value.TAGS)) entry += `<div class="griditem-tags"><i class="fas fa-tag textIcon"></i>`;
for (var i = 0; i < value.TAGS.length; i++)
{ {
entry += `<div class="griditem-tags"><i class="fas fa-tag textIcon"></i>`; entry += `<a class="griditem-taglink" href="#tag-${value.TAGS[i]}">${value.TAGS[i]}</a>`;
for (var i = 0; i < value.TAGS.length; i++) if (i+1 !== value.TAGS.length)
{ {
entry += `<a class="griditem-taglink" href="#tag-${value.TAGS[i]}">${value.TAGS[i]}</a>`; entry += `, `;
if (i + 1 != value.TAGS.length) }
{ };
entry += `, `; entry += `</div>`;
}
};
entry += `</div>`;
}
} }
// PROJECT // PROJECT
@ -256,30 +235,27 @@ function View()
} }
// NOTE // NOTE
if (SETTINGS.SHOWNOTE) if (SETTINGS.SHOWNOTE && typeof value.NOTE !== 'undefined')
{ {
if (this.isDefined(value.NOTE)) entry += this.buildArrayElement(value.NOTE, "griditem-note", "fas fa-sticky-note textIcon");
{
entry += this.buildArrayElement(value.NOTE, "griditem-note", "fas fa-sticky-note textIcon");
}
} }
// QUOTE // QUOTE
if (SETTINGS.SHOWQOTE) if (SETTINGS.SHOWQOTE && typeof value.QOTE !== 'undefined')
{ {
if (this.isDefined(value.QOTE)) entry += this.buildArrayElement(value.QOTE, "griditem-quote", "fas fa-comment textIcon");
{ }
entry += this.buildArrayElement(value.QOTE, "griditem-quote", "fas fa-comment textIcon");
} // TERM
if (SETTINGS.SHOWTERM && typeof value.TERM !== 'undefined')
{
entry += this.buildArrayElement(value.TERM, "griditem-term", "fas fa-ribbon textIcon");
} }
// PROGRESS // PROGRESS
if (SETTINGS.SHOWPROG) if (SETTINGS.SHOWPROG && typeof value.PROG !== 'undefined')
{ {
if (this.isDefined(value.PROG)) entry += `<div class="griditem-prog"><i class="fas fa-clock textIcon"></i>${value.PROG}</div>`;
{
entry += `<div class="griditem-prog"><i class="fas fa-clock textIcon"></i>${value.PROG}</div>`;
}
} }
// FILE // FILE
@ -307,21 +283,19 @@ function View()
} }
// IMAGE // IMAGE
if (SETTINGS.SHOWIMAG) if (
SETTINGS.SHOWIMAG
&& typeof value.TYPE !== 'undefined' && value.TYPE === 'image'
&& typeof value.FILE !== 'undefined'
)
{ {
if (this.isDefined(value.TYPE) && value.TYPE == 'image') entry += `<div class="image">`;
if (SETTINGS.SHOWOVERLAY)
{ {
if (this.isDefined(value.FILE)) entry += `<div class="image-overlay"></div>`;
{
entry += `<div class="image">`;
if (SETTINGS.SHOWOVERLAY)
{
entry += `<div class="image-overlay"></div>`;
}
entry += `<img class="griditem-image-img" src="content/media/${value.FILE}">`;
entry += `</div>`;
}
} }
entry += `<img class="griditem-image-img" src="content/media/${value.FILE}">`;
entry += `</div>`;
} }
entry += `</div>`; entry += `</div>`;
@ -380,8 +354,8 @@ function View()
this.stats = function(value) this.stats = function(value)
{ {
let menuContent = ``; let menuContent = ``;
if (window.showAdd != undefined && window.showAdd) if (window.showAdd !== undefined && window.showAdd)
{ {
// ADD // ADD
menuContent += `<div class="menu-itemgroup">`; menuContent += `<div class="menu-itemgroup">`;
@ -416,97 +390,30 @@ function View()
menuContent += `<div class="menu-itemgroup">`; menuContent += `<div class="menu-itemgroup">`;
for (var ty = 0; ty < Math.min(value.types.length, SETTINGS.STATSNUMTYPE); ty++) for (var ty = 0; ty < Math.min(value.types.length, SETTINGS.STATSNUMTYPE); ty++)
{ {
if (value.types[ty][0] == 'article') const type = value.types[ty][0];
{ const count = value.types[ty][1];
menuContent += `<a href='#type-article' class="menu-item">`; let icon = '';
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon far fa-newspaper"></i>`; switch (type) {
menuContent += `</a>`; case 'article': icon = 'far fa-newspaper'; break;
} case 'podcast': icon = 'fas fa-podcast'; break;
else if (value.types[ty][0] == 'podcast') case 'video': icon = 'fas fa-tv'; break;
{ case 'list': icon = 'fas fa-file-alt'; break;
menuContent += `<a href='#type-podcast' class="menu-item">`; case 'book': icon = 'fas fa-book-open'; break;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`; case 'game': icon = 'fas fa-gamepad'; break;
menuContent += `<i class="menu-itemicon fas fa-podcast"></i>`; case 'service': icon = 'fas fa-server'; break;
menuContent += `</a>`; case 'lecture': icon = 'fas fa-chalkboard-teacher'; break;
} case 'quote': icon = 'fas fa-comment'; break;
else if (value.types[ty][0] == 'video') case 'tool': icon = 'fas fa-wrench'; break;
{ case 'music': icon = 'fas fa-music'; break;
menuContent += `<a href='#type-video' class="menu-item">`; case 'image': icon = 'fas fa-image'; break;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`; case 'encyclopedia': icon = 'fas fa-globe'; break;
menuContent += `<i class="menu-itemicon fas fa-tv"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'list')
{
menuContent += `<a href='#type-list' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-file-alt"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'book')
{
menuContent += `<a href='#type-book' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-book-open"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'game')
{
menuContent += `<a href='#type-game' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-gamepad"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'service')
{
menuContent += `<a href='#type-service' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-server"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'lecture')
{
menuContent += `<a href='#type-lecture' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-chalkboard-teacher"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'quote')
{
menuContent += `<a href='#type-quote' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-comment"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'tool')
{
menuContent += `<a href='#type-tool' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-wrench"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'music')
{
menuContent += `<a href='#type-music' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-music"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'image')
{
menuContent += `<a href='#type-image' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-image"></i>`;
menuContent += `</a>`;
}
else if (value.types[ty][0] == 'encyclopedia')
{
menuContent += `<a href='#type-encyclopedia' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-globe"></i>`;
menuContent += `</a>`;
} }
menuContent += `<a href='#type-${type}' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${count}</div>`;
menuContent += `<i class="menu-itemicon ${icon}"></i>`;
menuContent += `</a>`;
} }
menuContent += `</div>`; menuContent += `</div>`;
@ -569,7 +476,7 @@ function View()
result += `<div class="${className}"><i class="${iconName}"></i>${data[i].substring(2)}</div>`; result += `<div class="${className}"><i class="${iconName}"></i>${data[i].substring(2)}</div>`;
} }
} }
else if (data[i].substring(0, 2) == "& ") else if (data[i].substring(0, 2) === "& ")
{ {
// New line in current item // New line in current item
result += `<div class="${className}">${data[i].substring(2)}</div>`; result += `<div class="${className}">${data[i].substring(2)}</div>`;
@ -613,7 +520,7 @@ function View()
{ {
domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1]; 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") // 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) if (splitArr[arrLen - 2].length === 2 && splitArr[arrLen - 1].length === 2)
{ {
// this is using a ccTLD // this is using a ccTLD
domain = splitArr[arrLen - 3] + '.' + domain; domain = splitArr[arrLen - 3] + '.' + domain;

View File

@ -12,8 +12,8 @@ function Wrap()
this.process = function() this.process = function()
{ {
for (i = 0; i < this.keys.length; i++) for (let i = 0; i < this.keys.length; i++)
{ {
let value = this.database[this.keys[i]]; let value = this.database[this.keys[i]];
this.database[this.keys[i]].TAGS = this.commaSplit(value.TAGS); this.database[this.keys[i]].TAGS = this.commaSplit(value.TAGS);
@ -57,8 +57,8 @@ function Wrap()
} }
else if (target == 'term') else if (target == 'term')
{ {
for (i = 0; i < this.keys.length; i++) for (let i = 0; i < this.keys.length; i++)
{ {
let value = this.database[this.keys[i]]; let value = this.database[this.keys[i]];
if (typeof value.TERM !== 'undefined') if (typeof value.TERM !== 'undefined')
{ {
@ -74,7 +74,7 @@ function Wrap()
// TAG // TAG
let tagRequest = decodeURI(splitTarget[1]); let tagRequest = decodeURI(splitTarget[1]);
for (let i = 0; i < this.keys.length; i++) for (let i = 0; i < this.keys.length; i++)
{ {
let value = this.database[this.keys[i]]; let value = this.database[this.keys[i]];
if (typeof value.TAGS !== 'undefined') if (typeof value.TAGS !== 'undefined')
{ {