SHARE
TWEET

Untitled

a guest Jan 12th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. URL Renaming via JavaScript
  2. $links.on('click', function(event) {
  3.  
  4.     var href = $(this).attr('href'),
  5.         chapter = (href.search(/chapter/) !== -1) ? href.substring(8) : 0;
  6.  
  7.     _saveState(chapter);
  8.  
  9.     return false;
  10.  
  11. });
  12.  
  13. $container.on('click', 'article.hs-content', function(event) {
  14.  
  15.     var id = $(this).attr('id'),
  16.         chapter = (id.search(/chapter/) !== -1) ? id.substring(7) : 0;
  17.  
  18.     _saveState(chapter);
  19.  
  20.     return false;
  21.  
  22. });
  23.  
  24. _saveState = function(chapter) {
  25.  
  26.     // adds a new state to the history object
  27.     // this will trigger the statechange on the window
  28.     if (History.getState().url.queryStringToJSON().chapter !== chapter) {
  29.  
  30.         History.pushState(null, null, '?chapter=' + chapter);
  31.  
  32.     }
  33. },
  34.    
  35. History.pushState(null, null, '?chapter=' + chapter);
  36.    
  37. _saveState = function(chapter) {
  38.  
  39.     // adds a new state to the history object
  40.     // this will trigger the statechange on the window
  41.     if (History.getState().url.queryStringToJSON().chapter !== chapter) {
  42.         var page;
  43.         if(chapter == 1)
  44.             page = "/about";
  45.         else if(chapter == 2)
  46.             page = "/services";
  47.         else
  48.             page = '?chapter=' + chapter;
  49.  
  50.         History.pushState(null, null, page);
  51.  
  52.     }
  53. },
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top