Skip to content

Instantly share code, notes, and snippets.

@mwgamera
Created March 24, 2013 06:08
Show Gist options
  • Save mwgamera/5230765 to your computer and use it in GitHub Desktop.
Save mwgamera/5230765 to your computer and use it in GitHub Desktop.
Plena Ek!-stila klavarilo en Javascripto kun jQuery. Tajpu ĉapelajn leterojn en la x- aŭ h-sistemo kaj ripeto sufikson por forigi supersignon. Aŭ/eŭ estas aŭtomate supersignata.
// klg, 2013. WTFPL 2.
(function($) {
$.fn.eoime = function() {
return this.each(function(next, element, table) {
function replace(len, str, p, s) {
p = element.selectionStart;
s = element.value;
element.value = s.substr(0, p - len) + str + s.substr(p);
element.setSelectionRange(p -= len - 1, p);
}
function keypress(fun) {
return function(e) {
return e.type !== "keydown" ? init : function(e) {
return e.type !== "keypress" ? init : fun(e);
};
};
}
function kr(subst, rev, len) {
return keypress(function(e, a, b) {
if (b = subst[a = e.which]) {
replace(len, b);
e.preventDefault();
return keypress(function(e) {
if (e.which === a) {
replace(b.length, rev);
}
});
}
});
}
function init(e, c) {
return e.type === "keypress" && table[e.which];
}
function sc(u) {
return String.fromCharCode(u);
}
table = {};
// aŭtomata aŭ/eŭ
$.each([65, 97, 69, 101], function(a, b) {
table[b] = kr({85: sc(364), 117: sc(365)}, "", 0);
})
// h&x-sistemo
$.each([85, 117, 67, 71, 72, 74, 83, 99, 103, 104, 106, 115], function(a, b, c) {
c = {} // a > 1: «ŭ» nur en x-sistemo (h-sistemo uzas klara «u»)
$.each(a > 1 ? [72, 88, 104, 120] : [88, 120], function(d, b) {
c[b] = sc([364, 365, 264, 284, 292, 308, 348, 265, 285, 293, 309, 349][a]);
})
table[b] = kr(c, sc(b), 1);
});
$(element).on({
"focus paste": function() {
next = init;
},
"keydown keypress": function(e) {
next = next(e) || init(e) || init;
}
});
});
};
})(jQuery);
// klg, 2013. WTFPL 2.
(function($){"use strict";$.fn.eoime=function(){return this.each(function(j,e,h){function k(a,c){var b,f;b=e.selectionStart;f=e.value;e.value=f.substr(0,b-a)+c+f.substr(b);e.setSelectionRange(b-=a-1,b)}function l(a){return function(c){return"keydown"!==c.type?d:function(b){return"keypress"!==b.type?d:a(b)}}}function m(a,c,b){return l(function(f,e,d){if(d=a[e=f.which])return k(b,d),f.preventDefault(),l(function(a){a.which===e&&k(d.length,c)})})}function d(a){return"keypress"===a.type&&h[a.which]}h={};function g(a){return String.fromCharCode(a)}$.each([65,97,69,101],function(a,c){h[c]=m({85:g(364),117:g(365)},"",0)});$.each([85,117,67,71,72,74,83,99,103,104,106,115],function(a,c,b){b={};$.each(1<a?[72,88,104,120]:[88,120],function(c,d){b[d]=g([364,365,264,284,292,308,348,265,285,293,309,349][a])});h[c]=m(b,g(c),1)});$(e).on({"focus paste":function(){j=d},"keydown keypress":function(a){j=j(a)||d(a)||d}})})}})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment