MediaWiki:Ticker.js: diferenças entre revisões

Fonte: Wikinotícias
Conteúdo apagado Conteúdo adicionado
Alchimista (discussão | contribs)
+ alteração, a pedido de User:Helder.wiki em [https://pt.wikipedia.org/w/index.php?diff=prev&oldid=38133530]
Alchimista (discussão | contribs)
m Revertidas edições por Alchimista, para a última versão por Sir Lestaty de Lioncourt
Linha 1: Linha 1:
/*jshint evil:true*/
/*global mw, $*/
var ticker_enabled = true;
var ticker_enabled = true;
if(navigator.userAgent.indexOf("MSIE") == -1){ //Disables for IE, AJAX etc is really bugged in IE, wont work without major rewrite and server-side extension.
var ticker_tl=[]; //Don't touch
var ticker_tl=new Array(); //Dont touch
var ticker_speed=20; //Increase to slow down, too low makes it go incredibly slow, 15 is about right
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_index=0; ticker_text_pos=0; //Dont touch
var ticker_str_length; //Don't touch
var ticker_str_length; //Dont touch
var ticker_contents; //Don't touch
var ticker_contents, ticker_row; //Dont 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.
//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_custompages = (ticker_custompages instanceof Array ? ticker_custompages : Array());
var ticker_custommsg = (ticker_custommsg instanceof Array ? ticker_custommsg : []);
var ticker_custommsg = (ticker_custommsg instanceof Array ? ticker_custommsg : Array());


// Add lines like the following to add custom tickers:
// Add lines like the following to add custom tickers:
Linha 16: Linha 15:
// Make sure that the /Tickersource page is formatted like [[Wikinews:Tickersource/Tickersource]] using DPLs
// Make sure that the /Tickersource page is formatted like [[Wikinews:Tickersource/Tickersource]] using DPLs
ticker_custompages['Portal:Futebol'] = 'Portal:Futebol/Tickersource';
ticker_custompages['Portal:Futebol'] = 'Portal:Futebol/Tickersource';



//Add custommsgs for all custom pages
//Add custommsgs for all custom pages
Linha 21: Linha 21:


function ticker_prepare(){
function ticker_prepare(){
ticker_str_length=ticker_tl[0].length;
ticker_str_length=ticker_tl[0].length
var content = document.getElementById('showticker').innerHTML;
var content = document.getElementById('showticker').innerHTML;
if(content !== ""){
if(content != ""){
content += "<br/>\n";
content += "<br/>\n";
}
}
Linha 30: Linha 30:
start = ticker_custommsg[wgBasePageName];
start = ticker_custommsg[wgBasePageName];
}
}
content += "<div id='ticker_start' style='font-weight: bold; font-size: 120%; display: inline;'>" + start + " <div style='font-size: smaller; display: inline;'>(<a href='" + mw.util.getUrl( ticker_toload, { 'action': 'purge' } ) + "'>Lista completa</a>)</div>:&nbsp;</div><div id='ticker_content' style='font-size: 120%; font-color: blue; display: inline;'></div>";
content += "<div id='ticker_start' style='font-weight: bold; font-size: 120%; display: inline;'>" + start + " <div style='font-size: smaller; display: inline;'>(<a href='" + wgServer + wgScript + "?title=" + ticker_toload + "&action=purge'>Lista completa</a>)</div>:&nbsp;</div><div id='ticker_content' style='font-size: 120%; font-color: blue; display: inline;'></div>";
document.getElementById('showticker').innerHTML = content;
document.getElementById('showticker').innerHTML = content;
}
}


var month=new Array(12);
var wgBasePageName = mw.config.get('wgPageName');
month[0]="January";
if(mw.config.get('wgPageName').indexOf("/") != -1){
month[1]="February";
wgBasePageName = mw.config.get('wgPageName').substring(0,mw.config.get('wgPageName').indexOf("/"));
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";

wgBasePageName = wgPageName;
if(wgPageName.indexOf("/") != -1){
wgBasePageName = wgPageName.substring(0,wgPageName.indexOf("/"));
}
}


Linha 42: Linha 56:


function ticker_load(){
function ticker_load(){
// can be set to false in a user's custom js file
if (ticker_enabled == true) { // can be set to false in a user's custom js file
try{
if( !ticker_enabled || ! $( '#showticker' ).length ){
var randomunusedtickervariable = document.getElementById('showticker').innerHTML;
}catch(err){
return;
return;
}
}
Linha 50: Linha 66:
ticker_toload = ticker_custompages[wgBasePageName];
ticker_toload = ticker_custompages[wgBasePageName];
}
}
xmlhttp = sajax_init_object();
$.ajax({
xmlhttp.overrideMimeType('text/xml');
url: mw.util.getUrl( ticker_toload, { 'action': 'render' } ),
xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?title=' + ticker_toload + '&action=render', true);
beforeSend: function( xhr ) {
xmlhttp.onload = function() {
xhr.overrideMimeType( 'text/xml' );
//this.responseXML is the DOM
var entries = this.responseText.split("\n");
//window.alert(this.responseText);
for(var i = 0; i < entries.length; i++){
var val = entries[i];
if(val.indexOf("<li>") == 0 && val.indexOf("<a") != -1){
val = val.substring(val.indexOf("\">")+2, val.indexOf("</a>"));
ticker_tl[ticker_tl.length] = val;
}
}
}
}).done(function( data, textStatus, jqXHR ) {
$( jqXHR.responseText ).find( 'li a' ).each(function(){
ticker_tl.push( $(this).html() );
});
ticker_prepare();
ticker_prepare();
ticker_tick(false, true);
ticker_tick(false, true);
});
}
xmlhttp.send( null );
}
}
}


Linha 70: Linha 93:
}
}
if(first){
if(first){
ticker_index = Math.floor(Math.random() * ticker_tl.length);
ticker_index = Math.round(Math.random() * ticker_tl.length-1);
ticker_text_pos=0;
ticker_text_pos=0;
ticker_str_length=ticker_tl[ticker_index].length;
ticker_str_length=ticker_tl[ticker_index].length;
}
}
ticker_contents='';
ticker_contents='';
ticker_row=Math.max(0,ticker_index-7);
//window.alert("TL: "+ticker_tl[ticker_index]);
//window.alert("TL: "+ticker_tl[ticker_index]);
document.getElementById("ticker_content").innerHTML = ("<a href=\"" + mw.util.getUrl( ticker_tl[ticker_index] ) + "\" title=\"" + mw.html.escape( ticker_tl[ticker_index] ) + "\">" + ticker_tl[ticker_index].substring(0,ticker_text_pos) + "_</a>").replace("\n", "");
document.getElementById("ticker_content").innerHTML = ("<a href=\"" + wgServer + wgArticlePath.replace("$1", escape(ticker_tl[ticker_index])) + "\" title=\"" + ticker_tl[ticker_index] + "\">" + ticker_tl[ticker_index].substring(0,ticker_text_pos) + "_</a>").replace("\n", "");
if(ticker_text_pos++>=ticker_str_length)
if(ticker_text_pos++>=ticker_str_length)
{
{
ticker_index++;
ticker_index++;
if(ticker_index<ticker_tl.length)
if(ticker_index!=ticker_tl.length)
{
{
ticker_text_pos=0;
ticker_text_pos=0;
Linha 90: Linha 114:
}
}
}else{
}else{
ticker_index = Math.floor(Math.random() * ticker_tl.length);
ticker_index = Math.round(Math.random() * ticker_tl.length-1);
ticker_text_pos=0;
ticker_text_pos=ticker_tl[ticker_index].indexOf("\">");
ticker_str_length=ticker_tl[ticker_index].length;
ticker_str_length=ticker_tl[ticker_index].length;
setTimeout("ticker_tick(true, false)",7000);
setTimeout("ticker_tick(true, false)",3000);
}
}
} else
} else
setTimeout("ticker_tick(false, false)",ticker_speed);
setTimeout("ticker_tick(false, false)",ticker_speed);

}
}


addLoadEvent(ticker_load);
// 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){
function sajax_init_object() {
$(ticker_load);
var A;
try {
// Try the new style before ActiveX so we don't
// unnecessarily trigger warnings in IE 7 when
// set to prompt about ActiveX usage
A = new XMLHttpRequest();
} catch (e) {
try {
A=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
A=new ActiveXObject("Microsoft.XMLHTTP");
} catch (oc) {
A=null;
}
}
}

return A;
}
}
}

Revisão das 13h31min de 15 de fevereiro de 2014

var ticker_enabled = true;
if(navigator.userAgent.indexOf("MSIE") == -1){ //Disables for IE, AJAX etc is really bugged in IE, wont work without major rewrite and server-side extension.
var ticker_tl=new Array(); //Dont 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; //Dont touch
var ticker_str_length; //Dont touch
var ticker_contents, ticker_row; //Dont 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 : Array());
var ticker_custommsg = (ticker_custommsg instanceof Array ? ticker_custommsg : Array());

// 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 [[Wikinews:Tickersource/Tickersource]] using DPLs
ticker_custompages['Portal:Futebol'] = 'Portal:Futebol/Tickersource';


//Add custommsgs for all custom pages
ticker_custommsg['Portal:Futebol'] = 'Últimas notícias do futebol';

function ticker_prepare(){
 ticker_str_length=ticker_tl[0].length
 var content = document.getElementById('showticker').innerHTML;
 if(content != ""){
  content += "<br/>\n";
 }
 var start = "Últimas notícias";
 if(ticker_custommsg[wgBasePageName]){
  start = ticker_custommsg[wgBasePageName];
 }
 content += "<div id='ticker_start' style='font-weight: bold; font-size: 120%; display: inline;'>" + start + " <div style='font-size: smaller; display: inline;'>(<a href='" + wgServer + wgScript + "?title=" + ticker_toload + "&action=purge'>Lista completa</a>)</div>:&nbsp;</div><div id='ticker_content' style='font-size: 120%; font-color: blue; display: inline;'></div>";
 document.getElementById('showticker').innerHTML = content;
}

var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";

wgBasePageName = wgPageName;
if(wgPageName.indexOf("/") != -1){
 wgBasePageName = wgPageName.substring(0,wgPageName.indexOf("/"));
}

var ticker_toload = "";

function ticker_load(){
if (ticker_enabled == true) { // can be set to false in a user's custom js file
 try{
  var randomunusedtickervariable = document.getElementById('showticker').innerHTML;
 }catch(err){
  return;
 }
 ticker_toload = "Wikinews:Tickersource/Tickersource";
 if(ticker_custompages[wgBasePageName]){
  ticker_toload = ticker_custompages[wgBasePageName];
 }
 xmlhttp = sajax_init_object();
 xmlhttp.overrideMimeType('text/xml');
 xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?title=' + ticker_toload + '&action=render', true);
 xmlhttp.onload = function() {
  //this.responseXML is the DOM
  var entries = this.responseText.split("\n");
  //window.alert(this.responseText);
  for(var i = 0; i < entries.length; i++){
   var val = entries[i];
   if(val.indexOf("<li>") == 0 && val.indexOf("<a") != -1){
    val = val.substring(val.indexOf("\">")+2, val.indexOf("</a>"));
    ticker_tl[ticker_tl.length] = val;
   }
  }
  ticker_prepare();
  ticker_tick(false, true);
 }
 xmlhttp.send( null );
}
}

function ticker_tick(reset, first)
{
  if(reset){
    document.getElementById("ticker_content").innerHTML = "";
  }
  if(first){
   ticker_index = Math.round(Math.random() * ticker_tl.length-1);
   ticker_text_pos=0;
   ticker_str_length=ticker_tl[ticker_index].length;
  }
  ticker_contents='';
  ticker_row=Math.max(0,ticker_index-7);
  //window.alert("TL: "+ticker_tl[ticker_index]);
  document.getElementById("ticker_content").innerHTML = ("<a href=\"" + wgServer + wgArticlePath.replace("$1", escape(ticker_tl[ticker_index])) + "\" title=\"" + ticker_tl[ticker_index] + "\">" + ticker_tl[ticker_index].substring(0,ticker_text_pos) + "_</a>").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.round(Math.random() * ticker_tl.length-1);
      ticker_text_pos=ticker_tl[ticker_index].indexOf("\">");
      ticker_str_length=ticker_tl[ticker_index].length;
      setTimeout("ticker_tick(true, false)",3000);
    }
  } else
    setTimeout("ticker_tick(false, false)",ticker_speed);
 
}

addLoadEvent(ticker_load);

function sajax_init_object() {
	var A;
	try {
		// Try the new style before ActiveX so we don't
		// unnecessarily trigger warnings in IE 7 when
		// set to prompt about ActiveX usage
		A = new XMLHttpRequest();
	} catch (e) {
		try {
			A=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				A=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (oc) {
				A=null;
			}
		}
	}

	return A;
}
}