Difference between revisions of "Common.js"
From Sega Retro
Scarred Sun (talk | contribs) m |
Scarred Sun (talk | contribs) |
||
Line 55: | Line 55: | ||
poot.find('.poot-tabs-titletext').html(poot.attr('originalTitle') + ' — ' + pootTabsHere.getTab(poot, poot.attr('pootSelected')).html()); | poot.find('.poot-tabs-titletext').html(poot.attr('originalTitle') + ' — ' + pootTabsHere.getTab(poot, poot.attr('pootSelected')).html()); | ||
var bestHeight = Math.max(poot.children('.poot-tabs-content').height(), Math.max(poot.children('.poot-tabs').height(), babysize)).toString() + 'px'; | var bestHeight = Math.max(poot.children('.poot-tabs-content').height(), Math.max(poot.children('.poot-tabs').height(), babysize)).toString() + 'px'; | ||
− | poot.children('.poot-tabs-content').css(' | + | poot.children('.poot-tabs-content').css('height', bestHeight); |
if(poot.attr('vertical')) { | if(poot.attr('vertical')) { | ||
− | poot.children('.poot-tabs').css(' | + | poot.children('.poot-tabs').css('height', bestHeight); |
} | } | ||
}, | }, |
Revision as of 14:14, 6 September 2020
// Fix file history issues on mobile if (document.querySelector(".filehistory").textContent != "") { var headers = document.querySelectorAll(".filehistory th"); Array.prototype.slice.call(headers).forEach(function (header) { if (header.textContent != "") { header.setAttribute("data-label", header.textContent); } else { header.classList.add("show-for-medium-up"); } }); var trs = document.querySelectorAll(".filehistory tr"); var i; for (i = 0; i < trs.length; i++) { var tds = trs[i].querySelectorAll("td"); var e; for (e = 0; e < tds.length; e++) { var dataLabel = headers[e].textContent; if (dataLabel != "") { tds[e].setAttribute("data-label", dataLabel); } } } } // PootTabs - it poots tabs on pages. var pootTabsHere = { animationsEnabled: $.support.opacity, getTab:function(poot, index) { return $(poot.children('.poot-tabs').children('ul').children('li')[parseInt(index)]); }, changeTab:function(poot, index, duration, force) { if(index == parseInt(poot.attr('pootSelected')) && !force && duration) return; if(!pootTabsHere.animationsEnabled) { duration = 0; } poot.attr('pootSelected', index.toString()); var babies = poot.children('.poot-tabs-content').children(); babies.each(function() { $(this).fadeOut(duration, function(){ $(this).removeClass('poot-tabs-selected'); }); }); $(babies[index]).each(function() { $(this).fadeIn(duration, function(){ $(this).addClass('poot-tabs-selected'); }); }); var cowtabs = poot.children('.poot-tabs').children('ul').children('li'); cowtabs.removeClass('poot-tabs-selected'); $(cowtabs[index]).addClass('poot-tabs-selected'); pootTabsHere.updatePoot(poot, $(babies[index]).height()); }, updatePoot:function(poot, babysize) { poot.find('.poot-tabs-titletext').html(poot.attr('originalTitle') + ' — ' + pootTabsHere.getTab(poot, poot.attr('pootSelected')).html()); var bestHeight = Math.max(poot.children('.poot-tabs-content').height(), Math.max(poot.children('.poot-tabs').height(), babysize)).toString() + 'px'; poot.children('.poot-tabs-content').css('height', bestHeight); if(poot.attr('vertical')) { poot.children('.poot-tabs').css('height', bestHeight); } }, toggleCollapse:function(poot) { var pootLinkText = poot.children('.poot-tabs-showhide').text().split(';'); var duration = pootTabsHere.animationsEnabled ? parseInt(poot.attr('pootslideduration')) : 0; if(poot.attr('pootcollapse') != 'true') { poot.attr('pootcollapse', 'true'); poot.find('.poot-tabs-hidelink a').text(pootLinkText[0]); poot.children('.poot-tabs, .poot-tabs-content').slideUp(duration); } else { poot.attr('pootcollapse', ''); poot.find('.poot-tabs-hidelink a').text(pootLinkText[1]); poot.children('.poot-tabs, .poot-tabs-content').slideDown(duration); } }, delayHeight:function(poot, selected) { setTimeout(function() { poot.attr('pootselected', selected.toString()); pootTabsHere.changeTab(poot, selected, 0, true); if(poot.hasClass('poot-tabs-collapsed')) { pootTabsHere.toggleCollapse(poot); } }, 100); }, poot:function() { var dis = $(this); var ind = 0; dis.attr('originalTitle', dis.find('.poot-tabs-titletext').html()); var selected = /poot-tabs-selected-(\d+)/i.exec(dis.attr('class')); if(selected) { pootTabsHere.delayHeight(dis, parseInt(selected[1])-1); } else { pootTabsHere.delayHeight(dis, 0); } var duration = dis.hasClass('poot-tabs-noanimations') ? 0 : 200; dis.attr('pootslideduration', dis.hasClass('poot-tabs-noanimations') ? '0' : '75'); dis.children('.poot-tabs').children('ul').children('li').each(function(){ var thisInd = ind; $(this).click(function(){ pootTabsHere.changeTab(dis, thisInd, duration, false); $(this).blur(); $(this).find('*').blur(); return false; }); ind++; }); var isVertical = dis.hasClass('poot-tabs-vertical'); dis.attr('pootvertical', isVertical ? 'true' : ''); if(isVertical) { var teenie = dis.children('.poot-tabs').width().toString() + 'px'; dis.children('.poot-tabs-content').css('margin-left', teenie); } dis.attr('pootcollapse', ''); // False dis.find('.poot-tabs-hidelink a').click(function(){ pootTabsHere.toggleCollapse(dis); return false; }); }, init:function() { $('.poot-tabs-container').each(pootTabsHere.poot); } }; $(pootTabsHere.init); // End of PootTabs // Responsive table behavior $(document).ready(function() { var switched = false; var updateTables = function() { if (($(window).width() < 767) && !switched ){ switched = true; $("table.responsive").each(function(i, element) { splitTable($(element)); }); return true; } else if (switched && ($(window).width() > 767)) { switched = false; $("table.responsive").each(function(i, element) { unsplitTable($(element)); }); } }; $(window).load(updateTables); $(window).on("redraw",function(){switched=false;updateTables();}); // An event to listen for $(window).on("resize", updateTables); function splitTable(original) { original.wrap("<div class='table-wrapper' />"); var copy = original.clone(); copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none"); copy.removeClass("responsive"); original.closest(".table-wrapper").append(copy); copy.wrap("<div class='pinned' />"); original.wrap("<div class='scrollable' />"); setCellHeights(original, copy); } function unsplitTable(original) { original.closest(".table-wrapper").find(".pinned").remove(); original.unwrap(); original.unwrap(); } function setCellHeights(original, copy) { var tr = original.find('tr'), tr_copy = copy.find('tr'), heights = []; tr.each(function (index) { var self = $(this), tx = self.find('th, td'); tx.each(function () { var height = $(this).outerHeight(true); heights[index] = heights[index] || 0; if (height > heights[index]) heights[index] = height; }); }); tr_copy.each(function (index) { $(this).height(heights[index]); }); } });