Created
November 4, 2010 19:17
-
-
Save higeorange/663002 to your computer and use it in GitHub Desktop.
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
(function($) { | |
$.fn.slideShow = function() { | |
var prefix = "slide"; | |
var l = location.protocol + "//" + location.hostname + location.pathname; | |
var pages = this.length; | |
var fragment_pattern = RegExp("#" + prefix + "(\\d+)"); | |
if(! fragment_pattern.test(location.hash)) { | |
location.href = l + "#" + prefix + "1"; // don't reload page with Firefox; | |
} | |
var pageNumber = function() { | |
var fragment; | |
return (fragment = location.hash) != "" ? | |
fragment.replace("#" + prefix, "") - 0 : | |
1; | |
}; | |
var previousPage = function() { | |
var ppn = pageNumber() - 1; | |
if (ppn >= 1) { | |
location.href = l + "#" + prefix + ppn; | |
} | |
}; | |
var nextPage = function() { | |
var npn = pageNumber() + 1; | |
if (npn <= pages) { | |
location.href = l + "#" + prefix + npn; | |
} | |
}; | |
$(document).keyup(function(e) { | |
switch (e.keyCode) { | |
case 38: // Up | |
previousPage(); | |
return; | |
case 40: //Down | |
nextPage(); | |
return; | |
default: | |
return; | |
} | |
}); | |
return this.each(function(i) { | |
var page = $(this); | |
page.attr("id", prefix + (i+1)).addClass(prefix); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment