1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/sql-vyuka/web/vstupniPole.js Fri May 29 01:31:01 2009 +0200
1.3 @@ -0,0 +1,67 @@
1.4 +/** Umožní zadávat tabulátor */
1.5 +
1.6 +var tab = "\t";
1.7 +
1.8 +function checkTab(evt) {
1.9 +
1.10 + var t = evt.target;
1.11 + var ss = t.selectionStart;
1.12 + var se = t.selectionEnd;
1.13 +
1.14 +
1.15 + // Tabulátor
1.16 + if (evt.keyCode == 9) {
1.17 + evt.preventDefault();
1.18 +
1.19 + // Víceřádkový výběr
1.20 + if (ss != se && t.value.slice(ss,se).indexOf("\n") != -1) {
1.21 + var pre = t.value.slice(0,ss);
1.22 + var sel = t.value.slice(ss,se).replace(/\n/g,"\n"+tab);
1.23 + var post = t.value.slice(se,t.value.length);
1.24 + t.value = pre.concat(tab).concat(sel).concat(post);
1.25 + t.selectionStart = ss + tab.length;
1.26 + t.selectionEnd = se + tab.length;
1.27 + }
1.28 +
1.29 + // Jednořádkový nebo žádný výběr
1.30 + else {
1.31 + t.value = t.value.slice(0,ss).concat(tab).concat(t.value.slice(ss,t.value.length));
1.32 + if (ss == se) {
1.33 + t.selectionStart = t.selectionEnd = ss + tab.length;
1.34 + }
1.35 + else {
1.36 + t.selectionStart = ss + tab.length;
1.37 + t.selectionEnd = se + tab.length;
1.38 + }
1.39 + }
1.40 + }
1.41 +
1.42 + // Backspace
1.43 + else if (evt.keyCode==8 && t.value.slice(ss - 4,ss) == tab) {
1.44 + evt.preventDefault();
1.45 + t.value = t.value.slice(0,ss - 4).concat(t.value.slice(ss,t.value.length));
1.46 + t.selectionStart = t.selectionEnd = ss - tab.length;
1.47 + }
1.48 +
1.49 + // Delete
1.50 + else if (evt.keyCode==46 && t.value.slice(se,se + 4) == tab) {
1.51 + evt.preventDefault();
1.52 + t.value = t.value.slice(0,ss).concat(t.value.slice(ss + 4,t.value.length));
1.53 + t.selectionStart = t.selectionEnd = ss;
1.54 + }
1.55 +
1.56 + // Doleva
1.57 + else if (evt.keyCode == 37 && t.value.slice(ss - 4,ss) == tab) {
1.58 + alert("levá");
1.59 + evt.preventDefault();
1.60 + t.selectionStart = t.selectionEnd = ss - 4;
1.61 + }
1.62 +
1.63 +
1.64 + // Doprava
1.65 + else if (evt.keyCode == 39 && t.value.slice(ss,ss + 4) == tab) {
1.66 + alert("pravá");
1.67 + evt.preventDefault();
1.68 + t.selectionStart = t.selectionEnd = ss + 4;
1.69 + }
1.70 +}
1.71 \ No newline at end of file