לדלג לתוכן

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

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית
שיע.ק (שיחה | תרומות)
יצירת דף עם התוכן "תמיכה בלשוניות, נכתב על ידי Yonidebest: $(function(){ var arrTabContent = new Array(); var arrTabStyle = new Array(); /* where: arr..."
 
מ לא בטוח שיש הבדל
 
(גרסת ביניים אחת של משתמש אחר אחד אינה מוצגת)
שורה 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) {
    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);
        };


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


//tabs2
//tabs2
mw.loader.using('jquery.ui.tabs', function () {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
     $('.tabWrapper').each(function () {
     if($content.find('.tabWrapper').length === 0) {
        var options = $('.tabWrapperOptions', this).text();
    return;
    }


         var tabBackground = options.match(/tabBackground:(.*?);/)[1];
    mw.loader.using( 'jquery.ui', function () {
        var tabBorder = options.match(/tabBorder:(.*?);/)[1];
         $content.find('.tabWrapper').each(function () {
        var defaultTab = options.match(/defaultTab:(.*?);/)[1];
            var options = $('.tabWrapperOptions', this).text();
 
           
        $(this).tabs({
            var tabBackground = options.match(/tabBackground:(.*?);/)[1];
            selected: defaultTab
            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');
         });
         });
        if (tabBackground) {
     });
            var tabs = $('.ui-tabs-nav li a', this);
            tabs.css('background', tabBackground)
            $(this).bind('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);
        }
        $('.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');
        });
    });
});