Guest User

Untitled

a guest
Jul 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. var paging = {
  2. "setup" : function(){
  3. //Add click event handlers to the image arrows that are used to page the content
  4. $('a.sprite.flip').unbind('click');
  5. $('a.sprite.flip').click(function(ev){
  6. //Stop the default anchor tag events
  7. ev.preventDefault();
  8. //The URL of the next page is stored on the anchor tags href attribute
  9. var url = $(this).attr("href");
  10. //Pass the URL into the AJAX content loader
  11. paging.load_content(url);
  12. });
  13. },
  14. "check_hash" : function(){
  15. //Grab everything in the URL after the #
  16. var hash = window.location.hash;
  17. if (hash != "" && hash.length > 3 && hash.substr(0,8) == "#!/page="){
  18. //If the href contains a page reference
  19. var link = hash.substr(8);
  20. //Store the old html in the event the AJAX fails
  21. paging.old_html = $('.content-wrapper').html();
  22. //Blank out the content wrapper
  23. $('.content-wrapper').html("");
  24. //AJAX the content
  25. paging.load_content("/pages/" + link);
  26. }
  27. },
  28. "load_content" : function(url){
  29. $.ajax({
  30. //The .json is specified here for our controller
  31. url: url + ".json",
  32. data : {},
  33. success : function(data,status,response){
  34. //Fade out the current content
  35. $('.content-wrapper').fadeOut("slow", function(){
  36. //Replace the html of the content wrapper with content returned through AJAX
  37. $('.content-wrapper').html(data.partial);
  38. //Fade in the new content
  39. $('.content-wrapper').fadeIn("slow", function(){
  40. //Update the current #! values (More on this later)
  41. window.location.hash = "!/page=" + data.callback;
  42. document.title = data.page_title;
  43. //Make the social plugins (facebook, twitter) update for the current page
  44. paging.refresh_social();
  45. //Setup the click handlers again
  46. paging.setup();
  47. });
  48. });
  49. },
  50. error: function(){
  51. if (paging.old_html != ""){
  52. //In the event of an error where the old_html contains the previous content, put that old content back in
  53. $(".content-wrapper").html(paging.old_html);
  54. paging.refresh_social();
  55. }
  56. else {
  57. //In the event of an error and we don't have the last page's content, show an error :(
  58. var error = "<p style='color:red;'>Sorry an error has occured, please try again or refresh the page</p>";
  59. $('.content-wrapper').html(error);
  60. }
  61. paging.setup();
  62. },
  63. dataType: "json"
  64. });
  65. },
  66. "refresh_social" : function(){
  67. $('a.twitter-share-button').each(function() {
  68. var tweet_button = new twttr.TweetButton($(this).get(0));
  69. tweet_button.render();
  70. });
  71. FB.XFBML.parse(document.getElementById('facebook'));
  72. }
  73. }
Add Comment
Please, Sign In to add comment