java/sql-vyuka/web/vstupniPole.js
author František Kučera <franta-hg@frantovo.cz>
Sun Apr 07 18:38:36 2013 +0200 (2013-04-07)
changeset 81 6fb319847482
parent 22 e56b79cc18a9
permissions -rw-r--r--
Oprava: Obecné ECMAScriptové nahrazování řetězců.
Chyba se projevovala v Chromiu, ve FF to fungovalo.
Při kliknutí na SQL v průvodci (např. „Restrikce – operátory“), které obsahuje víc > se nahradil jen první výskyt (ignorování nestandardního "g").
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace
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@80
     7
	var t = evt.target;
franta-hg@80
     8
	var ss = t.selectionStart;
franta-hg@80
     9
	var se = t.selectionEnd;
franta-hg@14
    10
franta-hg@14
    11
franta-hg@80
    12
	// Tabulátor
franta-hg@80
    13
	if (evt.keyCode == 9) {
franta-hg@80
    14
		evt.preventDefault();
franta-hg@14
    15
franta-hg@80
    16
		// Víceřádkový výběr
franta-hg@80
    17
		if (ss != se && t.value.slice(ss,se).indexOf("\n") != -1) {
franta-hg@80
    18
			var pre = t.value.slice(0,ss);
franta-hg@80
    19
			var sel = t.value.slice(ss,se).replace(/\n/g,"\n"+tab);
franta-hg@80
    20
			var post = t.value.slice(se,t.value.length);
franta-hg@80
    21
			t.value = pre.concat(tab).concat(sel).concat(post);
franta-hg@80
    22
			t.selectionStart = ss + tab.length;
franta-hg@80
    23
			t.selectionEnd = se + tab.length;
franta-hg@80
    24
		}
franta-hg@14
    25
franta-hg@80
    26
		// Jednořádkový nebo žádný výběr
franta-hg@80
    27
		else {
franta-hg@80
    28
			t.value = t.value.slice(0,ss).concat(tab).concat(t.value.slice(ss,t.value.length));
franta-hg@80
    29
			if (ss == se) {
franta-hg@80
    30
				t.selectionStart = t.selectionEnd = ss + tab.length;
franta-hg@80
    31
			}
franta-hg@80
    32
			else {
franta-hg@80
    33
				t.selectionStart = ss + tab.length;
franta-hg@80
    34
				t.selectionEnd = se + tab.length;
franta-hg@80
    35
			}
franta-hg@80
    36
		}
franta-hg@80
    37
	}
franta-hg@14
    38
franta-hg@80
    39
	// Backspace
franta-hg@80
    40
	else if (evt.keyCode==8 && t.value.slice(ss - 4,ss) == tab) {
franta-hg@80
    41
		evt.preventDefault();
franta-hg@80
    42
		t.value = t.value.slice(0,ss - 4).concat(t.value.slice(ss,t.value.length));
franta-hg@80
    43
		t.selectionStart = t.selectionEnd = ss - tab.length;
franta-hg@80
    44
	}
franta-hg@14
    45
franta-hg@80
    46
	// Delete
franta-hg@80
    47
	else if (evt.keyCode==46 && t.value.slice(se,se + 4) == tab) {
franta-hg@80
    48
		evt.preventDefault();
franta-hg@80
    49
		t.value = t.value.slice(0,ss).concat(t.value.slice(ss + 4,t.value.length));
franta-hg@80
    50
		t.selectionStart = t.selectionEnd = ss;
franta-hg@80
    51
	}
franta-hg@14
    52
franta-hg@80
    53
	// Doleva
franta-hg@80
    54
	else if (evt.keyCode == 37 && t.value.slice(ss - 4,ss) == tab) {
franta-hg@80
    55
		alert("levá");
franta-hg@80
    56
		evt.preventDefault();
franta-hg@80
    57
		t.selectionStart = t.selectionEnd = ss - 4;
franta-hg@80
    58
	}
franta-hg@14
    59
franta-hg@80
    60
	// Doprava
franta-hg@80
    61
	else if (evt.keyCode == 39 && t.value.slice(ss,ss + 4) == tab) {
franta-hg@80
    62
		alert("pravá");
franta-hg@80
    63
		evt.preventDefault();
franta-hg@80
    64
		t.selectionStart = t.selectionEnd = ss + 4;
franta-hg@80
    65
	}
franta-hg@80
    66
}