1(function() { 2 3 /** 4 * GeoKBD 0.3 - Georgian keyboard and text convertation library 5 * 6 * Copyright (c) 2007 Ioseb Dzmanashvili (http://www.code.ge) 7 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 8 */ 9 10 String.prototype.pasteTo = function(field) { 11 field.focus(); 12 if (document.selection) { 13 var selection = document.selection; 14 var range = selection.createRange(); 15 16 if (range) { 17 range.text = this; 18 } 19 range.collapse(false); 20 range.select(); 21 } else if (field.selectionStart || field.selectionEnd) { 22 var scrollTop = field.scrollTop, start = field.selectionStart, end = field.selectionEnd; 23 var value = field.value.substring(0, start) + this + field.value.substring(end, field.value.length); 24 field.value = value; 25 field.scrollTop = scrollTop; 26 field.selectionStart = field.selectionEnd = start + this.length; 27 } else { 28 field.value += this; 29 field.selectionStart = field.selectionEnd = field.value.length; 30 } 31 }, 32 33 String.prototype.translateToKA = function() { 34 35 /** 36 * Original idea by Irakli Nadareishvili 37 * http://www.sapikhvno.org/viewtopic.php?t=47&postdays=0&postorder=asc&start=10 38 */ 39 var index, chr, text = [], symbols = "abgdevzTiklmnopJrstufqRySCcZwWxjh"; 40 41 for (var i = 0; i < this.length; i++) { 42 chr = this.substr(i, 1); 43 if ((index = symbols.indexOf(chr)) >= 0) { 44 text.push(String.fromCharCode(index + 4304)); 45 } else { 46 text.push(chr); 47 } 48 } 49 return text.join(''); 50 }, 51 52 GeoKBD = { 53 54 browser: { 55 isOpera: navigator.userAgent.toLowerCase().indexOf('opera') > -1, 56 isIe: navigator.userAgent.toLowerCase().indexOf('msie') > -1, 57 isIe6: navigator.userAgent.toLowerCase().indexOf('msie 6') > -1, 58 isIe7: navigator.userAgent.toLowerCase().indexOf('msie 7') > -1 59 }, 60 61 event: { 62 63 get: function(e) { 64 return e || window.event; 65 }, 66 67 getKeyCode: function(e) { 68 e = this.get(e); 69 return e.keyCode || e.which; 70 }, 71 72 targetIs: function(e, tagName) { 73 e = this.get(e); 74 var t = e.target || e.srcElement; 75 return t.tagName.toLowerCase() == tagName ? t : null; 76 }, 77 78 attach: function(obj, eventName, fnc, capture) { 79 if (obj.addEventListener) { 80 obj.addEventListener(eventName, fnc, capture); 81 } else if (obj.attachEvent) { 82 return obj.attachEvent('on' + eventName, fnc); 83 } else { 84 obj['on' + eventName] = fnc; 85 } 86 }, 87 88 detach: function(obj, eventName, fnc, capture) { 89 if (obj.removeEventListener) { 90 obj.removeEventListener(eventName, fnc, capture); 91 } else if (obj.detachEvent) { 92 obj.detachEvent('on' + eventName, fnc); 93 } else { 94 obj['on' + eventName] = null; 95 } 96 }, 97 98 cancel: function(e) { 99 e = this.get(e); 100 if (e.stopPropagation) { 101 e.stopPropagation(); 102 e.preventDefault(); 103 } else { 104 e.cancelBubble = true; 105 e.returnValue = false; 106 } 107 } 108 109 }, 110 111 map: function(form, fieldName, switcher) { 112 113 var self = this; 114 115 form = (typeof form == 'string') ? document.forms[form] : form; 116 117 if (!form.fields || form.fields == undefined) form.fields = {}; 118 if (form.ka == undefined) form.ka = form[switcher] ? form[switcher].checked : true; 119 120 if (fieldName) { 121 if (typeof fieldName == 'string') fieldName = [fieldName]; 122 for (var i = 0; i < fieldName.length; i++) { 123 if (form[fieldName[i]] && !form.fields[fieldName[i]]) form.fields[fieldName[i]] = fieldName[i]; 124 } 125 } else { 126 var name, type; 127 for (var i = 0; i < form.elements.length; i++) { 128 if (form.elements[i].type) { 129 name = form.elements[i].name; type = form.elements[i].type.toLowerCase(); 130 if (type == 'text' || type == 'textarea') { 131 form.fields[name] = name; 132 } 133 } 134 } 135 } 136 137 switcher = switcher || 'geo'; 138 form.switcher = switcher; 139 140 form.onkeypress = function(e) { 141 142 e = self.event.get(e); 143 if (e.altKey || e.ctrlKey) return; 144 145 var target, _switcher = switcher, keyCode = self.event.getKeyCode(e); 146 147 if (keyCode == 96) { 148 if (this[_switcher]) { 149 this.ka = this[_switcher].checked = !this[_switcher].checked; 150 } else { 151 this.ka = !this.ka; 152 } 153 154 //by Elrian 155 SaveGeo(); 156 try{ 157 setKbVal(); 158 } 159 catch(e){ 160 } 161 //--- 162 return false; 163 } else if (this[_switcher]) { 164 this.ka = this[_switcher].checked; 165 } 166 167 if (!this.ka) return; 168 169 if ((target = (self.event.targetIs(e, 'textarea') || self.event.targetIs(e, 'input')))) { 170 if (!this.fields[target.name]) return; 171 text = String.fromCharCode(keyCode); 172 kaText = text.translateToKA(); 173 if (kaText != text) { 174 kaText.pasteTo(target); 175 return false; 176 } 177 } 178 } 179 180 form = null; 181 182 }, 183 184 mapIFrame: function(iframe) { 185 186 var __keypress = function(e) { 187 188 var doc = (e.target || e.srcElement).ownerDocument; 189 if (doc.ka == undefined) doc.ka = true; 190 var keyCode = GeoKBD.event.getKeyCode(e); 191 var text = String.fromCharCode(keyCode); 192 var form, switcher; 193 if (parent.document.forms[doc.parentForm]) { 194 form = parent.document.forms[doc.parentForm]; 195 if (form.switcher && form[form.switcher]) { 196 switcher = form[form.switcher]; 197 } 198 } 199 200 if (keyCode == 96) { 201 doc.ka = !doc.ka; 202 if (switcher) switcher.checked = doc.ka; 203 GeoKBD.event.cancel(e); 204 } else if (switcher) { 205 doc.ka = switcher.checked; 206 } 207 208 form = switcher = null; 209 210 if (doc.ka) { 211 var kaText = text.translateToKA(); 212 if (kaText != text) { 213 if (!GeoKBD.browser.isIe) { 214 doc.execCommand('InsertHTML', false, kaText); 215 } else { 216 var range = doc.selection.createRange(); 217 range.pasteHTML(kaText); 218 } 219 GeoKBD.event.cancel(e); 220 } 221 } 222 223 } 224 225 var __focus = function(e) { 226 if (!GeoKBD.browser.isIe) { 227 GeoKBD.event.attach(this.document, 'keypress', __keypress, true); 228 GeoKBD.event.detach(this, 'focus', __focus, true); 229 } else { 230 GeoKBD.event.attach(this.contentWindow.document, 'keypress', __keypress, true); 231 this.onfocus = null; 232 } 233 }; 234 235 var interval = window.setInterval(function() { 236 var el = typeof iframe=='string' ? document.getElementById(iframe) : iframe(); 237 if (el) { 238 for (var p = el.parentNode; p && p != document.body; p = p.parentNode) { 239 if (/form/i.test(p.tagName)) { 240 if (el.contentWindow.document) { 241 el.contentWindow.document.parentForm = p.name || p.id; 242 } else { 243 el.document.parentForm = p.name || p.id; 244 } 245 break; 246 } 247 } 248 if (!GeoKBD.browser.isIe) { 249 GeoKBD.event.attach(el.contentWindow, 'focus', __focus, true); 250 } else { 251 el.onfocus = __focus; 252 } 253 el = null; 254 window.clearInterval(interval); 255 } 256 }, 100); 257 258 } 259 260 }; 261 262 window.GeoKBD = GeoKBD; 263 264})();
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.