Permalink
Browse files

The page info is displayed using a router (url hashtag) instead of tr…

…acking the clicks on the menu
  • Loading branch information...
1 parent 91359e2 commit 4356516b865dc0611951395b7c38c919d3734c99 @juanmaorta committed Mar 20, 2012
Showing with 31 additions and 13 deletions.
  1. +22 −13 index.html
  2. +9 −0 libs/jquery.ba-hashchange.min.js
View
@@ -3,6 +3,7 @@
<title></title>
<meta charset="utf-8">
<script language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script language="Javascript" src="./libs/jquery.ba-hashchange.min.js"></script>
<script language="Javascript" src="./libs/mustache.js"></script>
<script language="Javascript" src="./app/cv.class.js" ></script>
<script language="Javascript" src="./app/mycv.json.js" ></script>
@@ -15,8 +16,8 @@
<ul id="menu">
<li><a href="#personal_info" title="personal">.displayPersonalInfo()</a></li>
<li><a href="#academic_info" title="academic">.displayAcademicInfo()</a></li>
- <li><a href="#technical_skill_info" title="professional">.displayProfesionalInfo()</a></li>
- <li><a href="#professional_info" title="tech">.displayTechnicalSkills()</a></li>
+ <li><a href="#professional_info" title="professional">.displayProfesionalInfo()</a></li>
+ <li><a href="#technical_skill_info" title="tech">.displayTechnicalSkills()</a></li>
<li><a href="#project_info" title="projects">.displayProjects()</a></li>
<li><a href="#hobbies_info" title="hobbies">.displayHobbies()</a></li>
</ul>
@@ -40,33 +41,41 @@
$maincont = $("#display_info");
$idcont = $("#id_info_cont");
- $("#menu a").click(function () {
- switch($(this).attr("title")) {
- case "personal":
+ // mini-router to load content
+ // so it will maintain state on page reloads
+
+ $(window).hashchange( function(){
+ var param = (window.location.hash.substr(1));
+ switch(param) {
+ case "personal_info":
myApp.displayPersonalInfo($maincont, candidate);
break;
- case "academic":
+ case "academic_info":
myApp.displayAcademicInfo($maincont, candidate);
break;
- case "professional":
+ case "professional_info":
myApp.displayProfesionalInfo($maincont, candidate);
break;
- case "tech":
+ case "technical_skill_info":
myApp.displayTechnicalSkills($maincont, candidate);
break;
- case "projects":
+ case "project_info":
myApp.displayProjects($maincont, candidate);
break;
- case "hobbies":
+ case "hobbies_info":
myApp.displayHobbies($maincont, candidate);
break;
+ default:
+ myApp.displayPersonalInfo($maincont, candidate);
+ break;
}
});
- // shows id info
+ $(window).hashchange();
+
+ // always show id info
myApp.displayIdInfo($idcont, candidate);
- // shows default content
- myApp.displayPersonalInfo($maincont, candidate);
+
// print
$("#footer").click(function () {
@@ -0,0 +1,9 @@
+/*
+ * jQuery hashchange event - v1.3 - 7/21/2010
+ * http://benalman.com/projects/jquery-hashchange-plugin/
+ *
+ * Copyright (c) 2010 "Cowboy" Ben Alman
+ * Dual licensed under the MIT and GPL licenses.
+ * http://benalman.com/about/license/
+ */
+(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

0 comments on commit 4356516

Please sign in to comment.