Skip to content

Instantly share code, notes, and snippets.

@higeorange
Created November 4, 2010 19:17
Show Gist options
  • Save higeorange/663002 to your computer and use it in GitHub Desktop.
Save higeorange/663002 to your computer and use it in GitHub Desktop.
(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