Line 1: |
Line 1: |
− | /**
| |
− | * Scrolling text
| |
− | *
| |
− | * Original from touhouwiki
| |
− | */
| |
− | function AutoScroll(objNotice) {
| |
− | $(objNotice).find("ul:first").animate({
| |
− | marginTop:"-25px"
| |
− | },500,function(){
| |
− | $(this).css({marginTop: "0px"}).find("li:first").appendTo(this);
| |
− | });
| |
− | }
| |
− |
| |
− | $(document).ready(function() {
| |
− | setInterval('AutoScroll("#scrollDiv")',10000);
| |
− | //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 );
| |
− |
| |
− | /**
| |
− | Filterable Function
| |
− | */
| |
− | $(function() {
| |
− | $(".showExtra").click(function() {
| |
− | $(this).closest("table").find(".extraRow").fadeIn("slow");$(this).closest("tr").remove();
| |
− | });
| |
− | filterTable();
| |
− | });
| |
− |
| |
− | // FilterTable
| |
| function filterTable(){ | | function filterTable(){ |
| $("table.filterable").each(function(){ | | $("table.filterable").each(function(){ |
Line 84: |
Line 49: |
| cond=Number(cond)+chg; | | cond=Number(cond)+chg; |
| $(this).attr("condition", cond); | | $(this).attr("condition", cond); |
− | if (cond==0) $(this).show(); | + | if (cond===0) $(this).show(); |
| else $(this).hide(); | | else $(this).hide(); |
| } | | } |
Line 102: |
Line 67: |
| } | | } |
| | | |
− | /**
| |
− | * Dynamic Navigation Bars (experimental)
| |
− | *
| |
− | * Description: See [[Wikipedia:NavFrame]].
| |
− | * Maintainers: UNMAINTAINED
| |
− | */
| |
− |
| |
− | /* set up the words in your language */
| |
− | var NavigationBarHide = '[' + collapseCaption + ']';
| |
− | var NavigationBarShow = '[' + expandCaption + ']';
| |
− | var indexNavigationBar = 0;
| |
− |
| |
| /** | | /** |
| * Shows and hides content and picture (if available) of navigation bars | | * Shows and hides content and picture (if available) of navigation bars |
Line 130: |
Line 83: |
| /* if shown now */ | | /* if shown now */ |
| if ( NavToggle.firstChild.data === NavigationBarHide ) { | | if ( NavToggle.firstChild.data === NavigationBarHide ) { |
− | for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { | + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
| if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { | | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { |
| NavChild.style.display = 'none'; | | NavChild.style.display = 'none'; |
Line 139: |
Line 92: |
| /* if hidden now */ | | /* if hidden now */ |
| } else if ( NavToggle.firstChild.data === NavigationBarShow ) { | | } else if ( NavToggle.firstChild.data === NavigationBarShow ) { |
− | for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { | + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
| if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { | | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { |
| NavChild.style.display = 'block'; | | NavChild.style.display = 'block'; |
Line 174: |
Line 127: |
| * "collapsed" to the NavFrame itself, just like with collapsible tables. | | * "collapsed" to the NavFrame itself, just like with collapsible tables. |
| */ | | */ |
− | for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) { | + | for ( NavChild = NavFrame.firstChild; NavChild !== null && !isCollapsed; NavChild = NavChild.nextSibling ) { |
| if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { | | if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { |
| if ( NavChild.style.display === 'none' ) { | | if ( NavChild.style.display === 'none' ) { |
Line 182: |
Line 135: |
| } | | } |
| if ( isCollapsed ) { | | if ( isCollapsed ) { |
− | for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { | + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
| if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { | | if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { |
| NavChild.style.display = 'none'; | | NavChild.style.display = 'none'; |
Line 223: |
Line 176: |
| | | |
| this.check = function () { | | this.check = function () { |
− | if($table.size() == 0){ | + | if($table.size() === 0){ |
| return; | | return; |
| } | | } |
Line 248: |
Line 201: |
| this.check(); | | this.check(); |
| }; | | }; |
− | } | + | }; |
− |
| + | |
− | $(function () { | + | $(function() { |
− | //Set table
| + | |
| + | // 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(){ | | $('.fixtable').each(function(){ |
| var tableHeadFix = new TableHeadFix(); | | var tableHeadFix = new TableHeadFix(); |
| tableHeadFix.init(this); | | 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); |
| + | |
| + | // From gbf.wiki |
| + | // Add a dynamic fixed header to tables with: |
| + | // 1) table with "header-fixed" class |
| + | // 2) a table row with "header-row" class |
| + | // TODO: tablesorter, tabbertab, resize |
| + | // mw.loader.using('jquery.tablesorter', function() { |
| + | var tables = []; |
| + | |
| + | function initializeStickyHeader() { |
| + | var $tables = $('.header-fixed'); |
| + | |
| + | if ($tables.length == 0) return; |
| + | |
| + | $tables.each(function(n) { |
| + | if ($(this).hasClass('header-fixed-done')) return; |
| + | if ($(this).hasClass('mw-collapsed')) { |
| + | console.debug('header-fixed: collapsed: ' + n) |
| + | $(this).find('.mw-collapsible-text').click(function() { |
| + | console.debug('header-fixed: click: ' + n) |
| + | setTimeout(function() { initializeStickyHeader(); }, 1000); |
| + | }) |
| + | return; |
| + | } |
| + | /* |
| + | var tabberTabParent = $(this).parent(".tabbertab")[0]; |
| + | var originalStyleDisplay; |
| + | if (tabberTabParent) { |
| + | originalStyleDisplay = tabberTabParent.style.display; |
| + | tabberTabParent.style.visibility = "hidden"; |
| + | tabberTabParent.style.display = "block"; |
| + | } |
| + | */ |
| + | var $headerRow = $(this).find('.header-row'); |
| + | var $newHeaderContent = $('<tbody>'); |
| + | $newHeaderContent.append($headerRow.clone()); |
| + | |
| + | var $columnsOld = $headerRow.find('td:not([colspan]),th:not([colspan])'); |
| + | var $newHeaderColgroup = $('<colgroup>'); |
| + | for (var i = 0; i < $columnsOld.length; i++) { |
| + | $newHeaderColgroup.append($('<col>').css('width', $columnsOld[i].getBoundingClientRect().width)); |
| + | } |
| + | |
| + | $(this).before( |
| + | $('<table>') |
| + | .addClass('header-fixed-helper') |
| + | .addClass('wikitable') |
| + | .css('position', 'sticky') |
| + | .css('top', '0') |
| + | .css('z-index', '9') |
| + | .css('display', 'none') |
| + | .css('background-color', '#fff') |
| + | .css('margin-top', '0') |
| + | .css('margin-bottom', '0') |
| + | .css('table-layout', 'fixed') |
| + | .append($newHeaderColgroup) |
| + | .append($newHeaderContent) |
| + | ); |
| + | tables.push({ table: this, helper: this.previousSibling }); |
| + | $(this.previousSibling).css('width', $(this).width() + 1); |
| + | /* |
| + | if (tabberTabParent) { |
| + | tabberTabParent.style.visibility = ""; |
| + | tabberTabParent.style.display = originalStyleDisplay; |
| + | } |
| + | */ |
| + | $(this).addClass('header-fixed-done'); |
| + | console.debug('header-fixed: fixed: ' + n) |
| + | }); |
| + | } |
| + | |
| + | $(window).on('scroll', function() { |
| + | var scrollOffset = $(this).scrollTop(); |
| + | for (var i = 0; i < tables.length; i++) { |
| + | var tableOffset = $(tables[i].table).offset().top; |
| + | var tableHeight = $(tables[i].table).height(); |
| + | var helperHeight = $(tables[i].helper).height(); |
| + | if ((scrollOffset > tableOffset) && (scrollOffset < (tableOffset + tableHeight - helperHeight))) { |
| + | if ($(tables[i].helper).is(':hidden')) { |
| + | $(tables[i].helper).show(); |
| + | } |
| + | } else { |
| + | $(tables[i].helper).hide(); |
| + | } |
| + | } |
| + | }); |
| + | |
| + | /* |
| + | var ts = $.fn.tablesorter; |
| + | $.fn.tablesorter = function() { |
| + | ts.apply(this, arguments); |
| + | initializeStickyHeader(); |
| + | } |
| + | */ |
| + | setTimeout(function() { initializeStickyHeader(); }, 1000); |
| + | //}) |
| + | |
| + | // 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)); |
| + | } |
| + | a.append(img); |
| + | $(this).append(a); |
| + | } 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); |
| + | $(this).append(video); |
| + | } |
| + | }); |
| + | |
| }); | | }); |