מדיה ויקי:Gadget-foldPortalMenus.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
(.)
מ (30 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-foldPortalMenus.js יובאו)
 
(28 גרסאות ביניים של 3 משתמשים אינן מוצגות)
שורה 1: שורה 1:
// Mediawiki:Gadget-foldPortalMenus.js
// allow folding of side-menus to emulate a feature which was removed from mediawiki.
$( function() {
$( function() {
"use strict";
"use strict";
 
function doit() {
var storageKey = 'sidemenuFolded',
var storageKey = 'portalFolded',
storage = $.jStorage.storageAvailable(),
skin = mw.config.get( 'skin' ),
portalSelector,
bodySelector,
foldedClass = 'foldmenu-folded',
expandedClass = 'foldmenu-expanded',
heights = {},
heights = {},
toggleElement = function( elem ) {
toggleElement = function( elem ) {
var id = elem.closest( 'div.portal' ).attr( 'id' ),
var id = elem.closest( portalSelector ).attr( 'id' ),
hide = ! elem.hasClass( 'foldmenu-folded' );
hide = ! elem.hasClass( foldedClass );
elem.toggleClass( 'foldmenu-expanded', !hide )
elem.toggleClass( expandedClass, !hide )
.toggleClass('foldmenu-folded', hide )
.toggleClass(foldedClass, hide )
.siblings( 'div.body' ).animate( { maxHeight: hide ? 0 : heights[id] } );
.siblings().stop( true ).animate( { maxHeight: hide ? 0 : heights[id] } );
updateState();
mw.storage.set( storageKey + id, JSON.stringify( hide ) );
},
preparePortalBody = function( index, elem ) {
var $elem = $( elem ),
id = $elem.closest( portalSelector ).attr( 'id' ),
height = $elem.height();
$elem.css( 'max-height', $elem.height() );
heights[id] = height;
},
prepareHeader = function( selector ) {
$( selector )
.addClass( expandedClass )
.prepend( $('<span>', { 'class': 'plus' } ).text( '+' ) )
.prepend( $('<span>', { 'class': 'minus' } ).text( '-' ) )
.click( function() { toggleElement( $(this) ) } );
},
},
updateState = function() {
recalcHeights = function() {
if (! storage)
$( portalSelector + ' ' + bodySelector ).each( function() {
return;
var $div = $( this ),
var folded = [];
id = $div.closest( 'div.portal' ).attr( 'id' ),
$( 'div.portal h3.foldmenu-folded' ).each( function( id, item ) {
clone = $div.clone()
folded.push( $( item ).closest( 'div.portal' ).attr( 'id' ) );
.css( { maxHeight: 50000, left: -5000, display: 'block' } )
.appendTo( 'body' ),
height = heights[id] = Math.max( (heights[id] || 0), clone.height() );
$div.css( { maxHeight: height } );
clone.remove();
});
},
restoreState = function() {
$( portalSelector ).each( function( index, item ) {
var $item = $( item ),
id = $item.attr( 'id' ),
$h3 = $( 'h3:first', item ),
toFold;
try {
toFold = mw.storage.get( storageKey + id );
if ( toFold ) toFold = JSON.parse( toFold );
} catch(e) {
toFold = false;
}
if ( toFold != $h3.hasClass( foldedClass ) )
toggleElement( $( 'h3:first', item ) );
});
});
$.jStorage.set( storageKey, folded );
};
};
 
$( 'div.portal h3#p-navigation-label' ).toggle( true );
switch( skin ) {
$( 'div.portal div.body' ).each( function() {
case 'vector-2022':
var $this = $( this ),
case 'vector':
id = $this.closest( 'div.portal' ).attr( 'id' ),
portalSelector = 'nav.portal';
height = $this.height();
bodySelector = 'div.vector-menu-content';
$this.css( 'max-height', $this.height() );
break;
heights[id] = height;
case 'monobook':
portalSelector = 'div.portlet';
bodySelector = 'div.pBody';
break;
default:
return;
}
$( portalSelector + ' h3#p-navigation-label' ).toggle( true );
$( portalSelector + ' ' + bodySelector ).each( preparePortalBody );
prepareHeader( portalSelector + ' h3' );
restoreState();
$( document ).on( 'new-portlet-link', function( event, portalId ) {
recalcHeights();
if ( ! portalId )
return;
var ps = '#' + portalId;
preparePortalBody( 0, ps );
prepareHeader( ps + ' h3' );
restoreState();
});
});
$( 'div.portal h3' )
} // doit
.addClass( 'foldmenu-expanded' )
setTimeout(doit, 777);
.prepend( $('<span>', { 'class': 'plus' } ).text( '+' ) )
.prepend( $('<span>', { 'class': 'minus' } ).text( '-' ) )
.click( function() { toggleElement( $(this) ) } );
if (storage)
$( $.jStorage.get( storageKey ) || [] ).each(function( index, item ) {
toggleElement( $( 'div.portal#' + item ).find( 'h3:first' ) );
});
});
});

גרסה אחרונה מ־12:19, 5 בדצמבר 2022

// Mediawiki:Gadget-foldPortalMenus.js
// allow folding of side-menus to emulate a feature which was removed from mediawiki.
$( function() {
	"use strict";
function doit() {
	var storageKey = 'portalFolded',
		skin = mw.config.get( 'skin' ),
		portalSelector,
		bodySelector,
		foldedClass = 'foldmenu-folded',
		expandedClass = 'foldmenu-expanded',
		heights = {},
		toggleElement = function( elem ) {
			var id = elem.closest( portalSelector ).attr( 'id' ),
				hide = ! elem.hasClass( foldedClass );
			elem.toggleClass( expandedClass, !hide )
				.toggleClass(foldedClass, hide )
				.siblings().stop( true ).animate( { maxHeight: hide ? 0 : heights[id] } );
			mw.storage.set( storageKey + id, JSON.stringify( hide ) );
		},
		preparePortalBody = function( index, elem ) {
			var $elem = $( elem ),
				id = $elem.closest( portalSelector ).attr( 'id' ),
				height = $elem.height();
			$elem.css( 'max-height', $elem.height() );
			heights[id] = height;
		},
		prepareHeader = function( selector ) {
			$( selector )
				.addClass( expandedClass )
				.prepend( $('<span>', { 'class': 'plus' } ).text( '+' ) )
				.prepend( $('<span>', { 'class': 'minus' } ).text( '-' ) )
				.click( function() { toggleElement( $(this) ) } );
		},
		recalcHeights = function() {
			$( portalSelector + ' ' + bodySelector ).each( function() {
				var $div = $( this ),
					id = $div.closest( 'div.portal' ).attr( 'id' ),
					clone = $div.clone()
						.css( { maxHeight: 50000, left: -5000, display: 'block' } )
						.appendTo( 'body' ),
					height = heights[id] = Math.max( (heights[id] || 0), clone.height() );
				$div.css( { maxHeight: height } );
				clone.remove();
			});
		},
		restoreState = function() {
			$( portalSelector ).each( function( index, item ) {
				var $item = $( item ),
					id = $item.attr( 'id' ),
					$h3 = $( 'h3:first', item ),
					toFold;
				try {
					toFold = mw.storage.get( storageKey + id );
					if ( toFold ) toFold = JSON.parse( toFold );
				} catch(e) {
					toFold = false;
				}
				if ( toFold != $h3.hasClass( foldedClass ) )
					toggleElement( $( 'h3:first', item ) );
			});
		};

	switch( skin ) {
		case 'vector-2022':
		case 'vector':
			portalSelector = 'nav.portal';
			bodySelector = 'div.vector-menu-content';
			break;
		case 'monobook':
			portalSelector = 'div.portlet';
			bodySelector = 'div.pBody';
			break;
		default:
			return;
	}
	
	$( portalSelector + ' h3#p-navigation-label' ).toggle( true );
	$( portalSelector + ' ' + bodySelector ).each( preparePortalBody );
	prepareHeader( portalSelector + ' h3' );
	restoreState();
	
	$( document ).on( 'new-portlet-link', function( event, portalId ) {
		recalcHeights();
		if ( ! portalId )
			return;
		var ps = '#' + portalId;
		preparePortalBody( 0, ps );
		prepareHeader( ps + ' h3' );
		restoreState();	
	});
} // doit
setTimeout(doit, 777);
});