memex/docs/logic/view.js

626 lines
18 KiB
JavaScript
Raw Normal View History

function View()
{
this.msnry = null;
2018-07-23 13:20:03 +00:00
this.overlay = null;
this.container = null;
this.grid = null;
this.menu = null;
var parent = this;
2018-07-23 13:20:03 +00:00
2018-07-22 19:45:04 +00:00
const SETTINGS = {
STATSNUMTAGS: 5,
STATSNUMTYPE: 10,
2018-07-24 11:50:04 +00:00
WIDEGRIDITEM: true,
2018-07-22 19:45:04 +00:00
USEMASONRY: true,
GRIDITEMIDBASE: 'item',
SHOWUPPER: true,
SHOWTITLE: true,
2018-08-13 15:29:24 +00:00
SHOWAUTH: true,
2018-07-22 19:45:04 +00:00
SHOWTYPE: true,
SHOWLINK: true,
SHOWLOWER: true,
SHOWTAGS: true,
SHOWPROJ: true,
2018-07-22 19:45:04 +00:00
SHOWNOTE: true,
SHOWQOTE: true,
SHOWTERM: true,
SHOWPROG: true,
SHOWIMAG: true,
SHOWOVERLAY: true
}
2018-07-21 17:46:18 +00:00
this.install = function()
{
2018-07-23 13:20:03 +00:00
this.overlay = document.getElementById("overlay");
this.container = document.getElementById("container");
this.grid = document.getElementById("grid");
this.menu = document.getElementById("menu");
2018-07-22 19:45:04 +00:00
if (SETTINGS.USEMASONRY)
{
2018-07-22 17:44:46 +00:00
this.msnry = new Masonry('.grid',
{
2018-09-15 13:37:29 +00:00
itemSelector: '.griditem',
columnWidth: 350,
gutter: 20,
fitWidth: true,
transitionDuration: 0,
});
}
}
2018-07-22 19:45:04 +00:00
this.display = function(db)
{
if (window.showAdd != undefined && window.showAdd)
{
main.add.setOverlay(false);
}
2018-07-23 13:20:03 +00:00
// BUILD
this.grid.innerHTML = '';
var dbKeys = Object.keys(db);
var i = 0;
while (i < dbKeys.length)
{
this.buildEntry(db, dbKeys[i]);
i++;
}
// LAYOUT
2018-07-22 19:45:04 +00:00
if (SETTINGS.USEMASONRY)
{
this.msnry.reloadItems();
this.msnry.layout();
}
2018-07-22 17:44:46 +00:00
var imgLoad = imagesLoaded( container );
// When all images finish: redo mansonry layout
imgLoad.on( 'always', function() { parent.msnry.layout(); } );
}
2018-10-29 14:04:20 +00:00
this.isDefined = function(value)
{
return (typeof value !== 'undefined');
}
this.buildEntry = function(db, key)
{
let value = db[key];
2018-09-15 13:37:29 +00:00
let itemClass = "griditem";
2018-07-22 19:45:04 +00:00
if (SETTINGS.WIDEGRIDITEM)
2018-07-17 14:36:13 +00:00
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.WIDE) && value.WIDE)
2018-07-18 13:06:29 +00:00
{
2018-09-15 13:37:29 +00:00
itemClass += " griditem-wide";
2018-07-18 13:06:29 +00:00
}
else if (typeof value.QOTE !== 'undefined')
2018-07-17 14:36:13 +00:00
{
if (Array.isArray(value.QOTE) && value.QOTE.length > 4)
{
2018-09-15 13:37:29 +00:00
itemClass += " griditem-wide";
2018-07-17 14:36:13 +00:00
}
}
}
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWIMAG)
2018-07-18 11:17:51 +00:00
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.TYPE) && value.TYPE == 'image')
2018-07-21 17:46:18 +00:00
{
2018-09-15 13:37:29 +00:00
itemClass += " griditem-image";
2018-07-21 17:46:18 +00:00
}
2018-07-18 11:17:51 +00:00
}
let entry = ``;
2018-07-18 13:06:29 +00:00
// ITEM DIV
2018-07-22 19:45:04 +00:00
entry += `<div class="${itemClass}" id="${SETTINGS.GRIDITEMIDBASE + value.DIID}">`;
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.LINK))
{
var idUrl = "url";
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.SEEN))
{
if (value.SEEN == "true")
{
idUrl = "urlseen";
}
}
// LINK START
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWLINK)
2018-07-21 17:46:18 +00:00
{
if (typeof value.LINK != 'object')
{
// If this item has only one link then make the whole title the link
entry += `<a class="griditem-link" href="${String(value.LINK)}" id="${idUrl}">`;
}
2018-07-21 17:46:18 +00:00
}
}
2018-07-18 11:17:51 +00:00
// UPPER CONTENT START
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWUPPER)
{
2018-09-15 13:37:29 +00:00
entry += `<div class="griditem-containerupper">`;
2018-07-21 17:46:18 +00:00
// TITLE
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWTITLE)
{
2018-09-15 13:37:29 +00:00
entry += `<div class="griditem-title">${key.to_properCase()}</div>`;
}
2018-07-21 17:46:18 +00:00
// LINK END
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWLINK)
2018-07-18 15:28:10 +00:00
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.LINK))
2018-07-21 17:46:18 +00:00
{
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>`;
}
2018-07-21 17:46:18 +00:00
}
2018-07-18 15:28:10 +00:00
}
2018-07-21 17:46:18 +00:00
// TYPE
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWTYPE)
2018-07-19 04:46:43 +00:00
{
2018-10-29 12:33:45 +00:00
entry += `<div class="griditem-typecontainer">`;
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.TYPE))
{
if (typeof value.TYPE == 'object')
2018-07-21 17:46:18 +00:00
{
2018-10-29 14:04:20 +00:00
// This entry has an array of types
for (var i = 0; i < value.TYPE.length; i++)
2018-10-29 12:33:45 +00:00
{
entry += this.doTypeIcon(value.TYPE[i]);
}
2018-07-21 17:46:18 +00:00
}
2018-10-29 14:04:20 +00:00
else
{
// This entry has a single type
entry += this.doTypeIcon(value.TYPE[i]);
}
}
2018-10-29 12:33:45 +00:00
entry += `</div>`; //griditem-typecontainer
2018-07-19 04:46:43 +00:00
}
2018-07-21 17:46:18 +00:00
// UPPER CONTENT END
entry += `</div>`;
}
2018-07-18 11:17:51 +00:00
// LOWER CONTENT START
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWLOWER)
{
2018-09-15 13:37:29 +00:00
entry += `<div class="griditem-containerlower">`;
2018-07-21 17:46:18 +00:00
2018-08-13 15:29:24 +00:00
// AUTHOR
if (SETTINGS.SHOWAUTH)
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.AUTH))
2018-08-13 15:29:24 +00:00
{
2018-09-15 14:15:16 +00:00
entry += `<div class="griditem-auth"><i class="fas fa-user textIcon"></i>${value.AUTH}</div>`;
2018-08-13 15:29:24 +00:00
}
}
2018-07-21 17:46:18 +00:00
// TAGS
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWTAGS)
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.TAGS))
{
2018-09-15 14:15:16 +00:00
entry += `<div class="griditem-tags"><i class="fas fa-tag textIcon"></i>`;
2018-07-21 17:46:18 +00:00
for (var i = 0; i < value.TAGS.length; i++)
{
entry += `<a class="griditem-taglink" href="#tag-${value.TAGS[i]}">${value.TAGS[i]}</a>`;
if (i + 1 != value.TAGS.length)
{
entry += `, `;
}
};
entry += `</div>`;
}
}
// PROJECT
if (SETTINGS.SHOWPROJ)
2018-10-29 14:04:20 +00:00
{
if (this.isDefined(value.PROJ))
{
entry += `<div class="griditem-proj"><i class="fas fa-leaf textIcon"></i>`;
for (var i = 0; i < value.PROJ.length; i++)
{
entry += `<a class="griditem-taglink" href="#proj-${value.PROJ[i]}">${value.PROJ[i]}</a>`;
if (i + 1 != value.PROJ.length)
2018-07-21 17:46:18 +00:00
{
entry += `, `;
}
};
entry += `</div>`;
}
2018-07-21 17:46:18 +00:00
}
2018-10-29 13:27:30 +00:00
// TERM
if (SETTINGS.SHOWTERM)
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.TERM))
2018-10-29 13:27:30 +00:00
{
entry += this.buildArrayElement(value.TERM, "griditem-term", "fas fa-ribbon textIcon");
}
}
2018-07-21 17:46:18 +00:00
// NOTE
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWNOTE)
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.NOTE))
2018-07-21 17:46:18 +00:00
{
2018-09-15 14:15:16 +00:00
entry += this.buildArrayElement(value.NOTE, "griditem-note", "fas fa-sticky-note textIcon");
2018-07-21 17:46:18 +00:00
}
}
2018-07-21 17:46:18 +00:00
// QUOTE
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWQOTE)
2018-07-21 17:46:18 +00:00
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.QOTE))
2018-07-21 17:46:18 +00:00
{
2018-09-15 14:15:16 +00:00
entry += this.buildArrayElement(value.QOTE, "griditem-quote", "fas fa-comment textIcon");
2018-07-21 17:46:18 +00:00
}
}
2018-07-21 17:46:18 +00:00
// PROGRESS
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWPROG)
2018-07-21 17:46:18 +00:00
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.PROG))
2018-07-21 17:46:18 +00:00
{
2018-09-15 14:15:16 +00:00
entry += `<div class="griditem-prog"><i class="fas fa-clock textIcon"></i>${value.PROG}</div>`;
2018-07-21 17:46:18 +00:00
}
}
2018-07-18 11:17:51 +00:00
2018-07-21 17:46:18 +00:00
// LOWER CONTENT END
entry += `</div>`;
}
2018-07-18 11:17:51 +00:00
// IMAGE
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWIMAG)
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.TYPE) && value.TYPE == 'image')
{
2018-10-29 14:04:20 +00:00
if (this.isDefined(value.FILE))
2018-07-21 17:46:18 +00:00
{
entry += `<div class="image">`;
2018-07-22 19:45:04 +00:00
if (SETTINGS.SHOWOVERLAY)
2018-07-21 17:46:18 +00:00
{
entry += `<div class="image-overlay"></div>`;
}
2018-09-15 13:37:29 +00:00
entry += `<img class="griditem-image-img" src="content/media/${value.FILE}">`;
2018-07-21 17:46:18 +00:00
entry += `</div>`;
}
}
}
entry += `</div>`;
this.grid.innerHTML += entry;
}
2018-10-29 12:33:45 +00:00
this.doTypeIcon = function(type, count)
{
let result = `<a class="griditem-type" href='#type-${String(type)}'>`;
2018-10-29 14:04:20 +00:00
switch (type)
2018-10-29 12:33:45 +00:00
{
2018-10-29 14:04:20 +00:00
case 'article':
result += `<i class="griditem-typeicon far fa-newspaper"></i>`;
break;
case 'podcast':
result += `<i class="griditem-typeicon fas fa-podcast"></i>`;
break;
case 'video':
result += `<i class="griditem-typeicon fas fa-tv"></i>`;
break;
case 'list':
result += `<i class="griditem-typeicon fas fa-file-alt"></i>`;
break;
case 'book':
result += `<i class="griditem-typeicon fas fa-book-open"></i>`;
break;
case 'game':
result += `<i class="griditem-typeicon fas fa-gamepad"></i>`;
break;
case 'service':
result += `<i class="griditem-typeicon fas fa-server"></i>`;
break;
case 'lecture':
result += `<i class="griditem-typeicon fas fa-chalkboard-teacher"></i>`;
break;
case 'quote':
result += `<i class="griditem-typeicon fas fa-comment"></i>`;
break;
case 'tool':
result += `<i class="griditem-typeicon fas fa-wrench"></i>`;
break;
case 'music':
result += `<i class="griditem-typeicon fas fa-music"></i>`;
break;
case 'image':
result += `<i class="griditem-typeicon fas fa-image"></i>`;
break;
case 'encyclopedia':
result += `<i class="griditem-typeicon fas fa-globe"></i>`;
break;
2018-10-29 12:33:45 +00:00
}
result += `</a>`;
return result;
}
2018-07-22 19:45:04 +00:00
this.stats = function(value)
{
let menuContent = ``;
if (window.showAdd != undefined && window.showAdd)
{
// ADD
2018-09-14 18:55:32 +00:00
menuContent += `<div class="menu-itemgroup">`;
menuContent += `<a href='#add' class="menu-item">`;
menuContent += `<b>a</b>dd`;
menuContent += `</a>`;
2018-09-14 18:55:32 +00:00
menuContent += `</div>`;
}
2018-07-23 13:20:03 +00:00
2018-08-13 16:30:09 +00:00
// TOTAL
2018-09-14 18:55:32 +00:00
menuContent += `<div class="menu-itemgroup">`;
menuContent += `<a href='#' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.total}</div>`;
menuContent += `<i class="menu-itemicon fas fa-asterisk"></i>`;
menuContent += `</a>`;
2018-09-14 18:55:32 +00:00
menuContent += `</div>`;
2018-08-13 16:30:09 +00:00
// DONE
2018-09-14 18:55:32 +00:00
menuContent += `<div class="menu-itemgroup">`;
2018-08-13 16:30:09 +00:00
2018-09-14 18:55:32 +00:00
menuContent += `<a href='#done-true' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.done}</div>`;
menuContent += `<i class="menu-itemicon fas fa-check"></i>`;
2018-08-13 16:30:09 +00:00
menuContent += `</a>`;
2018-09-14 18:55:32 +00:00
menuContent += `<a href='#done-false' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.total - value.done}</div>`;
menuContent += `<i class="menu-itemicon fas fa-times"></i>`;
2018-08-13 16:30:09 +00:00
menuContent += `</a>`;
2018-09-14 18:55:32 +00:00
menuContent += `</div>`;
menuContent += `<div class="menu-itemgroup">`;
2018-07-22 19:45:04 +00:00
for (var ty = 0; ty < Math.min(value.types.length, SETTINGS.STATSNUMTYPE); ty++)
{
2018-07-22 19:45:04 +00:00
if (value.types[ty][0] == 'article')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
menuContent += `<a href='#type-article' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon far fa-newspaper"></i>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'podcast')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
menuContent += `<a href='#type-podcast' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-podcast"></i>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'video')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
menuContent += `<a href='#type-video' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.types[ty][1]}</div>`;
menuContent += `<i class="menu-itemicon fas fa-tv"></i>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'list')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'book')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'game')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'service')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'lecture')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'quote')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'tool')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'music')
2018-07-17 14:09:23 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-17 14:09:23 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'image')
2018-07-18 16:28:01 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-18 16:28:01 +00:00
menuContent += `</a>`;
}
2018-07-22 19:45:04 +00:00
else if (value.types[ty][0] == 'encyclopedia')
2018-07-19 04:46:43 +00:00
{
2018-09-14 18:55:32 +00:00
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>`;
2018-07-19 04:46:43 +00:00
menuContent += `</a>`;
}
}
2018-09-14 18:55:32 +00:00
menuContent += `</div>`;
2018-09-14 22:53:56 +00:00
// TERM
2018-09-14 18:55:32 +00:00
menuContent += `<div class="menu-itemgroup">`;
2018-07-22 19:45:04 +00:00
if (value.terms > 0)
{
// menuContent += `<div class="menu-item-space"></div>`;
2018-09-14 18:55:32 +00:00
menuContent += `<a href='#term' class="menu-item">`;
menuContent += `<div class="menu-itemcount">${value.terms}</div>`;
menuContent += `<i class="menu-itemicon fas fa-ribbon"></i>`;
menuContent += `</a>`;
}
2018-09-14 18:55:32 +00:00
menuContent += `</div>`;
2018-07-17 18:17:43 +00:00
// TAGS
2018-09-14 18:55:32 +00:00
menuContent += `<div class="menu-itemgroup">`;
2018-07-22 19:45:04 +00:00
if (value.tags.length > 0)
{
2018-09-14 18:55:32 +00:00
menuContent += `<div class="menu-tagcontainer">`;
menuContent += `<i class="menu-tagicon fas fa-tag"></i>`;
2018-07-22 19:45:04 +00:00
for (var t = 0; t < Math.min(value.types.length, SETTINGS.STATSNUMTAGS); t++)
{
2018-09-14 18:55:32 +00:00
menuContent += `<a class="menu-tag" href='#tag-${value.tags[t][0]}'>`;
// menuContent += `<i class="fas fa-tag textIcon"></i>`;
2018-09-14 18:55:32 +00:00
menuContent += `<div class="menu-tagcount">${value.tags[t][1]}</div>`;
menuContent += `<div class="menu-taglabel">${value.tags[t][0]}</div>`;
menuContent += `</a>`;
}
menuContent += `</div>`;
}
2018-09-14 18:55:32 +00:00
menuContent += `</div>`;
this.menu.innerHTML = ``;
this.menu.innerHTML += menuContent;
}
2018-08-11 16:31:55 +00:00
this.buildArrayElement = function(data, className, iconName)
{
let result = '';
if (Array.isArray(data))
{
for (var i in data)
{
2018-10-29 14:17:10 +00:00
if (data[i].substring(0, 2) == "> ")
2018-08-11 16:31:55 +00:00
{
// New item
2018-08-12 14:48:17 +00:00
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();
}
2018-08-12 15:05:56 +00:00
result += `<div class="${className}"><i class="${iconName}"></i><b>${titleSplit[0]}</b>: ${titleSplit[1]}</div>`;
2018-08-12 14:48:17 +00:00
}
else
{
result += `<div class="${className}"><i class="${iconName}"></i>${data[i].substring(2)}</div>`;
}
2018-08-11 16:31:55 +00:00
}
else if (data[i].substring(0, 2) == "& ")
{
// New line in current item
result += `<div class="${className}">${data[i].substring(2)}</div>`;
}
2018-10-29 14:17:10 +00:00
else if (data[i].substring(0, 2) == "- ")
{
// Bullet point
result += `<div class="${className}"><i class="fas fa-caret-right textIcon"></i>${data[i].substring(2)}</div>`;
}
2018-08-11 16:31:55 +00:00
else
{
// Handle unformatted
result += `<div class="${className}"><i class="${iconName}"></i>${data[i]}</div>`;
}
}
}
else
{
// Handle not array
result += `<div class="${className}"><i class="${iconName}"></i>${data}</div>`;
}
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;
2018-07-22 17:44:46 +00:00
// extracting the root domain here
// if there is a subdomain
if (arrLen > 2)
{
domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1];
2018-07-22 17:44:46 +00:00
// 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)
{
2018-07-22 17:44:46 +00:00
// 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;
2018-07-22 17:44:46 +00:00
// find & remove protocol (http, ftp, etc.) and get hostname
2018-08-12 14:48:17 +00:00
if (url.indexOf("://") > -1)
{
hostname = url.split('/')[2];
}
2018-08-12 14:48:17 +00:00
else
{
hostname = url.split('/')[0];
}
2018-07-22 17:44:46 +00:00
// find & remove port number
hostname = hostname.split(':')[0];
2018-07-22 17:44:46 +00:00
// find & remove "?"
hostname = hostname.split('?')[0];
return hostname;
}
}