views:

656

answers:

3

So my site uses shadowbox (http://mjijackson.com/shadowbox/) to do display some dynamic text. Problem is I need the user to be able to copy and paste that text. Right-clicking and selecting copy works but ctrl+c doesn't (no keyboard shortcuts do) and most people use Ctrl+c right? You can see an example of what I'm talking about here: http://mjijackson.com/shadowbox/. Just go to the "web" exapmles and click "inline". Notice keyboard shortcuts do work on the "this page" example. The only difference between the two I see is the player js files they use. "Inline" uses the html.js player and "this page" uses iframe.js. Also, I believe it uses the mootools library. Any ideas?

+1  A: 

This problem is caused by some JavaScript which eats keyboard events. You can hit the escape key, for example, which is trapped by one of the .js files and causes the shadow box to close.

Your choices are to hack through the files and find the problem, or not use shadowbox. Good luck!

Robby Slaughter
+2  A: 

The best option is to disable keyboard navigation shortcuts in the shadowbox by setting the "enableKeys" option to false (see this page).

Alternatively you could do what Robby suggests and modify the shadowbox.js file, but only do this if you need to have the shadowbox keyboard navigation. I think that you want to search for this block of code and modify it so that it only cancels the default event if one of the shortcuts is used (I've added some line breaks and indention):

var handleKey=function(e){
    var code=SL.keyCode(e);
    SL.preventDefault(e);
    if(code==81||code==88||code==27){
        SB.close()
    }else{
        if(code==37){
            SB.previous()
        }else{
            if(code==39){
                SB.next()
            }else{
                if(code==32){
                    SB[(typeof slide_timer=="number"?"pause":"play")]()
                }
            }
        }
    }
};

I think you could change it to look more like this:

var handleKey=function(e){
    switch(SL.keyCode(e)) {
        case 81:
        case 88:
        case 27:
            SB.close()
            SL.preventDefault(e);
            break;

        case 37:
            SB.previous()
            SL.preventDefault(e);
            break;

        case 39:
            SB.next()
            SL.preventDefault(e);
            break;

        case 32:
            SB[(typeof slide_timer=="number"?"pause":"play")]()
            SL.preventDefault(e);
            break;
    }
};

This should prevent the shadowbox event handler from swallowing any keystrokes that it doesn't care about.

Prestaul
Great answer I really appreciate it!
mrjrdnthms
A: 

The solution is to set the enableKeys option to false. However, this doesn't seem to work on an open() call for inline HTML. It does work, however, if you set it in your init() call.

Ben Greenberg