Skip to content

Commit b8804bf

Browse files
committed
Changed UNBIND to not interfere with other events
1 parent 4f5fee1 commit b8804bf

File tree

1 file changed

+54
-50
lines changed

1 file changed

+54
-50
lines changed

jquery.geo.typing.js

+54-50
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,64 @@
66
* Licensed under GPL:
77
* http://www.gnu.org/licenses/gpl.html
88
*/
9-
(function($){
10-
$.fn.geo = function(opt) {
11-
var def = {
12-
turn: "on",
13-
};
14-
var opt = $.extend(def, opt);
15-
$(this).unbind();
16-
this.each(function() {
17-
$(this).keypress(function(e) {
18-
if(!e.ctrlKey && !e.altKey && !e.metaKey) {
19-
var code = (e.keyCode ? e.keyCode : e.which);
20-
if(code > 64 && code <= 127) {
21-
if(opt.turn == "off"){ return true; }else{
22-
e.preventDefault();
23-
var text = String.fromCharCode(ide(code));
24-
if (document.selection) {
25-
this.focus();
26-
var sel = document.selection.createRange();
27-
sel.select();
28-
sel.text = text;
29-
var lenght = sel.text.lenght;
30-
sel.moveStart('character', text.length);
31-
sel.moveEnd('character', text.length);
32-
}else if(this.selectionStart || this.selectionStart == 0){
33-
var start = this.selectionStart;
34-
var end = this.selectionEnd;
35-
var prefix = this.value.substring(0, start);
36-
var suffix = this.value.substring(end,this.value.length);
37-
var scrollTop = this.scrollTop;
38-
this.value = prefix + text + suffix;
39-
this.focus();
40-
this.selectionStart = start + text.length;
41-
this.selectionEnd = end + text.length;
42-
this.scrollTop = scrollTop;
43-
}else{
44-
this.value+=text;
45-
}
46-
}}}});});
9+
(function($) {
10+
$.fn.geo = function(opt) {
11+
var def = {
12+
turn: "on"
13+
};
14+
var opt = $.extend(def, opt);
15+
$(this).unbind('keypress');
16+
this.each(function() {
17+
$(this).keypress(function(e) {
18+
if (!e.ctrlKey && !e.altKey && !e.metaKey) {
19+
var code = (e.keyCode ? e.keyCode : e.which);
20+
if (code > 64 && code <= 127) {
21+
if (opt.turn === "on") {
22+
e.preventDefault();
23+
var text = String.fromCharCode(ide(code));
24+
if (document.selection) {
25+
this.focus();
26+
var sel = document.selection.createRange();
27+
sel.select();
28+
sel.text = text;
29+
var lenght = sel.text.lenght;
30+
sel.moveStart('character', text.length);
31+
sel.moveEnd('character', text.length);
32+
} else if (this.selectionStart || this.selectionStart === 0) {
33+
var start = this.selectionStart;
34+
var end = this.selectionEnd;
35+
var prefix = this.value.substring(0, start);
36+
var suffix = this.value.substring(end, this.value.length);
37+
var scrollTop = this.scrollTop;
38+
this.value = prefix + text + suffix;
39+
this.focus();
40+
this.selectionStart = start + text.length;
41+
this.selectionEnd = end + text.length;
42+
this.scrollTop = scrollTop;
43+
} else {
44+
this.value += text;
45+
}
46+
}
47+
}
48+
}
49+
});
50+
});
4751
// Mapping
48-
function ide(num){
52+
function ide(num) {
4953
var value = lookUp[num];
5054
return value ? value : num;
5155
}
5256
//lookup table
5357
var lookUp = {
54-
74: 4319, 82: 4326, 83: 4328, 90: 4331,
55-
97: 4304, 98: 4305, 99: 4330, 100:4307,
56-
101:4308, 102:4324, 103:4306, 104:4336,
57-
105:4312, 106:4335, 107:4313, 108:4314,
58-
109:4315, 110:4316, 111:4317, 112:4318,
59-
113:4325, 114:4320, 115:4321, 116:4322,
60-
84:4311, 117:4323, 118:4309, 119:4332,
61-
87:4333, 120:4334, 121:4327, 122:4310,
62-
67:4329,
58+
74: 4319, 82: 4326, 83: 4328, 90: 4331,
59+
97: 4304, 98: 4305, 99: 4330, 100: 4307,
60+
101: 4308, 102: 4324, 103: 4306, 104: 4336,
61+
105: 4312, 106: 4335, 107: 4313, 108: 4314,
62+
109: 4315, 110: 4316, 111: 4317, 112: 4318,
63+
113: 4325, 114: 4320, 115: 4321, 116: 4322,
64+
84: 4311, 117: 4323, 118: 4309, 119: 4332,
65+
87: 4333, 120: 4334, 121: 4327, 122: 4310,
66+
67: 4329
6367
};
64-
};
65-
})(jQuery);
68+
};
69+
})(jQuery);

0 commit comments

Comments
 (0)