کاربر:Raamin/monobook.js

از ویکی‌پدیا، دانشنامهٔ آزاد.

نکته: پس از ذخیره‌سازی ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را خالی کنید. موزیلا / فایرفاکس / Safari: کلید Shift را نگه‌دارید و روی دکمهٔ Reload کلیک کنید، یا کلید‌های Ctrl-Shift-R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های Cmd-Shift-Rاینترنت اکسپلورر: کلید Ctrl نگه‌دارید و روی دکمهٔ Refresh کلیک‌ کنید، یا کلید‌های Ctrl-F5 را با هم فشار دهید؛ Konqueror: روی دکمهٔ Reload کلیک کنید و یا کلید F5 را فشار دهید؛ اُپرا: کاربران اُپرا ممکن است لازم باشد که بطور کامل حافظهٔ نهانی مرورگر را در منوی Tools→Preferences خالی کنند.

/*<pre>*/
/* isiri2901.js - Standard Persian keyboard driver for JavaScript
 *
 * Copyright (C) 2000  Roozbeh Pournader
 * Copyright (C) 2003, 2005  Behdad Esfahbod
 * Copyright (C) 2005  Pooya Karimian
 * Copyright (C) 2005  Behnam Esfahbod
 * Copyright (C) 2005  Artyom Lukanin
 *
 * ChangeLog:
 * Mar 05, 2005  Pooya Karimian, FireFox/Mozilla support added.
 * Mar 20, 2005  Behdad Esfahbod, random fixes in Firefox support.
 * Apr 14, 2005  Behnam Esfahbod, U+0654, U+0670, U+00F7 added.
 * Apr 21, 2005  Behdad Esfahbod, Minimal Opera 8.0 support added.
 *               Alt+Ctrl+anything now is known to switch language.
 * Sep 06, 2005  Artyom Lukanin, FireFox 1.0.6 support added.
 * Sep 09, 2005  Behdad Esfahbod, Added fallback support back in,
 *               removed Opera code that doesn't was not worth it.
 * Sep 09, 2005  Behdad Esfahbod, Make toggleDir() with no object
 *               passed changing language, actually work.
 * Sep 09, 2005  Added U+FDFC RIAL SIGN!
 * Sep 09, 2005  Assigned U+0653 to shift+X.
 *
 * Licensed under GNU GPL.
 */

var isiri2901_lang = 1;        // 1: Persian, 0: English
var isiri2901_nativelang = 0;  // 1: Persian, 0: English

// Persian keyboard map based on ISIRI-2901

var isirikey = [
  0x0020, 0x0021, 0x061B, 0x066B, 0xFDFC, 0x066A, 0x060C, 0x06AF,
  0x0029, 0x0028, 0x002A, 0x002B, 0x0648, 0x002D, 0x002E, 0x002F,
  0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7,
  0x06F8, 0x06F9, 0x003A, 0x06A9, 0x003E, 0x003D, 0x003C, 0x061F,
  0x066C, 0x0624, 0x200C, 0x0698, 0x064A, 0x064D, 0x0625, 0x0623,
  0x0622, 0x0651, 0x0629, 0x00BB, 0x00AB, 0x0621, 0x0654, 0x005D,
  0x005B, 0x0652, 0x064B, 0x0626, 0x064F, 0x064E, 0x0670, 0x064C,
  0x0653, 0x0650, 0x0643, 0x062C, 0x005C, 0x0686, 0x00D7, 0x0640,
  0x200D, 0x0634, 0x0630, 0x0632, 0x06CC, 0x062B, 0x0628, 0x0644,
  0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x067E, 0x062F, 0x062E,
  0x062D, 0x0636, 0x0642, 0x0633, 0x0641, 0x0639, 0x0631, 0x0635,
  0x0637, 0x063A, 0x0638, 0x007D, 0x007C, 0x007B, 0x007E
];

// on Alt+Ctrl+anything, switch language
function PersianKeyDown(e)
{
  if (window.event)
    e = window.event;
  if (e.ctrlKey && e.altKey) {
    if (isiri2901_lang == 0)
      setPersian();
    else
      setEnglish();
    try {
      e.preventDefault();
    } catch (err) {
    }
    return false;
  }
  return true;
}

function PersianKeyPress(e)
{
  var key;

  if (window.event) {
    e = window.event;
    obj = e.srcElement;
    key = e.keyCode;
  } else {
    obj = e.target;
    key = e.charCode;
  }

  // Change to English, if user is using an OS non-English keyboard
  if (key >= 0x00FF) {
    isiri2901_nativelang = 1;
    setPersian();
  } else
    if (isiri2901_nativelang == 1) {
      isiri2901_nativelang = 0;
      setEnglish();
    }

  // Avoid processing if control or higher than ASCII
  // Or ctrl or alt is pressed.
  if (key < 0x0020 || key >= 0x007F || e.ctrlKey || e.altKey || e.metaKey)
    return true;

  if (isiri2901_lang == 1) { //If Persian

    // rewrite key
    if (key == 0x0020 && e.shiftKey) // Shift-space -> ZWNJ
      key = 0x200C;
    else
      key = isirikey[key - 0x0020];

    try {
      // Gecko before banning fake key emission.
      e.initKeyEvent("keypress", true, true, document.defaultView, false, false, true, false, 0, key, obj);
    } catch (err) {
    try {
      // Windows
      e.keyCode = key;
    } catch (err) {
    try {
      // Try inserting at cursor position, Gecko after banning fake key emission
      pnhMozStringInsert(obj, String.fromCharCode(key));
      e.preventDefault();
    } catch (err) {
      // Everything else, simply add to the end of buffer
      obj.value += String.fromCharCode(key);
      e.preventDefault();
    }}}
  }
  return true;
}


function setPersian (obj, quiet)
{
  isiri2901_lang = 1;
  if (obj) {
    obj.style.textAlign = "right";
    obj.style.direction = "rtl";
    obj.focus();
  }
  if (!quiet)
    window.defaultStatus = "Persian Keyboard (Press Ctrl+Alt+Space to change to English)";
}


function setEnglish (obj, quiet)
{
  isiri2901_lang = 0;
  if (obj) {
//    obj.style.textAlign = "left";
//    obj.style.direction = "ltr";
    obj.focus();
  }
  if (!quiet)
    window.defaultStatus = "English Keyboard (Press Ctrl+Alt+Space to change to Persian)";
}


function toggleDir (obj, quiet) {var isrtl = 0;
  if (obj){
    isrtl = obj.style.direction != 'ltr';
    if (isrtl){
        obj.style.textAlign = "left";
        obj.style.direction = "ltr";
        }
     else{
        obj.style.textAlign = "right";
        obj.style.direction = "rtl";
        }
    }
    else{
    isrtl = isiri2901_lang;
    if (isrtl)
        setEnglish(obj, quiet);
     else
        setPersian(obj, quiet);
    }
}



// Inserts a string at cursor
function pnhMozStringInsert(elt, newtext) {
        var PosStart = 100000;
        var PosEnd = PosStart;
        PosStart = elt.selectionStart;
        PosEnd = elt.selectionEnd;
        elt.value = elt.value.slice(0,PosStart)+newtext+elt.value.slice(PosEnd);
        var newpos = PosStart+newtext.length;
        elt.selectionStart = newpos;
        elt.selectionEnd = newpos;
        elt.focus();
}

addOnloadHook(
  function() { 
if(document){
setEnglish(document);


if(document.addEventListener){ //code for Moz 
document.addEventListener("keydown",PersianKeyDown,false); 
document.addEventListener("keypress",PersianKeyPress,false); 
}else{ 
document.attachEvent("onkeydown",PersianKeyDown); //code for IE 
document.attachEvent("onkeypress",PersianKeyPress); 
}

}

}
);


document.write('<script type="text/javascript" src="' 
             + 'http://fa.wikipedia.org/w/index.php?title=User:Behaafarid/EsfahbodTools.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');


document.write('<script type="text/javascript" src="' 
             + 'http://fa.wikipedia.org/w/index.php?title=User:Behaafarid/BehaafaridTools.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');


document.write('<script type="text/javascript" src="' 
             + 'http://fa.wikipedia.org/w/index.php?title=User:Raamin/revert.js'
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');






// Script from [[User:MarkS/extraeditbuttons.js]]

// This is based on the original code on Wikipedia:Tools/Editing tools
//
// The original code was on the project page and needed to be cut and paste to the user's
// monobook.js page. However, this caused problems with the quote marks. So I have moved 
// it to its own page. 
//
// I do not know a lot about Javascript so please do not ask for a complicated change


function InsertButtonsToToolBar()
{
 tooly = document.getElementById('toolbar');

 if (tooly != null) 
{
  URLFIX = "<a href=\"javascript:URLfix(document.editform.wpTextbox1);\"><img src=\"http://upload.wikimedia.org/wikipedia/fa/b/ba/Button_decode_URI.png\" title=\"تبدیل به یونیکد در آدرس‌های وب\"></a>";

  StrikeTextButton = "<a href=\"javascript:insertTags('<s>','</s>','Insert text here');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png\" alt=\"Strike\" title=\"Strike-through text\"></a>";

  LeftTexttButton = "<a href=\"javascript:insertTags('{{چپ‌چین}}\\n','\\n{{پایان چپ‌چین}}','متن چپ‌چین شده');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/e/ea/Button_align_left.png\" alt=\"Left-align\" title=\"Left-aligned text\"></a>";

  CenterTextButton = "<a href=\"javascript:insertTags('<div style=&quot;text-align: center;&quot;>','</div>','Centered text');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/5/5f/Button_center.png\" alt=\"Centered\" title=\"Centered text\"></a>";

  TableButton = "<a href=\"javascript:insertTags('\\n{| border=&quot;1&quot; \\n|- \\n| 1 || 2\\n|- \\n| 3 || 4','\\n|}\\n','');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/6/60/Button_insert_table.png\" alt=\"Table\" title=\"Insert table\"></a>";

  EenterButton = "<a href=\"javascript:insertTags('<br />','','');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png\" alt=\"Break\" title=\"Line break\"></a>";

  UpperTextButton = "<a href=\"javascript:insertTags('<sup>','</sup>','Superscript');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png\" alt=\"Superscript\" title=\"Superscript text\"></a>";

  LowerTextlButton = "<a href=\"javascript:insertTags('<sub>','</sub>','Subscript');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png\" alt=\"Subscript\" title=\"Subscript text\"></a>";

  SmallTextButton = "<a href=\"javascript:insertTags('<small>','</small>','Small text');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png\" alt=\"Small\" title=\"Small text\"></a>";

  CommentButton = "<a href=\"javascript:insertTags('<!--','-->','Comment here');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png\" alt=\"Comment\" title=\"Insert hidden comment\"></a>";

  GalleryButton = "<a href=\"javascript:insertTags('\\n<gallery>\\n','\\n</gallery>','Image:FileName.jpg|Caption1\\Image:FileName2.jpg|Caption2');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png\" alt=\"Gallery\" title=\"Insert a picture gallery\"></a>";

  SecondaryHeadlineButton = "<a href=\"javascript:insertTags('\\n===','===','Secondary headline');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/e/e9/Button_headline2.png\" alt=\"2nd header\" title=\"Insert secondary headline\"></a>";

ShiftingButton = "<a href=\"javascript:insertTags(':','',':');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/8/8e/Button_shifting.png\" alt=\"Tab\" title=\"Insert tab(s)\"></a>";

  BlockQuoteButton = "<a href=\"javascript:insertTags('<blockquote style=&quot;border: 1px solid blue; padding: 2em;&quot;>\\n','\\n</blockquote>','Block quote');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png\" alt=\"Block quote\" title=\"Insert block of quoted text\"></a>";

  FontColorButton = "<a href=\"javascript:insertTags('<span style=&quot;color: ColorName&quot;>','</span>','Span of text');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/1/1e/Button_font_color.png\" alt=\"Color\" title=\"Insert colored text\"></a>";

  CodeButton = "<a href=\"javascript:insertTags('<code>','</code>','Code');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/2/23/Button_code.png\" alt=\"Code\" title=\"Insert code\"></a>";

  SubLinkButton = "<a href=\"javascript:insertTags('[[Page#',']]','Sub_page');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/9/93/Button_sub_link.png\" alt=\"sub-page link\" title=\"Insert link to sub-page\"></a>";

  DefinitionListCodeButton = "<a href=\"javascript:insertTags('\\n; ',' : ','Insert text');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/d/d3/Button_definition_list.png\" alt=\"Definition\" title=\"Insert definition list\"></a>";

 

/* ابزار اضافه */


/*ناقص*/
Stub= " | <a href=\"javascript:insertTags('','{{ناقص}}','');\">ن</a>";

/*نامزد حذف سریع*/
Del= " | <a href=\"javascript:insertTags('','{{حذف سریع}}','');\">حذ</a>";

/* ویکی‌سازی*/
Wfy= " | <a href=\"javascript:insertTags('{{ویکی‌سازی}}','','');\">ویک</a>";

/*تمیزکاری*/
Rer= " | <a href=\"javascript:insertTags('{{تمیزکاری}}','','');\">تم</a>";

/* بدون منبع*/
NoS= " | <a href=\"javascript:insertTags('{{بدون منبع}}','','');\">بی‌م</a>";

/* حق تکثیر مشکوک*/
Sus= " | <a href=\"javascript:insertTags('{{حق تکثیر مشکوک}}','','');\">مشک</a>";

/*لحن نامناسب*/
Tone= " | <a href=\"javascript:insertTags('{{لحن نامناسب}}','','');\">لحن</a>";

/*منبع تصویر نامعلوم*/
Pic= " | <a href=\"javascript:insertTags('','{{منبع تصویر نامعلوم}}','');\">تص</a>";

/*ی‌ک‌عربی*/
YKArabic = " | <a href=\"javascript:YKarabic(document.editform.wpTextbox1);\">ي‌ك</a>";

/*فارسی‌سازی ارقام*/
Dig= " | <a href=\"javascript:digits(document.editform.wpTextbox1);\">123</a>|";


tooly.innerHTML = Stub + Del + Wfy + Rer + NoS + Sus + Tone + Pic + YKArabic + Dig + URLFIX + StrikeTextButton + LeftTexttButton + CenterTextButton + TableButton + EenterButton + UpperTextButton + LowerTextlButton + SmallTextButton + CommentButton + GalleryButton + SecondaryHeadlineButton + ShiftingButton + BlockQuoteButton + FontColorButton + CodeButton + SubLinkButton + DefinitionListCodeButton + tooly.innerHTML;
}
}
window.onload = InsertButtonsToToolBar;
/*</pre>*/