web/data/cubicweb.massmailing.js
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 21 Jul 2009 12:44:36 +0200
changeset 2400 17b1f0b80fe8
parent 2385 8fa16dc4b8c8
permissions -rw-r--r--
[primary] restore render_entity, as it is a bit too much work to update everything accordingly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2385
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     1
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     2
function insertText(text, areaId) {
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     3
    var textarea = jQuery('#' + areaId);
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     4
    if (document.selection) { // IE
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     5
        var selLength;
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     6
        textarea.focus();
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     7
        sel = document.selection.createRange();
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     8
        selLength = sel.text.length;
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     9
        sel.text = text;
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    10
        sel.moveStart('character', selLength-text.length);
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    11
        sel.select();
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    12
    } else if (textarea.selectionStart || textarea.selectionStart == '0') { // mozilla
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    13
        var startPos = textarea.selectionStart;
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    14
        var endPos = textarea.selectionEnd;
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    15
	// insert text so that it replaces the [startPos, endPos] part
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    16
        textarea.value = textarea.value.substring(0,startPos) + text + textarea.value.substring(endPos,textarea.value.length);
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    17
	// set cursor pos at the end of the inserted text
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    18
        textarea.selectionStart = textarea.selectionEnd = startPos+text.length;
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    19
        textarea.focus();
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    20
    } else { // safety belt for other browsers
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    21
        textarea.value += text;
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    22
    }
8fa16dc4b8c8 [js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
}