misc: display sidepage instantaneously (#60180)
This commit is contained in:
parent
c5c4772c5e
commit
3ed2236293
|
@ -1,6 +1,6 @@
|
|||
var gadjo_js = gadjo_js || {};
|
||||
(function () {
|
||||
if (gadjo_js.loaded) return
|
||||
if (gadjo_js.loaded) return;
|
||||
gadjo_js.loaded = true;
|
||||
var $ = jQuery;
|
||||
var popup_script_loaded = {};
|
||||
|
@ -381,51 +381,62 @@ var gadjo_js = gadjo_js || {};
|
|||
}
|
||||
}
|
||||
|
||||
var cookie_domain = window.location.hostname.split('.').slice(1).join('.');
|
||||
|
||||
function readCookie(name) { /* http://www.quirksmode.org/js/cookies.html */
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0;i < ca.length;i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function set_sidepage_status(sidepage_status) {
|
||||
storage.sidepage_status = sidepage_status;
|
||||
if (cookie_domain) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (10 * 86400 * 1000)); /* a long week */
|
||||
document.cookie = 'gadjo_sidepage_status=' + sidepage_status +
|
||||
'; expires=' + date.toGMTString() +
|
||||
(window.location.protocol == "https:" && "; Secure" || "") +
|
||||
'; sameSite=Strict' +
|
||||
'; domain=.' + cookie_domain +
|
||||
'; path=/';
|
||||
}
|
||||
}
|
||||
function get_sidepage_status() {
|
||||
if (window.location.protocol == 'file:') {
|
||||
/* don't open sidepage when loading from a file:// */
|
||||
return 'collapsed';
|
||||
}
|
||||
var sidepage_status = null;
|
||||
if (cookie_domain) {
|
||||
sidepage_status = readCookie('gadjo_sidepage_status');
|
||||
} else {
|
||||
sidepage_status = storage.sidepage_status;
|
||||
}
|
||||
if (!sidepage_status &&
|
||||
typeof(GADJO_DEFAULT_SIDEPAGE_STATUS) !== "undefined") {
|
||||
return GADJO_DEFAULT_SIDEPAGE_STATUS;
|
||||
}
|
||||
return sidepage_status;
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
if (document.body.dataset.gadjo === 'true' && document.getElementById('sidepage')) {
|
||||
document.body.setAttribute('data-has-sidepage', 'true');
|
||||
if (storage.gadjo_sidebar_menu) {
|
||||
$('#sidepage-menu').empty().append($(storage.gadjo_sidebar_menu));
|
||||
}
|
||||
if (window.innerWidth > 760 && get_sidepage_status() == 'expanded') {
|
||||
document.body.className += ' sidepage-expanded';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(function() {
|
||||
var cookie_domain = window.location.hostname.split('.').slice(1).join('.');
|
||||
|
||||
function readCookie(name) { /* http://www.quirksmode.org/js/cookies.html */
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0;i < ca.length;i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function set_sidepage_status(sidepage_status) {
|
||||
storage.sidepage_status = sidepage_status;
|
||||
if (cookie_domain) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (10 * 86400 * 1000)); /* a long week */
|
||||
document.cookie = 'gadjo_sidepage_status=' + sidepage_status +
|
||||
'; expires=' + date.toGMTString() +
|
||||
(window.location.protocol == "https:" && "; Secure" || "") +
|
||||
'; sameSite=Strict' +
|
||||
'; domain=.' + cookie_domain +
|
||||
'; path=/';
|
||||
}
|
||||
}
|
||||
function get_sidepage_status() {
|
||||
if (window.location.protocol == 'file:') {
|
||||
/* don't open sidepage when loading from a file:// */
|
||||
return 'collapsed';
|
||||
}
|
||||
var sidepage_status = null;
|
||||
if (cookie_domain) {
|
||||
sidepage_status = readCookie('gadjo_sidepage_status');
|
||||
} else {
|
||||
sidepage_status = storage.sidepage_status;
|
||||
}
|
||||
if (!sidepage_status &&
|
||||
typeof(GADJO_DEFAULT_SIDEPAGE_STATUS) !== "undefined") {
|
||||
return GADJO_DEFAULT_SIDEPAGE_STATUS;
|
||||
}
|
||||
return sidepage_status;
|
||||
}
|
||||
|
||||
$(document).on('click.gadjo', 'a[rel=popup], a[data-popup]', displayPopup);
|
||||
if ($('#sidepage').length) {
|
||||
var sidepage_button = $('#sidepage #applabel');
|
||||
|
@ -442,11 +453,6 @@ var gadjo_js = gadjo_js || {};
|
|||
$(window).trigger('gadjo:sidepage-toggled');
|
||||
}, 500);
|
||||
});
|
||||
if ($(window).width() > 760) {
|
||||
if (get_sidepage_status() == 'expanded') {
|
||||
$('body').toggleClass('sidepage-expanded');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$(function () { /* foldable elements with memory */
|
||||
|
@ -474,9 +480,6 @@ var gadjo_js = gadjo_js || {};
|
|||
});
|
||||
$(function () {
|
||||
if ($('body').data('gadjo')) {
|
||||
if ($('#sidepage').length == 1) {
|
||||
$('body').attr('data-has-sidepage', 'true');
|
||||
}
|
||||
/* add × to close notification messages */
|
||||
$('.messages > li').each(function(idx, elem) {
|
||||
var elem = $('<a aria-hidden="true" class="close">×</a>');
|
||||
|
@ -530,4 +533,7 @@ var gadjo_js = gadjo_js || {};
|
|||
return false;
|
||||
});
|
||||
});
|
||||
$(document).on('publik:menu-loaded', function() {
|
||||
storage.gadjo_sidebar_menu = document.getElementById('sidepage-menu').innerHTML;
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue