MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus Klartraum-Wiki
Morn (Diskussion | Beiträge) Die Seite wurde neu angelegt: „/** * Collapsible tables * * @version 2.0.1 (2013-03-26) * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js * @author [[User:R…“ |
Steeph (Diskussion | Beiträge) Abgewandelte Version von mw-collapsible eingefügt |
||
Zeile 98: | Zeile 98: | ||
$( createCollapseButtons ); | $( createCollapseButtons ); | ||
/** | |||
* Abgewandelte Version von mw-collapsible. | |||
* Für ausklappbare Bäume | |||
*/ | |||
mw.loader.implement("jquery.makeCollapsible", function ($, jQuery) { | |||
(function ($, mw) { | |||
function toggleElement($collapsible, action, $defaultToggle, options) { | |||
var $collapsibleContent, $containers, hookCallback; | |||
options = options || {}; | |||
if (!$collapsible.jquery) { | |||
return; | |||
} | |||
if (action !== 'expand' && action !== 'collapse') { | |||
return; | |||
} | |||
if ($defaultToggle === undefined) { | |||
$defaultToggle = null; | |||
} | |||
if ($defaultToggle !== null && !$defaultToggle.jquery) { | |||
return; | |||
} | |||
$collapsible.trigger(action === 'expand' ? 'beforeExpand.mw-collapsible' : 'beforeCollapse.mw-collapsible'); | |||
hookCallback = function () { | |||
$collapsible.trigger(action === 'expand' ? 'afterExpand.mw-collapsible' : 'afterCollapse.mw-collapsible'); | |||
}; | |||
if (!options.plainMode && $collapsible.is('table')) { | |||
if ($collapsible.find('> caption').length) { | |||
$containers = $collapsible.find('> * > tr'); | |||
} else { | |||
$containers = $collapsible.find('> tbody > tr'); | |||
} if ($defaultToggle) { | |||
$containers = $containers.not($defaultToggle.closest('tr')); | |||
} | |||
if (action === 'collapse') { | |||
if (options.instantHide) { | |||
$containers.hide(); | |||
hookCallback(); | |||
} else { | |||
$containers.stop(true, true).fadeOut().promise().done(hookCallback); | |||
} | |||
} else { | |||
$containers.stop(true, true).fadeIn().promise().done(hookCallback); | |||
} | |||
} else if (!options.plainMode && ($collapsible.is('ul') || $collapsible.is('ol'))) { | |||
$containers = $collapsible.find('> li'); | |||
if ($defaultToggle) { | |||
$containers = $containers.not($defaultToggle.parent()); | |||
} | |||
if (action === 'collapse') { | |||
if (options.instantHide) { | |||
$containers.hide(); | |||
hookCallback(); | |||
} else { | |||
$containers.stop(true, true).slideUp().promise().done(hookCallback); | |||
} | |||
} else { | |||
$containers.stop(true, true).slideDown().promise().done(hookCallback); | |||
} | |||
} else { | |||
$collapsibleContent = $collapsible.find('> .mw-collapsible-content'); | |||
if (!options.plainMode && $collapsibleContent.length) { | |||
if (action === 'collapse') { | |||
if (options.instantHide) { | |||
$collapsibleContent.hide(); | |||
hookCallback(); | |||
} else { | |||
$collapsibleContent.slideUp().promise().done(hookCallback); | |||
} | |||
} else { | |||
$collapsibleContent.slideDown().promise().done(hookCallback); | |||
} | |||
} else { | |||
if (action === 'collapse') { | |||
if (options.instantHide) { | |||
$collapsible.hide(); | |||
hookCallback(); | |||
} else { | |||
if ($collapsible.is('tr') || $collapsible.is('td') || $collapsible.is('th')) { | |||
$collapsible.fadeOut().promise().done(hookCallback); | |||
} else { | |||
$collapsible.slideUp().promise().done(hookCallback); | |||
} | |||
} | |||
} else { | |||
if ($collapsible.is('tr') || $collapsible.is('td') || $collapsible.is('th')) { | |||
$collapsible.fadeIn().promise().done(hookCallback); | |||
} else { | |||
$collapsible.slideDown().promise().done(hookCallback); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
function togglingHandler($toggle, $collapsible, e, options) { | |||
var wasCollapsed, $textContainer, collapseText, expandText; | |||
if (options === undefined) { | |||
options = {}; | |||
} | |||
if (e) { | |||
if (e.type === 'click' && options.linksPassthru && $.nodeName(e.target, 'a')) { | |||
return; | |||
} else if (e.type === 'keypress' && e.which !== 13 && e.which !== 32) { | |||
return; | |||
} else { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
} | |||
} | |||
if (options.wasCollapsed !== undefined) { | |||
wasCollapsed = options.wasCollapsed; | |||
} else { | |||
wasCollapsed = $collapsible.hasClass('mw-collapsed'); | |||
} | |||
$collapsible.toggleClass('mw-collapsed', !wasCollapsed); | |||
if (options.toggleClasses) { | |||
$toggle.toggleClass('mw-collapsible-toggle-collapsed', !wasCollapsed).toggleClass('mw-collapsible-toggle-expanded', wasCollapsed); | |||
} | |||
if (options.toggleText) { | |||
collapseText = options.toggleText.collapseText; | |||
expandText = options.toggleText.expandText; | |||
$textContainer = $toggle.find('> a'); | |||
if (!$textContainer.length) { | |||
$textContainer = $toggle; | |||
} | |||
$textContainer.text(wasCollapsed ? collapseText : expandText); | |||
} | |||
toggleElement($collapsible, wasCollapsed ? 'expand' : 'collapse', $toggle, options); | |||
} | |||
$.fn.makeCollapsible = function (options) { | |||
if (options === undefined) { | |||
options = {}; | |||
} | |||
return this.each(function () { | |||
var $collapsible, collapseText, expandText, $caption, $toggle, actionHandler, buildDefaultToggleLink, premadeToggleHandler, $toggleLink, $firstItem, | |||
collapsibleId, $customTogglers, firstval; | |||
$collapsible = $(this).addClass('mw-collapsible'); | |||
if ($collapsible.data('mw-made-collapsible')) { | |||
return; | |||
} else { | |||
$collapsible.data('mw-made-collapsible', true); | |||
} | |||
collapseText = options.collapseText || $collapsible.attr('data-collapsetext') || mw.msg('collapsible-collapse'); | |||
expandText = options.expandText || $collapsible.attr('data-expandtext') || mw.msg('collapsible-expand'); | |||
actionHandler = function (e, opts) { | |||
var defaultOpts = { | |||
toggleClasses: true, | |||
toggleText: { | |||
collapseText: collapseText, | |||
expandText: expandText | |||
} | |||
}; | |||
opts = $.extend(defaultOpts, options, opts); | |||
togglingHandler($(this), $collapsible, e, opts); | |||
}; | |||
buildDefaultToggleLink = function () { | |||
return $('<a href="#"></a>').text(collapseText).wrap('<span class="mw-collapsible-toggle"></span>').parent().prepend(' [').append('] ').on('click.mw-collapsible keypress.mw-collapsible', actionHandler); | |||
}; | |||
premadeToggleHandler = function (e, opts) { | |||
var defaultOpts = { | |||
toggleClasses: true, | |||
linksPassthru: true | |||
}; | |||
opts = $.extend(defaultOpts, options, opts); | |||
togglingHandler($(this), $collapsible, e, opts); | |||
}; | |||
if (options.$customTogglers) { | |||
$customTogglers = $(options.$customTogglers); | |||
} else { | |||
collapsibleId = $collapsible.attr('id') || ''; | |||
if (collapsibleId.indexOf('mw-customcollapsible-') === 0) { | |||
$customTogglers = $('.' + collapsibleId.replace('mw-customcollapsible', 'mw-customtoggle')); | |||
} | |||
} if ($customTogglers && $customTogglers.length) { | |||
actionHandler = function (e, opts) { | |||
var defaultOpts = {}; | |||
opts = $.extend(defaultOpts, options, opts); | |||
togglingHandler($(this), $collapsible, e, opts); | |||
}; | |||
$toggleLink = $customTogglers; | |||
$toggleLink.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); | |||
} else { | |||
if ($collapsible.is('table')) { | |||
$caption = $collapsible.find('> caption'); | |||
if ($caption.length) { | |||
$toggle = $caption.find('> .mw-collapsible-toggle'); | |||
if (!$toggle.length) { | |||
$toggleLink = buildDefaultToggleLink().appendTo($caption); | |||
} else { | |||
actionHandler = premadeToggleHandler; | |||
$toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); | |||
} | |||
} else { | |||
$firstItem = $collapsible.find( | |||
'tr:first th, tr:first td'); | |||
$toggle = $firstItem.find('> .mw-collapsible-toggle'); | |||
if (!$toggle.length) { | |||
$toggleLink = buildDefaultToggleLink().prependTo($firstItem.eq(-1)); | |||
} else { | |||
actionHandler = premadeToggleHandler; | |||
$toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); | |||
} | |||
} | |||
} else if ($collapsible.is('ul') || $collapsible.is('ol')) { | |||
$firstItem = $collapsible.find('li:first'); | |||
$toggle = $firstItem.find('> .mw-collapsible-toggle'); | |||
if (!$toggle.length) { | |||
firstval = $firstItem.attr('value'); | |||
if (firstval === undefined || !firstval || firstval === '-1' || firstval === -1) { | |||
$firstItem.attr('value', '1'); | |||
} | |||
$toggleLink = buildDefaultToggleLink(); | |||
$toggleLink.wrap('<li class="mw-collapsible-toggle-li"></li>').parent().prependTo($collapsible); | |||
} else { | |||
actionHandler = premadeToggleHandler; | |||
$toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); | |||
} | |||
} else { | |||
$toggle = $collapsible.find('> .mw-collapsible-toggle'); | |||
if (!$collapsible.find('> .mw-collapsible-content').length) { | |||
$collapsible.wrapInner( | |||
'<div class="mw-collapsible-content"></div>'); | |||
} | |||
if (!$toggle.length) { | |||
$toggleLink = buildDefaultToggleLink().prependTo($collapsible); | |||
} else { | |||
actionHandler = premadeToggleHandler; | |||
$toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); | |||
} | |||
} | |||
} | |||
$toggleLink.prop('tabIndex', 0); | |||
if (options.collapsed || $collapsible.hasClass('mw-collapsed')) { | |||
actionHandler.call($toggleLink.get(0), null, { | |||
instantHide: true, | |||
wasCollapsed: false | |||
}); | |||
} | |||
}); | |||
}; | |||
}(jQuery, mediaWiki)); | |||
}, { | |||
"css": [".mw-collapsible-toggle{float:left;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none} caption .mw-collapsible-toggle{float:none} li .mw-collapsible-toggle{float:none} .mw-collapsible-toggle-li{list-style:none}\n/* cache key: tobias_klartraumwiki-klartraumwiki_:resourceloader:filter:minify-css:7:6c1d24e90626cec584f0869483f983e7 */"] | |||
}, { | |||
"collapsible-collapse": "-", | |||
"collapsible-expand": "+" | |||
}); |
Version vom 6. Juni 2014, 05:53 Uhr
/** * Collapsible tables * * @version 2.0.1 (2013-03-26) * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js * @author [[User:R. Koot]] * @author [[User:Krinkle]] * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which * is supported in MediaWiki core. */ var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show'; function collapseTable( tableIndex ) { var Button = document.getElementById( 'collapseButton' + tableIndex ); var Table = document.getElementById( 'collapsibleTable' + tableIndex ); if ( !Table || !Button ) { return false; } var Rows = Table.rows; if ( Button.firstChild.data == collapseCaption ) { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = 'none'; } Button.firstChild.data = expandCaption; } else { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; } Button.firstChild.data = collapseCaption; } } function createClickHandler( tableIndex ) { return function ( e ) { e.preventDefault(); collapseTable( tableIndex ); } } function createCollapseButtons() { var tableIndex = 0; var NavigationBoxes = {}; var Tables = document.getElementsByTagName( 'table' ); for ( var i = 0; i < Tables.length; i++ ) { if ( $( Tables[i] ).hasClass( 'collapsible' ) ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0]; if ( !HeaderRow ) { continue; } var Header = HeaderRow.getElementsByTagName( 'th' )[0]; if ( !Header ) { continue; } NavigationBoxes[tableIndex] = Tables[i]; Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex ); var Button = document.createElement( 'span' ); var ButtonLink = document.createElement( 'a' ); var ButtonText = document.createTextNode( collapseCaption ); Button.style.styleFloat = 'right'; Button.style.cssFloat = 'right'; Button.style.fontWeight = 'normal'; Button.style.textAlign = 'right'; Button.style.width = '6em'; ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( '[' ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( ']' ) ); Header.insertBefore( Button, Header.childNodes[0] ); tableIndex++; } } for ( var i = 0; i < tableIndex; i++ ) { if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) { collapseTable( i ); } } } $( createCollapseButtons ); /** * Abgewandelte Version von mw-collapsible. * Für ausklappbare Bäume */ mw.loader.implement("jquery.makeCollapsible", function ($, jQuery) { (function ($, mw) { function toggleElement($collapsible, action, $defaultToggle, options) { var $collapsibleContent, $containers, hookCallback; options = options || {}; if (!$collapsible.jquery) { return; } if (action !== 'expand' && action !== 'collapse') { return; } if ($defaultToggle === undefined) { $defaultToggle = null; } if ($defaultToggle !== null && !$defaultToggle.jquery) { return; } $collapsible.trigger(action === 'expand' ? 'beforeExpand.mw-collapsible' : 'beforeCollapse.mw-collapsible'); hookCallback = function () { $collapsible.trigger(action === 'expand' ? 'afterExpand.mw-collapsible' : 'afterCollapse.mw-collapsible'); }; if (!options.plainMode && $collapsible.is('table')) { if ($collapsible.find('> caption').length) { $containers = $collapsible.find('> * > tr'); } else { $containers = $collapsible.find('> tbody > tr'); } if ($defaultToggle) { $containers = $containers.not($defaultToggle.closest('tr')); } if (action === 'collapse') { if (options.instantHide) { $containers.hide(); hookCallback(); } else { $containers.stop(true, true).fadeOut().promise().done(hookCallback); } } else { $containers.stop(true, true).fadeIn().promise().done(hookCallback); } } else if (!options.plainMode && ($collapsible.is('ul') || $collapsible.is('ol'))) { $containers = $collapsible.find('> li'); if ($defaultToggle) { $containers = $containers.not($defaultToggle.parent()); } if (action === 'collapse') { if (options.instantHide) { $containers.hide(); hookCallback(); } else { $containers.stop(true, true).slideUp().promise().done(hookCallback); } } else { $containers.stop(true, true).slideDown().promise().done(hookCallback); } } else { $collapsibleContent = $collapsible.find('> .mw-collapsible-content'); if (!options.plainMode && $collapsibleContent.length) { if (action === 'collapse') { if (options.instantHide) { $collapsibleContent.hide(); hookCallback(); } else { $collapsibleContent.slideUp().promise().done(hookCallback); } } else { $collapsibleContent.slideDown().promise().done(hookCallback); } } else { if (action === 'collapse') { if (options.instantHide) { $collapsible.hide(); hookCallback(); } else { if ($collapsible.is('tr') || $collapsible.is('td') || $collapsible.is('th')) { $collapsible.fadeOut().promise().done(hookCallback); } else { $collapsible.slideUp().promise().done(hookCallback); } } } else { if ($collapsible.is('tr') || $collapsible.is('td') || $collapsible.is('th')) { $collapsible.fadeIn().promise().done(hookCallback); } else { $collapsible.slideDown().promise().done(hookCallback); } } } } } function togglingHandler($toggle, $collapsible, e, options) { var wasCollapsed, $textContainer, collapseText, expandText; if (options === undefined) { options = {}; } if (e) { if (e.type === 'click' && options.linksPassthru && $.nodeName(e.target, 'a')) { return; } else if (e.type === 'keypress' && e.which !== 13 && e.which !== 32) { return; } else { e.preventDefault(); e.stopPropagation(); } } if (options.wasCollapsed !== undefined) { wasCollapsed = options.wasCollapsed; } else { wasCollapsed = $collapsible.hasClass('mw-collapsed'); } $collapsible.toggleClass('mw-collapsed', !wasCollapsed); if (options.toggleClasses) { $toggle.toggleClass('mw-collapsible-toggle-collapsed', !wasCollapsed).toggleClass('mw-collapsible-toggle-expanded', wasCollapsed); } if (options.toggleText) { collapseText = options.toggleText.collapseText; expandText = options.toggleText.expandText; $textContainer = $toggle.find('> a'); if (!$textContainer.length) { $textContainer = $toggle; } $textContainer.text(wasCollapsed ? collapseText : expandText); } toggleElement($collapsible, wasCollapsed ? 'expand' : 'collapse', $toggle, options); } $.fn.makeCollapsible = function (options) { if (options === undefined) { options = {}; } return this.each(function () { var $collapsible, collapseText, expandText, $caption, $toggle, actionHandler, buildDefaultToggleLink, premadeToggleHandler, $toggleLink, $firstItem, collapsibleId, $customTogglers, firstval; $collapsible = $(this).addClass('mw-collapsible'); if ($collapsible.data('mw-made-collapsible')) { return; } else { $collapsible.data('mw-made-collapsible', true); } collapseText = options.collapseText || $collapsible.attr('data-collapsetext') || mw.msg('collapsible-collapse'); expandText = options.expandText || $collapsible.attr('data-expandtext') || mw.msg('collapsible-expand'); actionHandler = function (e, opts) { var defaultOpts = { toggleClasses: true, toggleText: { collapseText: collapseText, expandText: expandText } }; opts = $.extend(defaultOpts, options, opts); togglingHandler($(this), $collapsible, e, opts); }; buildDefaultToggleLink = function () { return $('<a href="#"></a>').text(collapseText).wrap('<span class="mw-collapsible-toggle"></span>').parent().prepend(' [').append('] ').on('click.mw-collapsible keypress.mw-collapsible', actionHandler); }; premadeToggleHandler = function (e, opts) { var defaultOpts = { toggleClasses: true, linksPassthru: true }; opts = $.extend(defaultOpts, options, opts); togglingHandler($(this), $collapsible, e, opts); }; if (options.$customTogglers) { $customTogglers = $(options.$customTogglers); } else { collapsibleId = $collapsible.attr('id') || ''; if (collapsibleId.indexOf('mw-customcollapsible-') === 0) { $customTogglers = $('.' + collapsibleId.replace('mw-customcollapsible', 'mw-customtoggle')); } } if ($customTogglers && $customTogglers.length) { actionHandler = function (e, opts) { var defaultOpts = {}; opts = $.extend(defaultOpts, options, opts); togglingHandler($(this), $collapsible, e, opts); }; $toggleLink = $customTogglers; $toggleLink.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); } else { if ($collapsible.is('table')) { $caption = $collapsible.find('> caption'); if ($caption.length) { $toggle = $caption.find('> .mw-collapsible-toggle'); if (!$toggle.length) { $toggleLink = buildDefaultToggleLink().appendTo($caption); } else { actionHandler = premadeToggleHandler; $toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); } } else { $firstItem = $collapsible.find( 'tr:first th, tr:first td'); $toggle = $firstItem.find('> .mw-collapsible-toggle'); if (!$toggle.length) { $toggleLink = buildDefaultToggleLink().prependTo($firstItem.eq(-1)); } else { actionHandler = premadeToggleHandler; $toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); } } } else if ($collapsible.is('ul') || $collapsible.is('ol')) { $firstItem = $collapsible.find('li:first'); $toggle = $firstItem.find('> .mw-collapsible-toggle'); if (!$toggle.length) { firstval = $firstItem.attr('value'); if (firstval === undefined || !firstval || firstval === '-1' || firstval === -1) { $firstItem.attr('value', '1'); } $toggleLink = buildDefaultToggleLink(); $toggleLink.wrap('<li class="mw-collapsible-toggle-li"></li>').parent().prependTo($collapsible); } else { actionHandler = premadeToggleHandler; $toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); } } else { $toggle = $collapsible.find('> .mw-collapsible-toggle'); if (!$collapsible.find('> .mw-collapsible-content').length) { $collapsible.wrapInner( '<div class="mw-collapsible-content"></div>'); } if (!$toggle.length) { $toggleLink = buildDefaultToggleLink().prependTo($collapsible); } else { actionHandler = premadeToggleHandler; $toggleLink = $toggle.on('click.mw-collapsible keypress.mw-collapsible', actionHandler); } } } $toggleLink.prop('tabIndex', 0); if (options.collapsed || $collapsible.hasClass('mw-collapsed')) { actionHandler.call($toggleLink.get(0), null, { instantHide: true, wasCollapsed: false }); } }); }; }(jQuery, mediaWiki)); }, { "css": [".mw-collapsible-toggle{float:left;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none} caption .mw-collapsible-toggle{float:none} li .mw-collapsible-toggle{float:none} .mw-collapsible-toggle-li{list-style:none}\n/* cache key: tobias_klartraumwiki-klartraumwiki_:resourceloader:filter:minify-css:7:6c1d24e90626cec584f0869483f983e7 */"] }, { "collapsible-collapse": "-", "collapsible-expand": "+" });