לדלג לתוכן

מדיה ויקי:Tabs.js – הבדלי גרסאות

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית
שיע.ק (שיחה | תרומות)
עדכון בדיקה
מ לא בטוח שיש הבדל
 
שורה 1: שורה 1:
/* תמיכה בלשוניות, נכתב על ידי Yonidebest */
/* תמיכה בלשוניות, נכתב על ידי Yonidebest */
$(function(){
$(function(){
var arrTabContent = new Array();
    var arrTabContent = [];
var arrTabStyle = new Array();
    var arrTabStyle = [];
/* where:
    /* where:
  arrTabStyle['sX0'] = unselected background color
    arrTabStyle['sX0'] = unselected background color
  arrTabStyle['sX1'] = border color
    arrTabStyle['sX1'] = border color
  where: X = id
    where: X = id
*/
    */
 
   
function getTabContent(selectedID) {
    function getTabContent(selectedID) {
// clear styling of all tabs
    var td;
var id = (selectedID.indexOf('0') == 7) ? selectedID.slice(6, 8) : selectedID.slice(6, 7);
        // clear styling of all tabs
for (var i = 1; i <= 10; i++) {
        var id = (selectedID.indexOf('0') == 7) ? selectedID.slice(6, 8) : selectedID.slice(6, 7);
  var td = document.getElementById('custom' + id + 'Tab' + i);
        for (var i = 1; i <= 10; i++) {
  if (!td) break;
            td = document.getElementById('custom' + id + 'Tab' + i);
  td.style.background = arrTabStyle['s' + id + '0'];
            if (!td) {
  td.style.borderBottom = '1px solid ' + arrTabStyle['s' + id + '1'];
            break;
  td.style.cursor = 'pointer';
            }
}
            td.style.background = arrTabStyle['s' + id + '0'];
 
            td.style.borderBottom = '1px solid ' + arrTabStyle['s' + id + '1'];
// style the selected tab
            td.style.cursor = 'pointer';
var tdSelected = document.getElementById(selectedID);
        }
tdSelected.style.background = 'white';
       
tdSelected.style.borderBottom = 'none';
        // style the selected tab
tdSelected.style.cursor = 'default';
        var tdSelected = document.getElementById(selectedID);
 
        tdSelected.style.background = 'white';
// show the content
        tdSelected.style.borderBottom = 'none';
var tdContent = document.getElementById('custom' + id + 'TabsContent');
        tdSelected.style.cursor = 'default';
tdContent.innerHTML = arrTabContent['a' + id + ((id == 10) ? selectedID.slice(11) : selectedID.slice(10))];
       
}
        // show the content
 
        var tdContent = document.getElementById('custom' + id + 'TabsContent');
function customTabsLoad(id) {
        tdContent.innerHTML = arrTabContent['a' + id + ((id == 10) ? selectedID.slice(11) : selectedID.slice(10))];
// create main table
    }
try { // for IE
   
  var table = document.createElement('<TABLE ID="custom' + id + 'TabsTable"></TABLE>');
    function customTabsLoad(id) {
} catch (e) { // for FF
    var table;
  var table = document.createElement('TABLE');
    var td;
  table.id = 'custom' + id + 'TabsTable';
        // create main table
};
        try { // for IE
table.cellSpacing = '0';
            table = document.createElement('<TABLE ID="custom' + id + 'TabsTable"></TABLE>');
var customTabAlign = document.getElementById('custom' + id + 'TabAlign');
        } catch (e) { // for FF
if (!customTabAlign)
            table = document.createElement('TABLE');
  table.align = 'center';
            table.id = 'custom' + id + 'TabsTable';
else
        }
  table.align = customTabAlign.innerHTML;
        table.cellSpacing = '0';
if (table.align == 'center')
        var customTabAlign = document.getElementById('custom' + id + 'TabAlign');
  table.style.clear = 'both';
       
var customTabWidth = document.getElementById('custom' + id + 'TabWidth');
        if (!customTabAlign) {
if (!customTabWidth)
        table.align = 'center';
  table.width = '90%';
        } else {
else
        table.align = customTabAlign.innerHTML;
  table.width = customTabWidth.innerHTML;
    }
var tbody = document.createElement("tbody");
   
 
        if (table.align == 'center') {
// get style data into the array
        table.style.clear = 'both';
var customTabBackground = document.getElementById('custom' + id + 'TabBackground');
        }
if (!customTabBackground)
       
  arrTabStyle['s' + id + '0'] = '#DEFED6';
        var customTabWidth = document.getElementById('custom' + id + 'TabWidth');
else
        if (!customTabWidth) {
  arrTabStyle['s' + id + '0'] = customTabBackground.innerHTML;
        table.width = '90%';
var customTabBorder = document.getElementById('custom' + id + 'TabBorder');
        } else {
if (!customTabBorder)
        table.width = customTabWidth.innerHTML;
  arrTabStyle['s' + id + '1'] = '#45A22F';
        }
else
       
  arrTabStyle['s' + id + '1'] = customTabBorder.innerHTML;
        var tbody = document.createElement("tbody");
 
       
var tr1 = document.createElement("TR");
        // get style data into the array
var i;
        var customTabBackground = document.getElementById('custom' + id + 'TabBackground');
for (i = 1; i <= 10; i++) {
       
  // create the first row
        if (!customTabBackground) {
  var divTab = document.getElementById('custom' + id + 'Tab' + i);
        arrTabStyle['s' + id + '0'] = '#DEFED6';
  if (!divTab) break;
        } else {
 
        arrTabStyle['s' + id + '0'] = customTabBackground.innerHTML;
  try { // for IE
        }
  var td = document.createElement('<TD ID="' + divTab.getAttribute("id") + '"></TD>');
       
  } catch (e) { // for FF
        var customTabBorder = document.getElementById('custom' + id + 'TabBorder');
  var td = document.createElement('TD');
        if (!customTabBorder) {
  td.id = divTab.getAttribute("id");
        arrTabStyle['s' + id + '1'] = '#45A22F';
  };
        } else {
  td.style.textAlign = 'center';
        arrTabStyle['s' + id + '1'] = customTabBorder.innerHTML;
  td.style.fontWeight = 'bold';
        }
  td.style.border = '1px solid ' + arrTabStyle['s' + id + '1'];
       
  td.style.background = arrTabStyle['s' + id + '0'];
        var tr1 = document.createElement("TR");
  td.style.cursor = 'pointer';
        var i;
  td.innerHTML = divTab.getAttribute("title");
        var tdOnClick = function() {
  td.title = td.innerHTML;
        getTabContent(this.id);
  td.onclick = function() { javascript: getTabContent(this.id); }
        };
  tr1.appendChild(td);
 
  // add a space td cell
  var tdSpace = document.createElement('TD');
  tdSpace.style.backgroundColor = 'transparent';
  tdSpace.style.borderBottom = '1px solid ' + arrTabStyle['s' + id + '1'];
  tdSpace.innerHTML = '&nbsp;';
  tr1.appendChild(tdSpace);
 
  // populate the array
  arrTabContent['a' + id + i] = divTab.innerHTML;
}
tbody.appendChild(tr1);
 
// create the second row structure
var tr2 = document.createElement("TR");
try { // for IE
  var td = document.createElement('<TD ID="custom' + id + 'TabsContent"></TD>');
} catch (e) { // for FF
  var td = document.createElement('TD');
  td.id = 'custom' + id + 'TabsContent';
};
td.style.padding = '7px';
td.style.border = '1px solid ' + arrTabStyle['s' + id + '1'];
td.style.borderTop = 'none';
td.colSpan = (i - 1) * 2;
td.innerHTML = "טוען...";
tr2.appendChild(td);
tbody.appendChild(tr2);
 
// attach table
table.appendChild(tbody);
var mainDiv = document.getElementById('custom' + id + 'Tabs');
mainDiv.parentNode.insertBefore(table, mainDiv);
 
// load default tab
var defaultTab = document.getElementById('custom' + id + 'TabDefault');
if (!defaultTab)
  getTabContent('custom' + id + 'Tab1');
else
  getTabContent('custom' + id + 'Tab' + defaultTab.innerHTML);
 
// remove the div and wait notice
mainDiv.parentNode.removeChild(mainDiv);
var customTabsWait = document.getElementById('custom' + id + 'TabsWait');
customTabsWait.parentNode.removeChild(customTabsWait);
}
 
for (var i = 1; i <= 10; i++) {
  var customTabs = document.getElementById('custom' + i + 'Tabs');
  if (customTabs)
  customTabsLoad(i);
}


        for (i = 1; i <= 10; i++) {
            // create the first row
            var divTab = document.getElementById('custom' + id + 'Tab' + i);
            if (!divTab) break;
           
            try { // for IE
                td = document.createElement('<TD ID="' + divTab.getAttribute("id") + '"></TD>');
            } catch (e) { // for FF
                td = document.createElement('TD');
                td.id = divTab.getAttribute("id");
            }
           
            td.style.textAlign = 'center';
            td.style.fontWeight = 'bold';
            td.style.border = '1px solid ' + arrTabStyle['s' + id + '1'];
            td.style.background = arrTabStyle['s' + id + '0'];
            td.style.cursor = 'pointer';
            td.innerHTML = divTab.getAttribute("title");
            td.title = td.innerHTML;
            td.onclick = tdOnClick;
            tr1.appendChild(td);
           
            // add a space td cell
            var tdSpace = document.createElement('TD');
            tdSpace.style.backgroundColor = 'transparent';
            tdSpace.style.borderBottom = '1px solid ' + arrTabStyle['s' + id + '1'];
            tdSpace.innerHTML = '&nbsp;';
            tr1.appendChild(tdSpace);
           
            // populate the array
            arrTabContent['a' + id + i] = divTab.innerHTML;
        }
        tbody.appendChild(tr1);
       
        // create the second row structure
        var tr2 = document.createElement("TR");
       
        try { // for IE
            td = document.createElement('<TD ID="custom' + id + 'TabsContent"></TD>');
        } catch (e) { // for FF
            td = document.createElement('TD');
            td.id = 'custom' + id + 'TabsContent';
        }
       
        td.style.padding = '7px';
        td.style.border = '1px solid ' + arrTabStyle['s' + id + '1'];
        td.style.borderTop = 'none';
        td.colSpan = (i - 1) * 2;
        td.innerHTML = "טוען...";
        tr2.appendChild(td);
        tbody.appendChild(tr2);
       
        // attach table
        table.appendChild(tbody);
        var mainDiv = document.getElementById('custom' + id + 'Tabs');
        mainDiv.parentNode.insertBefore(table, mainDiv);
       
        // load default tab
        var defaultTab = document.getElementById('custom' + id + 'TabDefault');
        if (!defaultTab) {
        getTabContent('custom' + id + 'Tab1');
        } else {
        getTabContent('custom' + id + 'Tab' + defaultTab.innerHTML);
        }
       
        // remove the div and wait notice
        mainDiv.parentNode.removeChild(mainDiv);
        var customTabsWait = document.getElementById('custom' + id + 'TabsWait');
        customTabsWait.parentNode.removeChild(customTabsWait);
    }
   
    for (var i = 1; i <= 10; i++) {
        var customTabs = document.getElementById('custom' + i + 'Tabs');
        if (customTabs) {
        customTabsLoad(i);
        }
    }
});
});


//tabs2
//tabs2
mw.hook( 'wikipage.content' ).add( function ( $content ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
if($content.find('.tabWrapper').length === 0) return;
    if($content.find('.tabWrapper').length === 0) {
mw.loader.using( 'jquery.ui.tabs', function () {
    return;
$content.find('.tabWrapper').each(function () {
    }
    var options = $('.tabWrapperOptions', this).text();
 
    var tabBackground = options.match(/tabBackground:(.*?);/)[1];
    var tabBorder = options.match(/tabBorder:(.*?);/)[1];
    var defaultTab = options.match(/defaultTab:(.*?);/)[1];


    $(this).tabs({
    mw.loader.using( 'jquery.ui', function () {
        selected: defaultTab
        $content.find('.tabWrapper').each(function () {
    });
            var options = $('.tabWrapperOptions', this).text();
    if (tabBackground) {
           
        var tabs = $('.ui-tabs-nav li a', this);
            var tabBackground = options.match(/tabBackground:(.*?);/)[1];
        tabs.css('background', tabBackground)
            var tabBorder = options.match(/tabBorder:(.*?);/)[1];
        $(this).bind('tabsselect', function (e, ui) {
            var defaultTab = options.match(/defaultTab:(.*?);/)[1];
            tabs.css('background', tabBackground);
           
            $(ui.tab).css('background', '#ffffff');
            $(this).tabs({
        });
                selected: defaultTab
        $(tabs.get(defaultTab)).css('background', '#ffffff');
            });
    }
            if (tabBackground) {
    if (tabBorder) {
                var tabs = $('.ui-tabs-nav li a', this);
        $(this).css('border-color', tabBorder);
                tabs.css('background', tabBackground);
    }
                $(this).on('tabsselect', function (e, ui) {
    $content.find('.tabWrapper .ui-widget-content,.tabWrapper.ui-widget-content').removeClass('ui-widget-content');
                    tabs.css('background', tabBackground);
})
                    $(ui.tab).css('background', '#ffffff');
});
                });
                $(tabs.get(defaultTab)).css('background', '#ffffff');
            }
            if (tabBorder) {
                $(this).css('border-color', tabBorder);
            }
            $content.find('.tabWrapper .ui-widget-content,.tabWrapper.ui-widget-content').removeClass('ui-widget-content');
        });
    });
});
});

גרסה אחרונה מ־07:27, 3 באוגוסט 2020

/* תמיכה בלשוניות, נכתב על ידי Yonidebest */
$(function(){
    var arrTabContent = [];
    var arrTabStyle = [];
    /* where:
    arrTabStyle['sX0'] = unselected background color
    arrTabStyle['sX1'] = border color
    where: X = id
    */
    
    function getTabContent(selectedID) {
    	var td;
        // clear styling of all tabs
        var id = (selectedID.indexOf('0') == 7) ? selectedID.slice(6, 8) : selectedID.slice(6, 7);
        for (var i = 1; i <= 10; i++) {
            td = document.getElementById('custom' + id + 'Tab' + i);
            if (!td) {
            	break;
            }
            td.style.background = arrTabStyle['s' + id + '0'];
            td.style.borderBottom = '1px solid ' + arrTabStyle['s' + id + '1'];
            td.style.cursor = 'pointer';
        }
        
        // style the selected tab
        var tdSelected = document.getElementById(selectedID);
        tdSelected.style.background = 'white';
        tdSelected.style.borderBottom = 'none';
        tdSelected.style.cursor = 'default';
        
        // show the content
        var tdContent = document.getElementById('custom' + id + 'TabsContent');
        tdContent.innerHTML = arrTabContent['a' + id + ((id == 10) ? selectedID.slice(11) : selectedID.slice(10))];
    }
    
    function customTabsLoad(id) {
    	var table;
    	var td;
        // create main table
        try { // for IE
            table = document.createElement('<TABLE ID="custom' + id + 'TabsTable"></TABLE>');
        } catch (e) { // for FF
            table = document.createElement('TABLE');
            table.id = 'custom' + id + 'TabsTable';
        }
        table.cellSpacing = '0';
        var customTabAlign = document.getElementById('custom' + id + 'TabAlign');
        
        if (!customTabAlign) {
        	table.align = 'center';
        } else {
        	table.align = customTabAlign.innerHTML;
    	}
    	
        if (table.align == 'center') {
        	table.style.clear = 'both';
        }
        
        var customTabWidth = document.getElementById('custom' + id + 'TabWidth');
        if (!customTabWidth) {
        	table.width = '90%';
        } else {
        	table.width = customTabWidth.innerHTML;
        }
        
        var tbody = document.createElement("tbody");
        
        // get style data into the array
        var customTabBackground = document.getElementById('custom' + id + 'TabBackground');
        
        if (!customTabBackground) {
        	arrTabStyle['s' + id + '0'] = '#DEFED6';
        } else {
        	arrTabStyle['s' + id + '0'] = customTabBackground.innerHTML;
        }
        
        var customTabBorder = document.getElementById('custom' + id + 'TabBorder');
        if (!customTabBorder) {
        	arrTabStyle['s' + id + '1'] = '#45A22F';
        } else {
        	arrTabStyle['s' + id + '1'] = customTabBorder.innerHTML;
        }
        
        var tr1 = document.createElement("TR");
        var i;
        var tdOnClick = function() {
        	getTabContent(this.id);
        };

        for (i = 1; i <= 10; i++) {
            // create the first row
            var divTab = document.getElementById('custom' + id + 'Tab' + i);
            if (!divTab) break;
            
            try { // for IE
                td = document.createElement('<TD ID="' + divTab.getAttribute("id") + '"></TD>');
            } catch (e) { // for FF
                td = document.createElement('TD');
                td.id = divTab.getAttribute("id");
            }
            
            td.style.textAlign = 'center';
            td.style.fontWeight = 'bold';
            td.style.border = '1px solid ' + arrTabStyle['s' + id + '1'];
            td.style.background = arrTabStyle['s' + id + '0'];
            td.style.cursor = 'pointer';
            td.innerHTML = divTab.getAttribute("title");
            td.title = td.innerHTML;
            td.onclick = tdOnClick;
            tr1.appendChild(td);
            
            // add a space td cell
            var tdSpace = document.createElement('TD');
            tdSpace.style.backgroundColor = 'transparent';
            tdSpace.style.borderBottom = '1px solid ' + arrTabStyle['s' + id + '1'];
            tdSpace.innerHTML = '&nbsp;';
            tr1.appendChild(tdSpace);
            
            // populate the array
            arrTabContent['a' + id + i] = divTab.innerHTML;
        }
        tbody.appendChild(tr1);
        
        // create the second row structure
        var tr2 = document.createElement("TR");
        
        try { // for IE
            td = document.createElement('<TD ID="custom' + id + 'TabsContent"></TD>');
        } catch (e) { // for FF
            td = document.createElement('TD');
            td.id = 'custom' + id + 'TabsContent';
        }
        
        td.style.padding = '7px';
        td.style.border = '1px solid ' + arrTabStyle['s' + id + '1'];
        td.style.borderTop = 'none';
        td.colSpan = (i - 1) * 2;
        td.innerHTML = "טוען...";
        tr2.appendChild(td);
        tbody.appendChild(tr2);
        
        // attach table
        table.appendChild(tbody);
        var mainDiv = document.getElementById('custom' + id + 'Tabs');
        mainDiv.parentNode.insertBefore(table, mainDiv);
        
        // load default tab
        var defaultTab = document.getElementById('custom' + id + 'TabDefault');
        if (!defaultTab) {
        	getTabContent('custom' + id + 'Tab1');
        } else {
        	getTabContent('custom' + id + 'Tab' + defaultTab.innerHTML);
        }
        
        // remove the div and wait notice
        mainDiv.parentNode.removeChild(mainDiv);
        var customTabsWait = document.getElementById('custom' + id + 'TabsWait');
        customTabsWait.parentNode.removeChild(customTabsWait);
    }
    
    for (var i = 1; i <= 10; i++) {
        var customTabs = document.getElementById('custom' + i + 'Tabs');
        if (customTabs) {
        	customTabsLoad(i);
        }
    }
});

//tabs2
mw.hook( 'wikipage.content' ).add( function ( $content ) {
    if($content.find('.tabWrapper').length === 0) {
    	return;
    }

    mw.loader.using( 'jquery.ui', function () {
        $content.find('.tabWrapper').each(function () {
            var options = $('.tabWrapperOptions', this).text();
            
            var tabBackground = options.match(/tabBackground:(.*?);/)[1];
            var tabBorder = options.match(/tabBorder:(.*?);/)[1];
            var defaultTab = options.match(/defaultTab:(.*?);/)[1];
            
            $(this).tabs({
                selected: defaultTab
            });
            if (tabBackground) {
                var tabs = $('.ui-tabs-nav li a', this);
                tabs.css('background', tabBackground);
                $(this).on('tabsselect', function (e, ui) {
                    tabs.css('background', tabBackground);
                    $(ui.tab).css('background', '#ffffff');
                });
                $(tabs.get(defaultTab)).css('background', '#ffffff');
            }
            if (tabBorder) {
                $(this).css('border-color', tabBorder);
            }
            $content.find('.tabWrapper .ui-widget-content,.tabWrapper.ui-widget-content').removeClass('ui-widget-content');
        });
    });
});