MediaWiki:Feedback.js
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
/*jshint undef:true, strict:true */
/*global mw, $, newNode */
/**
* Create a new DOM node for the current document.
* Basic usage: var mySpan = newNode('span', "Hello World!")
* Supports attributes and event handlers*: var mySpan = newNode('span', {style:"color: red", focus: function(){alert(this)}, id:"hello"}, "World, Hello!")
* Also allows nesting to create trees: var myPar = newNode('p', newNode('b',{style:"color: blue"},"Hello"), mySpan)
*
* *event handlers, there are some issues with IE6 not registering event handlers on some nodes that are not yet attached to the DOM,
* it may be safer to add event handlers later manually.
**/
function newNode(tagname){
var node = document.createElement(tagname);
for( var i=1;i<arguments.length;i++ ){
if(typeof arguments[i] == 'string'){ //Text
node.appendChild( document.createTextNode(arguments[i]) );
}else if(typeof arguments[i] == 'object'){
if(arguments[i].nodeName){ //If it is a DOM Node
node.appendChild(arguments[i]);
}else{ //Attributes (hopefully)
for(var j in arguments[i]){
if(j == 'class'){ //Classname different because...
node.className = arguments[i][j];
}else if(j == 'style'){ //Style is special
node.style.cssText = arguments[i][j];
}else if(typeof arguments[i][j] == 'function'){ //Basic event handlers
try{ node.addEventListener(j,arguments[i][j],false); //W3C
}catch(e){try{ node.attachEvent('on'+j,arguments[i][j],"Language"); //MSIE
}catch(e){ node['on'+j]=arguments[i][j]; }} //Legacy
}else{
node.setAttribute(j,arguments[i][j]); //Normal attributes
}
}
}
}
}
return node;
}
/**
Adiciona uma seção de comentários à parte inferior das páginas, à esquerda.
Foi testado apenas no monobook por ter sido desenvolvido originalmente apenas para IPs.
**/
var fb_comment_page = "Wikilivros:Comentários";
var fb_comment_preload = "Wikilivros:Comentários/preload";
var fb_comment_intro = "Wikilivros:Comentários/intro";
var fb_title = "Comentários";
var fb_comment_url = mw.config.get('wgScript')+
"?title="+fb_comment_page+
"&action=edit§ion=new"+
"&preload="+encodeURIComponent(fb_comment_preload)+
"&editintro="+encodeURIComponent(fb_comment_intro)+
"&preloadtitle="+
encodeURIComponent("[[:"+mw.config.get('wgPageName').replace(/_/g, ' ')+"]]");
var fb_thanks = "Obrigado pela sua colaboração.";
var fb_comment = "Se tiver tempo, por favor, deixe um comentário.";
var fb_questions = [];
fb_questions[0] =
["Opine anonimamente sobre esta página do " + mw.config.get('wgSiteName') +":",
['Boa',
'Má',
'Desorganizada',
//'Mistake in definition', //redundante com o item 'Tem informações erradas'?
'Confusa',
'Não encontrei o que procurava',
'Incompleta',
'Tem informações erradas',
'Complicada demais']
];
var fb_options;
var fb_text;
var fb_sent = false;
var fb_sent2= false;
function fb_buildBox(){
var sidebar = document.getElementById('mw-panel');
if(!sidebar) return false;
var list = newNode('ul',{'id':'fb_list'});
for(var i=0;i<fb_options.length;i++){
list.appendChild(
newNode('li',
newNode('a',{'click':fb_click,'id':"FB"+i},fb_options[i])
)
);
}
sidebar.appendChild(
newNode('div',{'class':"portal expanded",'id':"p-feedback"},
newNode('a',{'name':"feedback"}),
newNode('h3',fb_title),
newNode('div',{'class':"body", 'style':"display: block;"},
newNode('p',{'style':'font-size: 90%'},fb_text),
list,
newNode('p',{'style':'font-size: 80%'},
newNode('a',{'href':fb_comment_url},fb_comment)
)
)
)
);
}
function fb_click(e){
var fb = false;
var fbi = false;
try{
fb = e.target.childNodes[0].nodeValue;
fbi = e.target.getAttribute('id').replace("FB",'');
}catch(e){ try{
fb = window.event.srcElement.childNodes[0].nodeValue;
fbi = window.event.srcElement.getAttribute('id').replace("FB",'');
} catch(e){ }}
if(fb){
fb_send(fb);
}
var list = document.getElementById('fb_list');
list.parentNode.insertBefore(
newNode('p',fb_thanks),list
);
list.parentNode.removeChild(list);
return false;
}
function fb_send(string) {
if (fb_sent) return false;
fb_sent = true;
var wiki = mw.config.get('wgServer').replace(/(https?:)?\/\/([^\.]*\.[^\.]*)\.org/,"$2");
var page = mw.config.get('wgPageName');
if (mw.config.get('wgCanonicalSpecialPageName') === 'Search'){
var sb = document.getElementById('lsearchbox');
if (sb) page += ('/' + sb.value);
}
var url = '//toolserver.org/~enwikt/feedback/?action=feedback' +
'&wiki=' + encodeURIComponent(wiki) +
'&title=' + encodeURIComponent(page) +
'&feedback=' + encodeURIComponent(string);
document.body.appendChild(
newNode('iframe',{'src':url,'style':'display:none'})
);
}
$(function () {
var index = Math.floor(Math.random()*(fb_questions.length));
fb_text = fb_questions[index][0];
fb_options = fb_questions[index][1];
fb_buildBox();
});