~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/composer/base/dialogs/EdInsertChars.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *   Charles Manske (cmanske@netscape.com)
 
23
 *   Neil Rashbrook (neil@parkwaycc.co.uk)
 
24
 */
 
25
 
 
26
//------------------------------------------------------------------
 
27
// From Unicode 3.0 Page 54. 3.11 Conjoining Jamo Behavior
 
28
var SBase = 0xac00;
 
29
var LBase = 0x1100;
 
30
var VBase = 0x1161;
 
31
var TBase = 0x11A7;
 
32
var LCount = 19;
 
33
var VCount = 21;
 
34
var TCount = 28;
 
35
var NCount = VCount * TCount;
 
36
// End of Unicode 3.0
 
37
 
 
38
// dialog initialization code
 
39
function Startup()
 
40
{
 
41
  if (!GetCurrentEditor())
 
42
  {
 
43
    window.close();
 
44
    return;
 
45
  }
 
46
 
 
47
  StartupLatin();
 
48
 
 
49
  // Dialog is non-modal:
 
50
  // Change button text: "Ok" to "Insert"; "Cancel" to "Close"
 
51
  var insertButton = document.documentElement.getButton("accept");
 
52
  if (insertButton)
 
53
  {
 
54
    insertButton.setAttribute("label", GetString("Insert"));
 
55
    insertButton.setAttribute("accesskey", GetString("InsertAccessKey"));
 
56
  }
 
57
 
 
58
  var cancelButton = document.getElementById("insertCharsDlg").getButton("cancel");
 
59
  if (cancelButton)
 
60
    cancelButton.setAttribute("label", GetString("Close"));
 
61
 
 
62
  // Set a variable on the opener window so we
 
63
  //  can track ownership of close this window with it
 
64
  window.opener.InsertCharWindow = window;
 
65
  window.sizeToContent();
 
66
 
 
67
  SetWindowLocation();
 
68
}
 
69
 
 
70
function onAccept()
 
71
{
 
72
  // Insert the character
 
73
  try {
 
74
    GetCurrentEditor().insertText(LatinM.label);
 
75
  } catch(e) {}
 
76
 
 
77
  // Set persistent attributes to save
 
78
  //  which category, letter, and character modifier was used
 
79
  CategoryGroup.setAttribute("category", category);
 
80
  CategoryGroup.setAttribute("letter_index", indexL);
 
81
  CategoryGroup.setAttribute("char_index", indexM);
 
82
  
 
83
  // Don't close the dialog
 
84
  return false;
 
85
}
 
86
 
 
87
// Don't allow inserting in HTML Source Mode
 
88
function onFocus()
 
89
{
 
90
  var enable = true;
 
91
  if ("gEditorDisplayMode" in window.opener)
 
92
    enable = !window.opener.IsInHTMLSourceMode();
 
93
 
 
94
  SetElementEnabled(document.documentElement.getButton("accept"), enable);
 
95
}
 
96
 
 
97
function onClose()
 
98
{
 
99
  window.opener.InsertCharWindow = null;
 
100
  SaveWindowLocation();
 
101
  return true;
 
102
}
 
103
 
 
104
//------------------------------------------------------------------
 
105
var LatinL;
 
106
var LatinM;
 
107
var LatinL_Label;
 
108
var LatinM_Label;
 
109
var indexL=0;
 
110
var indexM=0;
 
111
var indexM_AU=0;
 
112
var indexM_AL=0;
 
113
var indexM_U=0;
 
114
var indexM_L=0;
 
115
var indexM_S=0;
 
116
var LItems=0;
 
117
var category;
 
118
var CategoryGroup;
 
119
var initialize = true;
 
120
 
 
121
function StartupLatin()
 
122
{
 
123
 
 
124
  LatinL = document.getElementById("LatinL");
 
125
  LatinM = document.getElementById("LatinM");
 
126
  LatinL_Label = document.getElementById("LatinL_Label");
 
127
  LatinM_Label = document.getElementById("LatinM_Label");
 
128
 
 
129
  var Symbol      = document.getElementById("Symbol");
 
130
  var AccentUpper = document.getElementById("AccentUpper");
 
131
  var AccentLower = document.getElementById("AccentLower");
 
132
  var Upper       = document.getElementById("Upper");
 
133
  var Lower       = document.getElementById("Lower");
 
134
  CategoryGroup   = document.getElementById("CatGrp");
 
135
 
 
136
  // Initialize which radio button is set from persistent attribute...
 
137
  var category = CategoryGroup.getAttribute("category");
 
138
 
 
139
  // ...as well as indexes into the letter and character lists
 
140
  var index = Number(CategoryGroup.getAttribute("letter_index"));
 
141
  if (index && index >= 0)
 
142
    indexL = index;
 
143
  index = Number(CategoryGroup.getAttribute("char_index"));
 
144
  if (index && index >= 0)
 
145
    indexM = index;
 
146
 
 
147
 
 
148
  switch (category)
 
149
  {
 
150
    case "AccentUpper": // Uppercase Diacritical
 
151
      CategoryGroup.selectedItem = AccentUpper;
 
152
      indexM_AU = indexM;
 
153
      break;
 
154
    case "AccentLower": // Lowercase Diacritical
 
155
      CategoryGroup.selectedItem = AccentLower;
 
156
      indexM_AL = indexM;
 
157
      break;
 
158
    case "Upper": // Uppercase w/o Diacritical
 
159
      CategoryGroup.selectedItem = Upper;
 
160
      indexM_U = indexM;
 
161
      break;
 
162
    case "Lower": // Lowercase w/o Diacritical
 
163
      CategoryGroup.selectedItem = Lower;
 
164
      indexM_L = indexM;
 
165
      break;
 
166
    default:
 
167
      category = "Symbol";
 
168
      CategoryGroup.selectedItem = Symbol;
 
169
      indexM_S = indexM;
 
170
      break;
 
171
  }
 
172
 
 
173
  ChangeCategory(category);
 
174
  initialize = false;
 
175
}
 
176
 
 
177
function ChangeCategory(newCategory)
 
178
{
 
179
  if (category != newCategory || initialize)
 
180
  {
 
181
    category = newCategory;
 
182
    // Note: Must do L before M to set LatinL.selectedIndex
 
183
    UpdateLatinL();
 
184
    UpdateLatinM();
 
185
    UpdateCharacter();
 
186
  }
 
187
}
 
188
 
 
189
function SelectLatinLetter()
 
190
{
 
191
  if(LatinL.selectedIndex != indexL )
 
192
  {
 
193
    indexL = LatinL.selectedIndex;
 
194
    UpdateLatinM();
 
195
    UpdateCharacter();
 
196
  }
 
197
}
 
198
 
 
199
function SelectLatinModifier()
 
200
{
 
201
  if(LatinM.selectedIndex != indexM )
 
202
  {
 
203
    indexM = LatinM.selectedIndex;
 
204
    UpdateCharacter();
 
205
  }
 
206
}
 
207
function DisableLatinL(disable)
 
208
{
 
209
  if (disable) {
 
210
    LatinL_Label.setAttribute("disabled", "true");
 
211
    LatinL.setAttribute("disabled", "true");
 
212
  } else {
 
213
    LatinL_Label.removeAttribute("disabled");
 
214
    LatinL.removeAttribute("disabled");
 
215
  }
 
216
}
 
217
 
 
218
function UpdateLatinL()
 
219
{
 
220
  LatinL.removeAllItems();
 
221
  if (category == "AccentUpper" || category == "AccentLower")
 
222
  {
 
223
    DisableLatinL(false);
 
224
    // No Q or q
 
225
    var alphabet = category == "AccentUpper" ? "ABCDEFGHIJKLMNOPRSTUVWXYZ" : "abcdefghijklmnoprstuvwxyz";
 
226
    for (var letter = 0; letter < alphabet.length; letter++)
 
227
      LatinL.appendItem(alphabet.charAt(letter));
 
228
 
 
229
    LatinL.selectedIndex = indexL;
 
230
  }
 
231
  else
 
232
  {
 
233
    // Other categories don't hinge on a "letter"
 
234
    DisableLatinL(true);
 
235
    // Note: don't change the indexL so it can be used next time
 
236
  }
 
237
}
 
238
 
 
239
function UpdateLatinM()
 
240
{
 
241
  LatinM.removeAllItems();
 
242
  var i, accent;
 
243
  switch(category)
 
244
  {
 
245
    case "AccentUpper": // Uppercase Diacritical
 
246
      accent = upper[indexL];
 
247
      for(i=0; i < accent.length; i++)
 
248
        LatinM.appendItem(accent.charAt(i));
 
249
 
 
250
      if(indexM_AU < accent.length)
 
251
        indexM = indexM_AU;
 
252
      else
 
253
        indexM = accent.length - 1;
 
254
      indexM_AU = indexM;
 
255
      break;
 
256
 
 
257
    case "AccentLower": // Lowercase Diacritical
 
258
      accent = lower[indexL];
 
259
      for(i=0; i < accent.length; i++)
 
260
        LatinM.appendItem(accent.charAt(i));
 
261
 
 
262
      if(indexM_AL < accent.length)
 
263
        indexM = indexM_AL;
 
264
      else
 
265
        indexM = lower[indexL].length - 1;
 
266
      indexM_AL = indexM;
 
267
      break;
 
268
 
 
269
    case "Upper": // Uppercase w/o Diacritical
 
270
      for(i=0; i < otherupper.length; i++)
 
271
        LatinM.appendItem(otherupper.charAt(i));
 
272
 
 
273
      if(indexM_U < otherupper.length)
 
274
        indexM = indexM_U;
 
275
      else
 
276
        indexM = otherupper.length - 1;
 
277
      indexM_U = indexM;
 
278
      break;
 
279
 
 
280
    case "Lower": // Lowercase w/o Diacritical
 
281
      for(i=0; i < otherlower.length; i++)
 
282
        LatinM.appendItem(otherlower.charAt(i));
 
283
 
 
284
      if(indexM_L < otherlower.length)
 
285
        indexM = indexM_L;
 
286
      else
 
287
        indexM = otherlower.length - 1;
 
288
      indexM_L = indexM;
 
289
      break;
 
290
 
 
291
    case "Symbol": // Symbol
 
292
      for(i=0; i < symbol.length; i++)
 
293
        LatinM.appendItem(symbol.charAt(i));
 
294
 
 
295
      if(indexM_S < symbol.length)
 
296
        indexM = indexM_S;
 
297
      else
 
298
        indexM = symbol.length - 1;
 
299
      indexM_S = indexM;
 
300
      break;
 
301
  }
 
302
  LatinM.selectedIndex = indexM;
 
303
}
 
304
 
 
305
function UpdateCharacter()
 
306
{
 
307
  indexM = LatinM.selectedIndex;
 
308
 
 
309
  switch(category)
 
310
  {
 
311
    case "AccentUpper": // Uppercase Diacritical
 
312
      indexM_AU = indexM;
 
313
      break;
 
314
    case "AccentLower": // Lowercase Diacritical
 
315
      indexM_AL = indexM;
 
316
      break;
 
317
    case "Upper": // Uppercase w/o Diacritical
 
318
      indexM_U = indexM;
 
319
      break;
 
320
    case "Lower": // Lowercase w/o Diacritical
 
321
      indexM_L = indexM;
 
322
      break;
 
323
    case "Symbol":
 
324
      indexM_S = indexM;
 
325
      break;
 
326
  }
 
327
//dump("Letter Index="+indexL+", Character Index="+indexM+", Character = "+LatinM.label+"\n");
 
328
}
 
329
 
 
330
const upper=[
 
331
  // A
 
332
  "\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u0100\u0102\u0104\u01cd\u01de\u01de\u01e0\u01fa\u0200\u0202\u0226\u1e00\u1ea0\u1ea2\u1ea4\u1ea6\u1ea8\u1eaa\u1eac\u1eae\u1eb0\u1eb2\u1eb4\u1eb6",
 
333
  // B
 
334
  "\u0181\u0182\u0184\u1e02\u1e04\u1e06",
 
335
  // C
 
336
  "\u00c7\u0106\u0108\u010a\u010c\u0187\u1e08",
 
337
  // D
 
338
  "\u010e\u0110\u0189\u018a\u1e0a\u1e0c\u1e0e\u1e10\u1e12",
 
339
  // E
 
340
  "\u00C8\u00C9\u00CA\u00CB\u0112\u0114\u0116\u0118\u011A\u0204\u0206\u0228\u1e14\u1e16\u1e18\u1e1a\u1e1c\u1eb8\u1eba\u1ebc\u1ebe\u1ec0\u1ec2\u1ec4\u1ec6",
 
341
  // F
 
342
  "\u1e1e",
 
343
  // G
 
344
  "\u011c\u011E\u0120\u0122\u01e4\u01e6\u01f4\u1e20",
 
345
  // H
 
346
  "\u0124\u0126\u021e\u1e22\u1e24\u1e26\u1e28\u1e2a",
 
347
  // I
 
348
  "\u00CC\u00CD\u00CE\u00CF\u0128\u012a\u012C\u012e\u0130\u0208\u020a\u1e2c\u1e2e\u1ec8\u1eca",
 
349
  // J
 
350
  "\u0134\u01f0",
 
351
  // K
 
352
  "\u0136\u0198\u01e8\u1e30\u1e32\u1e34",
 
353
  // L
 
354
  "\u0139\u013B\u013D\u013F\u0141\u1e36\u1e38\u1e3a\u1e3c",
 
355
  // M
 
356
  "\u1e3e\u1e40\u1e42",
 
357
  // N
 
358
  "\u00D1\u0143\u0145\u0147\u014A\u01F8\u1e44\u1e46\u1e48\u1e4a",
 
359
  // O
 
360
  "\u00D2\u00D3\u00D4\u00D5\u00D6\u014C\u014E\u0150\u01ea\u01ec\u020c\u020e\u022A\u022C\u022E\u0230\u1e4c\u1e4e\u1e50\u1e52\u1ecc\u1ece\u1ed0\u1ed2\u1ed4\u1ed6\u1ed8\u1eda\u1edc\u1ede\u1ee0\u1ee2",
 
361
  // P
 
362
  "\u1e54\u1e56",
 
363
  // No Q
 
364
  // R
 
365
  "\u0154\u0156\u0158\u0210\u0212\u1e58\u1e5a\u1e5c\u1e5e",
 
366
  // S
 
367
  "\u015A\u015C\u015E\u0160\u0218\u1e60\u1e62\u1e64\u1e66\u1e68",
 
368
  // T
 
369
  "\u0162\u0164\u0166\u021A\u1e6a\u1e6c\u1e6e\u1e70",
 
370
  // U
 
371
  "\u00D9\u00DA\u00DB\u00DC\u0168\u016A\u016C\u016E\u0170\u0172\u0214\u0216\u1e72\u1e74\u1e76\u1e78\u1e7a\u1ee4\u1ee6\u1ee8\u1eea\u1eec\u1eee\u1ef0",
 
372
  // V
 
373
  "\u1e7c\u1e7e",
 
374
  // W
 
375
  "\u0174\u1e80\u1e82\u1e84\u1e86\u1e88",
 
376
  // X
 
377
  "\u1e8a\u1e8c",
 
378
  // Y
 
379
  "\u00DD\u0176\u0178\u0232\u1e8e\u1ef2\u1ef4\u1ef6\u1ef8",
 
380
  // Z
 
381
  "\u0179\u017B\u017D\u0224\u1e90\u1e92\u1e94"
 
382
];
 
383
 
 
384
const lower=[
 
385
  // a
 
386
  "\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u0101\u0103\u0105\u01ce\u01df\u01e1\u01fb\u0201\u0203\u0227\u1e01\u1e9a\u1ea1\u1ea3\u1ea5\u1ea7\u1ea9\u1eab\u1ead\u1eaf\u1eb1\u1eb3\u1eb5\u1eb7",
 
387
  // b
 
388
  "\u0180\u0183\u0185\u1e03\u1e05\u1e07",
 
389
  // c
 
390
  "\u00e7\u0107\u0109\u010b\u010d\u0188\u1e09",
 
391
  // d
 
392
  "\u010f\u0111\u1e0b\u1e0d\u1e0f\u1e11\u1e13",
 
393
  // e
 
394
  "\u00e8\u00e9\u00ea\u00eb\u0113\u0115\u0117\u0119\u011b\u0205\u0207\u0229\u1e15\u1e17\u1e19\u1e1b\u1e1d\u1eb9\u1ebb\u1ebd\u1ebf\u1ec1\u1ec3\u1ec5\u1ec7",
 
395
  // f
 
396
  "\u1e1f",
 
397
  // g
 
398
  "\u011d\u011f\u0121\u0123\u01e5\u01e7\u01f5\u1e21",
 
399
  // h
 
400
  "\u0125\u0127\u021f\u1e23\u1e25\u1e27\u1e29\u1e2b\u1e96",
 
401
  // i
 
402
  "\u00ec\u00ed\u00ee\u00ef\u0129\u012b\u012d\u012f\u0131\u01d0\u0209\u020b\u1e2d\u1e2f\u1ec9\u1ecb",
 
403
  // j
 
404
  "\u0135",
 
405
  // k
 
406
  "\u0137\u0138\u01e9\u1e31\u1e33\u1e35",
 
407
  // l
 
408
  "\u013a\u013c\u013e\u0140\u0142\u1e37\u1e39\u1e3b\u1e3d",
 
409
  // m
 
410
  "\u1e3f\u1e41\u1e43",
 
411
  // n
 
412
  "\u00f1\u0144\u0146\u0148\u0149\u014b\u01f9\u1e45\u1e47\u1e49\u1e4b",
 
413
  // o
 
414
  "\u00f2\u00f3\u00f4\u00f5\u00f6\u014d\u014f\u0151\u01d2\u01eb\u01ed\u020d\u020e\u022b\u22d\u022f\u0231\u1e4d\u1e4f\u1e51\u1e53\u1ecd\u1ecf\u1ed1\u1ed3\u1ed5\u1ed7\u1ed9\u1edb\u1edd\u1edf\u1ee1\u1ee3",
 
415
  // p
 
416
  "\u1e55\u1e57",
 
417
  // No q
 
418
  // r
 
419
  "\u0155\u0157\u0159\u0211\u0213\u1e59\u1e5b\u1e5d\u1e5f",
 
420
  // s
 
421
  "\u015b\u015d\u015f\u0161\u0219\u1e61\u1e63\u1e65\u1e67\u1e69",
 
422
  // t
 
423
  "\u0162\u0163\u0165\u0167\u021b\u1e6b\u1e6d\u1e6f\u1e71\u1e97",
 
424
  // u
 
425
  "\u00f9\u00fa\u00fb\u00fc\u0169\u016b\u016d\u016f\u0171\u0173\u01d4\u01d6\u01d8\u01da\u01dc\u0215\u0217\u1e73\u1e75\u1e77\u1e79\u1e7b\u1ee5\u1ee7\u1ee9\u1eeb\u1eed\u1eef\u1ef1",
 
426
  // v
 
427
  "\u1e7d\u1e7f",
 
428
  // w
 
429
  "\u0175\u1e81\u1e83\u1e85\u1e87\u1e89\u1e98",
 
430
  // x
 
431
  "\u1e8b\u1e8d",
 
432
  // y
 
433
  "\u00fd\u00ff\u0177\u0233\u1e8f\u1e99\u1ef3\u1ef5\u1ef7\u1ef9",
 
434
  // z
 
435
  "\u017a\u017c\u017e\u0225\u1e91\u1e93\u1e95"
 
436
];
 
437
 
 
438
 
 
439
const symbol = "\u00a1\u00a2\u00a3\u00a4\u00a5\u20ac\u00a6\u00a7\u00a8\u00a9\u2122\u00aa\u00ab\u00ac\u00ae\u00af\u00b0\u00b1\u00b2\u00b3\u00b4\u00b5\u00b6\u00b7\u00b8\u00b9\u00ba\u00bb\u00bc\u00bd\u00be\u00bf\u00d7\u00f7";
 
440
 
 
441
const otherupper = "\u00c6\u00d0\u00d8\u00de\u0132\u0152\u0186\u01c4\u01c5\u01c7\u01c8\u01ca\u01cb\u01F1\u01f2";
 
442
 
 
443
const otherlower = "\u00e6\u00f0\u00f8\u00fe\u00df\u0133\u0153\u01c6\u01c9\u01cc\u01f3";