MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus WIKI LAUER-FISCHER GmbH
Wechseln zu: Navigation, Suche
Zeile 1: Zeile 1:
 +
var cookieName = "sectionVisible"
 +
 
jQuery(document).ready(function () {
 
jQuery(document).ready(function () {
 
     // Register slideToggle() on each category.
 
     // Register slideToggle() on each category.
Zeile 34: Zeile 36:
 
     var expanded = makeOnClick.defaultExpanded
 
     var expanded = makeOnClick.defaultExpanded
  
     var cookie = getCookie("showSection" + n);
+
     var cookie = getCookie(cookieName + n.toString());
  
 
     if (cookie === null) {
 
     if (cookie === null) {
Zeile 83: Zeile 85:
 
         var expirationDate = now.toUTCString();
 
         var expirationDate = now.toUTCString();
  
         var cookie = "showSection" + k.toString() + "=" + (expanded ? "1" : "0") + "; Expires=" + expirationDate + "; path=/";
+
         var cookie = cookieName + k.toString() + "=" + (expanded ? "1" : "0") + "; Expires=" + expirationDate + "; path=/";
  
 
         document.cookie = cookie;
 
         document.cookie = cookie;
 
     }
 
     }
 
}
 
}

Version vom 12. April 2018, 14:13 Uhr

var cookieName = "sectionVisible"

jQuery(document).ready(function () {
    // Register slideToggle() on each category.
    jQuery("div.generated-sidebar.portlet").each(makeOnClick);
    makeOnClick.defaultExpanded = false;
    jQuery("#p-tb").each(makeOnClick);
});

// Registers the slideToggle() function on this and sets up the cookie
function makeOnClick(n) {
    "use strict";

    if (jQuery(this).children("h3").is(":hidden")) {
        return;
    }

    if (makeOnClick.defaultExpanded === undefined) {
        makeOnClick.defaultExpanded = true;
    }

    if (makeOnClick.n === undefined) {
        makeOnClick.n = 0;
    }

    if (makeOnClick.n > n) {
        n = makeOnClick.n + 1;
        makeOnClick.n++;
    }
    else {
        makeOnClick.n = n;
    }

    jQuery(this).attr({ "role": "button", "type": "button" });

    var expanded = makeOnClick.defaultExpanded

    var cookie = getCookie(cookieName + n.toString());

    if (cookie === null) {
        setStateCookie(n, expanded);
    }
    else {
        expanded = cookie === "1";
    }

    jQuery(this).children("h3").attr("aria-pressed", expanded ? "true" : "false");
    jQuery(this).children("h3").addClass(expanded ? "nav-expanded" : "nav-collapsed");

    if (expanded == false) {
        jQuery(this).children("div").hide();
    }

    jQuery(this).children("h3").click(function () {
        var newExpanded = jQuery(this).attr("aria-pressed") !== "true";
        setStateCookie(n, newExpanded);

        if (newExpanded) {
            jQuery(this).removeClass("nav-collapsed");
            jQuery(this).addClass("nav-expanded");
        }
        else {
            jQuery(this).removeClass("nav-expanded");
            jQuery(this).addClass("nav-collapsed");
        }

        jQuery(this).attr("aria-pressed", newExpanded ? "true" : "false");

        jQuery(this).parent().children("div.pBody:first-of-type").slideToggle('fast');
    })

    function getCookie(key) {
        "use strict";
        var cookieQuery = document.cookie.match('(?:^|;)\\s*' + key + '\\s*=\\s*([^;]+)');

        return cookieQuery === null ? null : cookieQuery.pop();
    }

    // Writes the  state of the k-th section into a cookie.
    function setStateCookie(k, expanded) {
        "use strict";
        var now = new Date();
        now.setFullYear(now.getFullYear() + 3);

        var expirationDate = now.toUTCString();

        var cookie = cookieName + k.toString() + "=" + (expanded ? "1" : "0") + "; Expires=" + expirationDate + "; path=/";

        document.cookie = cookie;
    }
}