-
Notifications
You must be signed in to change notification settings - Fork 5
/
jkeymagic.js
executable file
·95 lines (86 loc) · 2.47 KB
/
jkeymagic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
if (window.console) {
var log = function () {
if (0) console.log(arguments)
}
var error = function (m) {
if (0) console.error(m)
}
} else {
var log = function () {
/*msg = '';
for (var i = 0; i < arguments.length; i++) {
if (i != 0) msg += ' - ';
msg += arguments[i];
}
document.getElementById('dbgView').innerHTML = msg;*/
};
var error = function () {};
}
var getElement = function (object) {
var element = null;
if (typeof object !== 'object') {
element = document.getElementById(object);
if (typeof element !== 'object') {
return null;
} else {
return element;
}
} else {
element = object;
return element;
}
}
var addEventHandler = function (element, type, listener) {
if (element.addEventListener) {
element.addEventListener(type, listener, false);
} else if (element.attachEvent && listener.call) {
element.attachEvent("on" + type, function () {
return listener.call(element, window.event);
}
);
} else {
error('Can\'t add event listner')
}
}
var removeEventHandler = function (element, type, listener) {
if (element.removeEventListener) {
element.removeEventListener(type, listener, false);
} else if (element.detachEvent) {
element.detachEvent("on" + type, listener);
}
}
JKME = {
enabledTags: ['TEXTAREA', 'INPUT'],
config: {
showMenu: true,
menuClassName: 'jkMenu',
logoUrl: 'keymagic.png'
},
attach: function (element) {
return new JKME.engine(element);
},
detach: function (element) {
element = getElement(element);
try {
engine = element.$;
removeEventHandler(element, 'keypress', engine.onkeypress);
removeEventHandler(element, 'keydown', engine.onkeydown);
removeEventHandler(element, 'mousemove', engine.onmousemove);
removeEventHandler(element, 'mouseout', engine.onmouseout);
document.body.removeChild(engine.menu.el);
} catch (ex) {
error(ex);
return false;
}
return true;
},
switchLayout: function(element, keyboardName) {
el = getElement(element);
if (el === null) {
return;
}
if (el.$) {
el.$.switchLayout(keyboardName);
}
}
}