MediaWiki:Feedback.js

Puslapis iš Vikižodyno, laisvojo žodyno.

Dėmesio: Išsaugojus jums gali prireikti išvalyti jūsų naršyklės podėlį, kad pamatytumėte pokyčius.

  • Firefox / Safari: Laikydami Shift pasirinkite Perkrauti, arba paspauskite Ctrl-F5 ar Ctrl-R (sistemoje Apple Mac ⌘-R)
  • Google Chrome: Spauskite Ctrl-Shift-R (sistemoje Apple Mac ⌘-Shift-R)
  • Internet Explorer / Edge: Laikydami Ctrl paspauskite Naujinti, arba paspauskite Ctrl-F5
  • Opera: Eikite į Meniu → Nuostatos (sistemoje Apple Mac Opera → Nustatymai), tuomet Privatumas ir sauga → išvalyti naršymo podėlį → išsaugotos talpyklos vaizdai ir failai.
/** Adds a feedback to to the bottom of the page on the left. This has only been tested with Monobook as it is intended for IPs only.
  To see how it works, add 

  importScript('User:Conrad.Irwin/feedback.js'); to [[Special:Mypage/monobook.js]]

  Please note that this is still in BETA. Functionality of both the Javascript and Connel's php is liable to change without warning. 
**/
var fb_comment_url =  mw.config.get('wgScript')+
  "?title=Vikižodynas:Feedback"+
  "&action=edit&section=new"+
  "&preload=Vikižodynas:Feedback%2Fpreload"+
  "&editintro=Vikižodynas:Feedback%2Fintro"+
  "&preloadtitle="+
   encodeURIComponent("[[:"+mw.config.get('wgPageName').replace('_', ' ')+"]]");



var pn= mw.config.get('wgPageName').replace(/_/g,' ');
var fb_thanks = "Ačiū, kad skyrėte savo laiką, pateikdami pastabą Vikižodynui.";
//var fb_comment = "Jei neradote žodžio, (ir) arba, jei turite laiko, palikite savo platesnę pastabą(-as).";
var fb_comment = "Rašykite savo pastabą(-as).";

var fb_questions = new Array();

fb_questions[0] = 
//["Palikite savo anoniminę pastabą apie \""+pn+"\":",
["Balsuokite dėl \""+pn+"\":",
  ['Geras',  
   'Vidutinis', 
   'Blogas'/*, 
   'Netvarkingas', 
   'Klaida apibrėžime',
   'Prieštaringas apibrėžimas',
   'Neaprašyta lietuviška reikšmė',
   'Nepilnas apibrėžimas', 
   'Netikslus apibrėžimas',
   'Per sudėtingas apibrėžimas',
   'Trūksta vertimų'*/]
];

var fb_options;
var fb_text;
var fb_sent = false;
var fb_sent2= false;

function fb_init(){
  var index = Math.floor(Math.random()*(fb_questions.length)); 
  fb_text = fb_questions[index][0];
  fb_options = fb_questions[index][1]; 
  fb_buildBox();
}

function fb_buildBox(){
  var sidebar = document.getElementById('column-one');
  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':""+i},fb_options[i]) 
      )
    );
  }
  sidebar.insertBefore(    
    newNode('div',{'class':"portlet",'id':"p-feedb"},
      newNode('a',{'name':"feedback"}),
      newNode('h5',"jūsų nuomonė"),
      newNode('div',{'class':"pBody"},
        newNode('p',{'style':'font-size: 90%'},fb_text),
        list,
        newNode('p',{'style':'font-size: 80%'},
          newNode('a',{'href':fb_comment_url},fb_comment)
        )
      )
    ),
document.getElementById('p-search').nextSibling
  );
}
$(fb_init);
function fb_click(e){
  var fb = false;
  var fbi = false;
  
  try{
    fb = e.target.childNodes[0].nodeValue;
    fbi = e.target.getAttribute('id');
  }catch(e){ try{
    fb = window.event.srcElement.childNodes[0].nodeValue;
    fbi = window.event.srcElement.getAttribute('id');
  } catch(e){ }}
  
  if(fb){
    fb_send(fb);
    fb_send2(fb,fbi);
  }
  
  var list = document.getElementById('fb_list');
  
  list.parentNode.insertBefore(
    newNode('p',fb_thanks),list
  );
  list.parentNode.removeChild(list);
  
  return false;  
}
//Send to ~cmackenzie
function fb_send(string){
  if(fb_sent) return false;
  fb_sent=true;
  
  var wiki = mw.config.get('wgServer').replace(/https?:\/\/([^\.]*)\.([^\.]*)\.org/,"$1$2").replace(/pedia$/,'');
  
  var page = mw.config.get('wgPageName');
  if(mw.config.get('wgPageName') == 'Special:Search'){
    var sb = document.getElementById('lsearchbox');
    if(sb) page+='/'+sb.value;
  }
  var url = "http://tools.wikimedia.de/~cmackenzie/feedback.php"+
    "?fb_wiki="+wiki+
    "&fb_page="+encodeURI(page)+
    "&fb_revid="+encodeURI(wgCurRevisionId)+
    "&fb_comment="+encodeURI(string);

  document.body.appendChild(
    newNode('iframe',{'src':url,'style':'display:none'})
); 
}
//Send to ~daveross
function fb_send2(string,indx){
  if(fb_sent2) return false;
  fb_sent2  =true;
  var lang = mw.config.get('wgServer').replace(/^https?:\/\/([^\.]*).*$/,"$1");
  var wiki = mw.config.get('wgServer').replace(/https?:\/\/[^\.]*\.([^\.]*)\.org/,"$1");
  
  var page = mw.config.get('wgPageName');
  if(mw.config.get('wgPageName') == 'Special:Search'){
    var sb = document.getElementById('lsearchbox');
    if(sb) page+='/'+sb.value;
  }
  
  var url = 'http://tools.wikimedia.de/~daveross/feedback.php'
          + '?mode=submit'
          + '&lang='+encodeURI(lang)
          + '&wiki='+encodeURI(wiki)
          + '&page='+encodeURI(page)
          + '&revid='+encodeURI(wgCurRevisionId)
          + '&comment='+encodeURI(string)
          + '&comment_index='+encodeURI(indx*1+1);

  document.body.appendChild(
    newNode('iframe',{'src':url,'style':'display:none'})
  );

}

/* DOM abbreviation function */
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;
}