Reputation: 2149
So this is my code:
$(document).jkey('left',function(){
alert("Left key pressed");
$.galleryUtility.slideRight
});
This function is placed inside the galleryUtility
object. The goal is to call both the alert
and the slideRight
function when the left key is pressed.
So far when I press the left key it calls the alert but not the slideRight
function. I'm assuming this is because the slideRight
is an internal function of the galleryUtitity
object and $(document)
is outside the scope of the object?
So how can I call slideRight
from that function?
Upvotes: 0
Views: 69
Reputation: 2265
alert
will block all other code from running until the user interacts with the alert.
You need to switch the two lines to have your slideRight occur as you expect. An example showing alert
blocking other JavaScript: http://jsfiddle.net/Akkuma/r8bYp/
Additionally, you aren't executing slideRight
, which you need to do with $.galleryUtility.slideRight()
. As a word of caution you aren't following the jQuery paradigm when it comes to plugins, which is using a string to execute a method of the plugin ie. $.galleryUtility('slideRight')
. In fact, I'm not sure why you have galleryUtility living off of $ at all.
Upvotes: 3