1/* ******************************************************************** 2 ********************************************************************** 3 * HTML Virtual Keyboard Interface Script - v1.27 4 * Copyright (c) 2009 - GreyWyvern 5 * 6 * - Licenced for free distribution under the BSDL 7 * http://www.opensource.org/licenses/bsd-license.php 8 * 9 * Add a script-driven keyboard interface to text fields, password 10 * fields and textareas. 11 * 12 * See http://www.greywyvern.com/code/javascript/keyboard for examples 13 * and usage instructions. 14 * 15 * Version 1.27 - June 11, 2009 16 * - Danish keyboard layout added 17 * 18 * See full changelog at: 19 * http://www.greywyvern.com/code/javascript/keyboard.changelog.txt 20 * 21 * Keyboard Credits 22 * - Danish keyboard layout by Verner Kj�rsgaard 23 * - Slovak keyboard layout by Daniel Lara (www.learningslovak.com) 24 * - Belarusian, Serbian Cyrillic and Serbian Latin keyboard layouts by Evgeniy Titov 25 * - Bulgarian Phonetic keyboard layout by Samuil Gospodinov 26 * - Swedish keyboard layout by H�kan Sandberg 27 * - Romanian keyboard layout by Aurel 28 * - Farsi (Persian) keyboard layout by Kaveh Bakhtiyari (www.bakhtiyari.com) 29 * - Burmese keyboard layout by Cetanapa 30 * - Slovenian keyboard layout by Miran Zeljko 31 * - Hungarian keyboard layout by Antal Sall 'Hiromacu' 32 * - Arabic keyboard layout by Srinivas Reddy 33 * - Italian and Spanish (Spain) keyboard layouts by dictionarist.com 34 * - Lithuanian and Russian keyboard layouts by Ramunas 35 * - German keyboard layout by QuHno 36 * - French keyboard layout by Hidden Evil 37 * - Polish Programmers layout by moose 38 * - Turkish keyboard layouts by offcu 39 * - Dutch and US Int'l keyboard layouts by jerone 40 * - Portuguese keyboard layout by clisboa 41 * 42 */ 43var VKI_attach, VKI_close; 44 function VKI_buildKeyboardInputs() { 45 var self = this; 46 47 this.VKI_version = "1.27"; 48 this.VKI_target = this.VKI_visible = false; 49 this.VKI_shift = this.VKI_capslock = this.VKI_alternate = this.VKI_dead = false; 50 this.VKI_deadkeysOn = false; 51// this.VKI_kt = "US Int'l"; // Default keyboard layout 52 this.VKI_kt = "Russian"; 53 this.VKI_clearPasswords = false; // Clear password fields on focus 54 this.VKI_showVersion = true; 55 this.VKI_imageURI = "/keyboard/keyboard.png"; 56 this.VKI_clickless = false; 57 this.VKI_clicklessDelay = 500; 58 this.VKI_keyCenter = 3; 59 60 this.VKI_isIE = /*@cc_on!@*/false; 61 this.VKI_isIE6 = /*@if(@_jscript_version == 5.6)!@end@*/false; 62 this.VKI_isIElt8 = /*@if(@_jscript_version < 5.8)!@end@*/false; 63 this.VKI_isMoz = (navigator.product == "Gecko"); 64 this.VKI_isWebKit = RegExp("KHTML").test(navigator.userAgent); 65 66 67 /* ***** Create keyboards ************************************** */ 68 this.VKI_layout = {}; 69 this.VKI_layoutDDK = {}; 70 71 // - Lay out each keyboard in rows of sub-arrays. Each sub-array 72 // represents one key. 73 // 74 // - Each sub-array consists of four slots described as follows: 75 // example: ["a", "A", "\u00e1", "\u00c1"] 76 // 77 // a) Normal character 78 // A) Character + Shift or Caps 79 // \u00e1) Character + Alt or AltGr 80 // \u00c1) Character + Shift or Caps + Alt or AltGr 81 // 82 // You may include sub-arrays which are fewer than four slots. 83 // In these cases, the missing slots will be blanked when the 84 // corresponding modifier key (Shift or AltGr) is pressed. 85 // 86 // - If the second slot of a sub-array matches one of the following 87 // strings: 88 // "Tab", "Caps", "Shift", "Enter", "Bksp", "Alt" OR "AltGr" 89 // then the function of the key will be the following, 90 // respectively: 91 // - Insert a tab 92 // - Toggle Caps Lock (technically a Shift Lock) 93 // - Next entered character will be the shifted character 94 // - Insert a newline (textarea), or close the keyboard 95 // - Delete the previous character 96 // - Next entered character will be the alternate character 97 // 98 // The first slot of this sub-array will be the text to display 99 // on the corresponding key. This allows for easy localisation 100 // of key names. 101 // 102 // - Layout dead keys (diacritic + letter) should be added as 103 // arrays of two item arrays with hash keys equal to the 104 // diacritic. See the "this.VKI_deadkey" object below the layout 105 // definitions. In each two item child array, the second item 106 // is what the diacritic would change the first item to. 107 // 108 // - To disable dead keys for a layout, simply assign true to the 109 // this.VKI_layoutDDK (DDK = disable dead keys) object of the 110 // same name as the layout. See the Numpad layout below for an 111 // example. 112 // 113 // - Note that any characters beyond the normal ASCII set should be 114 // entered in escaped Unicode format. (eg \u00a3 = Pound symbol) 115 // You can find Unicode values for characters here: 116 // http://unicode.org/charts/ 117 // 118 // - To remove a keyboard, just delete it, or comment it out of the 119 // source code 120 121 this.VKI_layout.Numpad = [ // Number pad 122 [["$"], ["\u00a3"], ["\u20ac"], ["\u00a5"], ["/"], ["^"], ["Bksp", "Bksp"]], 123 [["."], ["7"], ["8"], ["9"], ["*"], ["<"], ["("], ["["]], 124 [["="], ["4"], ["5"], ["6"], ["-"], [">"], [")"], ["]"]],
125 [["0"], ["1"], ["2"], ["3"], ["+"], ["Enter", "Enter"]], 126 [[" "]] 127 ]; 128 this.VKI_layoutDDK.Numpad = true; 129 130 this.VKI_layout.Russian = [ // Russian Standard Keyboard 131 [["\u0451", "\u0401"], ["1", "!"], ["2", '"'], ["3", "\u2116"], ["4", ";"], ["5", "%"], ["6", ":"], ["7", "?"], ["8", "*"], ["9", "("], ["0", ")"], ["-", "_"], ["=", "+"], ["Bksp", "Bksp"]], 132 [["Tab", "Tab"], ["\u0439", "\u0419"], ["\u0446", "\u0426"], ["\u0443", "\u0423"], ["\u043A", "\u041A"], ["\u0435", "\u0415"], ["\u043D", "\u041D"], ["\u0433", "\u0413"], ["\u0448", "\u0428"], ["\u0449", "\u0429"], ["\u0437", "\u0417"], ["\u0445", "\u0425"], ["\u044A", "\u042A"], ["Enter", "Enter"]], 133 [["Caps", "Caps"], ["\u0444", "\u0424"], ["\u044B", "\u042B"], ["\u0432", "\u0412"], ["\u0430", "\u0410"], ["\u043F", "\u041F"], ["\u0440", "\u0420"], ["\u043E", "\u041E"], ["\u043B", "\u041B"], ["\u0434", "\u0414"], ["\u0436", "\u0416"], ["\u044D", "\u042D"], ["\\", "/"]], 134 [["Shift", "Shift"], ["/", "|"], ["\u044F", "\u042F"], ["\u0447", "\u0427"], ["\u0441", "\u0421"], ["\u043C", "\u041C"], ["\u0438", "\u0418"], ["\u0442", "\u0422"], ["\u044C", "\u042C"], ["\u0431", "\u0411"], ["\u044E", "\u042E"], [".", ","], ["Shift", "Shift"]], 135 [[" ", " "]] 136 ]; 137 138 this.VKI_layout["English"] = [ // US International Keyboard 139 [["`", "~"], ["1", "!", "\u00a1", "\u00b9"], ["2", "@", "\u00b2"], ["3", "#", "\u00b3"], ["4", "$", "\u00a4", "\u00a3"], ["5", "%", "\u20ac"], ["6", "^", "\u00bc"], ["7", "&", "\u00bd"], ["8", "*", "\u00be"], ["9", "(", "\u2018"], ["0", ")", "\u2019"], ["-", "_", "\u00a5"], ["=", "+", "\u00d7", "\u00f7"], ["Bksp", "Bksp"]], 140 [["Tab", "Tab"], ["q", "Q", "\u00e4", "\u00c4"], ["w", "W", "\u00e5", "\u00c5"], ["e", "E", "\u00e9", "\u00c9"], ["r", "R", "\u00ae"], ["t", "T", "\u00fe", "\u00de"], ["y", "Y", "\u00fc", "\u00dc"], ["u", "U", "\u00fa", "\u00da"], ["i", "I", "\u00ed", "\u00cd"], ["o", "O", "\u00f3", "\u00d3"], ["p", "P", "\u00f6", "\u00d6"], ["[", "{", "\u00ab"], ["]", "}", "\u00bb"], ["\\", "|", "\u00ac", "\u00a6"]], 141 [["Caps", "Caps"], ["a", "A", "\u00e1", "\u00c1"], ["s", "S", "\u00df", "\u00a7"], ["d", "D", "\u00f0", "\u00d0"], ["f", "F"], ["g", "G"], ["h", "H"], ["j", "J"], ["k", "K"], ["l", "L", "\u00f8", "\u00d8"], [";", ":", "\u00b6", "\u00b0"], ["'", '"', "\u00b4", "\u00a8"], ["Enter", "Enter"]], 142 [["Shift", "Shift"], ["z", "Z", "\u00e6", "\u00c6"], ["x", "X"], ["c", "C", "\u00a9", "\u00a2"], ["v", "V"], ["b", "B"], ["n", "N", "\u00f1", "\u00d1"], ["m", "M", "\u00b5"], [",", "<", "\u00e7", "\u00c7"], [".", ">"], ["/", "?", "\u00bf"], ["Shift", "Shift"]], 143 [[" ", " ", " ", " "], ["Alt", "Alt"]] 144 ]; 145 146 this.VKI_layout.Uzbek = [ // Uzbek Standard Keyboard 147 [["\u0451", "\u0401"], ["1", "!"], ["2", '"'], ["3", "\u2116"], ["4", ";"], ["5", "%"], ["6", ":"], ["7", "?"], ["8", "*"], ["9", "("], ["0", ")"], ["\u0493", "\u0492"], ["\u04B3", "\u04B2"], ["Bksp", "Bksp"]], 148 [["Tab", "Tab"], ["\u0439", "\u0419"], ["\u0446", "\u0426"], ["\u0443", "\u0423"], ["\u043A", "\u041A"], ["\u0435", "\u0415"], ["\u043D", "\u041D"], ["\u0433", "\u0413"], ["\u0448", "\u0428"], ["\u045E", "\u040E"], ["\u0437", "\u0417"], ["\u0445", "\u0425"], ["\u044A", "\u042A"], ["Enter", "Enter"]], 149 [["Caps", "Caps"], ["\u0444", "\u0424"], ["\u049B", "\u049A"], ["\u0432", "\u0412"], ["\u0430", "\u0410"], ["\u043F", "\u041F"], ["\u0440", "\u0420"], ["\u043E", "\u041E"], ["\u043B", "\u041B"], ["\u0434", "\u0414"], ["\u0436", "\u0416"], ["\u044D", "\u042D"], ["\\", "/"]], 150 [["Shift", "Shift"], ["/", "|"], ["\u044F", "\u042F"], ["\u0447", "\u0427"], ["\u0441", "\u0421"], ["\u043C", "\u041C"], ["\u0438", "\u0418"], ["\u0442", "\u0422"], ["\u044C", "\u042C"], ["\u0431", "\u0411"], ["\u044E", "\u042E"], [".", ","], ["Shift", "Shift"]], 151 [[" ", " "]] 152 ]; 153 /* ***** Define Dead Keys ************************************** */ 154 this.VKI_deadkey = {}; 155 156 // - Lay out each dead key set in one row of sub-arrays. The rows 157 // below are wrapped so uppercase letters are below their 158 // lowercase equivalents. 159 // 160 // - The first letter in each sub-array is the letter pressed after 161 // the diacritic. The second letter is the letter this key-combo 162 // will generate. 163 // 164 // - Note that if you have created a new keyboard layout and want 165 // it included in the distributed script, PLEASE TELL ME if you 166 // have added additional dead keys to the ones below. 167 168 this.VKI_deadkey['"'] = this.VKI_deadkey['\u00a8'] = [ // Umlaut / Diaeresis / Greek Dialytika 169 ["a", "\u00e4"], ["e", "\u00eb"], ["i", "\u00ef"], ["o", "\u00f6"], ["u", "\u00fc"], ["y", "\u00ff"], ["\u03b9", "\u03ca"], ["\u03c5", "\u03cb"], 170 ["A", "\u00c4"], ["E", "\u00cb"], ["I", "\u00cf"], ["O", "\u00d6"], ["U", "\u00dc"], ["Y", "\u0178"], ["\u0399", "\u03aa"], ["\u03a5", "\u03ab"] 171 ]; 172 this.VKI_deadkey['~'] = [ // Tilde 173 ["a", "\u00e3"], ["o", "\u00f5"], ["n", "\u00f1"], 174 ["A", "\u00c3"], ["O", "\u00d5"], ["N", "\u00d1"] 175 ]; 176 this.VKI_deadkey['^'] = [ // Circumflex 177 ["a", "\u00e2"], ["e", "\u00ea"], ["i", "\u00ee"], ["o", "\u00f4"], ["u", "\u00fb"], ["w", "\u0175"], ["y", "\u0177"], 178 ["A", "\u00c2"], ["E", "\u00ca"], ["I", "\u00ce"], ["O", "\u00d4"], ["U", "\u00db"], ["W", "\u0174"], ["Y", "\u0176"] 179 ]; 180 this.VKI_deadkey['\u02c7'] = [ // Baltic caron 181 ["c", "\u010D"], ["s", "\u0161"], ["z", "\u017E"], ["r", "\u0159"], ["d", "\u010f"], ["t", "\u0165"], ["n", "\u0148"], ["l", "\u013e"], ["e", "\u011b"], 182 ["C", "\u010C"], ["S", "\u0160"], ["Z", "\u017D"], ["R", "\u0158"], ["D", "\u010e"], ["T", "\u0164"], ["N", "\u0147"], ["L", "\u013d"], ["E", "\u011a"] 183 ]; 184 this.VKI_deadkey['\u02d8'] = [ // Romanian and Turkish breve 185 ["a", "\u0103"], ["g", "\u011f"], 186 ["A", "\u0102"], ["G", "\u011e"] 187 ]; 188 this.VKI_deadkey['`'] = [ // Grave 189 ["a", "\u00e0"], ["e", "\u00e8"], ["i", "\u00ec"], ["o", "\u00f2"], ["u", "\u00f9"], 190 ["A", "\u00c0"], ["E", "\u00c8"], ["I", "\u00cc"], ["O", "\u00d2"], ["U", "\u00d9"] 191 ]; 192 this.VKI_deadkey["'"] = this.VKI_deadkey['\u00b4'] = this.VKI_deadkey['\u0384'] = [ // Acute / Greek Tonos 193 ["a", "\u00e1"], ["e", "\u00e9"], ["i", "\u00ed"], ["o", "\u00f3"], ["u", "\u00fa"], ["y", "\u00fd"], ["\u03b1", "\u03ac"], ["\u03b5", "\u03ad"], ["\u03b7", "\u03ae"], ["\u03b9", "\u03af"], ["\u03bf", "\u03cc"], ["\u03c5", "\u03cd"], ["\u03c9", "\u03ce"], 194 ["A", "\u00c1"], ["E", "\u00c9"], ["I", "\u00cd"], ["O", "\u00d3"], ["U", "\u00da"], ["Y", "\u00dd"], ["\u0391", "\u0386"], ["\u0395", "\u0388"], ["\u0397", "\u0389"], ["\u0399", "\u038a"], ["\u039f", "\u038c"], ["\u03a5", "\u038e"], ["\u03a9", "\u038f"] 195 ]; 196 this.VKI_deadkey['\u02dd'] = [ // Hungarian Double Acute Accent 197 ["o", "\u0151"], ["u", "\u0171"], 198 ["O", "\u0150"], ["U", "\u0170"] 199 ]; 200 this.VKI_deadkey['\u0385'] = [ // Greek Dialytika + Tonos 201 ["\u03b9", "\u0390"], ["\u03c5", "\u03b0"] 202 ]; 203 this.VKI_deadkey['\u00b0'] = this.VKI_deadkey['\u00ba'] = [ // Ring 204 ["a", "\u00e5"], ["u", "\u016f"], 205 ["A", "\u00c5"], ["U", "\u016e"] 206 ]; 207 this.VKI_deadkey['\u02DB'] = [ // Ogonek 208 ["a", "\u0106"], ["e", "\u0119"], ["i", "\u012f"], ["o", "\u01eb"], ["u", "\u0173"], ["y", "\u0177"], 209 ["A", "\u0105"], ["E", "\u0118"], ["I", "\u012e"], ["O", "\u01ea"], ["U", "\u0172"], ["Y", "\u0176"] 210 ]; 211 this.VKI_deadkey['\u02D9'] = [ // Dot-above 212 ["c", "\u010B"], ["e", "\u0117"], ["g", "\u0121"], ["z", "\u017C"], 213 ["C", "\u010A"], ["E", "\u0116"], ["G", "\u0120"], ["Z", "\u017B"] 214 ]; 215 this.VKI_deadkey['\u00B8'] = this.VKI_deadkey['\u201a'] = [ // Cedilla 216 ["c", "\u00e7"], ["s", "\u015F"], 217 ["C", "\u00c7"], ["S", "\u015E"] 218 ]; 219 this.VKI_deadkey[','] = [ // Comma 220 ["s", (this.VKI_isIElt8) ? "\u015F" : "\u0219"], ["t", (this.VKI_isIElt8) ? "\u0163" : "\u021B"], 221 ["S", (this.VKI_isIElt8) ? "\u015E" : "\u0218"], ["T", (this.VKI_isIElt8) ? "\u0162" : "\u021A"] 222 ]; 223 224 225 226 /* **************************************************************** 227 * Attach the keyboard to an element 228 * 229 */ 230 this.VKI_attachKeyboard = VKI_attach = function(elem) { 231 if (elem.VKI_attached) return false;
232 var keybut = document.createElement('img'); 233// keybut.src = this.VKI_imageURI; 234 keybut.src = "/keyboard/keyboard.png"; 235 keybut.alt = "Keyboard"; 236 keybut.className = "keyboardInputInitiator"; 237 keybut.title = "ÐиÑÑÑалÑÐ½Ð°Ñ ÐºÐ»Ð°Ð²Ð¸Ð°ÑÑÑа"; 238 keybut.elem = elem; 239 keybut.onclick = function() { self.VKI_show(this.elem); }; 240 elem.VKI_attached = true; 241 elem.parentNode.insertBefore(keybut, (elem.dir == "rtl") ? elem : elem.nextSibling); 242 if (this.VKI_isIE) { 243 elem.onclick = elem.onselect = elem.onkeyup = function(e) { 244 if ((e || event).type != "keyup" || !this.readOnly) 245 this.range = document.selection.createRange(); 246 }; 247 } 248 }; 249 250 251 /* ***** Find tagged input & textarea elements ***************** */ 252 var inputElems = [ 253 document.getElementsByTagName('input'), 254 document.getElementsByTagName('textarea') 255 ]; 256 for (var x = 0, elem; elem = inputElems[x++];) 257 for (var y = 0, ex; ex = elem[y++];) 258 if ((ex.nodeName == "TEXTAREA" || ex.type == "text" || ex.type == "password") && ex.className.indexOf("keyboardInput") > -1) 259 this.VKI_attachKeyboard(ex); 260 261 262 /* ***** Build the keyboard interface ************************** */ 263 this.VKI_keyboard = document.createElement('table'); 264 this.VKI_keyboard.id = "keyboardInputMaster"; 265 this.VKI_keyboard.dir = "ltr"; 266 this.VKI_keyboard.cellSpacing = this.VKI_keyboard.border = "0"; 267 268 var thead = document.createElement('thead'); 269 var tr = document.createElement('tr'); 270 var th = document.createElement('th'); 271 var kblist = document.createElement('select'); 272 for (ktype in this.VKI_layout) { 273 if (typeof this.VKI_layout[ktype] == "object") { 274 var opt = document.createElement('option'); 275 opt.value = ktype; 276 opt.appendChild(document.createTextNode(ktype)); 277 kblist.appendChild(opt); 278 } 279 } 280 if (kblist.options.length) { 281 kblist.value = this.VKI_kt; 282 kblist.onchange = function() { 283 self.VKI_kt = this.value; 284 self.VKI_buildKeys(); 285 self.VKI_position(); 286 }; 287 th.appendChild(kblist); 288 } 289 290 var label = document.createElement('label'); 291 var checkbox = document.createElement('input'); 292 checkbox.type = "checkbox"; 293 checkbox.title = "Dead keys: " + ((this.VKI_deadkeysOn) ? "On" : "Off"); 294 checkbox.defaultChecked = this.VKI_deadkeysOn; 295 checkbox.onclick = function() { 296 self.VKI_deadkeysOn = this.checked; 297 this.title = "Dead keys: " + ((this.checked) ? "On" : "Off"); 298 self.VKI_modify(""); 299 return true; 300 }; 301 label.appendChild(this.VKI_deadkeysElem = checkbox); 302 checkbox.checked = this.VKI_deadkeysOn; 303 th.appendChild(label); 304 tr.appendChild(th); 305 306 var td = document.createElement('td'); 307 var clearer = document.createElement('span'); 308 clearer.id = "keyboardInputClear"; 309 clearer.appendChild(document.createTextNode("Clear")); 310 clearer.title = "Clear this input"; 311 clearer.onmousedown = function() { this.className = "pressed"; }; 312 clearer.onmouseup = function() { this.className = ""; }; 313 clearer.onclick = function() { 314 self.VKI_target.value = ""; 315 self.VKI_target.focus(); 316 return false; 317 }; 318 td.appendChild(clearer); 319 320 var closer = document.createElement('span'); 321 closer.id = "keyboardInputClose"; 322 closer.appendChild(document.createTextNode('X')); 323 closer.title = "Close this window"; 324 closer.onmousedown = function() { this.className = "pressed"; }; 325 closer.onmouseup = function() { this.className = ""; }; 326 closer.onclick = function() { self.VKI_close(); }; 327 td.appendChild(closer); 328 329 tr.appendChild(td); 330 thead.appendChild(tr); 331 this.VKI_keyboard.appendChild(thead); 332 333 var tbody = document.createElement('tbody'); 334 var tr = document.createElement('tr'); 335 var td = document.createElement('td'); 336 td.colSpan = "2"; 337 var div = document.createElement('div'); 338 div.id = "keyboardInputLayout"; 339 td.appendChild(div); 340 if (this.VKI_showVersion) { 341 var div = document.createElement('div'); 342 var ver = document.createElement('var'); 343 ver.appendChild(document.createTextNode("v" + this.VKI_version)); 344 div.appendChild(ver); 345 td.appendChild(div); 346 } 347 tr.appendChild(td); 348 tbody.appendChild(tr); 349 this.VKI_keyboard.appendChild(tbody); 350 351 if (this.VKI_isIE6) { 352 this.VKI_iframe = document.createElement('iframe');
353 this.VKI_iframe.style.position = "absolute"; 354 this.VKI_iframe.style.border = "0px none"; 355 this.VKI_iframe.style.filter = "mask()"; 356 this.VKI_iframe.style.zIndex = "999999"; 357 this.VKI_iframe.src = this.VKI_imageURI; 358 } 359 360 361 /* **************************************************************** 362 * Build or rebuild the keyboard keys 363 * 364 */ 365 this.VKI_buildKeys = function() { 366 this.VKI_shift = this.VKI_capslock = this.VKI_alternate = this.VKI_dead = false; 367 this.VKI_deadkeysOn = (this.VKI_layoutDDK[this.VKI_kt]) ? false : this.VKI_keyboard.getElementsByTagName('label')[0].getElementsByTagName('input')[0].checked; 368 369 var container = this.VKI_keyboard.tBodies[0].getElementsByTagName('div')[0]; 370 while (container.firstChild) container.removeChild(container.firstChild); 371 372 for (var x = 0, hasDeadKey = false, lyt; lyt = this.VKI_layout[this.VKI_kt][x++];) { 373 var table = document.createElement('table'); 374 table.cellSpacing = table.border = "0"; 375 if (lyt.length <= this.VKI_keyCenter) table.className = "keyboardInputCenter"; 376 var tbody = document.createElement('tbody'); 377 var tr = document.createElement('tr'); 378 for (var y = 0, lkey; lkey = lyt[y++];) { 379 var td = document.createElement('td'); 380 td.appendChild(document.createTextNode(lkey[0])); 381 382 var className = []; 383 if (this.VKI_deadkeysOn) 384 for (key in this.VKI_deadkey) 385 if (key === lkey[0]) { className.push("alive"); break; } 386 if (lyt.length > this.VKI_keyCenter && y == lyt.length) className.push("last"); 387 if (lkey[0] == " ") className.push("space"); 388 td.className = className.join(" "); 389 390 td.VKI_clickless = 0; 391 if (!td.click) { 392 td.click = function() { 393 var evt = this.ownerDocument.createEvent('MouseEvents'); 394 evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); 395 this.dispatchEvent(evt); 396 }; 397 } 398 td.onmouseover = function() { 399 if (self.VKI_clickless) { 400 var _self = this; 401 clearTimeout(this.VKI_clickless); 402 this.VKI_clickless = setTimeout(function() { _self.click(); }, self.VKI_clicklessDelay); 403 } 404 if (this.firstChild.nodeValue != "\xa0") this.className += " hover"; 405 }; 406 td.onmouseout = function() { 407 if (self.VKI_clickless) clearTimeout(this.VKI_clickless); 408 this.className = this.className.replace(/ ?(hover|pressed)/g, ""); 409 }; 410 td.onmousedown = function() { 411 if (self.VKI_clickless) clearTimeout(this.VKI_clickless); 412 if (this.firstChild.nodeValue != "\xa0") this.className += " pressed"; 413 }; 414 td.onmouseup = function() { 415 if (self.VKI_clickless) clearTimeout(this.VKI_clickless); 416 this.className = this.className.replace(/ ?pressed/g, ""); 417 }; 418 td.ondblclick = function() { return false; }; 419 420 switch (lkey[1]) { 421 case "Caps": 422 case "Shift": 423 case "Alt": 424 case "AltGr": 425 td.onclick = (function(type) { return function() { self.VKI_modify(type); return false; }; })(lkey[1]); 426 break; 427 case "Tab": 428 td.onclick = function() { self.VKI_insert("\t"); return false; }; 429 break; 430 case "Bksp": 431 td.onclick = function() { 432 self.VKI_target.focus(); 433 if (self.VKI_target.setSelectionRange) { 434 if (self.VKI_target.readOnly && self.VKI_isWebKit) { 435 var rng = [self.VKI_target.selStart || 0, self.VKI_target.selEnd || 0]; 436 } else var rng = [self.VKI_target.selectionStart, self.VKI_target.selectionEnd]; 437 if (rng[0] < rng[1]) rng[0]++; 438 self.VKI_target.value = self.VKI_target.value.substr(0, rng[0] - 1) + self.VKI_target.value.substr(rng[1]); 439 self.VKI_target.setSelectionRange(rng[0] - 1, rng[0] - 1); 440 if (self.VKI_target.readOnly && self.VKI_isWebKit) { 441 var range = window.getSelection().getRangeAt(0); 442 self.VKI_target.selStart = range.startOffset; 443 self.VKI_target.selEnd = range.endOffset; 444 } 445 } else if (self.VKI_target.createTextRange) { 446 try { 447 self.VKI_target.range.select(); 448 } catch(e) { self.VKI_target.range = document.selection.createRange(); } 449 if (!self.VKI_target.range.text.length) self.VKI_target.range.moveStart('character', -1); 450 self.VKI_target.range.text = ""; 451 } else self.VKI_target.value = self.VKI_target.value.substr(0, self.VKI_target.value.length - 1); 452 if (self.VKI_shift) self.VKI_modify("Shift"); 453 if (self.VKI_alternate) self.VKI_modify("AltGr");
454 self.VKI_target.focus(); 455 return true; 456 }; 457 break; 458 case "Enter": 459 td.onclick = function() { 460 if (self.VKI_target.nodeName != "TEXTAREA") { 461 self.VKI_close(); 462 this.className = this.className.replace(/ ?(hover|pressed)/g, ""); 463 } else self.VKI_insert("\n"); 464 return true; 465 }; 466 break; 467 default: 468 td.onclick = function() { 469 if (self.VKI_deadkeysOn && self.VKI_dead) { 470 if (self.VKI_dead != this.firstChild.nodeValue) { 471 for (key in self.VKI_deadkey) { 472 if (key == self.VKI_dead) { 473 if (this.firstChild.nodeValue != " ") { 474 for (var z = 0, rezzed = false, dk; dk = self.VKI_deadkey[key][z++];) { 475 if (dk[0] == this.firstChild.nodeValue) { 476 self.VKI_insert(dk[1]); 477 rezzed = true; 478 break; 479 } 480 } 481 } else { 482 self.VKI_insert(self.VKI_dead); 483 rezzed = true; 484 } break; 485 } 486 } 487 } else rezzed = true; 488 } self.VKI_dead = false; 489 490 if (!rezzed && this.firstChild.nodeValue != "\xa0") { 491 if (self.VKI_deadkeysOn) { 492 for (key in self.VKI_deadkey) { 493 if (key == this.firstChild.nodeValue) { 494 self.VKI_dead = key; 495 this.className += " dead"; 496 if (self.VKI_shift) self.VKI_modify("Shift"); 497 if (self.VKI_alternate) self.VKI_modify("AltGr"); 498 break; 499 } 500 } 501 if (!self.VKI_dead) self.VKI_insert(this.firstChild.nodeValue); 502 } else self.VKI_insert(this.firstChild.nodeValue); 503 } 504 505 self.VKI_modify(""); 506 return false; 507 }; 508 509 } 510 tr.appendChild(td); 511 tbody.appendChild(tr); 512 table.appendChild(tbody); 513 514 for (var z = 0; z < 4; z++) 515 if (this.VKI_deadkey[lkey[z] = lkey[z] || "\xa0"]) hasDeadKey = true; 516 } 517 container.appendChild(table); 518 } 519 this.VKI_deadkeysElem.style.display = (!this.VKI_layoutDDK[this.VKI_kt] && hasDeadKey) ? "inline" : "none"; 520 }; 521 522 this.VKI_buildKeys(); 523 VKI_disableSelection(this.VKI_keyboard); 524 525 526 /* **************************************************************** 527 * Controls modifier keys 528 * 529 */ 530 this.VKI_modify = function(type) { 531 switch (type) { 532 case "Alt": 533 case "AltGr": this.VKI_alternate = !this.VKI_alternate; break; 534 case "Caps": this.VKI_capslock = !this.VKI_capslock; break; 535 case "Shift": this.VKI_shift = !this.VKI_shift; break; 536 } var vchar = 0; 537 if (!this.VKI_shift != !this.VKI_capslock) vchar += 1; 538 539 var tables = this.VKI_keyboard.getElementsByTagName('table'); 540 for (var x = 0; x < tables.length; x++) { 541 var tds = tables[x].getElementsByTagName('td'); 542 for (var y = 0; y < tds.length; y++) { 543 var className = []; 544 var lkey = this.VKI_layout[this.VKI_kt][x][y]; 545 546 if (tds[y].className.indexOf('hover') > -1) className.push("hover"); 547 548 switch (lkey[1]) { 549 case "Alt": 550 case "AltGr": 551 if (this.VKI_alternate) className.push("dead"); 552 break; 553 case "Shift": 554 if (this.VKI_shift) className.push("dead"); 555 break; 556 case "Caps": 557 if (this.VKI_capslock) className.push("dead"); 558 break; 559 case "Tab": case "Enter": case "Bksp": break; 560 default: 561 if (type) tds[y].firstChild.nodeValue = lkey[vchar + ((this.VKI_alternate && lkey.length == 4) ? 2 : 0)]; 562 if (this.VKI_deadkeysOn) { 563 var char = tds[y].firstChild.nodeValue; 564 if (this.VKI_dead) { 565 if (char == this.VKI_dead) className.push("dead"); 566 for (var z = 0; z < this.VKI_deadkey[this.VKI_dead].length; z++) { 567 if (char == this.VKI_deadkey[this.VKI_dead][z][0]) { 568 className.push("target"); 569 break; 570 } 571 } 572 } 573 for (key in this.VKI_deadkey)
574 if (key === char) { className.push("alive"); break; } 575 } 576 } 577 578 if (y == tds.length - 1 && tds.length > this.VKI_keyCenter) className.push("last"); 579 if (lkey[0] == " ") className.push("space"); 580 tds[y].className = className.join(" "); 581 } 582 } 583 }; 584 585 586 /* **************************************************************** 587 * Insert text at the cursor 588 * 589 */ 590 this.VKI_insert = function(text) { 591 this.VKI_target.focus(); 592 if (this.VKI_target.maxLength) this.VKI_target.maxlength = this.VKI_target.maxLength; 593 if (typeof this.VKI_target.maxlength == "undefined" || 594 this.VKI_target.maxlength < 0 || 595 this.VKI_target.value.length < this.VKI_target.maxlength) { 596 if (this.VKI_target.setSelectionRange) { 597 if (this.VKI_target.readOnly && this.VKI_isWebKit) { 598 var rng = [this.VKI_target.selStart || 0, this.VKI_target.selEnd || 0]; 599 } else var rng = [this.VKI_target.selectionStart, this.VKI_target.selectionEnd]; 600 this.VKI_target.value = this.VKI_target.value.substr(0, rng[0]) + text + this.VKI_target.value.substr(rng[1]); 601 if (text == "\n" && window.opera) rng[0]++; 602 this.VKI_target.setSelectionRange(rng[0] + text.length, rng[0] + text.length); 603 if (this.VKI_target.readOnly && this.VKI_isWebKit) { 604 var range = window.getSelection().getRangeAt(0); 605 this.VKI_target.selStart = range.startOffset; 606 this.VKI_target.selEnd = range.endOffset; 607 } 608 } else if (this.VKI_target.createTextRange) { 609 try { 610 this.VKI_target.range.select(); 611 } catch(e) { this.VKI_target.range = document.selection.createRange(); } 612 this.VKI_target.range.text = text; 613 this.VKI_target.range.collapse(true); 614 this.VKI_target.range.select(); 615 } else this.VKI_target.value += text; 616 if (this.VKI_shift) this.VKI_modify("Shift"); 617 if (this.VKI_alternate) this.VKI_modify("AltGr"); 618 this.VKI_target.focus(); 619 } else if (this.VKI_target.createTextRange && this.VKI_target.range) 620 this.VKI_target.range.select(); 621 }; 622 623 624 /* **************************************************************** 625 * Show the keyboard interface 626 * 627 */ 628 this.VKI_show = function(elem) { 629 if (this.VKI_target = elem) { 630 if (this.VKI_visible != elem) { 631 if (this.VKI_isIE) { 632 if (!this.VKI_target.range) { 633 this.VKI_target.range = this.VKI_target.createTextRange(); 634 this.VKI_target.range.moveStart('character', this.VKI_target.value.length); 635 } this.VKI_target.range.select(); 636 } 637 try { this.VKI_keyboard.parentNode.removeChild(this.VKI_keyboard); } catch (e) {} 638 if (this.VKI_clearPasswords && this.VKI_target.type == "password") this.VKI_target.value = ""; 639 640 var elem = this.VKI_target; 641 this.VKI_target.keyboardPosition = "absolute"; 642 do { 643 if (VKI_getStyle(elem, "position") == "fixed") { 644 this.VKI_target.keyboardPosition = "fixed"; 645 break; 646 } 647 } while (elem = elem.offsetParent); 648 649 if (this.VKI_isIE6) document.body.appendChild(this.VKI_iframe); 650 document.body.appendChild(this.VKI_keyboard); 651 this.VKI_keyboard.style.top = this.VKI_keyboard.style.right = this.VKI_keyboard.style.bottom = this.VKI_keyboard.style.left = "auto"; 652 this.VKI_keyboard.style.position = this.VKI_target.keyboardPosition; 653 654 this.VKI_visible = this.VKI_target; 655 this.VKI_position(); 656 this.VKI_target.focus(); 657 } else this.VKI_close(); 658 } 659 }; 660 661 662 /* **************************************************************** 663 * Position the keyboard 664 * 665 */ 666 this.VKI_position = function() { 667 if (self.VKI_visible) { 668 var inputElemPos = VKI_findPos(self.VKI_target); 669 self.VKI_keyboard.style.top = inputElemPos[1] - ((self.VKI_target.keyboardPosition == "fixed" && !self.VKI_isIE && !self.VKI_isMoz) ? VKI_scrollDist()[1] : 0) + self.VKI_target.offsetHeight + 3 + "px";
670 self.VKI_keyboard.style.left = Math.min(VKI_innerDimensions()[0] - self.VKI_keyboard.offsetWidth - 15, inputElemPos[0]) + "px"; 671 if (self.VKI_isIE6) { 672 self.VKI_iframe.style.width = self.VKI_keyboard.offsetWidth + "px"; 673 self.VKI_iframe.style.height = self.VKI_keyboard.offsetHeight + "px"; 674 self.VKI_iframe.style.top = self.VKI_keyboard.style.top; 675 self.VKI_iframe.style.left = self.VKI_keyboard.style.left; 676 } 677 } 678 }; 679 680 681 if (window.addEventListener) { 682 window.addEventListener('resize', this.VKI_position, false); 683 } else if (window.attachEvent) 684 window.attachEvent('onresize', this.VKI_position); 685 686 687 /* **************************************************************** 688 * Close the keyboard interface 689 * 690 */ 691 this.VKI_close = VKI_close = function() { 692 if (this.VKI_visible) { 693 try { 694 this.VKI_keyboard.parentNode.removeChild(this.VKI_keyboard); 695 if (this.VKI_isIE6) this.VKI_iframe.parentNode.removeChild(this.VKI_iframe); 696 } catch (e) {} 697 this.VKI_target.focus(); 698 this.VKI_target = this.VKI_visible = false; 699 } 700 }; 701 }; 702 703 function VKI_findPos(obj) { 704 var curleft = curtop = 0; 705 do { 706 curleft += obj.offsetLeft; 707 curtop += obj.offsetTop; 708 } while (obj = obj.offsetParent); 709 return [curleft, curtop]; 710 } 711 712 function VKI_innerDimensions() { 713 if (self.innerHeight) { 714 return [self.innerWidth, self.innerHeight]; 715 } else if (document.documentElement && document.documentElement.clientHeight) { 716 return [document.documentElement.clientWidth, document.documentElement.clientHeight]; 717 } else if (document.body) 718 return [document.body.clientWidth, document.body.clientHeight]; 719 return [0, 0]; 720 } 721 722 function VKI_scrollDist() { 723 var html = document.getElementsByTagName('html')[0]; 724 if (html.scrollTop && document.documentElement.scrollTop) { 725 return [html.scrollLeft, html.scrollTop]; 726 } else if (html.scrollTop || document.documentElement.scrollTop) 727 return [html.scrollLeft + document.documentElement.scrollLeft, html.scrollTop + document.documentElement.scrollTop]; 728 return [0, 0]; 729 } 730 731 function VKI_getStyle(obj, styleProp) { 732 if (obj.currentStyle) { 733 var y = obj.currentStyle[styleProp]; 734 } else if (window.getComputedStyle) 735 var y = window.getComputedStyle(obj, null)[styleProp]; 736 return y; 737 } 738 739 function VKI_disableSelection(elem) { 740 elem.onselectstart = function() { return false; }; 741 elem.unselectable = "on"; 742 elem.style.MozUserSelect = "none"; 743 elem.style.cursor = "default"; 744 if (window.opera) elem.onmousedown = function() { return false; }; 745 } 746 747 748 /* ***** Attach this script to the onload event ****************** */ 749 if (window.addEventListener) { 750 window.addEventListener('load', VKI_buildKeyboardInputs, false); 751 } else if (window.attachEvent) 752 window.attachEvent('onload', VKI_buildKeyboardInputs);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.