DarkDaskin

nav-poll.html

Oct 18th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.90 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Y U NO WORK?</title>
  5.     <style>
  6.         body {
  7.             width: 100%;
  8.             height: 100%;
  9.             margin: 0;
  10.         }
  11.         #menu {
  12.             width: 100%;
  13.             height: 30px;
  14.             background: yellow;
  15.             font-size: 20px;
  16.             padding: 10px;
  17.         }
  18.         .active {
  19.             font-size: 24px;
  20.             font-weight: bold;
  21.         }
  22.         #frame {
  23.             width: 100%;
  24.             height: 100%;
  25.             min-height: 500px;
  26.             margin-top: 50px;
  27.             border: none;
  28.         }
  29.     </style>
  30.     <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  31.     <script type="text/javascript">
  32.         $(function () {
  33.             var isLoading = false;
  34.            
  35.             $('#menu a').click(function() {
  36.                 var link = this;
  37.                 selectLink(link);
  38.                
  39.                 isLoading = true;
  40.                 $('#frame').one('load', function() { isLoading = false; });
  41.                 $('#frame').attr('src', link.href);
  42.                
  43.                 (function poll () {
  44.                     var frameWindow = getFrameWindow();
  45.                     if (frameWindow.location.href == link.href) {
  46.                         frameWindow.history.replaceState({ linkId: link.id },frameWindow.document.title, frameWindow.location.href);
  47.                     } else {
  48.                         setTimeout(poll, 100);
  49.                     }
  50.                 })();
  51.                
  52.                 return false;
  53.             });
  54.            
  55.             setInterval(function () {
  56.                 if (!isLoading) {
  57.                     handleHistory('timer');
  58.                 }
  59.             }, 100);
  60.         });
  61.        
  62.         function getFrameWindow() {
  63.             return $('#frame')[0].contentWindow;
  64.         }
  65.        
  66.         function selectLink (link) {
  67.             $('#menu a').removeClass('active');
  68.             $(link).addClass('active');
  69.         }
  70.        
  71.         function handleHistory (caller) {
  72.             console.log('Handling history from ' + caller);
  73.             var state = getFrameWindow().history.state;
  74.             if (state)
  75.                 selectLink('#' + getFrameWindow().history.state.linkId);
  76.         }
  77.     </script>
  78. </head>
  79. <body>
  80.     <div id="menu">
  81.         <a id="1" href="out.cshtml?1">1</a>
  82.         <a id="2" href="out.cshtml?2">2</a>
  83.         <a id="3" href="out.cshtml?3">3</a>
  84.     </div>
  85.     <iframe id="frame"></iframe>
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment