mousetrap

accessing mutable variable in an event closure

对着背影说爱祢 提交于 2019-12-23 09:30:17
问题 I am trying to use the mousetrap javascript plugin to handle some key strokes in a similar fashion, so I thought to code them up as follows: var keys = [ 'b', 'i', 'u']; for (var i=0; i < 3; ++i) { var iKey = keys[i]; var iKeyUpper = iKey.toUpperCase(); Mousetrap.bind( [ 'command+' + iKey, 'command+' + iKeyUpper, 'ctrl+' + iKey, 'ctrl+' + iKeyUpper], ( function( e ) { console.log( "you clicked: " + i ); } ) ); } But, obviously, i is mutable. However, I am not sure how to write a closure where

Wordpress Attachment Page Navigate with Keyboard

久未见 提交于 2019-12-13 08:17:03
问题 I'm using WordPress. I want to navigate my attachment page with left and right key. Here is my codes, but not working; function GoToLocation(url) { window.location = url; } Mousetrap.bind("j", function() { //alert('j pressed' + document.getElementById("next").href); //document.getElementById("next").click(); window.location=<?php echo $image->next_image_link ?>; }); <script src="https://craig.global.ssl.fastly.net/js/rainbow-custom.min.js?39e99"></script> <script src="https://craig.global.ssl

Prevent keypress to bubble to input in mousetrap

别说谁变了你拦得住时间么 提交于 2019-12-12 01:57:17
问题 I am using mousetrap for capturing key presses. One of the shortcuts I want to define is to focus on an input. Mousetrap.bind('i', function() { $('.input').focus() }); The focussing works fine, but the 'i' keypress also gets bubbled to the input, and with being focussed, the input also gets populated with 'i'. Is there a way to prevent the 'i' from being written in the input? Any help is appreciated. Thanks 回答1: Right there in the documentation: As a convenience you can also return false in