Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var paging = {
- "setup" : function(){
- //Add click event handlers to the image arrows that are used to page the content
- $('a.sprite.flip').unbind('click');
- $('a.sprite.flip').click(function(ev){
- //Stop the default anchor tag events
- ev.preventDefault();
- //The URL of the next page is stored on the anchor tags href attribute
- var url = $(this).attr("href");
- //Pass the URL into the AJAX content loader
- paging.load_content(url);
- });
- },
- "check_hash" : function(){
- //Grab everything in the URL after the #
- var hash = window.location.hash;
- if (hash != "" && hash.length > 3 && hash.substr(0,8) == "#!/page="){
- //If the href contains a page reference
- var link = hash.substr(8);
- //Store the old html in the event the AJAX fails
- paging.old_html = $('.content-wrapper').html();
- //Blank out the content wrapper
- $('.content-wrapper').html("");
- //AJAX the content
- paging.load_content("/pages/" + link);
- }
- },
- "load_content" : function(url){
- $.ajax({
- //The .json is specified here for our controller
- url: url + ".json",
- data : {},
- success : function(data,status,response){
- //Fade out the current content
- $('.content-wrapper').fadeOut("slow", function(){
- //Replace the html of the content wrapper with content returned through AJAX
- $('.content-wrapper').html(data.partial);
- //Fade in the new content
- $('.content-wrapper').fadeIn("slow", function(){
- //Update the current #! values (More on this later)
- window.location.hash = "!/page=" + data.callback;
- document.title = data.page_title;
- //Make the social plugins (facebook, twitter) update for the current page
- paging.refresh_social();
- //Setup the click handlers again
- paging.setup();
- });
- });
- },
- error: function(){
- if (paging.old_html != ""){
- //In the event of an error where the old_html contains the previous content, put that old content back in
- $(".content-wrapper").html(paging.old_html);
- paging.refresh_social();
- }
- else {
- //In the event of an error and we don't have the last page's content, show an error :(
- var error = "<p style='color:red;'>Sorry an error has occured, please try again or refresh the page</p>";
- $('.content-wrapper').html(error);
- }
- paging.setup();
- },
- dataType: "json"
- });
- },
- "refresh_social" : function(){
- $('a.twitter-share-button').each(function() {
- var tweet_button = new twttr.TweetButton($(this).get(0));
- tweet_button.render();
- });
- FB.XFBML.parse(document.getElementById('facebook'));
- }
- }
Add Comment
Please, Sign In to add comment