Show
Ignore:
Timestamp:
05/24/12 15:47:48 (12 years ago)
Author:
František Kučera <franta-hg@…>
Branch:
default
Message:

Lepší odsazení JavaScriptu? (tabulátory).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • java/sql-vyuka/web/vstupniPole.js

    r22 r80  
    55function zpracujTabulatory(evt) { 
    66 
    7     var t = evt.target; 
    8     var ss = t.selectionStart; 
    9     var se = t.selectionEnd; 
     7        var t = evt.target; 
     8        var ss = t.selectionStart; 
     9        var se = t.selectionEnd; 
    1010 
    1111 
    12     // Tabulátor 
    13     if (evt.keyCode == 9) { 
    14         evt.preventDefault(); 
     12        // Tabulátor 
     13        if (evt.keyCode == 9) { 
     14                evt.preventDefault(); 
    1515 
    16         // Víceřádkový výběr 
    17         if (ss != se && t.value.slice(ss,se).indexOf("\n") != -1) { 
    18             var pre = t.value.slice(0,ss); 
    19             var sel = t.value.slice(ss,se).replace(/\n/g,"\n"+tab); 
    20             var post = t.value.slice(se,t.value.length); 
    21             t.value = pre.concat(tab).concat(sel).concat(post); 
    22             t.selectionStart = ss + tab.length; 
    23             t.selectionEnd = se + tab.length; 
    24         } 
     16                // Víceřádkový výběr 
     17                if (ss != se && t.value.slice(ss,se).indexOf("\n") != -1) { 
     18                        var pre = t.value.slice(0,ss); 
     19                        var sel = t.value.slice(ss,se).replace(/\n/g,"\n"+tab); 
     20                        var post = t.value.slice(se,t.value.length); 
     21                        t.value = pre.concat(tab).concat(sel).concat(post); 
     22                        t.selectionStart = ss + tab.length; 
     23                        t.selectionEnd = se + tab.length; 
     24                } 
    2525 
    26         // Jednořádkový nebo žádný výběr 
    27         else { 
    28             t.value = t.value.slice(0,ss).concat(tab).concat(t.value.slice(ss,t.value.length)); 
    29             if (ss == se) { 
    30                 t.selectionStart = t.selectionEnd = ss + tab.length; 
    31             } 
    32             else { 
    33                 t.selectionStart = ss + tab.length; 
    34                 t.selectionEnd = se + tab.length; 
    35             } 
    36         } 
    37     } 
     26                // Jednořádkový nebo žádný výběr 
     27                else { 
     28                        t.value = t.value.slice(0,ss).concat(tab).concat(t.value.slice(ss,t.value.length)); 
     29                        if (ss == se) { 
     30                                t.selectionStart = t.selectionEnd = ss + tab.length; 
     31                        } 
     32                        else { 
     33                                t.selectionStart = ss + tab.length; 
     34                                t.selectionEnd = se + tab.length; 
     35                        } 
     36                } 
     37        } 
    3838 
    39     // Backspace 
    40     else if (evt.keyCode==8 && t.value.slice(ss - 4,ss) == tab) { 
    41         evt.preventDefault(); 
    42         t.value = t.value.slice(0,ss - 4).concat(t.value.slice(ss,t.value.length)); 
    43         t.selectionStart = t.selectionEnd = ss - tab.length; 
    44     } 
     39        // Backspace 
     40        else if (evt.keyCode==8 && t.value.slice(ss - 4,ss) == tab) { 
     41                evt.preventDefault(); 
     42                t.value = t.value.slice(0,ss - 4).concat(t.value.slice(ss,t.value.length)); 
     43                t.selectionStart = t.selectionEnd = ss - tab.length; 
     44        } 
    4545 
    46     // Delete 
    47     else if (evt.keyCode==46 && t.value.slice(se,se + 4) == tab) { 
    48         evt.preventDefault(); 
    49         t.value = t.value.slice(0,ss).concat(t.value.slice(ss + 4,t.value.length)); 
    50         t.selectionStart = t.selectionEnd = ss; 
    51     } 
     46        // Delete 
     47        else if (evt.keyCode==46 && t.value.slice(se,se + 4) == tab) { 
     48                evt.preventDefault(); 
     49                t.value = t.value.slice(0,ss).concat(t.value.slice(ss + 4,t.value.length)); 
     50                t.selectionStart = t.selectionEnd = ss; 
     51        } 
    5252 
    53     // Doleva 
    54     else if (evt.keyCode == 37 && t.value.slice(ss - 4,ss) == tab) { 
    55         alert("levá"); 
    56         evt.preventDefault(); 
    57         t.selectionStart = t.selectionEnd = ss - 4; 
    58     } 
     53        // Doleva 
     54        else if (evt.keyCode == 37 && t.value.slice(ss - 4,ss) == tab) { 
     55                alert("levá"); 
     56                evt.preventDefault(); 
     57                t.selectionStart = t.selectionEnd = ss - 4; 
     58        } 
    5959 
    60     // Doprava 
    61     else if (evt.keyCode == 39 && t.value.slice(ss,ss + 4) == tab) { 
    62         alert("pravá"); 
    63         evt.preventDefault(); 
    64         t.selectionStart = t.selectionEnd = ss + 4; 
    65     } 
     60        // Doprava 
     61        else if (evt.keyCode == 39 && t.value.slice(ss,ss + 4) == tab) { 
     62                alert("pravá"); 
     63                evt.preventDefault(); 
     64                t.selectionStart = t.selectionEnd = ss + 4; 
     65        } 
    6666}