1,25 → 1,24 |
var latRusWorker = null; |
var latRusEnabled = false; |
var latRusShowHint = true; |
|
var LatRus = { |
inited: false, |
worker: null, |
enabled: false, |
showHint: true, |
|
init: function() |
{ |
LatRus.worker = new LatRusWorker_Rus(); |
latRusWorker = new Worker(); |
|
LatRus.setEnabled(false); |
inited = true; |
}, |
|
onKeyPress: function(aEvent) |
{ |
if(!LatRus.enabled) return; |
if(!latRusEnabled) return; |
if(aEvent.ctrlKey || aEvent.altKey || aEvent.charCode == 0) return true; |
if(aEvent.keyCode == 255) return; // our loop event |
|
var newEvent = aEvent.target.ownerDocument.createEvent("KeyEvents"); |
newEvent.initKeyEvent(aEvent.type, aEvent.bubbles, aEvent.cancelable, aEvent.view, |
false, false, false, false, 255, LatRus.worker.convertCode(aEvent.charCode)); |
false, false, false, false, 255, latRusWorker.convertCode(aEvent.charCode)); |
aEvent.preventDefault(); |
aEvent.originalTarget.dispatchEvent(newEvent); |
}, |
26,12 → 25,12 |
|
toggleEnabled: function() |
{ |
LatRus.setEnabled(!LatRus.enabled); |
LatRus.setEnabled(!latRusEnabled); |
}, |
|
setEnabled: function(enabled) |
{ |
LatRus.enabled = enabled; |
latRusEnabled = enabled; |
LatRus.updateEnabled(); |
}, |
|
39,12 → 38,12 |
{ |
var item = document.getElementById("context-latrus-enabled"); |
if(item) { |
item.setAttribute("checked", LatRus.enabled); |
item.setAttribute("checked", latRusEnabled); |
} |
|
var panel = document.getElementById("latrus-panel"); |
if(panel) { |
panel.label = (LatRus.enabled ? "RUS" : "LAT"); |
panel.label = (latRusEnabled ? "RUS" : "LAT"); |
} |
}, |
|
93,7 → 92,7 |
var selection = LatRus.getSelectedText(e); |
if(!selection) return; |
|
var res = LatRus.worker[transformation].call(LatRus.worker, selection); |
var res = latRusWorker[transformation].call(latRusWorker, selection); |
var start = e.selectionStart; |
var end = e.selectionEnd; |
var scrollTop = e.scrollTop; |
108,12 → 107,12 |
|
toggleHint: function() |
{ |
LatRus.setHint(!LatRus.ShowHint); |
LatRus.setHint(!latRusShowHint); |
}, |
|
setHint: function(showHint) |
{ |
LatRus.ShowHint = showHint; |
latRusShowHint = showHint; |
LatRus.updateHint(); |
}, |
|
121,17 → 120,17 |
{ |
var item = document.getElementById("panel-latrus-show-hint"); |
if(item) { |
item.setAttribute("checked", LatRus.ShowHint); |
item.setAttribute("checked", latRusShowHint); |
} |
|
var panel = document.getElementById("latrus_hint"); |
if(panel) { |
panel.hidden = !LatRus.ShowHint; |
panel.hidden = !latRusShowHint; |
} |
|
var splitter = document.getElementById("latrus_splitter"); |
if(splitter) { |
splitter.hidden = !LatRus.ShowHint; |
splitter.hidden = !latRusShowHint; |
} |
}, |
|
142,117 → 141,88 |
}; |
|
/* REGISTER */ |
if(!LatRus.inited && !window.frameElement) { |
if(!latRusWorker && !window.frameElement) { |
window.addEventListener('load', LatRus.init, false); |
window.addEventListener('keypress', LatRus.onKeyPress, true); |
} |
|
function LatRusWorker() |
Worker.engTable = new Array( |
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
'\"', '\'', '§', '$', '&', '/', '(', ')', '=', '?', '`', '-', |
'_', '#', '+', '*', ',', '.', 'ä', 'ö', 'ü', 'ß'); |
Worker.rusTable1 = new Array( |
'а', 'б', 'ц', 'д', 'е', 'ф', 'г', 'х', 'и', 'й', 'к', 'л', 'м', |
'н', 'о', 'п', 'ч', 'р', 'с', 'т', 'у', 'в', 'ш', 'ж', 'я', 'з', |
'ъ', 'ь', '§', '$', '&', '/', '(', ')', '=', '?', '`', '-', |
'_', '#', '+', '*', ',', '.', 'э', 'ы', 'ю', 'щ'); |
Worker.rusTable2 = new Array( |
'ф', 'и', 'с', 'в', 'у', 'а', 'п', 'р', 'ш', 'о', 'л', 'д', 'ь', |
'т', 'щ', 'з', 'й', 'к', 'ы', 'е', 'г', 'м', 'ц', 'ч', 'я', 'н', |
'\"', '/', 'â„–', ';', ':', '?', '*', '(', ')', '_', '=', '.', |
',', '\\', 'ъ', 'Ъ', 'б', 'ю'); |
|
function Worker() |
{ |
this.init(); |
this.convertCodes = new Object(); |
this.convertChars = new Object(); |
this.backCodes = new Object(); |
this.backChars = new Object(); |
|
Worker.buildConvertTable(Worker.engTable, Worker.rusTable1, true, this.convertCodes, this.convertChars); |
Worker.buildConvertTable(Worker.rusTable1, Worker.engTable, true, this.backCodes, this.backChars); |
} |
LatRusWorker.prototype = { |
init: function() |
{ |
this.convertCodes = new Object(); |
this.convertChars = new Object(); |
this.backCodes = new Object(); |
this.backChars = new Object(); |
}, |
|
buildConvertTable: function(fromTable, toTable, autoUpperCase, resCodes, resChars) |
{ |
for(var i = 0, l = Math.min(fromTable.length, toTable.length); i < l; ++i) { |
resCodes[fromTable[i].charCodeAt(0)] = toTable[i].charCodeAt(0); |
resChars[fromTable[i].charAt(0)] = toTable[i].charAt(0); |
if(autoUpperCase) { |
var fromUpper = fromTable[i].toUpperCase() |
if(fromUpper != fromTable[i]) { |
var toUpper = toTable[i].toUpperCase(); |
Worker.buildConvertTable = function(fromTable, toTable, autoUpperCase, resCodes, resChars) |
{ |
for(var i = 0, l = Math.min(fromTable.length, toTable.length); i < l; ++i) { |
resCodes[fromTable[i].charCodeAt(0)] = toTable[i].charCodeAt(0); |
resChars[fromTable[i].charAt(0)] = toTable[i].charAt(0); |
if(autoUpperCase) { |
var fromUpper = fromTable[i].toUpperCase() |
if(fromUpper != fromTable[i]) { |
var toUpper = toTable[i].toUpperCase(); |
|
resCodes[fromUpper.charCodeAt(0)] = toUpper.charCodeAt(0); |
resChars[fromUpper.charAt(0)] = toUpper.charAt(0); |
} |
resCodes[fromUpper.charCodeAt(0)] = toUpper.charCodeAt(0); |
resChars[fromUpper.charAt(0)] = toUpper.charAt(0); |
} |
} |
}, |
} |
} |
|
convertCode: function(c) |
{ |
return this.convert(this.convertCodes, c); |
}, |
Worker.prototype.convertCode = function(c) |
{ |
return this.convert(this.convertCodes, c); |
} |
|
convertStringForward: function(s) |
{ |
return this.convertString(this.convertChars, s); |
}, |
|
convertStringBackward: function(s) |
{ |
return this.convertString(this.backChars, s); |
}, |
|
convertString: function(table, s) |
{ |
var res = ""; |
|
for(var i = 0, l = s.length; i < l; ++i) { |
res += this.convert(table, s.charAt(i)); |
} |
|
return res; |
}, |
|
convert: function(table, c) |
{ |
if(table) { |
var r = table[c]; |
if(r != undefined) return r; |
} |
|
return c; // not found or no table |
}, |
Worker.prototype.convertStringForward = function(s) |
{ |
return this.convertString(this.convertChars, s); |
} |
|
function LatRusWorker_Rus() |
Worker.prototype.convertStringBackward = function(s) |
{ |
this.__super = LatRusWorker; |
LatRusWorker_Rus.prototype.__proto__ = this.__super.prototype; |
this.__super.call(this); |
return this.convertString(this.backChars, s); |
} |
LatRusWorker_Rus.prototype = { |
engTable: new Array( |
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
'\"', '\'', '§', '$', '&', '/', '(', ')', '=', '?', '`', '-', |
'_', '#', '+', '*', ',', '.', 'ä', 'ö', 'ü', 'ß'), |
|
rusTable: new Array( |
'а', 'б', 'ц', 'д', 'е', 'ф', 'г', 'х', 'и', 'й', 'к', 'л', 'м', |
'н', 'о', 'п', 'ч', 'р', 'с', 'т', 'у', 'в', 'ш', 'ж', 'я', 'з', |
'ъ', 'ь', '§', '$', '&', '/', '(', ')', '=', '?', '`', '-', |
'_', '#', '+', '*', ',', '.', 'э', 'ы', 'ю', 'щ'), |
Worker.prototype.convertString = function(table, s) |
{ |
var res = ""; |
|
for(var i = 0, l = s.length; i < l; ++i) { |
res += this.convert(table, s.charAt(i)); |
} |
|
init: function() |
{ |
this.__super.prototype.init.apply(this); |
|
this.buildConvertTable(this.engTable, this.rusTable, true, this.convertCodes, this.convertChars); |
this.buildConvertTable(this.rusTable, this.engTable, true, this.backCodes, this.backChars); |
}, |
return res; |
} |
|
function LatRusWorker_RusStd() |
Worker.prototype.convert = function(table, c) |
{ |
this.__super = LatRusWorker_Rus; |
LatRusWorker_RusStd.prototype.__proto__ = this.__super.prototype; |
this.__super.call(this); |
if(table) { |
var r = table[c]; |
if(r != undefined) return r; |
} |
|
return c; // not found or no table |
} |
LatRusWorker_RusStd.prototype = { |
rusTable: new Array( |
'ф', 'и', 'с', 'в', 'у', 'а', 'п', 'р', 'ш', 'о', 'л', 'д', 'ь', |
'т', 'щ', 'з', 'й', 'к', 'ы', 'е', 'г', 'м', 'ц', 'ч', 'я', 'н', |
'\"', '/', 'â„–', ';', ':', '?', '*', '(', ')', '_', '=', '.', |
',', '\\', 'ъ', 'Ъ', 'б', 'ю'), |
} |
|