forked from rDrama/rDrama
255 lines
84 KiB
JavaScript
255 lines
84 KiB
JavaScript
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).bootstrap=e()}(this,(function(){"use strict";const t=t=>{let e=t.getAttribute("data-bs-target");if(!e||"#"===e){let i=t.getAttribute("href");if(!i||!i.includes("#")&&!i.startsWith("."))return null;i.includes("#")&&!i.startsWith("#")&&(i="#"+i.split("#")[1]),e=i&&"#"!==i?i.trim():null}return e},e=e=>{const i=t(e);return i&&document.querySelector(i)?i:null},i=e=>{const i=t(e);return i?document.querySelector(i):null},n=t=>{t.dispatchEvent(new Event("transitionend"))},s=t=>!(!t||"object"!=typeof t)&&(void 0!==t.jquery&&(t=t[0]),void 0!==t.nodeType),o=t=>s(t)?t.jquery?t[0]:t:"string"==typeof t&&t.length>0?document.querySelector(t):null,r=(t,e,i)=>{Object.keys(i).forEach(n=>{const o=i[n],r=e[n],a=r&&s(r)?"element":null==(l=r)?""+l:{}.toString.call(l).match(/\s([a-z]+)/i)[1].toLowerCase();var l;if(!new RegExp(o).test(a))throw new TypeError(`${t.toUpperCase()}: Option "${n}" provided type "${a}" but expected type "${o}".`)})},a=t=>!(!s(t)||0===t.getClientRects().length)&&"visible"===getComputedStyle(t).getPropertyValue("visibility"),l=t=>!t||t.nodeType!==Node.ELEMENT_NODE||!!t.classList.contains("disabled")||(void 0!==t.disabled?t.disabled:t.hasAttribute("disabled")&&"false"!==t.getAttribute("disabled")),c=t=>{if(!document.documentElement.attachShadow)return null;if("function"==typeof t.getRootNode){const e=t.getRootNode();return e instanceof ShadowRoot?e:null}return t instanceof ShadowRoot?t:t.parentNode?c(t.parentNode):null},h=()=>{},d=t=>{t.offsetHeight},u=()=>{const{jQuery:t}=window;return t&&!document.body.hasAttribute("data-bs-no-jquery")?t:null},f=[],p=()=>"rtl"===document.documentElement.dir,m=t=>{var e;e=()=>{const e=u();if(e){const i=t.NAME,n=e.fn[i];e.fn[i]=t.jQueryInterface,e.fn[i].Constructor=t,e.fn[i].noConflict=()=>(e.fn[i]=n,t.jQueryInterface)}},"loading"===document.readyState?(f.length||document.addEventListener("DOMContentLoaded",()=>{f.forEach(t=>t())}),f.push(e)):e()},g=t=>{"function"==typeof t&&t()},_=(t,e,i=!0)=>{if(!i)return void g(t);const s=(t=>{if(!t)return 0;let{transitionDuration:e,transitionDelay:i}=window.getComputedStyle(t);const n=Number.parseFloat(e),s=Number.parseFloat(i);return n||s?(e=e.split(",")[0],i=i.split(",")[0],1e3*(Number.parseFloat(e)+Number.parseFloat(i))):0})(e)+5;let o=!1;const r=({target:i})=>{i===e&&(o=!0,e.removeEventListener("transitionend",r),g(t))};e.addEventListener("transitionend",r),setTimeout(()=>{o||n(e)},s)},b=(t,e,i,n)=>{let s=t.indexOf(e);if(-1===s)return t[!i&&n?t.length-1:0];const o=t.length;return s+=i?1:-1,n&&(s=(s+o)%o),t[Math.max(0,Math.min(s,o-1))]},v=/[^.]*(?=\..*)\.|.*/,y=/\..*/,w=/::\d+$/,E={};let A=1;const T={mouseenter:"mouseover",mouseleave:"mouseout"},O=/^(mouseenter|mouseleave)/i,C=new Set(["click","dblclick","mouseup","mousedown","contextmenu","mousewheel","DOMMouseScroll","mouseover","mouseout","mousemove","selectstart","selectend","keydown","keypress","keyup","orientationchange","touchstart","touchmove","touchend","touchcancel","pointerdown","pointermove","pointerup","pointerleave","pointercancel","gesturestart","gesturechange","gestureend","focus","blur","change","reset","select","submit","focusin","focusout","load","unload","beforeunload","resize","move","DOMContentLoaded","readystatechange","error","abort","scroll"]);function k(t,e){return e&&`${e}::${A++}`||t.uidEvent||A++}function L(t){const e=k(t);return t.uidEvent=e,E[e]=E[e]||{},E[e]}function x(t,e,i=null){const n=Object.keys(t);for(let s=0,o=n.length;s<o;s++){const o=t[n[s]];if(o.originalHandler===e&&o.delegationSelector===i)return o}return null}function D(t,e,i){const n="string"==typeof e,s=n?i:e;let o=I(t);return C.has(o)||(o=t),[n,s,o]}function S(t,e,i,n,s){if("string"!=typeof e||!t)return;if(i||(i=n,n=null),O.test(e)){const t=t=>function(e){if(!e.relatedTarget||e.relatedTarget!==e.delegateTarget&&!e.delegateTarget.contains(e.relatedTarget))return t.call(this,e)};n?n=t(n):i=t(i)}const[o,r,a]=D(e,i,n),l
|
||
|
|
||
|
if (window.location.pathname != '/submit')
|
||
|
{
|
||
|
document.addEventListener('keydown', (e) => {
|
||
|
if(!((e.ctrlKey || e.metaKey) && e.key === "Enter")) return;
|
||
|
|
||
|
const targetDOM = document.activeElement;
|
||
|
if(!(targetDOM instanceof HTMLTextAreaElement || targetDOM instanceof HTMLInputElement)) return;
|
||
|
|
||
|
const formDOM = targetDOM.parentElement;
|
||
|
|
||
|
const submitButtonDOMs = formDOM.querySelectorAll('input[type=submit], .btn-primary');
|
||
|
if(submitButtonDOMs.length === 0)
|
||
|
throw new TypeError("I am unable to find the submit button :(. Contact the head custodian immediately.")
|
||
|
|
||
|
const btn = submitButtonDOMs[0]
|
||
|
btn.click();
|
||
|
btn.disabled = true;
|
||
|
btn.classList.add('disabled');
|
||
|
setTimeout(() => {
|
||
|
btn.disabled = false;
|
||
|
btn.classList.remove('disabled');
|
||
|
}, 2000);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
addEventListener('show.bs.modal', function (e) {
|
||
|
location.hash = "modal";
|
||
|
});
|
||
|
|
||
|
addEventListener('hide.bs.modal', function (e) {
|
||
|
if(location.hash == "#modal") {
|
||
|
history.back();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
addEventListener('hashchange', function (e) {
|
||
|
if(location.hash != "#modal") {
|
||
|
const curr_modal = bootstrap.Modal.getInstance(document.getElementsByClassName('show')[0])
|
||
|
if (curr_modal) curr_modal.hide()
|
||
|
}
|
||
|
});
|
||
|
|
||
|
function disable(t) {
|
||
|
t.classList.add('disabled');
|
||
|
setTimeout(() => {
|
||
|
t.classList.remove("disabled");
|
||
|
}, 2000);
|
||
|
}
|
||
|
|
||
|
function autoExpand (field) {
|
||
|
xpos=window.scrollX;
|
||
|
ypos=window.scrollY;
|
||
|
|
||
|
field.style.height = 'inherit';
|
||
|
|
||
|
var computed = window.getComputedStyle(field);
|
||
|
|
||
|
var height = parseInt(computed.getPropertyValue('border-top-width'), 10)
|
||
|
+ parseInt(computed.getPropertyValue('padding-top'), 10)
|
||
|
+ field.scrollHeight
|
||
|
+ parseInt(computed.getPropertyValue('padding-bottom'), 10)
|
||
|
+ parseInt(computed.getPropertyValue('border-bottom-width'), 10);
|
||
|
|
||
|
field.style.height = height + 'px';
|
||
|
|
||
|
window.scrollTo(xpos,ypos);
|
||
|
};
|
||
|
|
||
|
document.addEventListener('input', function (event) {
|
||
|
if (event.target.tagName.toLowerCase() !== 'textarea') return;
|
||
|
autoExpand(event.target);
|
||
|
}, false);
|
||
|
|
||
|
function smoothScrollTop()
|
||
|
{
|
||
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||
|
}
|
||
|
|
||
|
// Click navbar to scroll back to top
|
||
|
(() => {
|
||
|
let toplisteners = [
|
||
|
document.querySelector('nav')
|
||
|
];
|
||
|
|
||
|
for (let i of toplisteners)
|
||
|
{
|
||
|
i.addEventListener('click', (e) => {
|
||
|
if (e.target.id === "navbar" ||
|
||
|
e.target.classList.contains("container-fluid") ||
|
||
|
e.target.id == "navbarResponsive" ||
|
||
|
e.target.id == "logo-container" ||
|
||
|
e.target.classList.contains("srd"))
|
||
|
smoothScrollTop();
|
||
|
}, false);
|
||
|
}
|
||
|
})();
|
||
|
|
||
|
// Dynamic shadow when the user scrolls
|
||
|
document.addEventListener('scroll',function (event) {
|
||
|
let nav = document.querySelector("nav");
|
||
|
let i = (Math.min(20, window.scrollY/4)+1)/21;
|
||
|
nav.style.boxShadow="0px 2px "+i*21+"px rgba(15,15,15,"+i*.3+")";
|
||
|
if (window.scrollY <= 0)
|
||
|
{
|
||
|
// nav.classList.remove("shadow");
|
||
|
nav.classList.remove("navbar-active");
|
||
|
nav.style.boxShadow = "unset";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// nav.classList.add("shadow");
|
||
|
nav.classList.add("navbar-active");
|
||
|
}
|
||
|
|
||
|
}, false);
|
||
|
|
||
|
function formkey() {
|
||
|
let formkey = document.getElementById("formkey")
|
||
|
if (formkey) return formkey.innerHTML;
|
||
|
else return null;
|
||
|
}
|
||
|
|
||
|
function expandDesktopImage(url) {
|
||
|
console.log('this')
|
||
|
const e = this.event
|
||
|
if(e.ctrlKey || e.metaKey || e.shiftKey || e.altKey)
|
||
|
return true;
|
||
|
e.preventDefault();
|
||
|
if (!url)
|
||
|
{
|
||
|
url = e.target.src
|
||
|
if (!url) url = e.target.dataset.src
|
||
|
}
|
||
|
document.getElementById("desktop-expanded-image").src = url.replace("200w_d.webp", "giphy.webp");
|
||
|
document.getElementById("desktop-expanded-image-link").href = url;
|
||
|
document.getElementById("desktop-expanded-image-wrap-link").href = url;
|
||
|
bootstrap.Modal.getOrCreateInstance(document.getElementById('expandImageModal')).show();
|
||
|
};
|
||
|
|
||
|
document.addEventListener("click", function(e){
|
||
|
const element = e.target
|
||
|
if (element instanceof HTMLImageElement && element.alt.startsWith('![]('))
|
||
|
expandDesktopImage()
|
||
|
});
|
||
|
|
||
|
function bs_trigger(e) {
|
||
|
let tooltipTriggerList = [].slice.call(e.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
||
|
tooltipTriggerList.map(function(element){
|
||
|
return bootstrap.Tooltip.getOrCreateInstance(element);
|
||
|
});
|
||
|
|
||
|
const popoverTriggerList = [].slice.call(e.querySelectorAll('[data-bs-toggle="popover"]'));
|
||
|
popoverTriggerList.map(function(popoverTriggerEl) {
|
||
|
const popoverId = popoverTriggerEl.getAttribute('data-content-id');
|
||
|
let contentEl;
|
||
|
try {contentEl = e.getElementById(popoverId);}
|
||
|
catch(t) {contentEl = document.getElementById(popoverId);}
|
||
|
if (contentEl) {
|
||
|
return bootstrap.Popover.getOrCreateInstance(popoverTriggerEl, {
|
||
|
content: contentEl.innerHTML,
|
||
|
html: true,
|
||
|
});
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
var bsTriggerOnReady = function() {
|
||
|
bs_trigger(document);
|
||
|
}
|
||
|
|
||
|
if (document.readyState === "complete" ||
|
||
|
(document.readyState !== "loading" && !document.documentElement.doScroll)) {
|
||
|
bsTriggerOnReady();
|
||
|
} else {
|
||
|
document.addEventListener("DOMContentLoaded", bsTriggerOnReady);
|
||
|
}
|
||
|
|
||
|
function post_toast(t, url, button1, button2, classname) {
|
||
|
t.disabled = true;
|
||
|
t.classList.add("disabled");
|
||
|
const xhr = new XMLHttpRequest();
|
||
|
xhr.open("POST", url);
|
||
|
xhr.setRequestHeader('xhr', 'xhr');
|
||
|
var form = new FormData()
|
||
|
form.append("formkey", formkey());
|
||
|
|
||
|
|
||
|
xhr.onload = function() {
|
||
|
let data
|
||
|
try {data = JSON.parse(xhr.response)}
|
||
|
catch(e) {console.log(e)}
|
||
|
if (xhr.status >= 200 && xhr.status < 300 && data && data['message']) {
|
||
|
document.getElementById('toast-post-success-text').innerText = data["message"];
|
||
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show();
|
||
|
|
||
|
if (button1)
|
||
|
{
|
||
|
if (typeof(button1) == 'boolean')
|
||
|
location.reload()
|
||
|
else {
|
||
|
document.getElementById(button1).classList.toggle(classname);
|
||
|
document.getElementById(button2).classList.toggle(classname);
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
||
|
if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"];
|
||
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')).show();
|
||
|
}
|
||
|
setTimeout(() => {
|
||
|
t.disabled = false;
|
||
|
t.classList.remove("disabled");
|
||
|
}, 2000);
|
||
|
};
|
||
|
|
||
|
xhr.send(form);
|
||
|
|
||
|
}
|
||
|
|
||
|
function escapeHTML(unsafe) {
|
||
|
return unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||
|
}
|
||
|
|
||
|
function changename(s1,s2) {
|
||
|
let files = document.getElementById(s2).files;
|
||
|
let filename = '';
|
||
|
for (const e of files) {
|
||
|
filename += e.name.substr(0, 20) + ', ';
|
||
|
}
|
||
|
document.getElementById(s1).innerHTML = escapeHTML(filename.slice(0, -2));
|
||
|
}
|
||
|
|
||
|
function showmore() {
|
||
|
const btn = this.event.target
|
||
|
const div = btn.parentElement.nextSibling
|
||
|
div.classList.toggle('d-none')
|
||
|
if (div.classList.contains('d-none'))
|
||
|
btn.innerHTML = 'SHOW MORE'
|
||
|
else
|
||
|
btn.innerHTML = 'SHOW LESS'
|
||
|
}
|
||
|
|
||
|
const timestamps = document.querySelectorAll('[data-time]');
|
||
|
|
||
|
for (const e of timestamps) {
|
||
|
const date = new Date(e.dataset.time*1000);
|
||
|
e.innerHTML = date.toString();
|
||
|
};
|
||
|
|
||
|
function timestamp(str, ti) {
|
||
|
const date = new Date(ti*1000);
|
||
|
document.getElementById(str).setAttribute("data-bs-original-title", date.toString());
|
||
|
};
|