tags:

views:

38

answers:

2

I use stackexchange.com, which uses the same editor stackoverflow has (the editor I use now) When I try to type a special character using right alt + key (other language characters), instead of my special character I get ctrl + key shorcut, e.g. Undo (by pressing right alt + z), numbered list (by pressing right alt + o), hyperlink (by pressing right alt + l) . Is there a way to fix it? Can I disable those shortcuts or fix them so I could use right alt key in my stackexchange site?

I have found the code which handles key shortucts in script /Content/Js/wmd.js. Is it possible to override it somehow in page which include this script by ?

the "key.metaKey" is Alt key I think and it causes the problem.

var setupEditor = function() {

            if (/\?noundo/.test(doc.location.href)) {
                    wmd.nativeUndo = true;
            }

            if (!wmd.nativeUndo) {
                    undoMgr = new wmd.undoManager(function() {
                            previewRefreshCallback();
                            setUndoRedoButtonStates();
                    });
            }

            makeSpritedButtonRow();


            var keyEvent = "keydown";
            if (global.isOpera) {
                    keyEvent = "keypress";
            }

            util.addEvent(inputBox, keyEvent, function(key){

                    // Check to see if we have a button key and, if so execute the callback.
                    if (key.ctrlKey || key.metaKey) {

                            var keyCode = key.charCode || key.keyCode;
                            var keyCodeStr = String.fromCharCode(keyCode).toLowerCase();

                            switch(keyCodeStr) {
                                    case "b":
                                            doClick(document.getElementById("wmd-bold-button"));
                                            break;
                                    case "i":
                                            doClick(document.getElementById("wmd-italic-button"));

           (.............)
A: 

You can override it with a Greasemonkey script. Redefine that function. You can try first with Firebug, on the console.

Victor
thanks, but the problem is that I can't modify included script loaded from /Content/Js/wmd.js . I can only add script at page that has code <script src=Content/Js/wmd.js>.
Wojtek
But with GM you can run the script in your answer automatically, no? Shouldn't it work?
Victor
A: 

I've prepared script and it works, but only localy. When I change page on the server it doesn't work.

<SCRIPT type="text/javascript">
var endthis = function() {
var jWmd = $("#wmd-input");
if(!jWmd) return;
   jWmd.keydown(function(e) {
   if (e.ctrlKey || e.metaKey) {
   if ((e.which == 90 || e.which == 76 || e.which == 73 || e.which == 73)) {
     return false;
   }
   jWmd.trigger(e)
   } else jWmd.trigger(e);

});

}
window.onLoad = endthis();
</SCRIPT>
Wojtek