MediaWiki:Common.js | ElderScrollsPortal.de

Hinweis: Nach dem Speichern muss der Browserchache geleert werden, um die Änderungen zu sehen:
Mozilla/Firefox: Strg-Shift-R, Internet Explorer: Strg-F5, Opera: F5, Safari: Cmd-Shift-R, Konqueror: F5.

/* Das folgende JavaScript wird für alle Benutzer geladen. */

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *                         http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
 *  Maintainers: [[en:User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = 'Verstecken';
var expandCaption = 'Anzeigen';
 
function collapseTable( tableIndex ) {
        var Button = document.getElementById( 'collapseButton' + tableIndex );
        var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
        if ( !Table || !Button ) {
                return false;
        }
 
        var Rows = Table.rows;
 
        if ( Button.firstChild.data == collapseCaption ) {
                for ( var i = 1; i < Rows.length; i++ ) {
                        Rows[i].style.display = 'none';
                }
                Button.firstChild.data = expandCaption;
        } else {
                for ( var i = 1; i < Rows.length; i++ ) {
                        Rows[i].style.display = Rows[0].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 ( hasClass( Tables[i], 'collapsible' ) ) {
 
                        /* only add button and increment count if there is a header row to work with */
                        var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
                        if ( !HeaderRow ) {
                                continue;
                        }
                        var Header = HeaderRow.getElementsByTagName( 'th' )[0];
                        if ( !Header ) {
                                continue;
                        }
 
                        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.className = 'collapseButton'; // Styles are declared in [[MediaWiki:Common.css]]
 
                        ButtonLink.style.color = Header.style.color;
                        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( ']' ) );
 
                        Header.insertBefore( Button, Header.childNodes[0] );
                        tableIndex++;
                }
        }
 
        for ( var i = 0;  i < tableIndex; i++ ) {
                if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
                        collapseTable( i );
                } else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {
                        var element = NavigationBoxes[i];
                        while ( element = element.parentNode ) {
                                if ( hasClass( element, 'outercollapse' ) ) {
                                        collapseTable( i );
                                        break;
                                }
                        }
                }
        }
}
 
addOnloadHook( createCollapseButtons );
 
/** Test if an element has a certain class **************************************
 *
 * Description: Uses regular expressions and caching for better performance.
 * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 */
 
var hasClass = ( function() {
        var reCache = {};
        return function( element, className ) {
                return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
        };
})();


// Copyright (c) 2012 All Right Reserved, http://scharesoft.de
//
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Author: Johannes Schmidt (Death-Lord)
// Email: johannes.schmidt95@gmx.de
// Date: 2012-05-28
// Summary: Displays a Help Bar for Weapon Tables, which shows the first row of a table
// License: CC-BY, http://creativecommons.org/licenses/by/3.0/de/
function HelpBar() 
{
	this.Last = 17;
	this.Opacity = 0;
	this.Hidden = 1;
	this.TimeOut;
	this.WidthBefore = 0;
	this.Trys = 0;
	this.HelpBar = document.getElementById('HelpBar');
	// bool HelpBar::ShowHelpBar(void)
	// Shows the Help Bar
	this.ShowHelpBar = function()
	{		
		// If a Timeout already set, maybe if actually hiding.
		if(this.TimeOut)
			// Stop that TimeOut
			clearTimeout(this.TimeOut);
		// If the Bar is hidden.
		if(this.Hidden == 1) {
			// Show it! (Set Style Attribute, to display: initial.
			document.getElementById('HelpBar').setAttribute('style', 'position: fixed; margin: 0px; top: 0px;  z-index:20; border: none; opacity: 0; display: initial;');
			// and set Hidden to 0.
			this.Hidden = 0;
		}		
		if(this.Trys > 2) {
			document.getElementById('HelpBar').setAttribute('style', 'position: fixed; margin: 0px; top: 0px;  z-index:20; border: none; opacity: 1; display: initial;');
		}
		// If not completely showed.
		if(this.Opacity < 1) {
			// Add Opacity + 0.1.
			this.Opacity = 1;
			
			// If JS didnt calculate right.
			if(this.Opacity > 1)
				// Set Opacity to 1.
				this.Opacity = 1;
			// And set the Style Attribute.			
			document.getElementById('HelpBar').setAttribute('style', 'position: fixed; margin: 0px; top: 0px;  z-index:20;  border: none; display: initial; opacity: 0;');
			
			// Start again
			this.TimeOut = setTimeout('Bar.ShowHelpBar()', 100);
			return false;
		// If completly showed.
		} else {
			// Return true
			return true;
		}		
	}
	
	// void HelpBar::HideHelpBar(void)
	// Hides the Help Bar	
	this.HideHelpBar = function()
	{		
		// If timeout already set, clear this timeout.
		if(this.TimeOut)
			clearTimeout(this.TimeOut);
		// If Opacity higher than 0.1
		if(this.Opacity > 0.1) {			
			this.Opacity = 0;
			// if opacity smaller than 0.
			if(this.Opacity < 0.1) 
				// Set it correctly to 0
				this.Opacity = 0;
			else if(this.Opacity >= 1) 
				this.Opacity = 1;
			// Set the style Attribute.
			document.getElementById('HelpBar').setAttribute('style', 'position: fixed; margin: 0px; top: 0px;  border: none; z-index:20; display: initial; opacity: '+this.Opacity+';');			
			// Start again.			
			this.TimeOut = setTimeout('Bar.HideHelpBar()', 100);
			
			// Set last to 15
			this.Last = 17;
			return;
		} else {			
			if(this.Hidden == 0) {
				document.getElementById('HelpBar').setAttribute('style', 'position: fixed;margin: 0px;  top: 0px;   border: none; z-index:20; opacity: 0; display: none;');
				this.Hidden = 1;
			}			
			// Set last to 15
			this.Last = 17;
			return;
		}
		return;
	}
	
	// void HelpBar::Checker(void)
	// Checks if the Help bar should be enabled
	this.Checker = function(Show)
	{
		try {
			if(document.getElementsByClassName('ListTable')[0].offsetWidth <= document.getElementById('column-content').offsetWidth) { 				
				// Check for all Tables if focused.
				var CountTables = document.getElementsByClassName('ListTable').length;
				
				for(i = 0; i < CountTables; ++i) {
					// Check if above current View.
					if(getOffsetTop(document.getElementsByClassName('ListTable')[i]) < window.pageYOffset) {																
						var Size = getOffsetTop(document.getElementsByClassName('ListTable')[i]) + document.getElementsByClassName('ListTable')[i].offsetHeight;				
						// Check if not overscrolled.				
						if(Size > window.pageYOffset) {												
							// Check if the real Header in Sight.							
							var Size = getOffsetTop(document.getElementsByClassName('ListTable')[i]) + document.getElementById('Col2'+i).offsetHeight - 15;							
							if(Size < window.pageYOffset) {				
								
								// if last higher than 10
								if(this.Last > 10)
									this.Last -= 1;
								// Adjust width for every column (10)
								for(j = 1; j < 11; ++j) {
									// Get the width of the column
									var Width = document.getElementById('Col'+j+i).offsetWidth;
									
									// Set the Width.
									document.getElementById('HelpBarCol'+j).setAttribute('style', 'width: '+Width+'px');								
									
									// Theres a little difference, so get it.
									Difference = document.getElementById('HelpBarCol'+j).offsetWidth - Width;

									// and adjust the width.
									Width -= Difference / (this.Last / 10);	
									
									// Set Attribute
									document.getElementById('HelpBarCol'+j).setAttribute('style', 'width: '+Width+'px');
									var ToleranceOne = document.getElementById('HelpBarCol'+j).offsetWidth - 0.1;
									var ToleranceTwo = document.getElementById('HelpBarCol'+j).offsetWidth + 0.1;
									if(this.WidthBefore > ToleranceOne && this.WidthBefore < ToleranceTwo && this.Trys == 510) {
										
									}
									// Show the bar.
									this.ShowHelpBar();												
									this.WidthBefore = document.getElementById('HelpBarCol'+j).offsetWidth;
								}																					
								
								++this.Trys;
								// and again.
								if(this.Trys < 3)
									Bar.Checker();
								else 
									setTimeout('Bar.Checker()', 500);
								return;
							}
						}				
					}		
				}
				// If not hidden
				if(this.Hidden == 0) {
					// Hide it.
					this.HideHelpBar();
					this.Trys = 0;
				}
			} else 
				this.HideHelpBar();
		// Catch the errors
		} catch (e) {					
			// and try again.
			setTimeout('Bar.Checker()', 500);
			return;
		}
		// Check again.
		setTimeout('Bar.Checker()', 500);
		return;
	}	
	// Constructor
	// Starts the Checker method
	this.Checker();
	this.HelpBar.OffsetTop = 0;
}
// Check if is the class ListTable set
if(typeof document.getElementsByClassName('ListTable')[0] != "undefined") {		
	// and the Table isnt bigger than the Content area
	if(document.getElementsByClassName('ListTable')[0].offsetWidth <= document.getElementById('column-content').offsetWidth) {
		// Set Bar 
		var Bar = new HelpBar;
		Bar.HelpBar = document.getElementById('HelpBar'); 
	}		
} 
function getOffsetTop (Element){
    var top = 0;
 
    if(!Element) 
		return false;     
    if(typeof Element != 'object' ) 
		return false;

    if(typeof Element.offsetTop != 'undefined')    {         
         while (Element && Element.tagName != 'BODY')         {
            top  += parseInt( Element.offsetTop );
            Element = Element.offsetParent;
         }
    }
    return top;
}