MediaWiki:Ticker.js

/*jshint evil:true*/ /*global mw, $*/ /*************************************************** * This script is deprecated. Use https://en.wikinews.org/wiki/MediaWiki:Ticker2.js * instead. ***************************************************/ var ticker_enabled = true; var ticker_tl=[]; //Don't touch var ticker_speed=20; //Increase to slow down, too low makes it go incredibly slow, 15 is about right var ticker_index=0, ticker_text_pos=0; //Don't touch var ticker_str_length; //Don't touch var ticker_contents; //Don't touch

//So people can make there own custom pages outside of the main source (add to this array in special:mypage/monobook.js etc), this will only initilize array if it doesn't already exist. var ticker_custompages = (ticker_custompages instanceof Array ? ticker_custompages : []); var ticker_custommsg = (ticker_custommsg instanceof Array ? ticker_custommsg : []);

// Add lines like the following to add custom tickers: // ticker_custompages['Portal:PORTALNAME'] = 'Portal:PORTALNAME/Tickersource'; // Make sure that the /Tickersource page is formatted like User:TheFearow/Tickersource using DPLs ticker_custompages['Portal:Football'] = 'Portal:Football/Tickersource'; ticker_custompages['Wikinews:Newsroom'] = 'Wikinews:Newsroom/Tickersource';

//Add custommsgs for all custom pages ticker_custommsg['Portal:Football'] = 'Latest football stories'; ticker_custommsg['Wikinews:Newsroom'] = 'Stories in development';

function ticker_prepare{ ticker_str_length=ticker_tl[0].length; var content = document.getElementById('showticker').innerHTML; if(content !== ""){ content += " \n"; } var start = "Latest stories"; if(ticker_custommsg[wgBasePageName]){ start = ticker_custommsg[wgBasePageName]; } content += "" + start + " (full list) :  "; document.getElementById('showticker').innerHTML = content; }

var wgBasePageName = mw.config.get('wgPageName'); if(mw.config.get('wgPageName').indexOf("/") != -1){ wgBasePageName = mw.config.get('wgPageName').substring(0,mw.config.get('wgPageName').indexOf("/")); }

var ticker_toload = "";

function ticker_load{ // can be set to false in a user's custom js file if( !ticker_enabled || ! $( '#showticker' ).length ){ return; } ticker_toload = "User:Matt/Tickersource"; if(ticker_custompages[wgBasePageName]){ ticker_toload = ticker_custompages[wgBasePageName]; } $.ajax({ url: mw.util.getUrl( ticker_toload, { 'action': 'render' } ),  beforeSend: function( xhr ) {   xhr.overrideMimeType( 'text/xml' );  } }).done(function( data, textStatus, jqXHR ) {  $( jqXHR.responseText ).find( 'li a' ).each(function{ ticker_tl.push( $(this).html ); }); ticker_prepare;  ticker_tick(false, true); }); }

function ticker_tick(reset, first) { if(reset){ document.getElementById("ticker_content").innerHTML = ""; } if(first){ ticker_index = Math.floor(Math.random * ticker_tl.length); ticker_text_pos=0; ticker_str_length=ticker_tl[ticker_index].length; } ticker_contents=''; //window.alert("TL: "+ticker_tl[ticker_index]); document.getElementById("ticker_content").innerHTML = ("" + ticker_tl[ticker_index].substring(0,ticker_text_pos) + "_").replace("\n", ""); if(ticker_text_pos++>=ticker_str_length) {   ticker_index++; if(ticker_index<ticker_tl.length) {     ticker_text_pos=0; ticker_str_length=ticker_tl[ticker_index].length; if(first){ setTimeout("ticker_tick(true, false)",3); }else{ setTimeout("ticker_tick(true, false)",7000); }   }else{ ticker_index = Math.floor(Math.random * ticker_tl.length); ticker_text_pos=0; ticker_str_length=ticker_tl[ticker_index].length; setTimeout("ticker_tick(true, false)",7000); } } else setTimeout("ticker_tick(false, false)",ticker_speed);

}

// Disables for IE, AJAX etc is really bugged in IE, wont work without major rewrite and server-side extension. if(navigator.userAgent.indexOf("MSIE") == -1){ $(ticker_load); }