Skip to content

Instantly share code, notes, and snippets.

@joecorcoran
Created June 15, 2009 08:04
Show Gist options
  • Save joecorcoran/130003 to your computer and use it in GitHub Desktop.
Save joecorcoran/130003 to your computer and use it in GitHub Desktop.
//get first part of current url, without hash
var base_path = window.location.href.split("#")[0];
var real_id = 0;
var current_page;
;(function($) {
//create new sammy app
var app = new Sammy.Application(function() {
with(this) {
//corresponds to routes like #/slide/1
get('#/slide/:page_id', function() { with(this) {
//cycle id is zero-based, so subtract 1 from the route id
real_id = params['page_id'] - 1;
//remove the navigation div as it gets rewritten each time .cycle is called (bit hacky)
$("#nav > *").remove();
//call cycle function
$('#holder')
.cycle({
after: function(curr, next, opts) {
current_page = opts.currSlide + 1;
next_page = opts.nextSlide + 1;
//update link displayed to user and url in address bar
$("#direct_link").html(base_path+"#/slide/"+current_page);
window.location.hash = "/slide/"+current_page;
},
startingSlide: real_id,
fx: 'fade',
easing: 'easeOutQuad',
speed: 500,
pager: '#nav',
timeout: 0
});
}});
//if page is accessed without hash (from main site nav, for instance), redirect to first slide
get('', function() { with(this) {
redirect('#/slide/1');
}});
}
});
$(function() {
//run your app!
app.run()
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment