MediaWiki:Fusion/scripts/Sidebar.js: Unterschied zwischen den Versionen
imported>Shisma (+sidebar) |
imported>Shisma (cookie plugin eingefügt) |
||
Zeile 46: | Zeile 46: | ||
}); | }); | ||
})(jQuery); | })(jQuery); | ||
+ | |||
+ | |||
+ | /** | ||
+ | * jQuery Cookie plugin | ||
+ | * | ||
+ | * Copyright (c) 2010 Klaus Hartl (stilbuero.de) | ||
+ | * Dual licensed under the MIT and GPL licenses: | ||
+ | * http://www.opensource.org/licenses/mit-license.php | ||
+ | * http://www.gnu.org/licenses/gpl.html | ||
+ | * | ||
+ | */ | ||
+ | jQuery.cookie = function (key, value, options) { | ||
+ | |||
+ | // key and at least value given, set cookie... | ||
+ | if (arguments.length > 1 && String(value) !== "[object Object]") { | ||
+ | options = jQuery.extend({}, options); | ||
+ | |||
+ | if (value === null || value === undefined) { | ||
+ | options.expires = -1; | ||
+ | } | ||
+ | |||
+ | if (typeof options.expires === 'number') { | ||
+ | var days = options.expires, t = options.expires = new Date(); | ||
+ | t.setDate(t.getDate() + days); | ||
+ | } | ||
+ | |||
+ | value = String(value); | ||
+ | |||
+ | return (document.cookie = [ | ||
+ | encodeURIComponent(key), '=', | ||
+ | options.raw ? value : cookie_encode(value), | ||
+ | options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE | ||
+ | options.path ? '; path=' + options.path : '', | ||
+ | options.domain ? '; domain=' + options.domain : '', | ||
+ | options.secure ? '; secure' : '' | ||
+ | ].join('')); | ||
+ | } | ||
+ | |||
+ | // key and possibly options given, get cookie... | ||
+ | options = value || {}; | ||
+ | var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent; | ||
+ | return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null; | ||
+ | }; | ||
+ | |||
+ | function cookie_encode(string){ | ||
+ | //full uri decode not only to encode ",; =" but to save uicode charaters | ||
+ | var decoded = encodeURIComponent(string); | ||
+ | //encod back common and allowed charaters {}:"#[] to save space and make the cookies more human readable | ||
+ | var ns = decoded.replace(/(%7B|%7D|%3A|%22|%23|%5B|%5D)/g,function(charater){return decodeURIComponent(charater);}); | ||
+ | return ns; | ||
+ | } |
Version vom 27. August 2012, 20:10 Uhr
(function ($) {
$(function() {
$('.sidebar-division').each(function() {
var divisionHeader = $(this).children('.division-header');
var expandabilityIndicator = '<span class="expandability-indicator">…</span>';
var divisionLabel = divisionHeader.html();
var cookieName = divisionLabel.toLowerCase().replace(/(<([^>]+)>)/ig,"");
$(divisionHeader).append(expandabilityIndicator);
if($.cookie('sidebar-division-state-' + cookieName) == 'collapsed') {
$(this).addClass('collapsed').children('.division-header').siblings().hide();
} else {
$(this).find('.expandability-indicator').hide();
}
});
$('.division-header').css({cursor:'pointer'}).click(function() {
var wrapper = $(this).parent();
if(wrapper.hasClass('collapsed')) {
var divisionLabel = $(this).children('strong').html();
var cookieName = divisionLabel.toLowerCase().replace(/(<([^>]+)>)/ig,"");
$(this).siblings().slideDown('slow');
$(this).find('.expandability-indicator').fadeOut();
wrapper.removeClass('collapsed');
$.cookie('sidebar-division-state-' + cookieName, 'expended');
} else {
var divisionLabel = $(this).children('strong').html();
var cookieName = divisionLabel.toLowerCase().replace(/(<([^>]+)>)/ig,"")
$(this).siblings().slideUp('slow');
$(this).find('.expandability-indicator').fadeIn();
wrapper.addClass('collapsed');
$.cookie('sidebar-division-state-' + cookieName, 'collapsed');
}
});
});
})(jQuery);
/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {
// key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);
if (value === null || value === undefined) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : cookie_encode(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
function cookie_encode(string){
//full uri decode not only to encode ",; =" but to save uicode charaters
var decoded = encodeURIComponent(string);
//encod back common and allowed charaters {}:"#[] to save space and make the cookies more human readable
var ns = decoded.replace(/(%7B|%7D|%3A|%22|%23|%5B|%5D)/g,function(charater){return decodeURIComponent(charater);});
return ns;
}