Эзоҳ: Баъди захира намудан, Шумо метавонед тағйиротҳои худро аз хотираи браузер гузариш карда, бубинед. Дар браузерҳои Mozilla / Firefox / Safari: тугмаи Shift-ро пахш намуда бо мушак Reload-ро пахш кунед, ё Ctrl-Shift-R-ро пахш намоед (Cmd-Shift-R барои компютерҳои Apple Mac); дар браузери IE: тугмаи Ctrl-ро пахш намуда бо мушак Refresh-ро пахш намоед, ё Ctrl-F5-ро пахш намоед; дар браузери Konqueror:: бо мушак Reload-ро пахш кунед, ё тугмаи F5-ро пахш намоед; дар браузери Opera ба Шумо пурра тоза кардани хотираи браузер ба воситаи Tools→Preferences лозим аст.

/*<pre>*/
/* isiri2901-tg.js - Tajik keyboard based on the Persian ISIRI-2901
 *
 * 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
 * Copyright (C) 2006  Kaveh D.
 *
 * 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.
 * Sep 02, 2006  Converted to Tajik.
 *
 * Licensed under GNU GPL.
 */

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

// Tajik keyboard map based on the Persian ISIRI-2901

var isirikey = [
  0x0020, 0x0021, 0x061B, 0x066B, 0xFDFC, 0x066A, 0x060C, 0x0433,
  0x0028, 0x0029, 0x002A, 0x002B, 0x0432, 0x002D, 0x002E, 0x002F,
  0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7,
  0x06F8, 0x06F9, 0x003A, 0x043A, 0x003E, 0x003D, 0x003C, 0x061F,
  0x066C, 0x0624, 0x200C, 0x0436, 0x0439, 0x064D, 0x0625, 0x0623,
  0x0622, 0x0651, 0x0629, 0x00BB, 0x00AB, 0x0621, 0x0654, 0x005D,
  0x005B, 0x0652, 0x064B, 0x0626, 0x0443, 0x0430, 0x0670, 0x064C,
  0x0653, 0x0435, 0x0643, 0x04B7, 0x005C, 0x0447, 0x00D7, 0x0640,
  0x200D, 0x0448, 0x0437, 0x0437, 0x0435, 0x0441, 0x0431, 0x043B,
  0x043E, 0x04B3, 0x0442, 0x043D, 0x043C, 0x043F, 0x0434, 0x0445,
  0x04B3, 0x0437, 0x0493, 0x0441, 0x0444, 0x044A, 0x0440, 0x0441,
  0x0442, 0x0493, 0x0437, 0x007D, 0x007C, 0x007B, 0x007E
];

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

function TajikKeyPress(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;
    setTajik();
  } 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 Tajik

    // 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 setTajik (obj, quiet)
{
  isiri2901_lang = 1;
  if (obj) {
//    obj.style.textAlign = "right";
//    obj.style.direction = "rtl";
    obj.focus();
  }
  if (!quiet)
    window.defaultStatus = "Tajik 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 Tajik)";
}


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
        setTajik(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",TajikKeyDown,false); 
document.addEventListener("keypress",TajikKeyPress,false); 
}else{ 
 //code for IE 
document.attachEvent("onkeydown",TajikKeyDown);
document.attachEvent("onkeypress",TajikKeyPress); 
}

}

}
);
/*</pre>*/