MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus WIKI LAUER-FISCHER GmbH
Wechseln zu: Navigation, Suche
 
(7 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
var cookieName = "sectionVisible"
 +
 
jQuery(document).ready(function () {
 
jQuery(document).ready(function () {
 +
    "use strict"
 
     // Register slideToggle() on each category.
 
     // Register slideToggle() on each category.
 +
    var makeOnClick = generateMakeOnClick();
 +
 
     jQuery("div.generated-sidebar.portlet").each(makeOnClick);
 
     jQuery("div.generated-sidebar.portlet").each(makeOnClick);
 
     makeOnClick.defaultExpanded = false;
 
     makeOnClick.defaultExpanded = false;
Zeile 7: Zeile 12:
  
 
// Registers the slideToggle() function on this and sets up the cookie
 
// Registers the slideToggle() function on this and sets up the cookie
function makeOnClick(n) {
+
function generateMakeOnClick() {
 
     "use strict";
 
     "use strict";
   
 
    if (makeOnClick.defaultExpanded === undefined) {
 
        makeOnClick.defaultExpanded = true;
 
    }
 
  
     if (makeOnClick.n === undefined) {
+
     var n = 0;
         makeOnClick.n = 0;
+
    var makeOnClick = function m() {
    }
+
         if (jQuery(this).children("h3").is(":hidden")) {
 +
            return;
 +
        }
  
    if (makeOnClick.n > n) {
+
         var k = n
         n = makeOnClick.n + 1;
 
        makeOnClick.n++;
 
    }
 
    else {
 
        makeOnClick.n = n;
 
    }
 
  
    jQuery(this).attr({ "role": "button", "type": "button" });
+
        n++
  
    var expanded = makeOnClick.defaultExpanded
+
        jQuery(this).attr({ "role": "button", "type": "button" });
  
    var cookie = getCookie("showSection" + n);
+
        var expanded = m.defaultExpanded
  
    if (cookie === null) {
+
        var cookie = getCookie(cookieName + k.toString());
        setStateCookie(n, expanded);
 
    }
 
    else {
 
        expanded = cookie === "1";
 
    }
 
  
    jQuery(this).children("h3").attr("aria-pressed", expanded ? "true" : "false");
+
        if (cookie === null) {
    jQuery(this).children("h3").addClass(expanded ? "nav-expanded" : "nav-collapsed");
+
            setStateCookie(k, expanded);
 
+
        }
    if (expanded == false) {
+
        else {
        jQuery(this).children("div").hide();
+
            expanded = cookie === "1";
    }
+
        }
  
    jQuery(this).children("h3").click(function () {
+
        jQuery(this).children("h3").attr("aria-pressed", expanded ? "true" : "false");
         var newExpanded = jQuery(this).attr("aria-pressed") !== "true";
+
         jQuery(this).children("h3").addClass(expanded ? "nav-expanded" : "nav-collapsed");
        setStateCookie(n, newExpanded);
 
  
         if (newExpanded) {
+
         if (expanded == false) {
            jQuery(this).removeClass("nav-collapsed");
+
             jQuery(this).children("div").hide();
            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).children("h3").click(function () {
 +
            var newExpanded = jQuery(this).attr("aria-pressed") !== "true";
 +
            setStateCookie(k, newExpanded);
  
        jQuery(this).parent().children("div.pBody:first-of-type").slideToggle('fast');
+
            if (newExpanded) {
    })
+
                jQuery(this).removeClass("nav-collapsed");
 +
                jQuery(this).addClass("nav-expanded");
 +
            }
 +
            else {
 +
                jQuery(this).removeClass("nav-expanded");
 +
                jQuery(this).addClass("nav-collapsed");
 +
            }
  
    function getCookie(key) {
+
            jQuery(this).attr("aria-pressed", newExpanded ? "true" : "false");
        "use strict";
 
        var cookieQuery = document.cookie.match('(?:^|;)\\s*' + key + '\\s*=\\s*([^;]+)');
 
  
        return cookieQuery === null ? null : cookieQuery.pop();
+
            jQuery(this).parent().children("div.pBody:first-of-type").slideToggle('fast');
 +
        })
 
     }
 
     }
  
     // Writes the  state of the k-th section into a cookie.
+
     makeOnClick.defaultExpanded = true
    function setStateCookie(k, expanded) {
 
        "use strict";
 
        var now = new Date();
 
        now.setFullYear(now.getFullYear() + 3);
 
  
        var expirationDate = now.toUTCString();
+
    return makeOnClick
 +
}
 +
function getCookie(key) {
 +
    "use strict";
 +
    var cookieQuery = document.cookie.match('(?:^|;)\\s*' + key + '\\s*=\\s*([^;]+)');
  
        var cookie = "showSection" + k.toString() + "=" + (expanded ? "1" : "0") + "; Expires=" + expirationDate + "; path=/";
+
    return cookieQuery === null ? null : cookieQuery.pop();
 +
}
  
        document.cookie = cookie;
+
// 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;
 
}
 
}

Aktuelle Version vom 13. April 2018, 14:59 Uhr

var cookieName = "sectionVisible"

jQuery(document).ready(function () {
    "use strict"
    // Register slideToggle() on each category.
    var makeOnClick = generateMakeOnClick();

    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 generateMakeOnClick() {
    "use strict";

    var n = 0;
    var makeOnClick = function m() {
        if (jQuery(this).children("h3").is(":hidden")) {
            return;
        }

        var k = n

        n++

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

        var expanded = m.defaultExpanded

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

        if (cookie === null) {
            setStateCookie(k, 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(k, 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');
        })
    }

    makeOnClick.defaultExpanded = true

    return makeOnClick
}
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;
}