Ugrás a tartalomhoz

Szerkesztő:Tgr/qpreview.js

A Wikipédiából, a szabad enciklopédiából

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
/**
 * QPreview
 * 
 * Enables a quick preview without refresh
 * Displays: * a render of the text in the edit box
             * categories and interwikis locally emulated
 * Doesn't display: * edit summary preview
                    * listing of the templates used
                    * other rare things like GeSHi colors (syntax highlighting)
 * Warning: the displayed categories and interwiki are locally emulated and may sometimes not be true
 * (missing if they are included within a template, displayed whereas they are in an includeonly, etc.)
 * 
 * Initial author: [[:en:User:Alex Smotrov|en:Alex Smotrov]] at [[:en:User:Alex Smotrov/qpreview.js]],
 *  completed by [[:fr:Utilisateur:Seb35|fr:Seb35]] to display interwikis and categories,
 *  adapted and translated by [[commons:User:Diti|Diti]] and [[commons:User:Dschwen|Dschwen]]
 *
 * see [{{fullurl:commons:MediaWiki:Gadget-QPreview.js|action=history}} the page history] for a complete authors list
 */ 
 
var qPreview =
{
 lang : "|aa;Qafár af|ab;Аҧсуа|af;Afrikaans|ak;Akan|als;Alemannisch|am;አማርኛ|an;Aragonés|ang;Anglo-Saxon|ar;العربية|arc;ܐܪܡܝܐ|arz;مصرى|as;অসমীয়া|ast;Asturianu|av;Авар|ay;Aymar aru|az;Azərbaycan|ba;Башҡорт|bar;Boarisch|bat-smg;Žemaitėška|be;Беларуская|be-x-old;Беларуская (тарашкевіца)|bg;Български|bh;भोजपुरी|bi;Bislama|bm;Bamanankan|bn;বাংলা|bo;བོད་ཡིག|bpy;ইমার ঠার/বিষ্ণুপ্রিয়া মণিপুরী|br;Brezhoneg|bs;Bosanski|bug;ᨅᨔ ᨕᨘᨁᨗ|bxr;Буряад|ca;Català|cbk-zam;Chavacano de Zamboanga|cdo;Mìng-dĕ̤ng-ngṳ̄|ce;Нохчийн|ceb;Cebuano|ch;Chamoru|cho|chr;ᏣᎳᎩ|chy;Tsetsêhestâhese|closed-zh-tw|co;Corsu|cr;Nēhiyawēwin / ᓀᐦᐃᔭᐍᐏᐣ|cs;Česky|csb;Kaszëbsczi|cu;Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ|cv;Чăвашла|cy;Cymraeg|da;Dansk|de;Deutsch|diq;Zazaki|dv;ދިވެހިބަސ|dz;ཇོང་ཁ|ee;Eʋegbe|el;Ελληνικά|eml;Emiliàn e rumagnòl|en;English|eo;Esperanto|es;Español|et;Eesti|eu;Euskara|fa;فارسی|ff;Fulfulde|fi;Suomi|fiu-vro;Võro|fj;Na Vosa Vakaviti|fo;Føroyskt|fr;Français|frp;Arpetan|fur;Furlan|fy;Frysk|ga;Gaeilge|gd;Gàidhlig|gl;Galego|glk;گیلکی|gn;Avañe'ẽ|got;𐌲𐌿𐍄𐌹𐍃𐌺|gu;ગુજરાતી|gv;Gaelg|ha;هَوُسَ|hak;Hak-kâ-fa|haw;Hawai`i|he;עברית|hi;हिन्दी|ho|hr;Hrvatski|hsb;Hornjoserbsce|ht;Kreyòl ayisyen|hu;Magyar|hy;Հայերեն|hz|ia;Interlingua|id;Bahasa Indonesia|ie;Interlingue|ig;Igbo|ii|ik;Iñupiak|ilo;Ilokano|io;Ido|is;Íslenska|it;Italiano|iu;ᐃᓄᒃᑎᑐᑦ/inuktitut|ja;日本語|jbo;Lojban|jv;Basa Jawa|ka;ქართული|kab;Taqbaylit|kg;Kongo|ki;Gĩkũyũ|kj|kk;Қазақша|kl;Kalaallisut|km;ភាសាខ្មែរ|kn;ಕನ್ನಡ|ko;한국어|kr|ks;कश्मीरी - (كشميري)|ksh;Ripoarisch|ku;Kurdî / كوردی|kv;Коми|kw;Kernewek|ky;Кыргызча|la;Latina|lad;Ladino|lb;Lëtzebuergesch|lbe;Лакку|lg;Luganda|li;Limburgs|lij;Líguru|lmo;Lumbaart|ln;Lingála|lo;ລາວ|lt;Lietuvių|lv;Latviešu|map-bms;Basa Banyumasan|mg;Malagasy|mh;Ebon|mi;Māori|mk;Македонски|ml;മലയാളം|mn;Монгол|mo|mr;मराठी|ms;Bahasa Melayu|mt;Malti|mus|my;Myanmasa|mzn;مَزِروني|na;Dorerin Naoero|nah;Nāhuatl|nan|nap;Nnapulitano|nds;Plattdüütsch|nds-nl;Nedersaksisch|ne;नेपाली|new;नेपाल भाषा|ng;Oshiwambo|nl;Nederlands|nn;Norsk (nynorsk)|no;Norsk (bokmål)|nov;Novial|nrm;Nouormand|nv;Diné bizaad|ny;Chi-Chewa|oc;Occitan|om;Oromoo|or;ଓଡ଼ିଆ|os;Иронау|pa;ਪੰਜਾਬੀ|pag;Pangasinan|pam;Kapampangan|pap;Papiamentu|pdc;Deitsch|pi;पािऴ|pih;Norfuk / Pitkern|pl;Polski|pms;Piemontèis|ps;پښتو|pt;Português|qu;Runa Simi|rm;Rumantsch|rmy;Romani|rn;Kirundi|ro;Română|roa-rup;Armãneashce|roa-tara;Tarandíne|ru;Русский|ru-sib|rw;Kinyarwanda|sa;संस्कृत|sc;Sardu|scn;Sicilianu|sco;Scots|sd;سنڌي|se;Sámegiella|sg;Sängö|sh;Srpskohrvatski / Српскохрватски|si;සිංහල|simple;Simple English|sk;Slovenčina|sl;Slovenščina|sm;Gagana Samoa|sn;chiShona|so;Soomaaliga|sq;Shqip|sr;Српски / Srpski|ss;SiSwati|st;Sesotho|su;Basa Sunda|sv;Svenska|sw;Kiswahili|ta;தமிழ்|te;తెలుగు|tet;Tetun|tg;Тоҷикӣ|th;ไทย|ti;ትግርኛ|tk;Türkmençe|tl;Tagalog|tlh|tn;Setswana|to;lea faka-Tonga|tokipona|tpi;Tok Pisin|tr;Türkçe|ts;Xitsonga|tt;Tatarça/Татарча|tum;chiTumbuka|tw;Twi|ty;Reo Mā`ohi|udm;Удмурт|ug;Uyghurche / ئۇيغۇرچە|uk;Українська|ur;اردو|uz;O'zbek|ve;Tshivenda|vec;Vèneto|vi;Tiếng Việt|vls;West-Vlams|vo;Volapük|wa;Walon|war;Winaray|wo;Wolof|wuu;吴语|xal;Хальмг|xh;isiXhosa|yi;ייִדיש|yo;Yorùbá|za;Sawcuengh|zea;Zeêuws|zh;中文|zh-classical;文言|zh-min-nan;Bân-lâm-gú|zh-yue;粵語|zu;isiZulu|",
 
 hook : null,
 btn : null,
 plang : null,
 catlinks: null,
 
 boundary : '--------p1415',
 
 // ex: qPreview.i18n.get('QPreview')
 i18n :
 {
  'Category' : { de: 'Kategorie', fr: 'Catégorie ', hu: 'Kategória' },
  'Categories' : { de: 'Kategorien', fr: 'Catégories ', hu: 'Kategóriák' },
  'Warning' : { de: 'Achtung', fr: 'Attention ', hu: 'Figyelmeztetés' },
  'Language' : { de: 'Sprachcode', fr: 'langue', hu: 'nyelv' },
  'in interwiki' : { de: 'wird in einem Interwikilink verwendet', fr: 'dans un interwiki', hu: 'interwiki: ' },
  'In Wikipedia' : { de: 'In Wikipedia', fr: 'Autres langues', hu: 'Wikipédia: ' },
  'QPreview' : { de: 'Schnellvorschau', fr: 'Aperçu', hu: 'Előnézet' },
 
  get : function( item )
  {
   if( qPreview.i18n[item] )
   {
    if( qPreview.i18n[item][wgUserLanguage] )
     return qPreview.i18n[item][wgUserLanguage];
    else
     return item;
   }
   else 
    return item + ' (i18n!)';
  }
 },
 
 button : function()
 {
  save = document.getElementById('wpSave');
  if( !save ) return;
 
  document.getElementById('wikiPreview').style.display = 'block';
 
  qPreview.plang = document.getElementById('p-lang');
  if( !qPreview.plang )
  {
   qPreview.plang = document.createElement('div');
   qPreview.plang.id = 'p-lang';
   qPreview.plang.setAttribute('class', 'portlet');
   qPreview.plang.style.display = 'none';
   qPreview.plang.innerHTML = '<h5>' + qPreview.i18n.get('In Wikipedia') 
    + '</h5><div class="pBody"><ul></ul></div>';
   toolbox = document.getElementById('p-tb');
   toolbox.parentNode.insertBefore( qPreview.plang, toolbox.nextSibling );
  }
 
  qPreview.catlinks = document.getElementById('catlinks');
  if( !qPreview.catlinks )
  {
   div = document.getElementsByTagName('div');
   for( i = 0; i < div.length; i++ )
   {
    if( div[i].className == 'printfooter' )
    {
     qPreview.catlinks = document.createElement('div');
     qPreview.catlinks.id = 'catlinks';
     qPreview.catlinks.className = 'catlinks';
     qPreview.catlinks.style.display = 'none';
     div[i].parentNode.insertBefore( qPreview.catlinks, div[i].nextSibling);
     break;
    }
   }
  }
 
  qPreview.btn = document.createElement('input');
  qPreview.btn.type = 'button';
  qPreview.btn.value = qPreview.i18n.get('QPreview');
  qPreview.btn.onclick = qPreview.preview;
  qPreview.btn.id = 'btnQPreview';
  qPreview.btn.setAttribute('tabindex', '6');
  save.parentNode.insertBefore( qPreview.btn, save.nextSibling );
 },
 
 preview : function()
 {
  var qPreviewLanguage = 
    wgServer.match(/.*\/\/(commons|incubator|meta|species|wikimediafoundation|www)/i) ? 
    '' : 
    wgServer.match(/.*\/\/([a-z-]*)\./i)[1];
 
  var divPreview = document.getElementById('wikiPreview');
  if (!divPreview) return;
 
  qPreview.btn.value = '…';
  var qPreviewEnd = false;
  var qPreviewTextbox = document.getElementById('wpTextbox1').value;
  if(document.editform.wpSection.value == 'new') 
   qPreviewTextbox = '== ' + document.editform.wpSummary.value 
    + " ==\n" + qPreviewTextbox;
 
  qPreviewAjax1 = sajax_init_object();
  qPreviewAjax2 = sajax_init_object();
 
  // Text processing
  qPreviewAjax1.open('POST', document.editform.action+'&live', true);
  qPreviewAjax1.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + qPreview.boundary );
  PostData = '--' + qPreview.boundary
   + '\nContent-Disposition: form-data; name="wpTextbox1"\n\n'
   + qPreviewTextbox + '\n--' + qPreview.boundary;
 
  if (qPreviewAjax1.overrideMimeType)
   qPreviewAjax1.overrideMimeType('text/html');
 
  qPreviewAjax1.onreadystatechange = function()
   {
    if (qPreviewAjax1.readyState != 4) return;
    html = qPreviewAjax1.responseText;
    html = html.replace(/<br style="clear: both;" \/>/,'').replace(/&gt;/g,'>').replace(/&lt;/g,'<');
    html = html.replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&apos;/g,"'");
    divPreview.innerHTML = html;
    var diffEnCours = document.getElementById('wikiDiff');
 
    // To hide the "Current changes" area if present.
    if (diffEnCours) diffEnCours.style.display = 'none';
 
    if(qPreviewEnd) 
     qPreview.btn.value = qPreview.i18n.get('QPreview');
    qPreviewEnd = true;
   };
 
  qPreviewAjax1.send(PostData);
 
  // Categories processing
  reg1 = new RegExp(' ','g'); reg2 = new RegExp('\\|.*');
  regexCat = new RegExp('\\[\\[ *Kategória: *(.*)\\]\\]', 'gi');
  qPreviewCat = qPreviewTextbox.match(regexCat);
  if(!qPreviewCat) 
  { 
   qPreview.catlinks.style.display = 'none'
 
   if(qPreviewEnd) 
    qPreview.btn.value = qPreview.i18n.get('QPreview'); 
   qPreviewEnd = true;
  }
  else
  {
   qPreviewTemp = '';
   for( i = 0; i < qPreviewCat.length; i++ )
   {
    qPreviewCat[i] = 'Kategória:' + qPreviewCat[i].replace(regexCat, '$1').replace(reg2, '');
    if(qPreviewCat[i] == 'Kategória:') 
     qPreviewCat.splice(i--, 1);
    else 
     qPreviewTemp += qPreviewCat[i]+'|';
   }
   if( qPreviewTemp )
   {
    qPreviewAjax2.open( 'GET', 
     wgServer
     + '/w/api.php?action=query&format=xml&prop=info&redirects&titles='
     + qPreviewTemp.substr(0, qPreviewTemp.length-1), true);
 
    qPreviewAjax2.onreadystatechange = function()
    {
     if(qPreviewAjax2.readyState != 4) return;
     qPreviewTemp = '';
     xmlDoc = qPreviewAjax2.responseXML;
     normalized = xmlDoc.getElementsByTagName('normalized');
 
     if(normalized.length)
      normalized = normalized[0].getElementsByTagName('n');
 
     redirects = xmlDoc.getElementsByTagName('redirects');
 
     if(redirects.length)
      redirects = redirects[0].getElementsByTagName('r');
 
     pages = xmlDoc.getElementsByTagName('pages')[0].getElementsByTagName('page');
 
     for( i = 0; i < qPreviewCat.length; i++ )
     {
      cat = qPreviewCat[i];
      missing = false;
      redirect = false;
      for(j=0; j<normalized.length; j++) 
       if(normalized[j].getAttribute('from') == cat) 
       { 
        cat = normalized[j].getAttribute('to'); 
        break;
       }
 
      for(j=0; j<pages.length; j++) 
       if( pages[j].getAttribute('title') == cat && 
           pages[j].getAttribute('missing') == '') 
       { 
        missing = true;
        break;
       }
 
      for(j=0; j<redirects.length; j++) 
       if(redirects[j].getAttribute('from') == cat) 
       {
        redirect = redirects[j].getAttribute('to');
        break;
       }
 
      qPreviewTemp += '<span dir="ltr"><a href="/wiki/' 
       + cat.replace(reg1, '_') + '" title="' 
       + cat + '"'+(missing ? ' class="new"' : '') 
       + (redirect ? ' style="font-style:italic;"' : '') + '>' 
       + cat.replace(/(?:Category):(.*)/, '$1')+'</a></span> | ';
     }
 
     qPreviewTemp = '<div id="mw-normal-catlinks">' 
      + '<a href="/wiki/Wikipédia:Hogyan használd a kategóriákat%3F" title="Wikipédia:Hogyan használd a kategóriákat?">'
      + ( ( pages.length > 1 ) ? 
          ( qPreview.i18n.get('Categories') ) : 
          ( qPreview.i18n.get('Category') ) )
      + '</a>: ' 
      + qPreviewTemp.substr(0, qPreviewTemp.length - 5 ) + '</div>';
 
     qPreview.catlinks.innerHTML = qPreviewTemp;
     qPreview.catlinks.style.display = 'block';
 
     if( qPreviewEnd ) 
      qPreview.btn.value = qPreview.i18n.get('QPreview');
     qPreviewEnd = true;
    };
    qPreviewAjax2.send(null);
   }
   else 
   {
    qPreview.catlinks.style.display = 'none'; 
 
    if(qPreviewEnd) 
     qPreview.btn.value = qPreview.i18n.get('QPreview'); 
    qPreviewEnd = true;
   }
  }
 
  // Interwiki processing
  qPreviewIw = '';
  reg3 = new RegExp('\\|'); reg4 = new RegExp('(.*)]'); reg5 = new RegExp(';(.*)');
  regexIw = new RegExp('\\[\\[ *(\\w{2,12}) *: *(.*)\\]\\]', 'gi');
  result = qPreviewTextbox.match(regexIw);
  if(!result) 
  { 
   qPreview.plang.style.display = 'none';
   return; 
  }
 
  for( i = 0; i < result.length; i++ )
  {
   r1 = result[i].replace(regexIw, '$1');
   r2 = result[i].replace(regexIw, '$2').replace(reg1, '_');
   r3 = qPreview.lang.search(RegExp('\\|'+r1+'(?:;|\\|)', 'i'));
   if(r1 == qPreviewLanguage) 
   {
    r3 = -1; 
    qPreviewIw += '<li class="interwiki-' + r1 
      + '"><b>' 
      + qPreview.i18n.get('Warning') + '</b>: ' 
      + qPreview.i18n.get('Language') + ' <b><u><i>' 
      + r1 + '</i></u></b> ' 
      + qPreview.i18n.get('in interwiki') + '</li>';
   }
 
   if(r3 != -1) 
   {
    r3 = qPreview.lang.substr(r3+1).replace(reg3,']');
    r3 = reg4.exec(r3)[1];
    qPreviewIw += '<li class="interwiki-' + r1 
     + '"><a href="http://' + r1 + '.wikipedia.org/wiki/'+r2+'">'
     + ( r3.indexOf(';') != -1 ? 
         reg5.exec(r3)[1] : 
         ( qPreview.i18n.get('Language') + ' \'' + r1 + '\'' ) ) 
     + '</a></li>'; }
   }
 
   qPreview.plang.getElementsByTagName('ul')[0].innerHTML = qPreviewIw;
   if(qPreviewIw)
    qPreview.plang.style.display = 'block';
   else
    qPreview.plang.style.display = 'none';
 
   if(qPreview.hook != undefined && 
      typeof(qPreview.hook) == 'function')
   qPreview.hook(qPreviewTextbox, qPreviewCat, qPreviewIw);

   if (typeof(interwikiTranslator) !== 'undefined')
     interwikiTranslator.init();       //Interwikik frissítése után interwikiFordito.js újrafuttatása

 }
};
 
$( qPreview.button );