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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
-
|
|
|
|
-
|
|
|
|
|
|
|
-
|
!
-
-
|
|
!
-
|
|
|
!
!
-
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
-
|
|
!
|
|
!
!
!
|
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {try{
var SCROLLHEIGHT = 200;
var documentBody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body;
var SmoothScroll = {
steps : 20,
duration : 100,
destinationx: null,
destinationy: null,
timerID: null,
callBackFunc: null,
setCallback : function(f) {
this.callBackFunc = f;
},
stop : function() {
if (this.timerID != null) {
clearTimeout(this.timerID);
this.timerID = null;
}
if ((this.destinationx != null) && (this.destinationy != null)) {
scrollTo(this.destinationx, this.destinationy);
this.destinationx = null;
this.destinationy = null;
}
},
scrollTo : function(destX, destY){
this.destinationx = destX;
this.destinationy = destY;
this.step = 0;
var self = this;
this.prevY = -1;
self.timerID = setTimeout(function() {
var y = documentBody.scrollTop;
yy = self.destinationy - ((self.destinationy - y) / 2);
if ((y == self.prevY) || (Math.abs(self.destinationy - yy) < 1) || (self.step + 1 == self.steps)) {
scrollTo(self.destinationx, self.destinationy);
setTimeout(function() { if (self.callBackFunc != null) self.callBackFunc(); }, 10);
self.destinationx = null;
self.destinationy = null;
} else {
scrollTo(self.destinationx, yy);
self.timerID = setTimeout(arguments.callee, (self.duration / self.steps) * (self.step + 1));
}
self.step++;
this.prevY = y;
}, (this.duration / this.steps) * this.step + 1);
}
};
var ShortcutKey = {
repKey: {
'8': 'BS','9': 'TAB','13': 'Enter','27': 'ESC',
'33': 'PageUp','34': 'PageDown',
'35': 'End','36': 'Home',
'37': 'Left','38': 'Up','39': 'Right','40': 'Down',
'45': 'Insert','46': 'Delete',
'188': ',', '189': '-', '190': '.','191': '/', '192': '@',
'219': '[', '220': '\\', '221': ']', '222': '^', '226': '\\'
},
deepKey: ['ESC', 'TAB', 'Home', 'End', 'Insert', 'Delete', 'C-.+', 'A-.+'].join('|'),
keyEvent: [],
init: function() {
document.body.attachEvent('onkeydown', ShortcutKey.keyHandle);
window.attachEvent('onunload', function() {
document.body.detachEvent('onkeydown', ShortcutKey.keyHandle);
window.detachEvent('onunload', arguments.callee);
});
},
keyHandle: function(event) {
var event = window.event;
var key = '';
var rep = false;
for (var i in ShortcutKey.repKey) {
if (i == event.keyCode) {
key = ShortcutKey.repKey[i];
rep = true;
break;
}
}
if (key == '')
key = String.fromCharCode(event.keyCode).toLowerCase();
key = (event.shiftKey) ? "S-" + key : key;
key = (event.ctrlKey) ? "C-" + key : key;
key = (event.altKey || event.metaKey) ? "A-" + key : key;
var re = new RegExp(ShortcutKey.deepKey);
var isDeep = re.test(key);
if ((document.activeElement.tagName.match(/input|textarea/i)) && (!isDeep)) return;
var func = ShortcutKey.keyEvent[key];
if(func){
func();
event.cancelBubble = true;
event.returnValue = false;
}
},
add: function(key, func) {
ShortcutKey.keyEvent[key] = func;
}
}
ShortcutKey.init();
if ((window.LDRize) && (window.LDRize.getCurrentParagraph())) {
window.LDRize.addKeyBind('S-j', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop + SCROLLHEIGHT);
});
window.LDRize.addKeyBind('S-k', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop - SCROLLHEIGHT);
});
} else {
ShortcutKey.add('j', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop + SCROLLHEIGHT);
});
ShortcutKey.add('k', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop - SCROLLHEIGHT);
});
}
}catch(e){}
}, 0);
|