web/index.html
changeset 5 62959dc4ff0d
parent 4 678402f3f5cd
child 6 9b3c3c34a288
--- a/web/index.html	Mon Oct 21 16:26:42 2013 +0200
+++ b/web/index.html	Mon Oct 21 18:48:58 2013 +0200
@@ -81,9 +81,10 @@
     </footer>
   </div>
   <script type="text/javascript" src="./lib/jquery-1.9.1.js"></script>
+  <script type="text/javascript" src="./lib/jquery.history.js"></script>
   <script type="text/javascript" src="./lib/bootstrap/js/bootstrap.min.js"></script>
   <script type="text/javascript">
-
+    
     var iframes = {
       "0" : "<iframe src='http://ldt.iri.centrepompidou.fr//ldtplatform/ldt/embediframe/?content_id=53574ae4-49e9-11e2-b4ad-00145ea4a2be&project_id=a94ee060-49e9-11e2-b4ad-00145ea4a2be&createannotation=True&tag_titles=&polemic=all&annotations_list=True&autostart=True&annotation=True' width='570' height='1300' seamless='seamless'></iframe>",
       "1" : "<p>iframe à venir, vidéo n°1</p>",
@@ -96,19 +97,17 @@
       "full" : "<iframe src='http://ldt.iri.centrepompidou.fr//ldtplatform/ldt/embediframe/?content_id=62083f72-363c-11e3-8068-00145ea4a2be&project_id=032aebaa-37de-11e3-a863-00145ea4a2be&createannotation=True&tag_titles=&polemic=all&annotations_list=True&autostart=True&annotation=True' width='570' height='1300' seamless='seamless'></iframe>",
     };
 
-    $(function() {
-      $(".videolink").click(function(e){
-        playVideo($(this).attr("data-videoid"));
-      });
-      // load first video
-      playVideo("full");
-    });
-
-    function displayIframe(n){
+    function displayIframe(n, update_h){
       $("#videocontainer").html(iframes[n]);
+      
+      // update history
+      update_h = typeof update_h !== 'undefined' ? update_h : true;
+      if(update_h){
+        update_history("iframe=" + n);
+      }
     }
     
-    function playVideo(n){
+    function playVideo(n, update_h){
       if (n=="1" || n=="2" || n=="3" || n=="4" || n=="5" || n=="6" || n=="7" || n=="1r" || n=="2r" || n=="3r" || n=="4r" || n=="5r" || n=="6r" || n=="7r"){
         $("#videocontainer").html("<p>à venir, vidéo n°" + n + "</p>");
       }
@@ -213,7 +212,46 @@
       
         $("#videocontainer").html(s.replace(/__NUM_JSON__/g, n));
       }
+      
+      // update history
+      update_h = typeof update_h !== 'undefined' ? update_h : true;
+      if(update_h){
+        update_history("v=" + n);
+      }
     }
+    
+    //Functions to manage history with parameters
+    function getURLParameter(name) {
+        return decodeURI(
+            (RegExp(name + '=' + '(.+?)(&|$)').exec(location.hash)||[,null])[1]
+        );
+    }
+    function update_history(s){
+        History.replaceState(null, null, "#" + s);
+    }
+    
+    // on load
+    $(function() {
+      $(".videolink").click(function(e){
+        playVideo($(this).attr("data-videoid"));
+      });
+      // load first video with get parameter
+      var first = "full";
+      var iframe = getURLParameter("iframe");
+      if(iframe=="null"){
+        var v = getURLParameter("v");
+        if(v=="null"){
+          playVideo(first, false);
+        }
+        else{
+          playVideo(v, false);
+        }
+      }
+      else{
+        displayIframe(iframe, false)
+	  }
+    });
+    
   </script>
 </body>
 </html>
\ No newline at end of file