`;
// Choose the Section after which you want to place the widget
const aboveWidgetID = "#services";
// ADD LINK TO NAV BAR //
// If you want to add a link of the widget to the navigation bar, use: | YES = 1 - NO = 0 |
const boolAddLink = 0;
// Name the new widget's URL (no spaces, no uppercases, no underlines, nor symbols. Try to be UNIQUE)
const newWidgetName = "new-widget";
// The Navigation Title of the Widget's Link
const newNavLinkText = "";
// CODE NEEDS SCRIPT - ALWAYS TRUE FOR ELFSIGHT //
// If you want to add a custom script for the widget to the navigation bar, use: | YES = 1 - NO = 0 |
const boolAddScript = 1;
// Add any script to the widget with a source link
const widgetScriptSrc = `https://apps.elfsight.com/p/platform.js`;
//-------------------- EDIT ABOVE --------------------//
//-------------------- FUNCTIONS --------------------//
// Needs to create Script element, to workaround non-script strings
function loadScript(widgetScriptSrc) {
let widgetScript = document.createElement("script");
widgetScript.setAttribute('type', 'text/javascript');
widgetScript.setAttribute('src', widgetScriptSrc);
widgetScript.defer = true;
return widgetScript;
}
// Adds feed to after the chosen section
function addWidget(newSection, existingSection) {
existingSection.parentNode.insertBefore(newSection, existingSection.nextSibling);
}
// Add link to the nav bar
function addLink(aboveWidgetID, newWidgetName, newNavLinkText) {
if (boolAddLink) {
let navBar = document.getElementsByTagName("nav")[0].getElementsByTagName("ul")[0].children;
let newLink
for (let i = 0; i < navBar.length; i++) {
let navLink = navBar[i].firstChild.href.split("/");
if (navLink.pop() == aboveWidgetID) {
newLink = navBar[i].cloneNode(true);
newLink.getElementsByTagName("a")[0].textContent = newNavLinkText;
newLink.getElementsByTagName("a")[0].href = "#" + newWidgetName;
navBar[i].parentElement.insertBefore(newLink, navBar[i + 1]);
break;
}
}
}
}
//-------------------- ENGINE --------------------//
// Find given section
let aboveWidget = document.querySelector(aboveWidgetID);
// Create widget section
let widgetSection = document.createElement("section");
widgetSection.innerHTML = widgetHTML;
if (boolAddLink) {
widgetSection.id = newWidgetName;
}
if (boolAddScript) {
widgetSection.appendChild(loadScript(widgetScriptSrc));
}
// Finalize it
addWidget(widgetSection, aboveWidget);
addLink(aboveWidgetID, newWidgetName, newNavLinkText);
return;
}