home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / editor / EdInsertChars.js < prev    next >
Encoding:
JavaScript  |  2001-08-30  |  14.4 KB  |  577 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Baki Bon <bakibon@yahoo.com>   (original author)
  22.  */
  23.  
  24. //------------------------------------------------------------------
  25. // From Unicode 3.0 Page 54. 3.11 Conjoining Jamo Behavior
  26. var SBase = 0xac00;
  27. var LBase = 0x1100;
  28. var VBase = 0x1161;
  29. var TBase = 0x11A7;
  30. var LCount = 19;
  31. var VCount = 21;
  32. var TCount = 28;
  33. var NCount = VCount * TCount;
  34. // End of Unicode 3.0
  35.  
  36. // dialog initialization code
  37. function Startup()
  38. {
  39.   if (!InitEditorShell())
  40.     return;
  41.  
  42.   StartupLatin();
  43.  
  44.   doSetOKCancel(onOK, Cancel);
  45.  
  46.  
  47.   // Dialog is non-modal:
  48.   // Change "Ok" to "Insert, change "Cancel" to "Close"
  49.   var okButton = document.getElementById("ok");
  50.   if (okButton)
  51.     okButton.setAttribute("label", GetString("Insert"));
  52.  
  53.   var cancelButton = document.getElementById("cancel");
  54.   if (cancelButton)
  55.     cancelButton.setAttribute("label", GetString("Close"));
  56.  
  57.   // Set a variable on the opener window so we
  58.   //  can track ownership of close this window with it
  59.   window.opener.InsertCharWindow = window;
  60.   window.sizeToContent();
  61.  
  62.   SetWindowLocation();
  63. }
  64.  
  65. function onOK()
  66. {
  67.   // Insert the character
  68.   // Note: Assiated parent window and editorShell
  69.   //  will be changed to whatever editor window has the focus
  70.   window.editorShell.InsertSource(LatinChar);
  71.  
  72.   // Set persistent attributes to save
  73.   //  which category, letter, and character modifier was used
  74.   CategoryGroup.setAttribute("category", category);
  75.   CategoryGroup.setAttribute("letter_index", indexL);
  76.   CategoryGroup.setAttribute("char_index", indexM);
  77.  
  78.   // Return true only for modal window
  79.   //return true;
  80. }
  81.  
  82. function Unload()
  83. {
  84.   window.opener.InsertCharWindow = null;
  85.   SaveWindowLocation();
  86. }
  87.  
  88. function Cancel()
  89. {
  90.   // This will trigger call to "Unload()"
  91.   window.close();
  92. }
  93.  
  94. //------------------------------------------------------------------
  95. var LatinL;
  96. var LatinM;
  97. var LatinL_Label;
  98. var LatinM_Label;
  99. var LatinChar;
  100. var indexL=0;
  101. var indexM=0;
  102. var indexM_AU=0;
  103. var indexM_AL=0;
  104. var indexM_U=0;
  105. var indexM_L=0;
  106. var indexM_S=0;
  107. var LItems=0;
  108. var category;
  109. var CategoryGroup;
  110. var initialize = true;
  111.  
  112. function StartupLatin()
  113. {
  114.  
  115.   LatinL = document.getElementById("LatinL");
  116.   LatinM = document.getElementById("LatinM");
  117.   LatinL_Label = document.getElementById("LatinL_Label");
  118.   LatinM_Label = document.getElementById("LatinM_Label");
  119.  
  120.   var Symbol      = document.getElementById("Symbol");
  121.   var AccentUpper = document.getElementById("AccentUpper");
  122.   var AccentLower = document.getElementById("AccentUpper");
  123.   var Upper       = document.getElementById("Upper");
  124.   var Lower       = document.getElementById("Lower");
  125.   CategoryGroup   = document.getElementById("CatGrp");
  126.  
  127.   // Initialize which radio button is set from persistent attribute...
  128.   var category = CategoryGroup.getAttribute("category");
  129.  
  130.   // ...as well as indexes into the letter and character lists
  131.   var index = Number(CategoryGroup.getAttribute("letter_index"));
  132.   if (index && index >= 0)
  133.     indexL = index;
  134.   index = Number(CategoryGroup.getAttribute("char_index"));
  135.   if (index && index >= 0)
  136.     indexM = index;
  137.  
  138.  
  139.   switch (category)
  140.   {
  141.     case "AccentUpper": // Uppercase Diacritical
  142.       AccentUpper.checked = true;
  143.       indexM_AU = indexM;
  144.       break;
  145.     case "AccentLower": // Lowercase Diacritical
  146.       AccentLower.checked = true;
  147.       indexM_AL = indexM;
  148.       break;
  149.     case "Upper": // Uppercase w/o Diacritical
  150.       Upper.checked = true;
  151.       indexM_U = indexM;
  152.       break;
  153.     case "Lower": // Lowercase w/o Diacritical
  154.       Lower.checked = true;
  155.       indexM_L = indexM;
  156.       break;
  157.     default:
  158.       category = "Symbol";
  159.       Symbol.checked = true;
  160.       indexM_S = indexM;
  161.       break;
  162.   }
  163.  
  164.   ChangeCategory(category);
  165.   initialize = false;
  166. }
  167.  
  168. function ChangeCategory(newCategory)
  169. {
  170.   if (category != newCategory || initialize)
  171.   {
  172.     category = newCategory;
  173.     // Note: Must do L before M to set LatinL.selectedIndex
  174.     UpdateLatinL();
  175.     UpdateLatinM();
  176.     UpdateCharacter();
  177.   }
  178. }
  179.  
  180. function SelectLatinLetter()
  181. {
  182.   if(LatinL.selectedIndex != indexL )
  183.   {
  184.     indexL = LatinL.selectedIndex;
  185.     UpdateLatinM();
  186.     UpdateCharacter();
  187.   }
  188. }
  189.  
  190. function SelectLatinModifier()
  191. {
  192.   if(LatinM.selectedIndex != indexM )
  193.   {
  194.     indexM = LatinM.selectedIndex;
  195.     UpdateCharacter();
  196.   }
  197. }
  198. function DisableLatinL(disable)
  199. {
  200.   LatinL_Label.setAttribute("disabled", disable ? "true" : "false");
  201. }
  202.  
  203. function UpdateLatinL()
  204. {
  205.   ClearMenulist(LatinL);
  206.   if (category == "AccentUpper" || category == "AccentLower")
  207.   {
  208.     DisableLatinL(false);
  209.     var basic;
  210.  
  211.     // Fill the list
  212.     if (category == "AccentUpper")   // Uppercase Diacritical
  213.     {
  214.       for(basic=0; basic < 26; basic++)
  215.         AppendStringToMenulist(LatinL , String.fromCharCode(0x41 + basic));
  216.     }
  217.     else  // Lowercase Diacritical
  218.     {
  219.       for(basic=0; basic < 26; basic++)
  220.        AppendStringToMenulist(LatinL , String.fromCharCode(0x61 + basic));
  221.     }
  222.     // Set the selected item
  223.     if (indexL > 25)
  224.       indexL = 25;
  225.     LatinL.selectedIndex = indexL;
  226.   }
  227.   else
  228.   {
  229.     // Other categories don't hinge on a "letter"
  230.     DisableLatinL(true);
  231.     // Note: don't change the indexL so it can be used next time
  232.   }
  233. }
  234.  
  235. function UpdateLatinM()
  236. {
  237.   ClearMenulist(LatinM);
  238.   var i, basic;
  239.   switch(category)
  240.   {
  241.     case "AccentUpper": // Uppercase Diacritical
  242.       for(basic=0; basic < upper[indexL].length; basic++)
  243.         AppendStringToMenulist(LatinM ,
  244.              String.fromCharCode(upper[indexL][basic]));
  245.  
  246.       if(indexM_AU < upper[indexL].length)
  247.         indexM = indexM_AU;
  248.       else
  249.         indexM = upper[indexL].length - 1;
  250.       indexM_AU = indexM;
  251.       break;
  252.  
  253.     case "AccentLower": // Lowercase Diacritical
  254.       for(basic=0; basic < lower[indexL].length; basic++)
  255.         AppendStringToMenulist(LatinM ,
  256.              String.fromCharCode(lower[indexL][basic]));
  257.  
  258.       if(indexM_AL < lower[indexL].length)
  259.         indexM = indexM_AL;
  260.       else
  261.         indexM = lower[indexL].length - 1;
  262.       indexM_AL = indexM;
  263.       break;
  264.  
  265.     case "Upper": // Uppercase w/o Diacritical
  266.       for(i=0; i < otherupper.length; i++)
  267.         AppendStringToMenulist(LatinM, String.fromCharCode(otherupper[i]));
  268.  
  269.       if(indexM_U < otherupper.length)
  270.         indexM = indexM_U;
  271.       else
  272.         indexM = otherupper.length - 1;
  273.       indexM_U = indexM;
  274.       break;
  275.  
  276.     case "Lower": // Lowercase w/o Diacritical
  277.       for(i=0; i < otherlower.length; i++)
  278.         AppendStringToMenulist(LatinM , String.fromCharCode(otherlower[i]));
  279.  
  280.       if(indexM_L < otherlower.length)
  281.         indexM = indexM_L;
  282.       else
  283.         indexM = otherlower.length - 1;
  284.       indexM_L = indexM;
  285.       break;
  286.  
  287.     case "Symbol": // Symbol
  288.       for(i=0; i < symbol.length; i++)
  289.         AppendStringToMenulist(LatinM , String.fromCharCode(symbol[i]));
  290.  
  291.       if(indexM_S < symbol.length)
  292.         indexM = indexM_S;
  293.       else
  294.         indexM = symbol.length - 1;
  295.       indexM_S = indexM;
  296.       break;
  297.   }
  298.   LatinM.selectedIndex = indexM;
  299. }
  300.  
  301. function UpdateCharacter()
  302. {
  303.   indexM = LatinM.selectedIndex;
  304.  
  305.   switch(category)
  306.   {
  307.     case "AccentUpper": // Uppercase Diacritical
  308.       LatinChar = String.fromCharCode(upper[indexL][indexM]);
  309.       indexM_AU = indexM;
  310.       break;
  311.     case "AccentLower": // Lowercase Diacritical
  312.       LatinChar = String.fromCharCode(lower[indexL][indexM]);
  313.       indexM_AL = indexM;
  314.       break;
  315.     case "Upper": // Uppercase w/o Diacritical
  316.       LatinChar = String.fromCharCode(otherupper[indexM]);
  317.       indexM_U = indexM;
  318.       break;
  319.     case "Lower": // Lowercase w/o Diacritical
  320.       LatinChar = String.fromCharCode(otherlower[indexM]);
  321.       indexM_L = indexM;
  322.       break;
  323.     case "Symbol":
  324.       LatinChar =  String.fromCharCode(symbol[indexM]);
  325.       indexM_S = indexM;
  326.       break;
  327.   }
  328. //dump("Letter Index="+indexL+", Character Index="+indexM+", Character = "+LatinChar+"\n");
  329. }
  330.  
  331. var upper=[
  332. [ // A
  333.   0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5,
  334.   0x0100, 0x0102, 0x0104, 0x01cd, 0x01de, 0x01de, 0x01e0, 0x01fa,
  335.   0x0200, 0x0202, 0x0226,
  336.   0x1e00, 0x1ea0, 0x1ea2, 0x1ea4, 0x1ea6, 0x1ea8, 0x1eaa, 0x1eac,
  337.   0x1eae, 0x1eb0, 0x1eb2, 0x1eb4, 0x1eb6
  338. ], [ // B
  339.   0x0181, 0x0182, 0x0184,
  340.   0x1e02, 0x1e04, 0x1e06
  341. ], [ // C
  342.   0x00c7, 0x0106, 0x0108, 0x010a, 0x010c,
  343.   0x0187,
  344.   0x1e08
  345. ], [ // D
  346.   0x010e, 0x0110,
  347.   0x0189,
  348.   0x018a,
  349.   0x1e0a, 0x1e0c, 0x1e0e, 0x1e10, 0x1e12
  350. ], [ // E
  351.   0x00C8, 0x00C9, 0x00CA, 0x00CB,
  352.   0x0112, 0x0114, 0x0116, 0x0118, 0x011A,
  353.   0x0204, 0x0206, 0x0228,
  354.   0x1e14, 0x1e16, 0x1e18, 0x1e1a, 0x1e1c,
  355.   0x1eb8, 0x1eba, 0x1ebc, 0x1ebe, 0x1ec0, 0x1ec2, 0x1ec4, 0x1ec6
  356. ], [ // F
  357.   0x1e1e
  358. ], [ // G
  359.   0x011c, 0x011E, 0x0120, 0x0122,
  360.   0x01e4, 0x01e6, 0x01f4,
  361.   0x1e20
  362. ], [ // H
  363.   0x0124, 0x0126,
  364.   0x021e,
  365.   0x1e22, 0x1e24, 0x1e26, 0x1e28, 0x1e2a
  366. ], [ // I
  367.   0x00CC, 0x00CD, 0x00CE, 0x00CF,
  368.   0x0128, 0x012a, 0x012C, 0x012e, 0x0130,
  369.   0x0208, 0x020a,
  370.   0x1e2c, 0x1e2e,
  371.   0x1ec8, 0x1eca
  372. ], [ // J
  373.   0x0134,
  374.   0x01f0
  375. ], [ // K
  376.   0x0136,
  377.   0x0198, 0x01e8,
  378.   0x1e30, 0x1e32, 0x1e34
  379. ], [ // L
  380.   0x0139, 0x013B, 0x013D, 0x013F, 0x0141,
  381.   0x1e36, 0x1e38, 0x1e3a, 0x1e3c
  382. ], [ // M
  383.   0x1e3e, 0x1e40, 0x1e42
  384. ], [ // N
  385.   0x00D1,
  386.   0x0143, 0x0145, 0x0147, 0x014A,
  387.   0x01F8,
  388.   0x1e44, 0x1e46, 0x1e48, 0x1e4a
  389. ], [ // O
  390.   0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6,
  391.   0x014C, 0x014E, 0x0150,
  392.   0x01ea, 0x01ec,
  393.   0x020c, 0x020e, 0x022A, 0x022C, 0x022E, 0x0230,
  394.   0x1e4c, 0x1e4e, 0x1e50, 0x1e52,
  395.   0x1ecc, 0x1ece, 0x1ed0, 0x1ed2, 0x1ed4, 0x1ed6, 0x1ed8, 0x1eda, 0x1edc, 0x1ede,
  396.   0x1ee0, 0x1ee2
  397. ], [ // P
  398.   0x1e54, 0x1e56
  399. ], [ // Q
  400.   0x0051
  401. ], [ // R
  402.   0x0154, 0x0156, 0x0158,
  403.   0x0210, 0x0212,
  404.   0x1e58, 0x1e5a, 0x1e5c, 0x1e5e
  405. ], [ // S
  406.   0x015A, 0x015C, 0x015E, 0x0160,
  407.   0x0218,
  408.   0x1e60, 0x1e62, 0x1e64, 0x1e66, 0x1e68
  409. ], [ // T
  410.   0x0162, 0x0164, 0x0166,
  411.   0x021A,
  412.   0x1e6a, 0x1e6c, 0x1e6e, 0x1e70
  413. ], [ // U
  414.   0x00D9, 0x00DA, 0x00DB, 0x00DC,
  415.   0x0168, 0x016A, 0x016C, 0x016E, 0x0170, 0x0172,
  416.   0x0214, 0x0216,
  417.   0x1e72, 0x1e74, 0x1e76, 0x1e78, 0x1e7a,
  418.   0x1ee4, 0x1ee6, 0x1ee8, 0x1eea, 0x1eec, 0x1eee, 0x1ef0
  419. ], [ // V
  420.   0x1e7c, 0x1e7e
  421. ], [ // W
  422.   0x0174,
  423.   0x1e80, 0x1e82, 0x1e84, 0x1e86, 0x1e88
  424. ], [ // X
  425.   0x1e8a, 0x1e8c
  426. ], [ // Y
  427.   0x00DD,
  428.   0x0176, 0x0178,
  429.   0x0232,
  430.   0x1e8e,
  431.   0x1ef2, 0x1ef4, 0x1ef6, 0x1ef8
  432. ], [ // Z
  433.   0x0179, 0x017B, 0x017D,
  434.   0x0224,
  435.   0x1e90, 0x1e92, 0x1e94
  436. ] ];
  437. var lower=[
  438. [ // a
  439.   0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5,
  440.   0x0101, 0x0103, 0x0105,
  441.   0x01ce, 0x01df, 0x01e1, 0x01fb,
  442.   0x0201, 0x0203, 0x0227,
  443.   0x1e01, 0x1e9a,
  444.   0x1ea1, 0x1ea3, 0x1ea5, 0x1ea7, 0x1ea9, 0x1eab, 0x1ead, 0x1eaf,
  445.   0x1eb1, 0x1eb3, 0x1eb5, 0x1eb7
  446. ], [ // b
  447.   0x0180, 0x0183, 0x0185,
  448.   0x1e03, 0x1e05, 0x1e07
  449. ], [ // c
  450.   0x00e7,
  451.   0x0107, 0x0109, 0x010b, 0x010d,
  452.   0x0188,
  453.   0x1e09
  454. ], [ // d
  455.   0x010f, 0x0111,
  456.   0x1e0b, 0x1e0d, 0x1e0f, 0x1e11, 0x1e13
  457. ], [ // e
  458.   0x00e8, 0x00e9, 0x00ea, 0x00eb,
  459.   0x0113, 0x0115, 0x0117, 0x0119, 0x011b,
  460.   0x0205, 0x0207, 0x0229,
  461.   0x1e15, 0x1e17, 0x1e19, 0x1e1b, 0x1e1d,
  462.   0x1eb9, 0x1ebb, 0x1ebd, 0x1ebf,
  463.   0x1ec1, 0x1ec3, 0x1ec5, 0x1ec7
  464. ], [ // f
  465.   0x1e1f
  466. ], [ // g
  467.   0x011d, 0x011f, 0x0121, 0x0123,
  468.   0x01e5, 0x01e7, 0x01f5,
  469.   0x1e21
  470. ], [ // h
  471.   0x0125, 0x0127,
  472.   0x021f,
  473.   0x1e23, 0x1e25, 0x1e27, 0x1e29, 0x1e2b, 0x1e96
  474. ], [ // i
  475.   0x00ec, 0x00ed, 0x00ee, 0x00ef,
  476.   0x0129, 0x012b, 0x012d, 0x012f, 0x0131,
  477.   0x01d0,
  478.   0x0209, 0x020b,
  479.   0x1e2d, 0x1e2f,
  480.   0x1ec9, 0x1ecb
  481. ], [ // j
  482.   0x0135,
  483. ], [ // k
  484.   0x0137, 0x0138,
  485.   0x01e9,
  486.   0x1e31, 0x1e33, 0x1e35
  487. ], [ // l
  488.   0x013a, 0x013c, 0x013e, 0x0140, 0x0142,
  489.   0x1e37, 0x1e39, 0x1e3b, 0x1e3d
  490. ], [ // m
  491.   0x1e3f, 0x1e41, 0x1e43
  492. ], [ // n
  493.   0x00f1,
  494.   0x0144, 0x0146, 0x0148, 0x0149, 0x014b,
  495.   0x01f9,
  496.   0x1e45, 0x1e47, 0x1e49, 0x1e4b
  497. ], [ // o
  498.   0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6,
  499.   0x014d, 0x014f, 0x0151,
  500.   0x01d2, 0x01eb, 0x01ed,
  501.   0x020d, 0x020e, 0x022b, 0x22d, 0x022f, 0x0231,
  502.   0x1e4d, 0x1e4f, 0x1e51, 0x1e53,
  503.   0x1ecd, 0x1ecf,
  504.   0x1ed1, 0x1ed3, 0x1ed5, 0x1ed7, 0x1ed9, 0x1edb, 0x1edd, 0x1edf,
  505.   0x1ee1, 0x1ee3
  506. ], [ // p
  507.   0x1e55, 0x1e57
  508. ], [ // q
  509.   0x0071
  510. ], [ // r
  511.   0x0155, 0x0157, 0x0159,
  512.   0x0211, 0x0213,
  513.   0x1e59, 0x1e5b, 0x1e5d, 0x1e5f
  514. ], [ // s
  515.   0x015b, 0x015d, 0x015f, 0x0161,
  516.   0x0219,
  517.   0x1e61, 0x1e63, 0x1e65, 0x1e67, 0x1e69
  518. ], [ // t
  519.   0x0162, 0x0163, 0x0165, 0x0167,
  520.   0x021b,
  521.   0x1e6b, 0x1e6d, 0x1e6f, 0x1e71,
  522.   0x1e97
  523. ], [ // u
  524.   0x00f9, 0x00fa, 0x00fb, 0x00fc,
  525.   0x0169, 0x016b, 0x016d, 0x016f, 0x0171, 0x0173,
  526.   0x01d4, 0x01d6, 0x01d8, 0x01da, 0x01dc,
  527.   0x0215, 0x0217,
  528.   0x1e73, 0x1e75, 0x1e77, 0x1e79, 0x1e7b,
  529.   0x1ee5, 0x1ee7, 0x1ee9, 0x1eeb, 0x1eed, 0x1eef,
  530.   0x1ef1
  531. ], [ // v
  532.   0x1e7d, 0x1e7f
  533. ], [ // w
  534.   0x0175,
  535.   0x1e81, 0x1e83, 0x1e85, 0x1e87, 0x1e89, 0x1e98,
  536. ], [ // x
  537.   0x1e8b, 0x1e8d
  538. ], [ // y
  539.   0x00fd, 0x00ff,
  540.   0x0177,
  541.   0x0233,
  542.   0x1e8f, 0x1e99, 0x1ef3, 0x1ef5, 0x1ef7, 0x1ef9
  543. ], [ // z
  544.   0x017a, 0x017c, 0x017e,
  545.   0x0225,
  546.   0x1e91, 0x1e93, 0x1e95
  547. ] ];
  548.  
  549.  
  550. var symbol = [
  551.         0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
  552. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac,         0x00ae, 0x00af,
  553. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
  554. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
  555. 0x00d7, 0x00f7
  556. ];
  557.  
  558. var otherupper = [
  559. 0x00c6, 0x00d0, 0x00d8, 0x00de,
  560. 0x0132,
  561. 0x0152,
  562. 0x0186,
  563. 0x01c4, 0x01c5,
  564. 0x01c7, 0x01c8,
  565. 0x01ca, 0x01cb,
  566. 0x01F1, 0x01f2
  567. ];
  568. var otherlower = [
  569. 0x00e6, 0x00f0, 0x00f8, 0x00fe, 0x00df,
  570. 0x0133,
  571. 0x0153,
  572. 0x01c6,
  573. 0x01c9,
  574. 0x01cc,
  575. 0x01f3
  576. ];
  577.