franta-hg@14
|
1 |
/** Umožní zadávat tabulátor */
|
franta-hg@14
|
2 |
|
franta-hg@14
|
3 |
var tab = "\t";
|
franta-hg@14
|
4 |
|
franta-hg@22
|
5 |
function zpracujTabulatory(evt) {
|
franta-hg@14
|
6 |
|
franta-hg@14
|
7 |
var t = evt.target;
|
franta-hg@14
|
8 |
var ss = t.selectionStart;
|
franta-hg@14
|
9 |
var se = t.selectionEnd;
|
franta-hg@14
|
10 |
|
franta-hg@14
|
11 |
|
franta-hg@14
|
12 |
// Tabulátor
|
franta-hg@14
|
13 |
if (evt.keyCode == 9) {
|
franta-hg@14
|
14 |
evt.preventDefault();
|
franta-hg@14
|
15 |
|
franta-hg@14
|
16 |
// Víceřádkový výběr
|
franta-hg@14
|
17 |
if (ss != se && t.value.slice(ss,se).indexOf("\n") != -1) {
|
franta-hg@14
|
18 |
var pre = t.value.slice(0,ss);
|
franta-hg@14
|
19 |
var sel = t.value.slice(ss,se).replace(/\n/g,"\n"+tab);
|
franta-hg@14
|
20 |
var post = t.value.slice(se,t.value.length);
|
franta-hg@14
|
21 |
t.value = pre.concat(tab).concat(sel).concat(post);
|
franta-hg@14
|
22 |
t.selectionStart = ss + tab.length;
|
franta-hg@14
|
23 |
t.selectionEnd = se + tab.length;
|
franta-hg@14
|
24 |
}
|
franta-hg@14
|
25 |
|
franta-hg@14
|
26 |
// Jednořádkový nebo žádný výběr
|
franta-hg@14
|
27 |
else {
|
franta-hg@14
|
28 |
t.value = t.value.slice(0,ss).concat(tab).concat(t.value.slice(ss,t.value.length));
|
franta-hg@14
|
29 |
if (ss == se) {
|
franta-hg@14
|
30 |
t.selectionStart = t.selectionEnd = ss + tab.length;
|
franta-hg@14
|
31 |
}
|
franta-hg@14
|
32 |
else {
|
franta-hg@14
|
33 |
t.selectionStart = ss + tab.length;
|
franta-hg@14
|
34 |
t.selectionEnd = se + tab.length;
|
franta-hg@14
|
35 |
}
|
franta-hg@14
|
36 |
}
|
franta-hg@14
|
37 |
}
|
franta-hg@14
|
38 |
|
franta-hg@14
|
39 |
// Backspace
|
franta-hg@14
|
40 |
else if (evt.keyCode==8 && t.value.slice(ss - 4,ss) == tab) {
|
franta-hg@14
|
41 |
evt.preventDefault();
|
franta-hg@14
|
42 |
t.value = t.value.slice(0,ss - 4).concat(t.value.slice(ss,t.value.length));
|
franta-hg@14
|
43 |
t.selectionStart = t.selectionEnd = ss - tab.length;
|
franta-hg@14
|
44 |
}
|
franta-hg@14
|
45 |
|
franta-hg@14
|
46 |
// Delete
|
franta-hg@14
|
47 |
else if (evt.keyCode==46 && t.value.slice(se,se + 4) == tab) {
|
franta-hg@14
|
48 |
evt.preventDefault();
|
franta-hg@14
|
49 |
t.value = t.value.slice(0,ss).concat(t.value.slice(ss + 4,t.value.length));
|
franta-hg@14
|
50 |
t.selectionStart = t.selectionEnd = ss;
|
franta-hg@14
|
51 |
}
|
franta-hg@14
|
52 |
|
franta-hg@14
|
53 |
// Doleva
|
franta-hg@14
|
54 |
else if (evt.keyCode == 37 && t.value.slice(ss - 4,ss) == tab) {
|
franta-hg@14
|
55 |
alert("levá");
|
franta-hg@14
|
56 |
evt.preventDefault();
|
franta-hg@14
|
57 |
t.selectionStart = t.selectionEnd = ss - 4;
|
franta-hg@14
|
58 |
}
|
franta-hg@14
|
59 |
|
franta-hg@14
|
60 |
// Doprava
|
franta-hg@14
|
61 |
else if (evt.keyCode == 39 && t.value.slice(ss,ss + 4) == tab) {
|
franta-hg@14
|
62 |
alert("pravá");
|
franta-hg@14
|
63 |
evt.preventDefault();
|
franta-hg@14
|
64 |
t.selectionStart = t.selectionEnd = ss + 4;
|
franta-hg@14
|
65 |
}
|
franta-hg@14
|
66 |
} |