Line 1: |
Line 1: |
− | /** | + | function filterTable(){ |
− | * Scrolling text
| + | $("table.filterable").each(function(){ |
− | *
| + | var i=0; |
− | * Copied from zh.kcwiki.moe
| + | var cols; |
− | */
| + | $(this).find("tr:first-child th, tr:first-child td").each(function(){ |
| + | if (!$(this).hasClass("unfilterable")){ |
| + | cols=[]; |
| + | $(this).closest("table").find("tr td:nth-child("+(i+1)+")").each(function(){ |
| + | cols.push($(this).text()); |
| + | }); |
| + | cols = arrayUnique(cols); |
| + | l=0; |
| + | for (j=0; j<cols.length; j++){ |
| + | t=charLength(cols[j]); |
| + | if (l<t) l=t; |
| + | } |
| + | $(this).css("position","relative"); |
| + | $(this).html('<a href="javascript:void(0)" class="showFilterMenu">'+$(this).html()+'▼</a>'); |
| + | $(this).append($('<div class="filterMenu hidden" style="position: absolute; top: '+$(this).height()+35+'px; left: 0; width: '+(50+l*7)+'px; text-align: left; padding: 5px; border: 1px #333333 solid; -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px; background: inherit; z-index: 1"></div>')); |
| + | for (j=0; j<cols.length; j++){ |
| + | $(this).find(".filterMenu").append('<div><input type="checkbox" value="'+cols[j]+'" col="'+(i+1)+'" class="filterOption" checked>'+cols[j]+'</div>'); |
| + | } |
| + | } |
| + | i++; |
| + | }); |
| + | $(this).find("tr:nth-child(n+1)").attr("condition", 0); |
| + | }); |
| + | $(".showFilterMenu").click(function(){ |
| + | if ($(this).parent().find(".filterMenu:visible").length){ |
| + | $(".filterMenu").slideUp(150); |
| + | }else{ |
| + | $(".filterMenu").slideUp(150); |
| + | $(this).parent().find(".filterMenu").slideDown(150); |
| + | } |
| + | }); |
| + | $(document).mouseup(function(e){ |
| + | var container = $(".filterMenu"); |
| + | if (!container.is(e.target) && container.has(e.target).length === 0){ |
| + | container.slideUp(150); |
| + | } |
| + | }); |
| + | $(".filterOption").click(function(){ |
| + | col=$(this).attr("col"); |
| + | val=$(this).val(); |
| + | if ($(this).is(":checked")) chg=1; else chg=-1; |
| + | $(this).closest("table").find("tr:nth-child(n+1)").each(function(){ |
| + | if ($(this).find("td:nth-child("+col+")").text()==val){ |
| + | var cond=$(this).attr("condition"); |
| + | cond=Number(cond)+chg; |
| + | $(this).attr("condition", cond); |
| + | if (cond===0) $(this).show(); |
| + | else $(this).hide(); |
| + | } |
| + | }); |
| + | }); |
| + | } |
| + | |
| + | function arrayUnique(a) { |
| + | return a.reduce(function(p, c) { |
| + | if (p.indexOf(c) < 0) p.push(c); |
| + | return p; |
| + | }, []); |
| + | } |
| | | |
− | function AutoScroll(objNotice) { | + | function charLength(s){ |
− | $(objNotice).find("ul:first").animate({
| + | return s.length+(encodeURI(s).split(/%..|./).length-1-s.length)/2; |
− | marginTop:"-25px"
| |
− | },500,function(){
| |
− | $(this).css({marginTop: "0px"}).find("li:first").appendTo(this);
| |
− | });
| |
| } | | } |
− |
| |
− | $(document).ready(function() {
| |
− | setInterval('AutoScroll("#scrollDiv")',5000);
| |
− | //image loading effect
| |
− | $('img').on('load', function(e){
| |
− | var target = $(this);
| |
− | target.css('opacity', 0).animate({opacity: 1}, 1000);
| |
− | });
| |
− | });
| |
| | | |
− |
| |
− | mw.hook( 'wikipage.content' ).add( createCollapseButtons );
| |
− |
| |
| /** | | /** |
− | * Dynamic Navigation Bars. See [[Wikipedia:NavFrame]] | + | * Shows and hides content and picture (if available) of navigation bars |
− | * | + | * Parameters: |
− | * Based on script from en.wikipedia.org, 2008-09-15. | + | * indexNavigationBar: the index of navigation bar to be toggled |
− | * | + | **/ |
− | * @source www.mediawiki.org/wiki/MediaWiki:Gadget-NavFrame.js
| + | window.toggleNavigationBar = function ( indexNavigationBar, event ) { |
− | * @maintainer Helder.wiki, 2012–2013
| + | var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar ); |
− | * @maintainer Krinkle, 2013
| + | var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar ); |
− | */
| + | var NavChild; |
− | ( function () {
| |
− |
| |
− | // Set up the words in your language
| |
− | var collapseCaption = 'hide'; | |
− | var expandCaption = 'show'; | |
| | | |
− | var navigationBarHide = '[' + collapseCaption + ']';
| + | if ( !NavFrame || !NavToggle ) { |
− | var navigationBarShow = '[' + expandCaption + ']';
| + | return false; |
| + | } |
| | | |
− | /** | + | /* if shown now */ |
− | * Shows and hides content and picture (if available) of navigation bars.
| + | if ( NavToggle.firstChild.data === NavigationBarHide ) { |
− | *
| + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
− | * @param {number} indexNavigationBar The index of navigation bar to be toggled
| + | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { |
− | * @param {jQuery.Event} e Event object
| + | NavChild.style.display = 'none'; |
− | */
| + | } |
− | function toggleNavigationBar( indexNavigationBar, e ) {
| + | } |
− | var navChild,
| + | NavToggle.firstChild.data = NavigationBarShow; |
− | navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ),
| |
− | navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
| |
| | | |
− | // Prevent browser from jumping to href "#"
| + | /* if hidden now */ |
− | e.preventDefault();
| + | } else if ( NavToggle.firstChild.data === NavigationBarShow ) { |
| + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
| + | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { |
| + | NavChild.style.display = 'block'; |
| + | } |
| + | } |
| + | NavToggle.firstChild.data = NavigationBarHide; |
| + | } |
| | | |
− | if ( !navFrame || !navToggle ) {
| + | event.preventDefault(); |
− | return false;
| + | }; |
− | }
| |
− |
| |
− | // If shown now
| |
− | if ( navToggle.firstChild.data == navigationBarHide ) {
| |
− | for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
| |
− | if ( hasClass( navChild, 'NavPic' ) ) {
| |
− | navChild.style.display = 'none';
| |
− | }
| |
− | if ( hasClass( navChild, 'NavContent' ) ) {
| |
− | navChild.style.display = 'none';
| |
− | }
| |
− | }
| |
− | navToggle.firstChild.data = navigationBarShow;
| |
− |
| |
− | // If hidden now
| |
− | } else if ( navToggle.firstChild.data == navigationBarShow ) {
| |
− | for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
| |
− | if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
| |
− | navChild.style.display = 'block';
| |
− | }
| |
− | }
| |
− | navToggle.firstChild.data = navigationBarHide;
| |
− | }
| |
− | }
| |
| | | |
− | /** | + | /* adds show/hide-button to navigation bars */ |
− | * Adds show/hide-button to navigation bars.
| |
− | *
| |
− | * @param {jQuery} $content
| |
− | */
| |
| function createNavigationBarToggleButton( $content ) { | | function createNavigationBarToggleButton( $content ) { |
− | var i, j, navFrame, navToggle, navToggleText, navChild,
| + | var NavChild; |
− | indexNavigationBar = 0,
| + | /* iterate over all < div >-elements */ |
− | navFrames = $content.find( 'div.NavFrame' ).toArray();
| + | var $divs = $content.find( 'div' ); |
| + | $divs.each( function ( i, NavFrame ) { |
| + | /* if found a navigation bar */ |
| + | if ( $( NavFrame ).hasClass( 'NavFrame' ) ) { |
| | | |
− | // Iterate over all (new) nav frames
| + | indexNavigationBar++; |
− | for ( i = 0; i < navFrames.length; i++ ) {
| + | var NavToggle = document.createElement( 'a' ); |
− | navFrame = navFrames[i];
| + | NavToggle.className = 'NavToggle'; |
− | // If found a navigation bar
| + | NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); |
− | indexNavigationBar++;
| + | NavToggle.setAttribute( 'href', '#' ); |
− | navToggle = document.createElement( 'a' );
| + | $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) ); |
− | navToggle.className = 'NavToggle';
| |
− | navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
| |
− | navToggle.setAttribute( 'href', '#' );
| |
− | $( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
| |
| | | |
− | navToggleText = document.createTextNode( navigationBarHide );
| + | var isCollapsed = $( NavFrame ).hasClass( 'collapsed' ); |
− | for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
| + | /** |
− | if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
| + | * Check if any children are already hidden. This loop is here for backwards compatibility: |
− | if ( navChild.style.display == 'none' ) {
| + | * the old way of making NavFrames start out collapsed was to manually add style="display:none" |
− | navToggleText = document.createTextNode( navigationBarShow );
| + | * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make |
− | break;
| + | * the content visible without JavaScript support), the new recommended way is to add the class |
− | }
| + | * "collapsed" to the NavFrame itself, just like with collapsible tables. |
− | }
| + | */ |
− | }
| + | for ( NavChild = NavFrame.firstChild; NavChild !== null && !isCollapsed; NavChild = NavChild.nextSibling ) { |
| + | if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { |
| + | if ( NavChild.style.display === 'none' ) { |
| + | isCollapsed = true; |
| + | } |
| + | } |
| + | } |
| + | if ( isCollapsed ) { |
| + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
| + | if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { |
| + | NavChild.style.display = 'none'; |
| + | } |
| + | } |
| + | } |
| + | var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide ); |
| + | NavToggle.appendChild( NavToggleText ); |
| | | |
− | navToggle.appendChild( navToggleText );
| + | /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */ |
− | // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
| + | for( var j = 0; j < NavFrame.childNodes.length; j++ ) { |
− | for ( j = 0; j < navFrame.childNodes.length; j++ ) {
| + | if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) { |
− | if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
| + | NavToggle.style.color = NavFrame.childNodes[j].style.color; |
− | navFrame.childNodes[j].appendChild( navToggle );
| + | NavFrame.childNodes[j].appendChild( NavToggle ); |
− | }
| + | } |
− | }
| + | } |
− | navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
| + | NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); |
− | }
| + | } |
| + | } ); |
| } | | } |
| | | |
| mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); | | mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); |
| | | |
− | /** | + | // Fix Table Header |
− | * Collapsible tables
| + | var TableHeadFix = function () { |
− | *
| + | var obj, $table, $newtable, $win; |
− | * @version 2.0.2 (2014-03-14)
| + | obj = this; |
− | * @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.
| |
− | */
| |
− | /*global $, mw */
| |
− | var autoCollapse = 2;
| |
− | var collapseCaption = 'hide';
| |
− | var expandCaption = 'show';
| |
| | | |
− | function collapseTable( tableIndex ) { | + | this.clonehead = function () { |
− | var Button = document.getElementById( 'collapseButton' + tableIndex );
| + | $newtable = $table.clone(); |
− | var Table = document.getElementById( 'collapsibleTable' + tableIndex );
| + | $newtable.find('tr:gt(0)').remove(); |
| | | |
− | if ( !Table || !Button ) {
| + | $newtable.css('top', '0'); |
− | return false;
| + | $newtable.css('position', 'fixed'); |
− | }
| + | // Fixed by kk @ 2015-04-03 |
| + | $newtable.css('margin-top', '0'); |
| + | $newtable.hide(); |
| + | }; |
| | | |
− | var Rows = Table.rows;
| |
− | var i;
| |
| | | |
− | if ( Button.firstChild.data === collapseCaption ) {
| + | this.check = function () { |
− | for ( i = 1; i < Rows.length; i++ ) {
| + | if($table.size() === 0){ |
− | Rows[i].style.display = 'none';
| + | return; |
− | }
| + | } |
− | Button.firstChild.data = expandCaption;
| + | var scrollTop = $win.scrollTop(); |
− | } else {
| + | var start_offset = $table.offset(); |
− | for ( i = 1; i < Rows.length; i++ ) {
| + | if (scrollTop > start_offset.top && scrollTop <= (start_offset.top + $table.height())) { |
− | Rows[i].style.display = Rows[0].style.display;
| + | $newtable.show(); |
− | }
| + | } else { |
− | Button.firstChild.data = collapseCaption;
| + | $newtable.hide(); |
− | }
| + | } |
− | } | + | }; |
| | | |
− | function createClickHandler( tableIndex ) { | + | this.event = function () { |
− | return function ( e ) {
| + | $win.bind('scroll', obj.check); |
− | e.preventDefault();
| + | }; |
− | collapseTable( tableIndex );
| |
− | };
| |
− | }
| |
| | | |
− | function createCollapseButtons() { | + | this.init = function (obj) { |
− | var tableIndex = 0;
| + | $win = $(window); |
− | var NavigationBoxes = {};
| + | $table = $(obj); |
− | var Tables = document.getElementsByTagName( 'table' );
| + | this.clonehead(); |
− | var i;
| + | $table.after($newtable); |
| | | |
− | for ( i = 0; i < Tables.length; i++ ) { | + | this.event(); |
− | if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
| + | this.check(); |
− | /* 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; | + | $(function() { |
| + | |
| + | // Extension:SoundManager2Button |
| + | // TODO: initialize properly so this isn't needed |
| + | if (window.soundManager && window.soundManager.beginDelayedInit && !window.soundManager.enabled) { |
| + | console.debug('KLUDGE: calling window.soundManager.beginDelayedInit()'); |
| + | window.soundManager.beginDelayedInit(); |
| + | } |
| + | |
| + | // Table things |
| + | |
| + | $(".showExtra").click(function() { |
| + | $(this).closest("table").find(".extraRow").fadeIn("slow");$(this).closest("tr").remove(); |
| + | }); |
| + | |
| + | filterTable(); |
| + | |
| + | $('.fixtable').each(function(){ |
| + | var tableHeadFix = new TableHeadFix(); |
| + | tableHeadFix.init(this); |
| + | }); |
| + | |
| + | // Template:Map/ImageNode |
| + | |
| + | function supportTemplateMapImageNode() { |
| + | $('.map-image > span > a').off('click'); |
| + | $('.map-image > span > a').click(function (e) { |
| + | e.preventDefault(); |
| + | var $element = $($(this).attr('href')); |
| + | var $container = $element.parent(); |
| + | $container.scrollTop($container.scrollTop() - $container.offset().top + $element.offset().top); |
| + | }); |
| + | } |
| + | supportTemplateMapImageNode(); |
| + | mw.hook('wikipage.content').add(supportTemplateMapImageNode); |
| + | |
| + | // Basic video support using <img> and <video> elements |
| + | |
| + | $('.video').each(function () { |
| + | var src = $(this).data('src') || ''; |
| + | var parts = src.split('.'); |
| + | var ext = parts[parts.length - 1] || ''; |
| + | if (ext === 'webp') { |
| + | var a = $('<a>').addClass('image').attr('href', '/File:' + src); |
| + | var img = $('<img>'); |
| + | for (var attr in $(this).data()) { |
| + | img.attr(attr, (attr === 'src' ? 'https://en.kancollewiki.net/Special:Filepath/' : '') + $(this).data(attr)); |
| } | | } |
− | var Header = HeaderRow.getElementsByTagName( 'th' )[0]; | + | a.append(img); |
− | if ( !Header ) { | + | $(this).append(a); |
− | continue; | + | } else { |
| + | var video = $('<video>').attr('controls', ''); |
| + | var source = $('<source>').attr('type', 'video/' + ext); |
| + | for (var attr in $(this).data()) { |
| + | var el = attr === 'src' || attr === 'type' ? source : video; |
| + | el.attr(attr, (attr === 'src' ? 'https://en.kancollewiki.net/Special:Filepath/' : '') + $(this).data(attr)); |
| } | | } |
− |
| + | video.append(source); |
− | NavigationBoxes[tableIndex] = Tables[i];
| + | $(this).append(video); |
− | Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
| |
− |
| |
− | var Button = document.createElement( 'span' );
| |
− | var ButtonLink = document.createElement( 'a' );
| |
− | var ButtonText = document.createTextNode( collapseCaption ); | |
− | // TODO: Declare styles in [[MediaWiki:Gadget-collapsibleTables.css]]
| |
− | // Button.className = 'collapseButton';
| |
− | 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.setAttribute( 'href', '#' );
| |
− | $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) );
| |
− | ButtonLink.appendChild( ButtonText );
| |
− |
| |
− | Button.appendChild( document.createTextNode( '[' ) );
| |
− | Button.appendChild( ButtonLink );
| |
− | Button.appendChild( document.createTextNode( ']' ) );
| |
− |
| |
− | Header.insertBefore( Button, Header.firstChild );
| |
− | tableIndex++;
| |
| } | | } |
− | } | + | }); |
− |
| + | |
− | for ( i = 0; i < tableIndex; i++ ) {
| + | }); |
− | if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) ||
| + | |
− | ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) )
| + | (function(mw, $) { |
− | ) { | + | |
− | collapseTable( i ); | + | "use strict"; |
| + | |
| + | $(document).ready(function() { |
| + | |
| + | console.log('DetailToggle v1.0.0'); |
| + | |
| + | // custom hidable content and togglers supported by local storage |
| + | |
| + | if (typeof(Storage) === "undefined") { |
| + | return; |
| + | } |
| + | |
| + | var ToggleStorage = function(property, property_default) { |
| + | if (!localStorage[property]) { |
| + | localStorage[property] = property_default; |
| + | } |
| + | return { |
| + | toggle: function() { |
| + | localStorage[property] = localStorage[property] === "show" ? "hide" : "show"; |
| + | }, |
| + | on: function() { |
| + | return localStorage[property] === "show"; |
| + | } |
| + | }; |
| + | } |
| + | |
| + | function update(toggle_element, toggle) { |
| + | var property = toggle_element.data("target") || "default", |
| + | property_anti = toggle_element.data("anti-target"), |
| + | property_default = toggle_element.data("default") || "show", |
| + | property_classes = toggle_element.data("classes") && toggle_element.data("classes").split(' ').map(function (e) { return "toggle-class-" + e.trim() }).join(' '), |
| + | target = "toggle-target-" + property, |
| + | target_class = "." + target, |
| + | anti_target_class, |
| + | toggleStorage = ToggleStorage(target, property_default); |
| + | if (property_anti) { |
| + | anti_target_class = ".toggle-anti-target-" + property; |
| + | } |
| + | if (toggle) { |
| + | toggleStorage.toggle(); |
| + | } |
| + | var toggle_show_selector = '.toggle[data-target="' + property + '"] .toggle-show', |
| + | toggle_hide_selector = '.toggle[data-target="' + property + '"] .toggle-hide'; |
| + | if (toggleStorage.on()) { |
| + | $(toggle_show_selector).show(); |
| + | $(toggle_hide_selector).hide(); |
| + | if (property_classes) { |
| + | $(target_class).addClass(property_classes); |
| + | } else { |
| + | $(target_class).show(); |
| + | } |
| + | if (anti_target_class) { |
| + | $(anti_target_class).hide(); |
| + | } |
| + | } else { |
| + | $(toggle_show_selector).hide(); |
| + | $(toggle_hide_selector).show(); |
| + | if (property_classes) { |
| + | $(target_class).removeClass(property_classes); |
| + | } else { |
| + | $(target_class).hide(); |
| + | } |
| + | if (anti_target_class) { |
| + | $(anti_target_class).show(); |
| + | } |
| + | } |
| + | $(window).trigger("WideTablesScan"); |
| + | } |
| + | |
| + | //Local storage for multi toggles. |
| + | var MultiToggleStorage = function(property, property_default) { |
| + | if (!localStorage[property]) { |
| + | localStorage[property] = property_default; |
| + | } |
| + | return { |
| + | set: function(value) { |
| + | localStorage[property] = value; |
| + | }, |
| + | get: function(value) { |
| + | return localStorage[property]; |
| + | }, |
| + | on: function(value) { |
| + | return localStorage[property] === value; |
| + | } |
| + | }; |
| + | } |
| + | |
| + | //Update a multi toggle. If selected is passed it is set as the state of the multi toggle. Pass "none" to selected to deselect when the multi toggle is a filter. |
| + | function multi_update(multi_toggle_element, selected) { |
| + | var property = multi_toggle_element.data("target") || "default", |
| + | property_states = multi_toggle_element.data("states"), |
| + | property_default = multi_toggle_element.data("default"), |
| + | property_filter = multi_toggle_element.data("filter") || false, //Whether or not the multi toggle is a filter |
| + | property_base_colspan = multi_toggle_element.data("base-colspan"), |
| + | target = "multi-toggle-target-" + property; |
| + | //make sure the states are an array. |
| + | if (!property_states || !Array.isArray(property_states) || property_states.length < 1) { |
| + | multi_toggle_element.hide(); |
| + | return; |
| + | } else if (property_filter && property_states[0] !== "none") { |
| + | property_states.splice(0, 0, "none") |
| + | } |
| + | //need to set default here rather than in the declaration above to ensure the states are valid. |
| + | if (!property_default) { |
| + | property_default = property_states[0]; |
| + | } |
| + | var multiToggleStorage = MultiToggleStorage(target, property_default); |
| + | //set the new state of the multi toggle. |
| + | if (selected && property_states.indexOf(selected) >= 0) { |
| + | //If the selected filter was re-selected, that is a remove filter action. |
| + | if ((property_filter && multiToggleStorage.on(selected))) { |
| + | selected = "none"; |
| + | } |
| + | multiToggleStorage.set(selected); |
| + | } else { |
| + | //No selection, so we are initializing the multi toggle. |
| + | selected = multiToggleStorage.get() |
| + | } |
| + | //Update non-selected states |
| + | var hide_selectors = []; |
| + | var show_selectors = []; |
| + | property_states.forEach(function(state) { |
| + | var toggle_active_selector = '.multi-toggle[data-target="' + property + '"] .multi-toggle-button[data-state="' + state + '"] .multi-toggle-active', |
| + | toggle_inactive_selector = '.multi-toggle[data-target="' + property + '"] .multi-toggle-button[data-state="' + state + '"] .multi-toggle-inactive'; |
| + | if (selected !== state) { |
| + | $(toggle_active_selector).hide(); |
| + | $(toggle_inactive_selector).show(); |
| + | if (selected === "none") { |
| + | show_selectors.push("." + target + "-" + state); |
| + | } else { |
| + | hide_selectors.push("." + target + "-" + state); |
| + | } |
| + | } else { |
| + | $(toggle_active_selector).show(); |
| + | $(toggle_inactive_selector).hide(); |
| + | show_selectors.push("." + target + "-" + state); |
| + | } |
| + | }) |
| + | $(hide_selectors.join(',')).hide(); |
| + | //Update selected state last |
| + | $(show_selectors.join(',')).show(); |
| + | //Update colspan for custom rows. |
| + | if (property_filter) { |
| + | if (selected === "none") { |
| + | $(".custom-row." + target).attr("colSpan", property_base_colspan); |
| + | } else { |
| + | $(".custom-row." + target).attr("colSpan", property_base_colspan - property_states.length + 2); |
| + | } |
| + | } |
| + | //cleanup |
| + | $(window).trigger("WideTablesScan"); |
| + | } |
| + | |
| + | function updateContent() { |
| + | |
| + | $(".toggle").each(function() { |
| + | var toggle_element = $(this); |
| + | toggle_element.show(); |
| + | update(toggle_element); |
| + | if (toggle_element.hasClass('toggle-passive')) { |
| + | return; |
| + | } |
| + | toggle_element.off("click"); |
| + | toggle_element.click(function() { |
| + | update(toggle_element, true); |
| + | }); |
| + | }); |
| + | |
| + | //Activate multi toggles. |
| + | var targets = {}; |
| + | $(".multi-toggle").each(function() { |
| + | var multi_toggle_element = $(this), |
| + | multi_toggle_buttons = multi_toggle_element.children(".multi-toggle-button"), |
| + | target = multi_toggle_element.data("target") || "default"; |
| + | multi_toggle_element.show(); |
| + | if (!targets.hasOwnProperty(target)) |
| + | targets[target] = multi_toggle_element; |
| + | //Remove click event handlers from all multi toggle buttons |
| + | multi_toggle_buttons.off("click"); |
| + | //Add click event handler for all multi toggle buttons to trigger multi_update with select action. |
| + | multi_toggle_buttons.click(function() { |
| + | multi_update(multi_toggle_element, $(this).data("state")); |
| + | }); |
| + | }); |
| + | //call multi-update once for each target to allow multiple controls |
| + | //without horrible lag |
| + | Object.keys(targets).forEach(function (key) {multi_update(targets[key])}); |
| + | |
| + | // .mw-collapsible togglers |
| + | |
| + | $(".mw-collapsible-expand-all").each(function() { |
| + | var toggle_element = $(this); |
| + | toggle_element.off("click"); |
| + | toggle_element.click(function() { |
| + | $(".mw-collapsible-toggle.mw-collapsible-toggle-collapsed").click(); |
| + | }); |
| + | }); |
| + | |
| + | $(".mw-collapsible-collapse-all").each(function() { |
| + | var toggle_element = $(this); |
| + | toggle_element.off("click"); |
| + | toggle_element.click(function() { |
| + | $(".mw-collapsible-toggle:not(.mw-collapsible-toggle-collapsed)").click(); |
| + | }); |
| + | }); |
| + | |
| + | $(".mw-collapsible-toggle-all").each(function() { |
| + | var toggle_element = $(this); |
| + | toggle_element.off("click"); |
| + | toggle_element.click(function() { |
| + | $(".mw-collapsible-toggle").click(); |
| + | }); |
| + | }); |
| + | |
| + | } |
| + | |
| + | updateContent(); |
| + | mw.hook("wikipage.content").add(updateContent); |
| + | |
| + | function showPageSizeWarning() { |
| + | var newpp = $(".mw-parser-output").contents().filter(function () { return this.nodeType === 8 && this.data.match(/Post‐expand include size: (\d+)\/(\d+) bytes/); }); |
| + | if (!newpp.length) return; |
| + | var sizes = newpp[0].data.match(/Post‐expand include size: (\d+)\/(\d+) bytes/); |
| + | var usage = +sizes[1] / +sizes[2]; |
| + | if (usage >= 0.95) { |
| + | $('#content').prepend('<pre style="color: red; text-align: center;">Warning: post‐expand include size is over 95%</pre>'); |
| + | } |
| } | | } |
− | }
| |
− | }
| |
− |
| |
− | mw.hook( 'wikipage.content' ).add( createCollapseButtons );
| |
| | | |
− | importArticles({
| + | showPageSizeWarning(); |
− | type: "script",
| + | |
− | articles: [ | + | }); |
− | "User:Gensui_Hime/js/countdown.js"
| + | |
− | ]
| + | }(mediaWiki, jQuery)); |
− | }); | |