|
|
Line 1: |
Line 1: |
− | /* Function that returns an object by ID for various browsers
| |
− | * Taken from http://www.netlobo.com/javascript_get_element_id.html */
| |
| | | |
− | function returnObjById( id ) {
| |
− |
| |
− | if (document.getElementById)
| |
− | var returnVar = document.getElementById(id);
| |
− |
| |
− | else if (document.all)
| |
− | var returnVar = document.all[id];
| |
− |
| |
− | else if (document.layers)
| |
− | var returnVar = document.layers[id];
| |
− |
| |
− | return returnVar;
| |
− | }
| |
− |
| |
− | // PootTabs by User:WindPower over at Portal Wiki
| |
− | // It puts 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
| |