MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

/* Script for Geo location */
 * $.getJSON("http://www.ti.com/general/docs/readAkamaiHeaders0.tsp", function(data){window.tiUserGeo = data;});

/** * Collapsible tables * * Allows tables to be collapsed, showing only the header. See NavFrame. * * @version 2.0.3 (2014-03-14) * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js * @author User:R. Koot * @author User:Krinkle * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which * is supported in MediaWiki core. */

var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show';

function collapseTable( tableIndex ) { var Button = document.getElementById( 'collapseButton' + tableIndex ); var Table = document.getElementById( 'collapsibleTable' + tableIndex );

if ( !Table || !Button ) { return false; }

var Rows = Table.rows; var i;

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

function createClickHandler( tableIndex ) { return function ( e ) { e.preventDefault; collapseTable( tableIndex ); }; }

function createCollapseButtons { var tableIndex = 0; var NavigationBoxes = {}; var Tables = document.getElementsByTagName( 'table' ); var i;

for ( i = 0; i < Tables.length; i++ ) { if ( $( Tables[i] ).hasClass( '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 ); // Styles are declared in MediaWiki:Common.css Button.className = 'collapseButton';

ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); ButtonLink.setAttribute( 'href', '#' ); $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) ); ButtonLink.appendChild( ButtonText );

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

Header.insertBefore( Button, Header.firstChild ); tableIndex++; }   }

for ( i = 0; i < tableIndex; i++ ) { if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) ||           ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) )        ) { collapseTable( i ); }       else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) { var element = NavigationBoxes[i]; while ((element = element.parentNode)) { if ( $( element ).hasClass( 'outercollapse' ) ) { collapseTable ( i ); break; }           }        }    } }

mw.hook( 'wikipage.content' ).add( createCollapseButtons ); //================================================ // Functions for MSP430 UART Frequency Calculator //================================================ function _MSP430UartTbit_TX(mode, i, s_mod, f_mod) {   switch (mode) {       case 0: // Ideal return(1/baudrate); case 1: // Low Frequency Baudrate Generation return((1/brclk)*(lf_div_i + UCSx_mod[s_mod % 8][i % 8])); case 2: // Oversampling Baudrate Generation if(SX_BUG) { // with Sx bug: return((1/brclk)*((16+UCSx_mod[s_mod % 8][i % 8] - (i > 0 ? UCSx_mod[s_mod % 8][(i-1) % 8]:0) )*osr_div_i + f_mod)); }           else { // No Sx bug: return((1/brclk)*((16+UCSx_mod[s_mod % 8][i % 8])*osr_div_i + f_mod)); } break; default: // Ideal return(1/baudrate); } } // Tbit_TX_ideal

function _MSP430UartTX_error(mode, s_mod , f_mod, return_max_error) {   var i = 0; var t_ideal= 0; var t_usci= 0; var bit_error= 0;

return_max_error.max_error = 0; return_max_error.max_neg_error = 0; return_max_error.max_pos_error = 0;

for (i= 0; i < NO_BITS; i++) { t_ideal= t_ideal + _MSP430UartTbit_TX(0, i, 0, 0); t_usci = t_usci + _MSP430UartTbit_TX(mode, i, s_mod, f_mod); bit_error= (t_usci - t_ideal) * baudrate * 100; if (bit_error < return_max_error.max_neg_error) { return_max_error.max_neg_error = bit_error; }       if (bit_error > return_max_error.max_pos_error) { return_max_error.max_pos_error= bit_error; }       if ((bit_error*bit_error) > ((return_max_error.max_error)*(return_max_error.max_error))) { return_max_error.max_error= bit_error; }   } // for i

return return_max_error; } // _TX_error

function _MSP430UartRX_error(mode, s_mod, f_mod, t_sync, return_max_error) {   var i;    var j;    var half_bit_clocks; var t_ideal= 0; var t_usci= 0; var bit_error= 0;

return_max_error.max_error= 0; return_max_error.max_pos_error= 0; return_max_error.max_neg_error= 0;

for (i= 0; i < NO_BITS; i++) {       t_ideal= (i + 0.5) / baudrate; t_usci= 0; for (j= 0; j < i; j++) { t_usci = t_usci + _MSP430UartTbit_TX(mode, j, s_mod, f_mod); } if (mode == 2) // Oversampling Baudrate Generation {           if (SX_BUG) { if (f_mod == 15) { t_usci= t_usci + (1/brclk)*(t_sync + (8+UCSx_mod[s_mod%8][i%8] - (i > 0 ? UCSx_mod[s_mod % 8][(i-1) % 8]:0) )*osr_div_i + parseInt(7 + UCSx_mod[s_mod%8][i%8])); } else { t_usci= t_usci + (1/brclk)*(t_sync + (8+UCSx_mod[s_mod%8][i%8] - (i > 0 ? UCSx_mod[s_mod % 8][(i-1) % 8]:0) )*osr_div_i + parseInt((f_mod+1)/2)); } }           else { // not defined SX_BUG if (f_mod == 15) { t_usci= t_usci + (1/brclk)*(t_sync + (8+UCSx_mod[s_mod%8][i%8])*osr_div_i + parseInt(7 + UCSx_mod[s_mod%8][i%8])); } else { t_usci= t_usci + (1/brclk)*(t_sync + (8+UCSx_mod[s_mod%8][i%8])*osr_div_i + parseInt((f_mod+1)/2)); } } // SX_BUG }       else // Low Frequency Baudrate Generation { t_usci= t_usci + (1/brclk)*(t_sync + parseInt(lf_div_i/2) + UCSx_mod[s_mod%8][i%8]); }

bit_error= (t_usci - t_ideal) * baudrate * 100;

if (bit_error < return_max_error.max_neg_error) { return_max_error.max_neg_error= bit_error; } if (bit_error > return_max_error.max_pos_error) { return_max_error.max_pos_error= bit_error; } if ((bit_error*bit_error) > ((return_max_error.max_error)*(return_max_error.max_error))) { return_max_error.max_error= bit_error; } } // for i

return return_max_error; } // _RX_error

function _MSP430UartRX_error_worst_case(mode, s_mod, f_mod, worst_case_error) { //  var max_error, max_pos_error, max_neg_error; var max_worse_case_error = { max_error : 0, max_pos_error : 0, max_neg_error : 0 };

_MSP430UartRX_error(mode, s_mod, f_mod, -0.5, max_worse_case_error); worst_case_error= max_worse_case_error.max_error; _MSP430UartRX_error(mode, s_mod, f_mod, 0.0, max_worse_case_error); if ((worst_case_error)*(worst_case_error) < max_worse_case_error.max_error*max_worse_case_error.max_error) { worst_case_error= max_worse_case_error.max_error; }   _MSP430UartRX_error(mode, s_mod, f_mod, +0.5, max_worse_case_error); if ((worst_case_error)*(worst_case_error) < max_worse_case_error.max_error*max_worse_case_error.max_error) { worst_case_error= max_worse_case_error.max_error; }

return worst_case_error; } // _RX_error_worst_case

/* * Calculate baud dividers based on target baudrates */ function _MSP430UartCalculateBaudDividers(brclk_f, baudrate_f , overSampling) {   var outputText = ""; if(VERBOSE) { console.debug(" "); console.debug("executing _CalculateBaudDividers\n" ); console.debug("Brclk frequency [Hz]= " + brclk_f + "\n"); console.debug("Baudrate [Baud] = " + baudrate_f + "\n"); console.debug("overSampling = " + overSampling + "\n"); }

var s_mod, f_mod; var opt_s_mod, opt_f_mod; var status = 1; var max_error = { max_error : 0, max_pos_error : 0, max_neg_error : 0 };

var abs_max = { max_error : 0, max_pos_error : 0, max_neg_error : 0 };

if ((baudrate_f===0) && (brclk_f===0)) { status = -1; return status; }   else { baudrate = baudrate_f; brclk = brclk_f; }

// brclk= brclk * 1E6;       // Convert MHz   -> Hz    // baudrate= baudrate * 1E3;  // Convert kBaud -> Baud

lf_div_f= (brclk)/(baudrate); lf_div_i= parseInt(lf_div_f);

if((lf_div_i > 0) && (overSampling === 0)) { if (STD_CALC) { opt_s_mod= Math.round((lf_div_f-lf_div_i)*8); opt_f_mod = 0; _MSP430UartTX_error(1, opt_s_mod, 0, abs_max); }       else { // not defined STD_CALC opt_s_mod= -1; opt_f_mod = 0; abs_max.max_error= abs_max.max_pos_error= abs_max.max_neg_error= 0;

for (s_mod= 0; s_mod < 8; s_mod++) {               if (OPT_FOR_RX) { // Optimize for minimal receive error _MSP430UartRX_error_worst_case(1, s_mod, 0, max_error.max_error); }               else { // not defined OPT_FOR_RX _MSP430UartTX_error(1, s_mod, 0, max_error); }

if (((max_error.max_error*max_error.max_error) < (abs_max.max_error*abs_max.max_error)) ||                   (opt_s_mod == -1)) {                   abs_max.max_error= max_error.max_error; abs_max.max_pos_error= max_error.max_pos_error; abs_max.max_neg_error= max_error.max_neg_error; opt_s_mod= s_mod; }           } // for s_mod

} // STD_CALC

UCxBR0UART = lf_div_i & 0xFF; UCxBR1UART = lf_div_i >> 8; UCxBRS = opt_s_mod; UCxBRF = opt_f_mod;

_MSP430UartTX_error(1, opt_s_mod, 0, max_error);

outputText += " "; outputText += " Low Frequency Baud Rate Generation "; outputText += "Divider = " + lf_div_f + "; BRDIV = " + lf_div_i + " "; outputText += "S-Modulation UCBRSx = " + opt_s_mod + " ";

outputText += "UCxBR0UART = " + UCxBR0UART + " "; outputText += "UCxBR1UART = " + UCxBR1UART + " "; outputText += "UCxBRS = " + UCxBRS + " "; outputText += "UCxBRF = " + UCxBRF + " ";

outputText += "Max. TX bit error: " + max_error.max_error + "(" + max_error.max_neg_error + ", " + max_error.max_pos_error + ")" + " "; abs_max.max_error= abs_max.max_pos_error= abs_max.max_neg_error= 0; _MSP430UartRX_error(1, opt_s_mod, 0, -0.5, max_error); if (max_error.max_error > abs_max.max_error) { abs_max.max_error= max_error.max_error; } if (max_error.max_pos_error > abs_max.max_pos_error) { abs_max.max_pos_error= max_error.max_pos_error; } if (max_error.max_neg_error < abs_max.max_neg_error) { abs_max.max_neg_error= max_error.max_neg_error; } outputText += "Max. RX bit error (sync.: -0.5 BRCLK): " + max_error.max_error + "(" + max_error.max_neg_error + "," + max_error.max_pos_error + ")" + " "; _MSP430UartRX_error(1, opt_s_mod, 0, 0, max_error); if (max_error.max_error > abs_max.max_error) { abs_max.max_error= max_error.max_error; } if (max_error.max_pos_error > abs_max.max_pos_error) { abs_max.max_pos_error= max_error.max_pos_error; } if (max_error.max_neg_error < abs_max.max_neg_error) { abs_max.max_neg_error= max_error.max_neg_error; } outputText += "Max. RX bit error (sync.: +/-0 BRCLK): " + max_error.max_error + "(" + max_error.max_neg_error + "," + max_error.max_pos_error + ")" + " "; _MSP430UartRX_error(1, opt_s_mod, 0, +0.5, max_error); if (max_error.max_error > abs_max.max_error) { abs_max.max_error= max_error.max_error; } if (max_error.max_pos_error > abs_max.max_pos_error) { abs_max.max_pos_error= max_error.max_pos_error; } if (max_error.max_neg_error < abs_max.max_neg_error) { abs_max.max_neg_error= max_error.max_neg_error; } outputText += "Max. RX bit error (sync.: +0.5 BRCLK): " + max_error.max_error + "(" + max_error.max_neg_error + "," + max_error.max_pos_error + ")" + " "; outputText += "Max. RX bit error (over: -0.5,0,+0.5): " + abs_max.max_error + "(" + abs_max.max_neg_error + "," + abs_max.max_pos_error + ")" + " ";

}

else if ((lf_div_f >= 16) && (overSampling == 1)) {

outputText += " " + " "; outputText += " Oversampling Baud Rate Generation " + " ";

osr_div_f= (brclk)/(baudrate)/16; osr_div_i= parseInt(osr_div_f);

if (STD_CALC) { if (osr_div_i <= 1) {  opt_f_mod= 0; // The FX modulation does not work with a BR divider <=1 because the prescaler is bypassed in this case. }           else {  opt_f_mod= parseInt((osr_div_f-osr_div_i)*16); } // else opt_s_mod= 0; _MSP430UartTX_error(2, opt_s_mod, opt_f_mod, abs_max); }       else { // not defined STD_CALC opt_s_mod= -1; abs_max.max_error= abs_max_pos_error= abs_max.max_neg_error= 0;

for (f_mod=0; f_mod < (osr_div_i <= 1 ? 1 : 16); f_mod++) // Loop length depends on "osr_div_i" because FX modulation does not work with a BR divider <=1 because the prescaler is bypassed in this case. // osr_div_i<=1 => only f_mod = 0 is valid // osr_div_i >1 => f_mod can vary between 0 and 15. {               for (s_mod= 0; s_mod < 8; s_mod++) {                   if (OPT_FOR_RX) { // Optimize for minimal receive error _MSP430UartRX_error_worst_case(2, s_mod, f_mod, max_error.max_error); }                   else { // not defined OPT_FOR_RX _MSP430UartTX_error(2, s_mod, f_mod, max_error); }                   if (((max_error.max_error*max_error.max_error) < (abs_max.max_error*abs_max.max_error)) ||                        (opt_s_mod == -1)) {                      abs_max.max_error= max_error.max_error; abs_max.max_pos_error= max_error.max_pos_error; abs_max.max_neg_error= max_error.max_neg_error; opt_s_mod= s_mod; opt_f_mod= f_mod; }               } // for s_mod } // for f_mod } // STD_CALC

if (osr_div_i==1) { osr_div_i= 2; _MSP430UartTX_error(2, 0, 0, max_error); if ((max_error.max_error*max_error.max_error) < (abs_max.max_error*abs_max.max_error)) { abs_max.max_error= max_error.max_error; abs_max.max_pos_error= max_error.max_pos_error; abs_max.max_neg_error= max_error.max_neg_error; opt_s_mod= 0; opt_f_mod= 0; }           else { osr_div_i= 1; }       }

_MSP430UartTX_error(2, opt_s_mod, opt_f_mod, max_error);

if ((max_error.max_error*max_error.max_error) > (50*50)) {

outputText += "... not feasible! Max. error > 50%" + " ";

status = -1; }       else {           UCxBR0UART = osr_div_i & 0xFF; UCxBR1UART = osr_div_i >> 8; UCxBRS = opt_s_mod; UCxBRF = opt_f_mod;

outputText += "Divider= " + osr_div_f + "; BRDIV= " + osr_div_i + " "; outputText += "S-Modulation UCBRSx= " + opt_s_mod + " "; outputText += "F-Modulation UCBRFx= " + opt_f_mod + " "; outputText += "UCxBR0UART = " + UCxBR0UART + " " ; outputText += "UCxBR1UART = " + UCxBR1UART + " "; outputText += "UCxBRS = " + UCxBRS + " "; outputText += "UCxBRF = " + UCxBRF + " "; outputText += "Max. TX bit error: " + max_error.max_error + "(" + max_error.max_neg_error + "," + max_error.max_pos_error + ")" + " ";

abs_max.max_error= abs_max.max_pos_error= abs_max.max_neg_error= 0; _MSP430UartRX_error(2, opt_s_mod, opt_f_mod, -0.5, max_error); if (max_error.max_error > abs_max.max_error) { abs_max.max_error= max_error.max_error; } if (max_error.max_pos_error > abs_max.max_pos_error) { abs_max.max_pos_error= max_error.max_pos_error; } if (max_error.max_neg_error < abs_max.max_neg_error) { abs_max.max_neg_error= max_error.max_neg_error; } outputText += "Max. RX bit error (sync.: -0.5 BRCLK): " + max_error.max_error + "(" + max_error.max_neg_error + "," + max_error.max_pos_error + ")" + " "; _MSP430UartRX_error(2, opt_s_mod, opt_f_mod, 0, max_error); if (max_error.max_error > abs_max.max_error) { abs_max.max_error= max_error.max_error; } if (max_error.max_pos_error > abs_max.max_pos_error) { abs_max.max_pos_error= max_error.max_pos_error; } if (max_error.max_neg_error < abs_max.max_neg_error) { abs_max.max_neg_error= max_error.max_neg_error; } outputText += "Max. RX bit error (sync.: +/-0 BRCLK): " + max_error.max_error + "(" + max_error.max_neg_error + "," + max_error.max_pos_error + ")" + " "; _MSP430UartRX_error(2, opt_s_mod, opt_f_mod, +0.5, max_error); if (max_error.max_error > abs_max.max_error) { abs_max.max_error= max_error.max_error; } if (max_error.max_pos_error > abs_max.max_pos_error) { abs_max.max_pos_error= max_error.max_pos_error; } if (max_error.max_neg_error < abs_max.max_neg_error) { abs_max.max_neg_error= max_error.max_neg_error; } outputText += "Max. RX bit error (sync.: +0.5 BRCLK): " + max_error.max_error + "(" + max_error.max_neg_error + "," + max_error.max_pos_error + ")" + " "; outputText += "Max. RX bit error (over: -0.5,0,+0.5): " + abs_max.max_error + "(" + abs_max.max_neg_error + "," + abs_max.max_pos_error + ")" + " ";

} //else } // if   else {

outputText += "... not feasible!" + " ";

status = -1; } // else

if (VERBOSE) { console.debug("Exiting _CalculateBaudDividers gracefully" + " "); }

return outputText; } // _CalculateBaudDividers

/* * Calculate bit dividers based on target bitrates for SPI Mode */ function _MSP430UartCalculateSPIBitDividers(brclk, bitrate) {	if (VERBOSE) { outputText += "executing inside _CalculateSPIBitDividers; brclk = " + brclk + " baudrate = " + bitrate + " "; }

var f_div_f; var f_div_i; var status;

// Check if bitrate is possible f_div_f = brclk / bitrate; f_div_i = Math.round(f_div_f);

outputText += "Divider = " + f_div_f + " "; outputText += "localBRDIV = " + f_div_i + " ";

if(f_div_f > 1) {       UCxBR0SPI = f_div_i & 0xFF; UCxBR1SPI = f_div_i >> 8;

status = 1; }   else {       status = -1; }

outputText += "UCxBR0SPI = " + UCxBR0SPI + " "; outputText += "UCxBR1SPI = " + UCxBR1SPI + " " ;

return status; }

/* * Calculate bit dividers based on target bitrates for I2C Mode */ function _MSP430UartCalculateI2CBitDividers(brclk, bitrate) {	if (VERBOSE) { outputText += "executing inside _CalculateI2CBitDividers; brclk = " + brclk + " baudrate = " + bitrate + " "; }

var f_div_f; var f_div_i; var status;

// Check if bitrate is possible f_div_f = brclk / bitrate; f_div_i = Math.round(f_div_f);

if (VERBOSE) { outputText += "Divider = " + f_div_f + " "; outputText += "BRDIV = " + f_div_i + " "; }

if(f_div_f > 1) {       UCxBR0I2C = f_div_i & 0xFF; UCxBR1I2C = f_div_i >> 8;

status = 1; }   else {       status = -1; }

if (VERBOSE) { outputText += "UCxBR0I2C = " + UCxBR0I2C + " "; outputText += "UCxBR1I2C = " + UCxBR1I2C + " "; }   return status; }

function MSP430UartnumericCheck(field) { var value = field.value; if (isNaN(value)) field.style.backgroundColor = 'red'; else field.style.backgroundColor = 'white'; }

function MSP430UartCalculate { if (isNaN(document.getElementById("clockspeed").value) || isNaN(document.getElementById("baudrate").value)) {

document.getElementById("usciDividers").innerHTML = "Input Error: values must be numeric "; } else {   clockSpeed = parseInt(document.getElementById("clockspeed").value); baudRate = parseInt(document.getElementById("baudrate").value); document.getElementById("usciDividers").innerHTML = _MSP430UartCalculateBaudDividers(clockSpeed,baudRate,0) + _MSP430UartCalculateBaudDividers(clockSpeed,baudRate,1); }

}

//================================================ // End of MSP430 UART Frequency Calculator //================================================

//=============================================== // Start of MSP430 Checksum Calculator //===============================================

// function for checking valid hexadecimal string function isHex(string) { for (i=0; i<string.length; i++) {   if (isNaN(parseInt(string.charAt(i), 16))) {	 return false; } }  return true; }

// MSP430 BSL calculate function function MSP430BslChksmCalc(bsl_type, bsl_bytes) { // get bsl packet data string var data = bsl_bytes.value.replace (/\s+/g, '') var ckh, ckl;

// check if string has even length if(data.length & 0x01) {   alert("BSL Packet data should have even length"); } else if (isHex(data) == false) {   alert("Invalid hexadecimal string"); } else {   // initialize checksum ckl = ckh = 0;

// check BSL type if(bsl_type[0].checked) {     // ROM based BSL var even = 0; var byte_string = new String; for(i=0 ; i<data.length ; i+=2) {	   // read every two characters from the string to form a byte byte_string = data[i] + data [i+1]

// parse the byte string and do the XOR if(even == 0) {		 ckl ^= parseInt(byte_string, 16); }		else {		 ckh ^= parseInt(byte_string, 16); }

// toggle flag even ^= 0x01; }

// invert the result ckl ^= 0xFF; ckh ^= 0xFF;

// shows the checksum alert("CKL=0x" + ckl.toString(16).toUpperCase + ", CKH=0x" + ckh.toString(16).toUpperCase); }   else {     // Flash based BSL var CRC = 0xFFFF; var byte_string = new String; for(i=0 ; i>8) ^ data_byte) & 0xff; x ^= x>>4; CRC = (CRC << 8) ^ (x << 12) ^ (x <<5) ^ x;     }

// shows the checksum alert("CKL=0x" + (CRC & 0xFF).toString(16).toUpperCase + ", CKH=0x" + ((CRC>>8)&0xFF).toString(16).toUpperCase); } } } //=============================================== // End of MSP430 Checksum Calculator //===============================================

/** * Dynamic Navigation Bars (experimental) * * Description: See NavFrame. * Maintainers: UNMAINTAINED */

/* set up the words in your language */ var NavigationBarHide = '[' + collapseCaption + ']'; var NavigationBarShow = '[' + expandCaption + ']';

/** * Shows and hides content and picture (if available) of navigation bars * Parameters: *    indexNavigationBar: the index of navigation bar to be toggled **/ window.toggleNavigationBar = function ( indexNavigationBar, event ) { var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar ); var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar ); var NavChild;

if ( !NavFrame || !NavToggle ) { return false; }

/* if shown now */ if ( NavToggle.firstChild.data === NavigationBarHide ) { for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { NavChild.style.display = 'none'; }       }    NavToggle.firstChild.data = NavigationBarShow;

/* if hidden now */ } else if ( NavToggle.firstChild.data === NavigationBarShow ) { for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { NavChild.style.display = 'block'; }       }        NavToggle.firstChild.data = NavigationBarHide; }

event.preventDefault; };

/* adds show/hide-button to navigation bars */ function createNavigationBarToggleButton { var indexNavigationBar = 0; var NavFrame; var NavChild; /* iterate over all -elements */ var divs = document.getElementsByTagName( 'div' ); for ( var i = 0; (NavFrame = divs[i]); i++ ) { /* if found a navigation bar */ if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {

indexNavigationBar++; var NavToggle = document.createElement( 'a' ); NavToggle.className = 'NavToggle'; NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); NavToggle.setAttribute( 'href', '#' ); $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );

var isCollapsed = $( NavFrame ).hasClass( 'collapsed' ); /**            * Check if any children are already hidden. This loop is here for backwards compatibility: * the old way of making NavFrames start out collapsed was to manually add style="display:none" * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make            * the content visible without JavaScript support), the new recommended way is to add the class * "collapsed" to the NavFrame itself, just like with collapsible tables. */           for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { if ( NavChild.style.display === 'none' ) { isCollapsed = true; }               }            }            if ( isCollapsed ) { for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { NavChild.style.display = 'none'; }               }            }            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide ); NavToggle.appendChild( NavToggleText );

/* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */ for( var j = 0; j < NavFrame.childNodes.length; j++ ) { if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) { NavToggle.style.color = NavFrame.childNodes[j].style.color; NavFrame.childNodes[j].appendChild( NavToggle ); }           }            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); }   } }

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

/** * Uploadwizard_newusers * Switches in a message for non-autoconfirmed users at Upload * * Maintainers: User:Krimpet */ function uploadwizard_newusers { if ( mw.config.get( 'wgNamespaceNumber' ) === 4 && mw.config.get( 'wgTitle' ) === 'Upload' && mw.config.get( 'wgAction' ) === 'view' ) { var oldDiv = document.getElementById( 'autoconfirmedusers' ), newDiv = document.getElementById( 'newusers' ); if ( oldDiv && newDiv ) { var userGroups = mw.config.get( 'wgUserGroups' ); if ( userGroups ) { for ( var i = 0; i < userGroups.length; i++ ) { if ( userGroups[i] === 'autoconfirmed' ) { oldDiv.style.display = 'block'; newDiv.style.display = 'none'; return; }               }            }            oldDiv.style.display = 'none'; newDiv.style.display = 'block'; return; }   } }