Added scripts for content, Improved tables and buttons
Update scripts.php, sidebar.php, and 20 more files...
This commit is contained in:
49
resources/NibblePoker/js/nibblepoker-code.js
Normal file
49
resources/NibblePoker/js/nibblepoker-code.js
Normal file
@@ -0,0 +1,49 @@
|
||||
// Highlights the code blocks when included on a page.
|
||||
// This command is separated in its own file since highlight.js isn't on every page and because I can't use JS
|
||||
// in a script element without using an external .js file.
|
||||
|
||||
Array.from(document.getElementsByClassName("code")).forEach(eCodeContainer => {
|
||||
let language = null;
|
||||
|
||||
eCodeContainer.classList.forEach(cCodeContainer => {
|
||||
if(cCodeContainer.startsWith("language-")) {
|
||||
language = cCodeContainer;
|
||||
}
|
||||
});
|
||||
|
||||
if(language !== null) {
|
||||
Array.from(eCodeContainer.children).forEach(eCodeLine => {
|
||||
if(eCodeLine.classList.contains("code-line")) {
|
||||
eCodeLine.classList.add(language);
|
||||
hljs.highlightElement(eCodeLine);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Adding the action to copy the code to elements with the "js-code-copy" class.
|
||||
// The search works by searching the closest parent with the "code" class or that is a "code" element, and then
|
||||
// reading each of its children with the "code-line" class.
|
||||
|
||||
Array.from(document.getElementsByClassName("js-code-copy")).forEach(eCodeCopyButton => {
|
||||
let eParentCodeBlock = eCodeCopyButton;
|
||||
|
||||
while(eParentCodeBlock != null &&!eParentCodeBlock.classList.contains("code") &&
|
||||
eParentCodeBlock.nodeName.toLowerCase() !== "code") {
|
||||
eParentCodeBlock = eParentCodeBlock.parentElement;
|
||||
}
|
||||
|
||||
if(eParentCodeBlock != null) {
|
||||
let code = "";
|
||||
|
||||
Array.from(eParentCodeBlock.children).forEach(eCodeLine => {
|
||||
if(eCodeLine.classList.contains("code-line")) {
|
||||
code += eCodeLine.textContent + "\n"
|
||||
}
|
||||
});
|
||||
|
||||
eCodeCopyButton.onclick = function() {
|
||||
navigator.clipboard.writeText(code);
|
||||
};
|
||||
}
|
||||
});
|
77
resources/NibblePoker/js/nibblepoker-glider.js
Normal file
77
resources/NibblePoker/js/nibblepoker-glider.js
Normal file
@@ -0,0 +1,77 @@
|
||||
// Creating the galleries from Glider.js
|
||||
window.addEventListener('load', function(){
|
||||
document.querySelectorAll(".glider").forEach(element => {
|
||||
new Glider(element, {
|
||||
slidesToShow: 1,
|
||||
draggable: true,
|
||||
scrollLock: true,
|
||||
scrollLockDelay: 125,
|
||||
rewind: true,
|
||||
arrows: {
|
||||
prev: element.previousSibling,
|
||||
next: element.nextSibling
|
||||
},
|
||||
responsive: [
|
||||
{
|
||||
breakpoint: 768,
|
||||
settings: {
|
||||
slidesToShow: 2,
|
||||
duration: 0.25
|
||||
}
|
||||
},{
|
||||
breakpoint: 992,
|
||||
settings: {
|
||||
slidesToShow: 3,
|
||||
slidesToScroll: 1
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// Processing the images
|
||||
const eImages = [];
|
||||
|
||||
// Converting the Node to a HTMLElement if needed and desired.
|
||||
element.childNodes[0].childNodes.forEach(childrenNode => {
|
||||
if(childrenNode.nodeType !== Node.ELEMENT_NODE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Casting from a Node to a proper HTMLElement because of course we have to add this step in JS...
|
||||
const eChildElement = childrenNode.cloneNode(true);
|
||||
|
||||
if(eChildElement.tagName.toLowerCase() !== "img") {
|
||||
return;
|
||||
}
|
||||
|
||||
eChildElement.onclick = function() {
|
||||
let imageElement = document.getElementById("modal-img");
|
||||
imageElement.src = eChildElement.src;
|
||||
imageElement.alt = eChildElement.alt;
|
||||
halfmoon.toggleModal('modal-content-image-viewer');
|
||||
console.log("Opening image...");
|
||||
};
|
||||
|
||||
// Saving the element for later.
|
||||
eImages.push(eChildElement);
|
||||
});
|
||||
|
||||
// Removing the nodes so that the desired ones can be reinserted later.
|
||||
// We start from the rear to prevent issues with de-ordering as we delete them !
|
||||
for(let i = element.childNodes[0].childNodes.length - 1; i >= 0; i--) {
|
||||
element.childNodes[0].removeChild(element.childNodes[0].childNodes[i]);
|
||||
}
|
||||
|
||||
eImages.forEach(eImageElement => {
|
||||
element.childNodes[0].appendChild(eImageElement);
|
||||
});
|
||||
});
|
||||
|
||||
// The default modal animation looks like ass, jesus...
|
||||
let eImgModalCloseButton = document.getElementById("modal-img-close");
|
||||
if(eImgModalCloseButton != null) {
|
||||
eImgModalCloseButton.onclick = function() {
|
||||
halfmoon.toggleModal('modal-content-image-viewer');
|
||||
}
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user