-
-
Save Wolfr/1337697 to your computer and use it in GitHub Desktop.
| jwerty.key('←', function () { | |
| // Check if we are on the first slide, if so, do not execute | |
| if (!$('.introSlide').is(":visible")) { | |
| prevSlide(); | |
| buttonToggle(); | |
| }; | |
| }); | |
| $('#prevSlide').click(function() { | |
| // Check if we are on the first slide, if so, do not execute | |
| if (!$('.introSlide').is(":visible")) { | |
| prevSlide(); | |
| buttonToggle(); | |
| }; | |
| }); |
jwerty.key('←', function () {
showNext();
});
$('#prevSlide').click(function() {
showNext();
});
function showNext(){
// Check if we are on the first slide, if so, do not execute
if (!$('.introSlide').is(":visible")) {
prevSlide();
buttonToggle();
}
}jwerty.key('←', function () {
checkFirstSlide()
});
$('#prevSlide').click(function() {
checkFirstSlide()
});
// Check if we are on the first slide, if so, do not execute
function checkFirstSlide() {
if (!$('.introSlide').is(":visible")) {
prevSlide();
buttonToggle();
}
}
I wanted to do something like to make it elegant. WARNING! BOGUS CODE!
jwerty.key('←'), $('#prevSlide').click, function () {
// Check if we are on the first slide, if so, do not execute
if (!$('.introSlide').is(":visible")) {
prevSlide();
buttonToggle();
};
});
But functions it is then... bah
Not sure if you can combine a click and a keypress event like that...
jwerty.key('←', showNext);
$('#prevSlide').click(showNext);
function showNext(){
// Check if we are on the first slide, if so, do not execute
if (!$('.introSlide').is(":visible")) {
prevSlide();
buttonToggle();
}
}So we can remove the anonymous functions say eising
Example:
jwerty.key('↑', function () {
resetSlides();
});
$('.resetSlides').click(function() {
resetSlides();
});
How?
(NM you were faster :))
jwerty.key('↑', function () {
resetSlides();
});
$('.resetSlides').click(function() {
resetSlides();
});Could be just…
jwerty.key('↑', resetSlides);
$('.resetSlides').click(resetSlides);But actually you don’t need a named function at all:
var $resetSlides = $('.resetSlides');
$resetSlides.click(function() {
// teh coads
});
jwerty.key('↑', $resetSlides.click); // i.e. just trigger a `click` event on `$resetSlides`Hmm yeah, that makes sense. Your 2nd code block is more readable and I can keep all my functions apart so went for that. The 3rd code block is more 1337 I guess ;)
You could put the ! .introSlide visible check into a separate function.
That way you can call that function on key change or on click instead of repeating the code twice.