javascriptkeyboard-shortcutsmootools

Using shadowbox disables keyboard shortcuts?


So my site uses 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? You can see an example of what I'm talking about here.

Just go to the "web" examples 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?


Solution

  • 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.