میڈیاویکی:Gadget-quickedit-search.js

شیعہ اشعار سے
نظرثانی بتاریخ 19:26، 22 جون 2023ء از dfghjk>Admin (۱ نسخه واردشده)
(فرق) → پرانا نسخہ | تازہ ترین نسخہ (فرق) | تازہ نسخہ ← (فرق)

یاد دہانی: محفوظ کرنے کے بعد ان تبدیلیوں کو دیکھنے کے لیے آپ کو اپنے براؤزر کا کیش (cache) صاف کرنا ہوگا۔

  • فائرفاکس/ سفاری: جب Reload پر کلک کریں تو Shift دباکر رکھیں، یا Ctrl-F5 یا Ctrl-R دبائیں (Mac پر R-⌘)
  • گوگل کروم: Ctrl-Shift-R دبائیں (Mac پر Shift-R-⌘)
  • انٹرنیٹ ایکسپلورر: جب Refresh پر کلک کریں تو Ctrl یا Ctrl-F5 دبائیں
  • اوپیرا: Tools → Preferences میں جائیں اور کیش (cache) صاف کریں
/*<pre>*/
 
/* * * * * * * * * * * * * * * *
 * quickedit-search.js for [[de:Benutzer:ASM/quickedit.js]]
 *
 * [[en:User:Zocky]]'s Search Box script
 * customized by [[de:Benutzer:ASM]] for QuickEdit
 *
 * original script: [[en:User:Zocky/SearchBox.js]]
 * * * * * * * * * * * * * * * */

// Search box for Mediawiki
// (c) 2006 [[User:Zocky]], released under GPL

var sr$t;
var sr$f;
var sr$s;
var sr$r;
var sr$re;
var sr$mc;

function $e(id) {return document.getElementById(id)}

function srBack()
{
  if (sr$s.value=='') {sr$t.focus(); return }

  if (sr$re.checked) {
    var searchString = sr$s.value;
  } else {
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
  }

  searchString="("+searchString+")(?![\\s\\S]*"+searchString+")";
  if (sr$mc.checked)
    var re=new RegExp(searchString);
  else
    var re=new RegExp(searchString,"i");

  var res = re.exec (sr$t.value.substring(0,sr$t.selectionStart));
  if (!res) {
    var res = re.exec (sr$t.value)
  }

  if (res)
  {
    sr$t.selectionStart=res.index;
    sr$t.selectionEnd=res.index+res[1].length;
  }
  else sr$t.selectionStart=sr$t.selectionEnd;
  
  srSync();
}

function srNext()
{
  if (sr$s.value=='') {sr$t.focus(); return }

  if (sr$re.checked) {
    var searchString = sr$s.value;
  } else {
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
  }

  if (sr$mc.checked)
    var re=new RegExp(searchString,"g");
  else
    var re=new RegExp(searchString,"gi");

  re.lastIndex=sr$t.selectionEnd;
  var res = re.exec (sr$t.value)
  if (!res) {
    re.lastIndex=0;
    var res = re.exec (sr$t.value)
  }

  if (res)
  {
    sr$t.selectionStart=res.index;
    sr$t.selectionEnd=res.index+res[0].length;
  }
  else sr$t.selectionStart=sr$t.selectionEnd;
  srSync();
}

function srReplace()
{

  var sels=sr$t.selectionStart;
  var sele=sr$t.selectionEnd;
  var selr=sr$t.value.length-sele;

  if (sr$s.value=='' || sels==sele) {sr$t.focus(); return }

  if (sr$re.checked) {
    var searchString = sr$s.value;
    var replaceString = sr$r.value;

  } else {
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
    replaceString=sr$r.value.replace(/([\$\\])/g,'\\$1');
  }

  if (sr$mc.checked)
    var re=new RegExp(searchString,"g");
  else
    var re=new RegExp(searchString,"gi");

  re.lastIndex=sels;
  var res = re.exec (sr$t.value);
  var $$=0;
  if (res && res.index==sels && res[0].length==sele-sels)
  {
    if (sr$re.checked) {
      replaceString=replaceString.replace(/\\\\/g,'&backslash;').replace(/\\\$/g,'&dollar;')
      var replaceBits=(" "+replaceString).split(/(?=\$\d)/);
      replaceString=replaceBits[0].substring(1);
      for (var i=1; i<replaceBits.length; i++)
      {
        $$=replaceBits[i][1]-'0';
        if ($$<res.length)
           replaceString += res[$$] + replaceBits[i].substring(2)
        else
           replaceString += replaceBits[i];
     }
     replaceString=replaceString.replace (/\\n/,"\n").replace (/&backslash;/g,"\\").replace
                                         (/&dollar;/g,"\$")

    }
     sr$t.value= sr$t.value.substring(0,sels) + replaceString + sr$t.value.substring(sele);
  }

  sr$t.selectionStart=sels;
  sr$t.selectionEnd=sr$t.value.length-selr;
  srSync();
}


function srReplaceall()
{
  if (!sr$s.value) {sr$t.focus(); return }

  var sels=sr$t.selectionStart;
  var sele=sr$t.selectionEnd;
  var selr=sr$t.value.length-sele;

  var reps;

  if (sr$re.checked) {
    var searchString = sr$s.value;
    var replaceString = sr$r.value.replace(/\\\\/,'&backslash;').replace(/\\n/,'\n').replace(/&backslash;/,"\\");
  } else {
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
    replaceString=sr$r.value.replace(/([\$\\])/g,'\\$1');
  }

  if (sele>sels)
    reps=sr$t.value.substring(sels,sele);
  else
    reps=sr$t.value;
 
  if (sr$mc.checked)
    var re=new RegExp(searchString,"g");
  else
    var re=new RegExp(searchString,"gi");
  
  var replaceCounter=0;

  var replaceFunc=function(){replaceCounter++;return replaceString};

  reps=reps.replace(re,replaceFunc);

  if (sele>sels)
    sr$t.value = sr$t.value.substring(0,sels) + reps + sr$t.value.substring(sele);
  else
    sr$t.value = reps;

  sr$t.selectionStart=sels;
  sr$t.selectionEnd=sele>sels ? sr$t.value.length-selr : sels;
  window.status = replaceCounter+" ocurrences of " + searchString + " replaced.";
  srSync();
}

function srToggleCase()
{
  var sels=sr$t.selectionStart;
  var sele=sr$t.selectionEnd;
  var selr=sr$t.value.length-sele;
  var selt=sr$t.value.substring(sels,sele);

  if (sele>sels)
  {
    if (selt==selt.toUpperCase())
      selt=selt.toLowerCase()
    else if (selt==selt.toLowerCase() && sele-sels>1)
      selt=selt.substring(0,1).toUpperCase()+selt.substring(1).toLowerCase()
    else
      selt=selt.toUpperCase();

    sr$t.value = sr$t.value.substring(0,sels) + selt + sr$t.value.substring(sele);
    sr$t.selectionStart=sels;
    sr$t.selectionEnd=sele>sels ? sr$t.value.length-selr : sels;
  }
  srSync();
}


function srSync()
{
    var i;
    var allLines=0;
    var lineNo=0;
    var w=sr$t.cols-5;

    var dummy=sr$t.value.split("\n");
    for (i=0;i<dummy.length;i++){allLines+=Math.ceil(dummy[i].length/w)}

    var dummy=sr$t.value.substring(0,sr$t.selectionStart).split("\n");
    for (i=0;i<dummy.length;i++){lineNo+=Math.ceil(dummy[i].length/w)}

//    alert (w+" "+lineNo+"/"+allLines);

    sr$t.scrollTop=sr$t.scrollHeight*(lineNo-10)/allLines;
    sr$t.focus();
}

//</pre>