1 /* ***** BEGIN LICENSE BLOCK *****
  2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3  *
  4  * The contents of this file are subject to the Mozilla Public License Version
  5  * 1.1 (the "License"); you may not use this file except in compliance with
  6  * the License. You may obtain a copy of the License at
  7  * http://www.mozilla.org/MPL/
  8  *
  9  * Software distributed under the License is distributed on an "AS IS" basis,
 10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11  * for the specific language governing rights and limitations under the
 12  * License.
 13  *
 14  * The Initial Developer of the Original Code is Fireinput Inc.
 15  *
 16  * Portions created by the Initial Developer are Copyright (C) 2007
 17  * the Initial Developer. All Rights Reserved.
 18  *
 19  * Contributor(s):
 20  *     Olly Ja <ollyja@gmail.com>
 21  *
 22  * Alternatively, the contents of this file may be used under the terms of
 23  * either the GNU General Public License Version 2 or later (the "GPL"), or
 24  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 25  * in which case the provisions of the GPL or the LGPL are applicable instead
 26  * of those above. If you wish to allow use of your version of this file only
 27  * under the terms of either the GPL or the LGPL, and not to allow others to
 28  * use your version of this file under the terms of the MPL, indicate your
 29  * decision by deleting the provisions above and replace them with the notice
 30  * and other provisions required by the GPL or the LGPL. If you do not delete
 31  * the provisions above, a recipient may use your version of this file under
 32  * the terms of any one of the MPL, the GPL or the LGPL.
 33  *
 34  * ***** END LICENSE BLOCK ***** 
 35  */
 36 const monthNumber =["零","一,正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二,腊"]; 
 37 const weekNumber = ["日,天", "一", "二", "三", "四", "五", "六"]; 
 38 
 39 
 40 const chineseBigNumber =  ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾"]; 
 41 
 42 const symbolGroup  = ["\u2010","\u2013","\u2014","\u2015","\u2016","\u2018","\u2019","\u201C",
 43                       "\u201D","\u2025","\u2026","\u2030","\u2032","\u2033","\u2035","\u203B",
 44                       "\u20AC","\u2103","\u2105","\u2109","\u2116","\u2121","\u3001","\u3002",
 45                       "\u3003","\u3005","\u3006","\u3007","\u3008","\u3009","\u300A","\u300B",
 46                       "\u300C","\u300D","\u300E","\u300F","\u3010","\u3011","\u3012","\u3013",
 47                       "\u3014","\u3015","\u3016","\u3017","\u301D","\u301E","\u3021","\u3022",
 48                       "\u3023","\u3024","\u3025","\u3026","\u3027","\u3028","\u3029","\u303E",
 49                       "\uFE30","\uFE31","\uFE33","\uFE34","\uFE35","\uFE36","\uFE37","\uFE38",
 50                       "\uFE39","\uFE3A","\uFE3B","\uFE3C","\uFE3D","\uFE3E","\uFE3F","\uFE40",
 51                       "\uFE41","\uFE42","\uFE43","\uFE44","\uFE49","\uFE4A","\uFE4B","\uFE4C",
 52                       "\uFE4D","\uFE4E","\uFE4F","\uFE50","\uFE51","\uFE52","\uFE54","\uFE55",
 53                       "\uFE56","\uFE57","\uFE59","\uFE5A","\uFE5B","\uFE5C","\uFE5D","\uFE5E",
 54                       "\uFE5F","\uFE60","\uFE61","\uFE62","\uFE63","\uFE64","\uFE65","\uFE66",
 55                       "\uFE68","\uFE69","\uFE6A","\uFE6B","\uFF01","\uFF02","\uFF03","\uFF04",
 56                       "\uFF05","\uFF06","\uFF07","\uFF08","\uFF09","\uFF0A","\uFF0B","\uFF0C",
 57                       "\uFF0D","\uFF0E","\uFF0F","\uFF1A","\uFF1B","\uFF1C","\uFF1D","\uFF1E",
 58                       "\uFF1F","\uFF20","\uFF3B","\uFF3C","\uFF3D","\uFF3E","\uFF3F","\uFF40",
 59                       "\uFF5B","\uFF5C","\uFF5D","\uFF5E","\uFFE0","\uFFE1","\uFFE2","\uFFE3",
 60                       "\uFFE4","\uFFE5","\u00A7","\u00A8","\u00B0","\u00B1","\u00B7","\u00D7",
 61                       "\u00F7","\u3231","\u00AE","\u00BF","\u00BA","\u00BB"]; 
 62 
 63 const specialNumber = ["\u2160","\u2161","\u2162","\u2163","\u2164","\u2165","\u2166","\u2167",
 64                        "\u2168","\u2169","\u216A","\u216B","\u2170","\u2171","\u2172","\u2173",
 65                        "\u2174","\u2175","\u2176","\u2177","\u2178","\u2179","\u2460","\u2461",
 66                        "\u2462","\u2463","\u2464","\u2465","\u2466","\u2467","\u2468","\u2469",
 67                        "\u2474","\u2475","\u2476","\u2477","\u2478","\u2479","\u247A","\u247B",
 68                        "\u247C","\u247D","\u247E","\u247F","\u2480","\u2481","\u2482","\u2483",
 69                        "\u2484","\u2485","\u2486","\u2487","\u2488","\u2489","\u248A","\u248B",
 70                        "\u248C","\u248D","\u248E","\u248F","\u2490","\u2491","\u2492","\u2493",
 71                        "\u2494","\u2495","\u2496","\u2497","\u2498","\u2499","\u249A","\u249B",
 72                        "\u3220","\u3221","\u3222","\u3223","\u3224","\u3225","\u3226","\u3227",
 73                        "\u3228","\u3229","\u00BC","\u00BD","\u00BE"]; 
 74 
 75 const currencySymbol= ["\u5143","\u00A3","\u20AC","\uFF04","\uFFE0","\uFFE1","\uFFE5"]; 
 76 
 77 const arrowSymbol =   ["\u2190","\u2191","\u2192","\u2193","\u2194","\u2195","\u2196","\u2197"]; 
 78 
 79 const mathSymbol =    ["\u2200","\u2202","\u2203","\u2205","\u2206","\u2207","\u2208","\u2209",
 80                        "\u220B","\u220F","\u2211","\u2212","\u2215","\u2217","\u2219","\u221A",
 81                        "\u221D","\u221E","\u221F","\u2220","\u2223","\u2225","\u2227","\u2228",
 82                        "\u2229","\u222A","\u222B","\u222C","\u222E","\u2234","\u2235","\u2236",
 83                        "\u2237","\u223C","\u223D","\u2245","\u2248","\u224C","\u2252","\u2260",
 84                        "\u2261","\u2264","\u2265","\u2266","\u2267","\u226A","\u226B","\u226E",
 85                        "\u226F","\u2282","\u2283","\u2284","\u2286","\u2287","\u2295","\u2297",
 86                        "\u2299","\u22A5","\u22BF","\u22C5","\u2312","\u2320","\u2321","\u2329",
 87                        "\u232A","\u33D1","\u33D2","\u00B1","\u00D7","\u00F7"]; 
 88 
 89 const latinSymbol =   ["\u0101","\u00E1","\u0103","\u00E0","\u00E8","\u00E9","\u00EA","\u00EC",
 90                        "\u00ED","\u00F2","\u00F3","\u00F9","\u00FA","\u00FC","\u0101","\u0113",
 91                        "\u011B","\u012B","\u0144","\u0148","\u014D","\u016B","\u01CE","\u01D0",
 92                        "\u01D2","\u01D4","\u01D6","\u01D8","\u01DA","\u01DC","\u01F9","\u0251",
 93                        "\u0261"]; 
 94 
 95 const greekSymbol =   ["\u0391","\u0392","\u0393","\u0394","\u0395","\u0396","\u0397","\u0398",
 96                        "\u0399","\u039A","\u039B","\u039C","\u039D","\u039E","\u039F","\u03A0",
 97                        "\u03A1","\u03A3","\u03A4","\u03A5","\u03A6","\u03A7","\u03A8","\u03A9",
 98                        "\u03B1","\u03B2","\u03B3","\u03B4","\u03B5","\u03B6","\u03B7","\u03B8", 
 99                        "\u03B9","\u03BA","\u03BB","\u03BC","\u03BD","\u03BE","\u03BF","\u03C0", 
100                        "\u03C1","\u03C2","\u03C3","\u03C4","\u03C5","\u03C6","\u03C7","\u03C8", 
101                        "\u03C9","\u03D1","\u03D5"]; 
102 
103 const tableSymbol =   ["\u2500","\u2501","\u2502","\u2503","\u2504","\u2505","\u2506","\u2507",
104                        "\u2508","\u2509","\u250A","\u250B","\u250C","\u250D","\u250E","\u250F",
105                        "\u2510","\u2511","\u2512","\u2513","\u2514","\u2515","\u2516","\u2517",
106                        "\u2518","\u2519","\u251A","\u251B","\u251C","\u251D","\u251E","\u251F",
107                        "\u2520","\u2521","\u2522","\u2523","\u2524","\u2525","\u2526","\u2527",
108                        "\u2528","\u2529","\u252A","\u252B","\u252C","\u252D","\u252E","\u252F",
109                        "\u2530","\u2531","\u2532","\u2533","\u2534","\u2535","\u2536","\u2537",
110                        "\u2538","\u2539","\u253A","\u253B","\u253C","\u253D","\u253E","\u253F",
111                        "\u2540","\u2541","\u2542","\u2543","\u2544","\u2545","\u2546","\u2547",
112                        "\u2548","\u2549","\u254A","\u254B","\u2550","\u2551","\u2552","\u2553",
113                        "\u2554","\u2555","\u2556","\u2557","\u2558","\u2559","\u255A","\u255B",
114                        "\u255C","\u255D","\u255E","\u255F","\u2560","\u2561","\u2562","\u2563",
115                        "\u2564","\u2565","\u2566","\u2567","\u2568","\u2569","\u256A","\u256B",
116                        "\u256C","\u256D","\u256E","\u256F","\u2570","\u2571","\u2572","\u2573"]; 
117 
118 const blockSymbol =   ["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588",
119                        "\u2589","\u258A","\u258B","\u258C","\u258D","\u258E","\u258F","\u2593",
120                        "\u2594","\u2595"]; 
121 
122 const geometrySymbol =    ["\u25A0","\u25A1","\u25B2","\u25B3","\u25BC","\u25BD","\u25E2","\u25E3",
123                        "\u25E4","\u25E5","\u25C6","\u25C7","\u25CB","\u25CE","\u25CF","\u2605",
124                        "\u2606","\u2609","\u2640","\u2641","\u2642"]; 
125 
126 const sideSymbol =    ["\u2E81","\u2E84","\u2E88","\u2E8B","\u2E8C","\u2E97","\u2EA7","\u2EAA",
127                        "\u2EAE","\u2EB3","\u2EB6","\u2EB7","\u2EBB","\u2ECA"]; 
128 
129 const measureSymbol=  ["\u338E","\u338F","\u339C","\u339D","\u339E","\u33A1","\u33C4","\u33CE","\u33D5"]; 
130 
131 const pinyinSymbol =  ["\u0101","\u00E1","\u01CE","\u00E0","\u0100","\u00C1","\u01CD","\u00C0","\u0113",
132                        "\u00E9","\u011B","\u00E8","\u0112","\u00C9","\u011A","\u00C8","\u012B","\u00ED",
133                        "\u01D0","\u00EC","\u012A","\u00CD","\u01CF","\u00CC","\u014D","\u00F3","\u01D2",
134                        "\u00F2", "\u014C","\u00D3","\u01D1","\u00D2","\u016B","\u00FA","\u01D4","\u00F9",
135                        "\u016A","\u00DA","\u01D3","\u00D9","\u01D6","\u01D8","\u01DA","\u01DC","\u00FC",
136                        "\u01D5","\u01D7","\u01D9","\u01DB","\u00DC"]; 
137 
138 const allSymbols = [ 
139                      {group: "fireinput.measure.label", key: "danwei", symbol: measureSymbol},
140                      {group: "fireinput.geometry.label", key: "jihe", symbol: geometrySymbol},
141                      {group: "fireinput.block.label", key: "tu'an", symbol: blockSymbol},
142                      {group: "fireinput.table.label", key: "zhibiao", symbol: tableSymbol},
143                      {group: "fireinput.greek.label", key: "greek,xila", symbol: greekSymbol},
144                      {group: "fireinput.latin.label", key: "latin", symbol: latinSymbol},
145                      {group: "fireinput.math.label", key: "shuxue", symbol: mathSymbol},
146                      {group: "fireinput.arrow.label", key: "jiantou", symbol: arrowSymbol},
147                      {group: "fireinput.currency.label", key: "huobi", symbol: currencySymbol},
148                      {group: "fireinput.special.number.label", key: "shuzi", symbol: specialNumber},
149                      {group: "fireinput.normal.symbol.label", key: "fuhao", symbol: symbolGroup},
150                      {group: "fireinput.chinese.number.label", key: "shuzi", symbol: chineseBigNumber}
151                 ]; 
152 
153 
154 
155 
156 var FireinputSpecialChar = 
157 {
158 
159     refreshMenu: function()
160     {
161        // get default language first 
162        var defaultLanguage = FireinputPrefDefault.getInterfaceLanguage();
163 
164        for(var i=allSymbols.length-1; i>=0; i--)
165        {
166           var groupName = allSymbols[i].group;
167 
168           var menuID = document.getElementById(allSymbols[i].group + "_menu");
169           if(!menuID)
170           {
171              continue; 
172           }
173           var label = FireinputUtils.getLocaleString(groupName + defaultLanguage);
174           menuID.setAttribute("label", label);
175        }
176 
177        // refresh for date/time 
178        var menuID = document.getElementById("fireinput.datetime.label" +"_menu");
179        if(menuID)
180        {
181           var label = FireinputUtils.getLocaleString("fireinput.datetime.label" + defaultLanguage);
182           menuID.setAttribute("label", label);
183        }
184 
185     }, 
186 
187     addGroup: function(menuElement)
188     {
189        // get default language first 
190        var defaultLanguage = FireinputPrefDefault.getInterfaceLanguage();
191 
192        // add date/time 
193        var label = FireinputUtils.getLocaleString("fireinput.datetime.label" + defaultLanguage);
194        var subMenu = document.createElement("menu");
195        var subMenupopup = document.createElement("menupopup");
196        subMenu.setAttribute("label", label);
197        subMenu.setAttribute("id", "fireinput.datetime.label"+"_menu");
198        var self = this; 
199 
200        subMenu.addEventListener("DOMMenuItemActive", function(event) { self.updateDateTime(event); }, true); 
201 
202        subMenupopup.setAttribute("id", "fireinput.datetime.label"); 
203 
204        subMenu.appendChild(subMenupopup);
205        menuElement.appendChild(subMenu);
206  
207        for(var i=allSymbols.length-1; i>=0; i--)
208        {
209           var groupName = allSymbols[i].group;
210 
211           var menuID = document.getElementById(allSymbols[i].group); 
212           if(!menuID)
213           { 
214              var label = FireinputUtils.getLocaleString(groupName + defaultLanguage);
215              var subMenu = document.createElement("menu"); 
216              var subMenupopup = document.createElement("menupopup"); 
217              subMenu.setAttribute("label", label); 
218              subMenu.setAttribute("id", allSymbols[i].group+"_menu"); 
219 
220              this.addGroupSymbol(subMenupopup, allSymbols[i].symbol); 
221              subMenupopup.setAttribute("id", allSymbols[i].group); 
222 
223              subMenu.appendChild(subMenupopup); 
224              menuElement.appendChild(subMenu); 
225 
226           }
227           else 
228           {
229              this.addGroupSymbol(menuID, allSymbols[i].symbol); 
230           }
231        }
232     },
233 
234     addGroupSymbol: function(menuItem, symbols)
235     {
236        var num = 5; 
237 
238        if(symbols.length > 50)
239           num = 10; 
240        for(var i=symbols.length-1; i>=0;)
241        {
242  
243           var toolbar = document.createElement("toolbar"); 
244           toolbar.setAttribute("class", "specialcharbar"); 
245           var j=0; 
246           for(j=0; j<num && (i-j) >=0; j++)
247           {
248              var text = symbols[i-j]; 
249 
250              var label = document.createElement("label"); 
251              label.setAttribute("value", text); 
252              label.setAttribute("tooltiptext", this.toUnicodeHex(text)); 
253              label.setAttribute("class", "specialcharlabel");
254              label.onclick=function(event) { Fireinput.insertSpecialCharAt(event); }; 
255              toolbar.appendChild(label); 
256           }
257           i-= j; 
258           
259           menuItem.appendChild(toolbar); 
260        }
261     },
262 
263     updateDateTime: function(event)
264     {
265        var subMenupopup = document.getElementById("fireinput.datetime.label"); 
266        while(subMenupopup.hasChildNodes())
267        {
268           subMenupopup.removeChild(subMenupopup.lastChild);
269        }
270 
271        this.addGroupSymbol(subMenupopup, this.getMonth());
272        this.addGroupSymbol(subMenupopup, this.getWeek());
273        this.addGroupSymbol(subMenupopup, this.getTime());
274 
275     },
276 
277     getMonth: function()
278     {
279 
280        var current = new Date(); 
281        var year  = current.getFullYear(); 
282        var month = current.getMonth();
283        var day =  current.getDate(); 
284        var monthArray = new Array(); 
285 
286        var monthValue = monthNumber[month+1]; 
287        var monthValueArray = monthValue.split(","); 
288        // format: 2007年4月10日
289        monthArray.push(year + "年" + (month+1) + "月" + day + "日"); 
290 
291        var year1= year; 
292        var aYear = monthNumber[parseInt(year1/1000)].split(",")[0]; 
293        year1 %= 1000; 
294        aYear += monthNumber[parseInt(year1/100)].split(",")[0]; 
295        year1 %= 100; 
296        aYear += monthNumber[parseInt(year1/10)].split(",")[0]; 
297        year1 %= 10; 
298        aYear += monthNumber[year1].split(",")[0]; 
299 
300        var day1 = day; 
301        var aDay = "";
302        if(day1 < 10)
303           aDay = monthNumber[day].split(",")[0];
304        else
305        {
306           if(day1 >= 20)
307              aDay = monthNumber[parseInt(day1/10)].split(",")[0];
308 
309           aDay += monthNumber[10].split(",")[0];
310           if(day1 % 10)
311              aDay += monthNumber[day % 10].split(",")[0];
312        }
313 
314        // format: 二零零七年四月二十二日
315        for(var i=0; i<monthValueArray.length; i++)
316          monthArray.push(aYear + "年" + monthValueArray[i] + "月" + aDay + "日"); 
317 
318        var bigYear = chineseBigNumber[parseInt(year/1000)]; 
319        year %= 1000; 
320        bigYear += chineseBigNumber[parseInt(year/100)]; 
321        year %= 100; 
322        bigYear += chineseBigNumber[parseInt(year/10)]; 
323        year %= 10; 
324        bigYear += chineseBigNumber[year]; 
325 
326  
327        var bigMonth = ""; 
328        if(month < 10)
329           bigMonth = chineseBigNumber[month+1];
330        else 
331        {
332           bigMonth = chineseBigNumber[10]; 
333           bigMonth += chineseBigNumber[month % 10 +1]; 
334        }
335    
336        var bigDay = ""; 
337        if(day < 10)
338           bigDay = chineseBigNumber[day]; 
339        else 
340        {
341           if(day >= 20)
342              bigDay = chineseBigNumber[parseInt(day/10)]; 
343 
344           bigDay += chineseBigNumber[10]; 
345           if(day % 10)
346              bigDay += chineseBigNumber[day % 10]; 
347        }
348      
349        // format 贰零零柒年肆月贰拾贰日
350        monthArray.push(bigYear + "年" + bigMonth + "月" + bigDay + "日"); 
351 
352        return monthArray; 
353     },
354 
355     getWeek: function()
356     {
357        var current = new Date();
358        var day =  current.getDay(); 
359        var weekArray = new Array(); 
360        var weekValueArray = weekNumber[day].split(","); 
361        for(var i=0; i<weekValueArray.length; i++)
362        {  
363           weekArray.push("星期" + weekValueArray[i]); 
364           weekArray.push("礼拜" + weekValueArray[i]); 
365        }
366 
367        return weekArray; 
368     },
369 
370     getTime: function()
371     {
372        var current = new Date();
373        var hour =  current.getHours(); 
374        var minute =  current.getMinutes(); 
375        var second =  current.getSeconds(); 
376 
377        var timeArray = new Array(); 
378        timeArray.push(hour + "点" + minute + "分" + second + "秒"); 
379 
380        if(hour < 6)
381           timeArray.push("凌晨" + hour + "点" + minute + "分" + second + "秒"); 
382        else if(hour < 10)
383           timeArray.push("早上" + hour + "点" + minute + "分" + second + "秒"); 
384        else if(hour < 12)
385           timeArray.push("上午" + hour + "点" + minute + "分" + second + "秒"); 
386        else if (hour < 20)
387           timeArray.push("下午" + (hour-12) + "点" + minute + "分" + second + "秒"); 
388        else 
389           timeArray.push("晚上" + (hour-12) + "点" + minute + "分" + second + "秒"); 
390 
391        return timeArray; 
392     },
393 
394     toUnicodeHex: function(uniStr)
395     {
396        var uniHex = uniStr.charCodeAt(0).toString(16);
397        while(uniHex.length<4)
398        {
399           uniHex = "0" + uniHex;
400        }
401        return uniHex.toUpperCase();
402     }
403 };              


syntax highlighted by Code2HTML, v. 0.9.1