Am Samstag, 3. Januar 2015 19:13:11 UTC+1 schrieb Jim Lehmer:
>
> One objection people might have is I could simply use the HTML character 
> entities for the troublesome characters, but then I have to look them up 
> each time.
>

Nope. Here is a handy bookmarklet for you:

javascript:void((function()%7B%0Avar%20ta%3D%20document.activeElement%3B%
0Avar%20tag%3Dta.tagName.toLowerCase()%3B%0Avar%20type%3Dta.type.toLowerCase
()%3B%0Avar%20types%3D%22%3Aemail%3Anumber%3Apassword%3Asearch%3Atel%3Atext%
3Aurl%3A%22%3B%0Aif%20(%20tag%20%3D%3D%20'textarea'%20%7C%7C%20tag%20%3D%3D%
20'input'%20%26%26%20types.indexOf(%22%3A%22%2Btype%2B%22%3A%22)%20%3E%3D%
200%20)%20%7B%0A%09var%20startPos%20%3D%20ta.selectionStart%3B%0A%09var%
20endPos%20%3D%20ta.selectionEnd%3B%0A%09if%20(%20startPos%20%3D%3D%20endPos
%20%26%26%20startPos%20%3E%200%20)%20--startPos%3B%0A%09var%20insert%20%3D%
20%22%22%3B%0A%09for%20(%20var%20i%20%3D%20startPos%20%3B%20i%20%3C%20endPos
%20%3B%20%2B%2Bi%20)%20%7B%0A%09%09insert%20%2B%3D%20%22%26%23%22%20%2B%20ta
.value.charCodeAt(i)%20%2B%20%22%3B%22%3B%0A%09%7D%0A%09ta.value%3D%20ta.
value.substr(0%2CstartPos)%20%2B%20insert%20%2B%20ta.value.substr(endPos)%3B
%0A%09var%20evt%20%3D%20document.createEvent(%22HTMLEvents%22)%3B%0A%09var%
20s%3D%20startPos%20%3C%20endPos%3B%0A%09endPos%3D%20startPos%2Binsert.
length%0A%09if%20(!s)%20startPos%3D%20endPos%3B%0A%09ta.setSelectionRange(
startPos%2C%20endPos)%3B%0A%09evt.initEvent('input'%2C%20true%2C%20true%20)%
3B%0A%09ta.dispatchEvent(evt)%3B%0A%7D%0A%7D)())%3B

Simply select the nasty characters and invoke this bookmarklet. Or just 
invoke it right after typing the nasty character.

Here is the beautified code:

javascript:void((function(){
var ta= document.activeElement;
var tag=ta.tagName.toLowerCase();
var type=ta.type.toLowerCase();
var types=":email:number:password:search:tel:text:url:";
if ( tag == 'textarea' || tag == 'input' && types.indexOf(":"+type+":") >= 0 
) {
    var startPos = ta.selectionStart;
    var endPos = ta.selectionEnd;
    if ( startPos == endPos && startPos > 0 ) --startPos;
    var insert = "";
    for ( var i = startPos ; i < endPos ; ++i ) {
        insert += "&#" + ta.value.charCodeAt(i) + ";";
    }
    ta.value= ta.value.substr(0,startPos) + insert + ta.value.substr(endPos
);
    var evt = document.createEvent("HTMLEvents");
    var s= startPos < endPos;
    endPos= startPos+insert.length
    if (!s) startPos= endPos;
    ta.setSelectionRange(startPos, endPos);
    evt.initEvent('input', true, true );
    ta.dispatchEvent(evt);
}
})());



-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

Reply via email to