Gebruiker:Pslits/Inductiveload/Visibility.js

Uit Wikisource

Let op! Nadat u de veranderingen heeft opgeslagen, moet u de cache van uw browser nog legen om ze daadwerkelijk te zien.

Mozilla (incl. Firefox) Ctrl+Shift+R
Internet Explorer Ctrl+F5
Opera F5
Safari Cmd+R
Konqueror F5
/***************************************************************
/ Annotation switching
/ complain to User:Inductiveload
/**************************************************************/

//Map of properties of the different categories of visibility switch
var classUIProperties = {'typographic-long-s': {
                            'category'   : 'arch-typo',
                            'text1'      : 's',
                            'text2'      : 'ſ',
                            'text'       : 'long s (ſ)',
                            'title'      : 'long s (ſ)',
                            'buttonID'   : 't-showhide-long-s'},
                            
                        'extiw': {
                            'category'   : 'links',
                            'text'       : 'interwiki links',
                            'title'      : 'links to external Wikimedia projects',
                            'buttonID'   : 't-showhide-extiw'},
                    }


function checkForElementsOfClass(className)
{ //see if we have any elements of a certain class
    return $('.'+className).length > 0 ;    
}

// a function to allow custom 
function setupVisibilityButton(className, checkForElements)
{  //don't give a button if we don't have the elements to govern
    if (!checkForElements || checkForElementsOfClass(className)){
                
        switch( classUIProperties[className]['category'])
        {
            case 'links':
                var shownAlready = !($('#bodyContent .'+className+':first').hasClass('disabledlink') );
                var linkTarget = 'javascript:enableDisableLinks("'+className+'",'+!shownAlready+')';
                break;
            
            case 'arch-typo':
                var shownAlready = !($('.'+className+':first').text() == classUIProperties[className]['text1']);
                var linkTarget = 'javascript:toggleTypoVisibility("'+className+'",'+!shownAlready+')';
                break;
        
        }
        
        //the properties are independent of the category
        var showHide = shownAlready ? 'Hide ' : 'Show ';
        var linkText = showHide + classUIProperties[className]['text'];
        var linkTitle = showHide + classUIProperties[className]['title'];
        var buttonID = classUIProperties[className]['buttonID'];
        
        //If we already have the button, update it 
        if($('#'+buttonID).length){
            $('#'+buttonID+' a').attr({href:linkTarget, title:linkTitle});
            $('#'+buttonID+' a').html(linkText)

        }
        else{ // Add the button to the sidebar
            mw.util.addPortletLink('p-tb', linkTarget, linkText, buttonID, linkTitle,  '', '#t-print');
        }
    }
    else
    {
    //if (wgUserName == 'InductiveLoad')  alert('No ' + className + ' elements found!')    
    }

}


/******************************************************************************
 * typography switching
 * ***************************************************************************/

function toggleTypoVisibility(className, show)
{   //toggle a class's visibility on or off according to "show"
    if (checkForElementsOfClass(className)){

        $("."+className).text(show ? classUIProperties[className]['text2'] : classUIProperties[className]['text1']);
        
        setupVisibilityButton(className, false)
    }
}


$( function() { setupVisibilityButton('typographic-long-s', true) } );


/******************************************************************************
 * link disabling
 * ***************************************************************************/

function enableDisableLinks(className, enabled){
    $('.'+ className).toggleClass('disabledlink', !enabled)
    setupVisibilityButton(className, false)
}

$( function() { setupVisibilityButton('extiw', true) } );