Last active
December 17, 2015 16:38
-
-
Save joshdcomp/5639764 to your computer and use it in GitHub Desktop.
Capturing a shift+cmd+click event and doing stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Functionality for capturing a command + shift + click | |
* Note: does not work for the key you have mapped for context menu | |
*/ | |
var cmdShiftClick = { | |
//set an object property for holding shift | |
isShift : false, | |
//set another for holding command or control | |
isCtrl : false, | |
init : function(){ | |
var self = this; | |
//set our object props to true on keydown | |
$(document).keydown(function(e){ | |
//is shift key? | |
if ( e.shiftKey ) { | |
self.isShift = true; | |
} | |
//is control key? | |
if ( e.ctrlKey ) { | |
self.isCtrl = true; | |
} | |
//is command key? | |
if ( e.keyCode === 91 | |
|| e.keyCode === 92 ){ | |
self.isCtrl = true; | |
} | |
}); | |
//on keyup, reset our object props | |
$(document).keyup(function(e){ | |
self.isShift = false; | |
self.isCtrl = false; | |
}); | |
//fire our event on click | |
$('#sandra_b').on('click', function(e) { | |
e.preventDefault(); | |
self.doStuff(e); | |
});//on.click | |
},//init() | |
/** | |
* Do something | |
* @param event object e | |
* @return void | |
*/ | |
doStuff : function(e){ | |
var self = this; | |
var $andra = $(e.target); | |
if ( self.isShift && self.isCtrl ) { | |
$andra.siblings('.filling').slideToggle(250); | |
$andra.parent('#pi_the_net').toggleClass('open'); | |
} | |
//reset our props to false | |
self.isShift = false; | |
self.isCtrl = false; | |
},//doStuff() | |
};//cmdShiftClick | |
$(document).ready(function(){ | |
cmdShiftClick.init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment