tiny-sel.js - input selection for tinyJS

tiny-sel.js extends the Selection-Methods with .S(), which returns or changes (selectively) selected text in input elements.


tiny-sel.js [1464b] - tiny-sel-min.js.gz [435b]


The t.sel-method requires only tiny.js. Other scripts are not necessary.


The methode .S() takes up to two arguments. If none is given, a selection-object is returned. If only one argument is given, the whole selection will be replaced with its content; if two are given, the occurrences of the first arguments content will be replaced by the content of the second argument.


The Selection-Object has the following format:

    text: [String, selected text-content],
    start: [Integer, index of the first selected character, starting at 0],
    end: [Integer, index of the last selected character],
    length: [Integer, length of the selection]


(function() {
    var ti=t('#testinput');
    var re=t('#result');
    window.setInterval(function() { re.h(ti.S().text); }, 45);
    t('#censor').e('mousedown', function() { t('#testinput').S('[CENSORED]'); });
    t('#xforu').e('mousedown', function() { t('#testinput').S('u', 'x'); });