לדלג לתוכן

מדיה ויקי:Gadget-rollBackSummary.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
מאין תקציר עריכה
מאין תקציר עריכה
שורה 1: שורה 1:
var slideShowLinks = [];
/** Collapsible tables *********************************************************
var currentImage;
*
*  Description: Allows tables to be collapsed, showing only the header. See
*              [[Wikipedia:NavFrame]].
*  Maintainers: [[User:R. Koot]]
*/


function changeSlideShowImage(text) {
var autoCollapse = 2;
var slideshowimage = document.getElementById('slideshowimage');
var collapseCaption = ( wgUserLanguage == "he" ) ? "הסתרה": "Hide";
var slideshowimagelink = document.getElementById('slideshowimagelink');
var expandCaption = ( wgUserLanguage == "he" ) ? "הצגה" : "Show";
var slideshowlinkimage = document.getElementById('slideshowlinkimage');


var rx = /id="file"><a href="([^"]*)"><img alt="[^"]*" src="\1"/g;
function collapseTable( tableIndex )
var m = rx.exec(text);
{
//slideshowimage.parentNode.parentNode.innerText = text;
    var Button = document.getElementById( "collapseButton" + tableIndex );
if (!m) return;
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
    var allRows = Table.getElementsByTagName( "tr" );  


slideshowimage.setAttribute('src', m[1]);
    if ( !Table || !Button || allRows.length == 0 ) {
slideshowimage.setAttribute('alt', slideShowLinks[currentImage].title);
        return;
slideshowimagelink.href = wgServer + wgScriptPath + '/' + slideShowLinks[currentImage].title;
    }
slideshowimagelink.title = slideShowLinks[currentImage].title;
slideshowlinkimage.innerHTML = slideShowLinks[currentImage].title;
slideshowlinkimage.href = wgServer + wgScriptPath + '/' + slideShowLinks[currentImage].title;


var slideshowlinkleft = document.getElementById('slideshowlinkleft');
    var Rows = allRows[0].parentNode.childNodes;
var slideshowlinkright = document.getElementById('slideshowlinkright');
alert(currentImage);
alert(slideShowLinks.length - 1);
if (currentImage == 0)
  slideshowlinkleft.innerHTML = "";
else
  slideshowlinkleft.innerHTML = '>';
if (currentImage == slideShowLinks.length - 1)
  slideshowlinkright.innerHTML = "";
else
  slideshowlinkright.innerHTML = '<';
}
 
function toggleSlideShowImage(direction) {
var slideshowlinkimage = document.getElementById('slideshowlinkimage');
slideshowlinkimage.innerHTML = 'טוען, אנא המתן...';


// figure out which image to load
    if ( Button.firstChild.data == collapseCaption ) {
if (direction) // = 1 = up
        for ( var i = 1; i < Rows.length; i++ ) {
  currentImage++;
            if ( Rows[i].nodeType == 1 ) {
else // = 0 = down
                Rows[i].style.display = "none";
  currentImage--;
            }
        }
// load image page
        Button.firstChild.data = expandCaption;
var a = sajax_init_object();
    } else {
a.open('GET', wgServer + wgScript + '?title=' + encodeURIComponent(slideShowLinks[currentImage].title), true);
        for ( var i = 1; i < Rows.length; i++ ) {
a.onreadystatechange = function() {
            if ( Rows[i].nodeType == 1 ) {
  if (a.readyState != 4) return;
                Rows[i].style.display = "";
  changeSlideShowImage(a.responseText);
            }
  // alert("[" + a.status + ":" + a.statusText + "]\n" + a.responseText);
        }
};
        Button.firstChild.data = collapseCaption;
a.send(null);
    }
}
}


function initSlideShow() {
function createCollapseButtons()
if (!(wgPageName == 'מיוחד:כל_הדפים' && getParamValue('namespace') == 6)) return;
{
 
    var tableIndex = 0;
// get all link in page and remove non-images
    var NavigationBoxes = new Object();
slideShowLinksTemp = document.getElementsByTagName('A');
    var Tables = document.getElementsByTagName( "table" );
for (var i = 0; i < slideShowLinksTemp.length; i++)
  if (slideShowLinksTemp[i].title.indexOf('תמונה:') == 0)
  slideShowLinks.push(slideShowLinksTemp[i]);
 
// create the frame, hide almost everything else
var tables = document.getElementById('bodyContent').getElementsByTagName('TABLE');
tables[2].style.display = 'none';
 
var td1SS = document.createElement('TD');
td1SS.className = 'slideShowTD';
 
var img1SS = document.createElement('IMG');
img1SS.id = 'slideshowimage';
var aSS = document.createElement('A');
aSS.id = 'slideshowimagelink';
aSS.appendChild(img1SS);
td1SS.appendChild(aSS);
 
var tr1SS = document.createElement('TR');
tr1SS.appendChild(td1SS);


var td2SS = document.createElement('TD');
    for ( var i = 0; i < Tables.length; i++ ) {
td2SS.className = 'slideShowTD';
        if ( Tables[i].className.indexOf("collapsible") != -1 ) {
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );


var a1SS = document.createElement('A');
            var Button    = document.createElement( "span" );
a1SS.id = 'slideshowlinkleft';
            var ButtonLink = document.createElement( "a" );
a1SS.href = 'javascript:toggleSlideShowImage(1)'; // 1 = left/up
            var ButtonText = document.createTextNode( collapseCaption );
a1SS.innerHTML = '>';


var a2SS = document.createElement('A');
            Button.style.styleFloat = "left";
a2SS.id = 'slideshowlinkright';
            Button.style.cssFloat = "left";
a2SS.href = 'javascript:toggleSlideShowImage(0)'; // 0 = right/down
            Button.style.fontWeight = "normal";
a2SS.innerHTML = '<';
            Button.style.textAlign = "left";
            Button.style.width = "6em";


var a3SS = document.createElement('A');
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
a3SS.id = 'slideshowlinkimage';
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
a3SS.innerHTML = '';
            ButtonLink.appendChild( ButtonText );


td2SS.appendChild(a2SS);
            Button.appendChild( document.createTextNode( "[" ) );
td2SS.appendChild(document.createTextNode(' | '));
            Button.appendChild( ButtonLink );
td2SS.appendChild(a3SS);
            Button.appendChild( document.createTextNode( "]" ) );
td2SS.appendChild(document.createTextNode(' | '));
td2SS.appendChild(a1SS);


var tr2SS = document.createElement('TR');
            var Header;
tr2SS.appendChild(td2SS);
            if (Tables[i].className.indexOf("otherrow") != -1)
var tbodySS = document.createElement('TBODY');
                Header = getElementsByClassName(Tables[i], "TD", "headerrow")[0];
tbodySS.appendChild(tr1SS);
            else
tbodySS.appendChild(tr2SS);
                Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
var tableSS = document.createElement('TABLE');
            /* only add button and increment count if there is a header row to work with */
tableSS.className = 'slideshowTable';
            if (Header) {
tableSS.appendChild(tbodySS);
                Header.insertBefore( Button, Header.childNodes[0] );
tables[2].parentNode.insertBefore(tableSS, tables[2]);
                tableIndex++;
            }
        }
    }


  // start the show
    for ( var i = 0; i < tableIndex; i++ ) {
currentImage = 1;
        if ( NavigationBoxes[i].className.indexOf("collapsed") != -1 || ( tableIndex >= autoCollapse && NavigationBoxes[i].className.indexOf("autocollapse") != -1 ) ) {
toggleSlideShowImage(0);
            collapseTable( i );
        }
    }
}
}


addOnloadHook(initSlideShow);
addOnloadHook(createCollapseButtons);

גרסה מ־13:13, 5 בפברואר 2009

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[Wikipedia:NavFrame]].
 *  Maintainers: [[User:R. Koot]]
 */

var autoCollapse = 2;
var collapseCaption = ( wgUserLanguage == "he" ) ? "הסתרה": "Hide";
var expandCaption = ( wgUserLanguage == "he" ) ? "הצגה" : "Show";

function collapseTable( tableIndex )
{
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
    var allRows = Table.getElementsByTagName( "tr" ); 

    if ( !Table || !Button || allRows.length == 0 ) {
        return;
    }

    var Rows = allRows[0].parentNode.childNodes;

    if ( Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            if ( Rows[i].nodeType == 1 ) {
                Rows[i].style.display = "none";
            }
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( var i = 1; i < Rows.length; i++ ) {
            if ( Rows[i].nodeType == 1 ) {
                Rows[i].style.display = "";
            }
        }
        Button.firstChild.data = collapseCaption;
    }
}

function createCollapseButtons()
{
    var tableIndex = 0;
    var NavigationBoxes = new Object();
    var Tables = document.getElementsByTagName( "table" );

    for ( var i = 0; i < Tables.length; i++ ) {
        if ( Tables[i].className.indexOf("collapsible") != -1 ) {
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );

            var Button     = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( collapseCaption );

            Button.style.styleFloat = "left";
            Button.style.cssFloat = "left";
            Button.style.fontWeight = "normal";
            Button.style.textAlign = "left";
            Button.style.width = "6em";

            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
            ButtonLink.appendChild( ButtonText );

            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );

            var Header;
            if (Tables[i].className.indexOf("otherrow") != -1)
                Header = getElementsByClassName(Tables[i], "TD", "headerrow")[0];
            else
                Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
            /* only add button and increment count if there is a header row to work with */
            if (Header) {
                Header.insertBefore( Button, Header.childNodes[0] );
                tableIndex++;
            }
        }
    }

    for ( var i = 0;  i < tableIndex; i++ ) {
        if ( NavigationBoxes[i].className.indexOf("collapsed") != -1 || ( tableIndex >= autoCollapse && NavigationBoxes[i].className.indexOf("autocollapse") != -1 ) ) {
            collapseTable( i );
        }
    }
}

addOnloadHook(createCollapseButtons);