2020-03-02 17:12:43 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2016-05-13 16:13:31 +00:00
|
|
|
/** Load jQuery extensions **/
|
2020-03-25 11:47:00 +00:00
|
|
|
//Code via: https://stackoverflow.com/a/13106698
|
2016-05-13 16:13:31 +00:00
|
|
|
$.fn.highlight = function (fadeOut) {
|
|
|
|
fadeOut = typeof fadeOut !== 'undefined' ? fadeOut : 5000;
|
|
|
|
$(this).each(function () {
|
2020-03-02 09:33:56 +00:00
|
|
|
let el = $(this);
|
2016-05-13 16:13:31 +00:00
|
|
|
$("<div/>")
|
|
|
|
.width(el.outerWidth())
|
|
|
|
.height(el.outerHeight())
|
|
|
|
.css({
|
|
|
|
"position": "absolute",
|
|
|
|
"left": el.offset().left,
|
|
|
|
"top": el.offset().top,
|
|
|
|
"background-color": "#ffff99",
|
|
|
|
"opacity": ".7",
|
|
|
|
"z-index": "9999999",
|
|
|
|
"border-top-left-radius": parseInt(el.css("borderTopLeftRadius"), 10),
|
|
|
|
"border-top-right-radius": parseInt(el.css("borderTopRightRadius"), 10),
|
|
|
|
"border-bottom-left-radius": parseInt(el.css("borderBottomLeftRadius"), 10),
|
|
|
|
"border-bottom-right-radius": parseInt(el.css("borderBottomRightRadius"), 10)
|
|
|
|
}).appendTo('body').fadeOut(fadeOut).queue(function () { $(this).remove(); });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-05-12 14:40:33 +00:00
|
|
|
/** Setup jQuery.timeago **/
|
2016-05-13 16:13:31 +00:00
|
|
|
$.timeago.settings.cutoff = 365 * 24 * 60 * 60 * 1000; // Display original dates older than 1 year
|
2011-12-31 14:12:05 +00:00
|
|
|
$("time").timeago();
|
2011-08-17 03:14:30 +00:00
|
|
|
|
2020-02-04 01:59:08 +00:00
|
|
|
/** Setup sidebar toggle **/
|
2020-03-02 09:33:56 +00:00
|
|
|
let sidebar_hidden = [];
|
2012-03-12 18:04:46 +00:00
|
|
|
try {
|
2023-12-26 02:36:51 +00:00
|
|
|
sidebar_hidden = (shm_cookie_get("ui-sidebar-hidden") || "").split("|");
|
2020-03-02 09:33:56 +00:00
|
|
|
for (let i=0; i<sidebar_hidden.length; i++) {
|
|
|
|
if(sidebar_hidden[i].length > 0) {
|
2012-03-12 18:04:46 +00:00
|
|
|
$(sidebar_hidden[i]+" .blockbody").hide();
|
|
|
|
}
|
2014-04-24 03:31:20 +00:00
|
|
|
}
|
2012-03-12 18:04:46 +00:00
|
|
|
}
|
2020-03-02 09:33:56 +00:00
|
|
|
catch(err) {}
|
2012-03-02 23:57:27 +00:00
|
|
|
$(".shm-toggler").each(function(idx, elm) {
|
2020-03-02 09:33:56 +00:00
|
|
|
let tid = $(elm).data("toggle-sel");
|
|
|
|
let tob = $(tid+" .blockbody");
|
2012-03-02 23:57:27 +00:00
|
|
|
$(elm).click(function(e) {
|
|
|
|
tob.slideToggle("slow");
|
2014-04-24 03:31:20 +00:00
|
|
|
if(sidebar_hidden.indexOf(tid) === -1) {
|
2012-03-02 23:57:27 +00:00
|
|
|
sidebar_hidden.push(tid);
|
|
|
|
}
|
|
|
|
else {
|
2020-03-02 09:33:56 +00:00
|
|
|
for (let i=0; i<sidebar_hidden.length; i++) {
|
2020-02-04 01:59:08 +00:00
|
|
|
if (sidebar_hidden[i] === tid) {
|
2012-03-02 23:57:27 +00:00
|
|
|
sidebar_hidden.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-26 02:36:51 +00:00
|
|
|
shm_cookie_set("ui-sidebar-hidden", sidebar_hidden.join("|"));
|
2014-04-24 03:31:20 +00:00
|
|
|
});
|
2012-03-02 23:57:27 +00:00
|
|
|
});
|
|
|
|
|
2020-02-04 01:59:08 +00:00
|
|
|
/** setup unlocker buttons **/
|
2012-03-10 18:50:10 +00:00
|
|
|
$(".shm-unlocker").each(function(idx, elm) {
|
2020-03-02 09:33:56 +00:00
|
|
|
let tid = $(elm).data("unlock-sel");
|
|
|
|
let tob = $(tid);
|
2012-03-10 18:50:10 +00:00
|
|
|
$(elm).click(function(e) {
|
|
|
|
$(elm).attr("disabled", true);
|
|
|
|
tob.attr("disabled", false);
|
|
|
|
});
|
|
|
|
});
|
2020-02-04 01:59:08 +00:00
|
|
|
|
2023-01-30 21:35:12 +00:00
|
|
|
/** setup copyable things */
|
|
|
|
$(".shm-clicktocopy").each(function(idx, elm) {
|
|
|
|
$(elm).click(function(e) {
|
|
|
|
navigator.clipboard.writeText($(elm).text());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-04 01:59:08 +00:00
|
|
|
/** setup arrow key bindings **/
|
2020-03-02 17:18:53 +00:00
|
|
|
document.addEventListener("keyup", function(e) {
|
2020-03-02 12:16:47 +00:00
|
|
|
if ($(e.target).is('input,textarea')) { return; }
|
2020-02-04 01:59:08 +00:00
|
|
|
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) { return; }
|
2020-03-02 09:19:45 +00:00
|
|
|
if (e.keyCode === 37 && $("[rel='previous']").length) {
|
2020-02-04 02:00:26 +00:00
|
|
|
window.location.href = $("[rel='previous']").attr("href");
|
2020-02-04 01:59:08 +00:00
|
|
|
}
|
2020-03-02 09:19:45 +00:00
|
|
|
else if (e.keyCode === 39 && $("[rel='next']").length) {
|
2020-02-04 01:59:08 +00:00
|
|
|
window.location.href = $("[rel='next']").attr("href");
|
|
|
|
}
|
|
|
|
});
|
2012-02-07 11:33:42 +00:00
|
|
|
});
|