Add ability to pass URL for the card title
This commit is contained in:
31
js/main.js
31
js/main.js
@@ -265,6 +265,7 @@ function parseAndCreate(jsonData) {
|
|||||||
function createSqr(sqrData, index) {
|
function createSqr(sqrData, index) {
|
||||||
// Create a new square division with the passed element
|
// Create a new square division with the passed element
|
||||||
name = sqrData["name"];
|
name = sqrData["name"];
|
||||||
|
link = sqrData["url"];
|
||||||
links = sqrData["links"];
|
links = sqrData["links"];
|
||||||
color = sqrData["color"];
|
color = sqrData["color"];
|
||||||
|
|
||||||
@@ -286,9 +287,7 @@ function createSqr(sqrData, index) {
|
|||||||
|
|
||||||
div.classList.add(customClass);
|
div.classList.add(customClass);
|
||||||
|
|
||||||
h4 = document.createElement("h4")
|
h4 = getTitle(name, link);
|
||||||
h4.textContent = name
|
|
||||||
|
|
||||||
|
|
||||||
div.appendChild(h4)
|
div.appendChild(h4)
|
||||||
|
|
||||||
@@ -309,6 +308,32 @@ function createSqr(sqrData, index) {
|
|||||||
return div
|
return div
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTitle(titleContent, linkHref=null) {
|
||||||
|
/**
|
||||||
|
* Create the title for the sqr card.
|
||||||
|
*
|
||||||
|
* The card will be optionally clicable and will open
|
||||||
|
* a new link.
|
||||||
|
*
|
||||||
|
* If the link is not passed in the config then the title
|
||||||
|
* will not be clickable.
|
||||||
|
*/
|
||||||
|
h4 = document.createElement("h4");
|
||||||
|
|
||||||
|
if (!linkHref) {
|
||||||
|
h4.textContent = titleContent;
|
||||||
|
return h4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the link is passed, create a nested child
|
||||||
|
a = document.createElement("a");
|
||||||
|
a.setAttribute("href", linkHref);
|
||||||
|
a.textContent = titleContent;
|
||||||
|
|
||||||
|
h4.appendChild(a);
|
||||||
|
return h4;
|
||||||
|
}
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
|
||||||
function isValidTimeZone(tz) {
|
function isValidTimeZone(tz) {
|
||||||
|
|||||||
Reference in New Issue
Block a user