You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ca...@apache.org on 2012/08/30 21:24:09 UTC

svn commit: r1379077 - /rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js

Author: carlucci
Date: Thu Aug 30 19:24:08 2012
New Revision: 1379077

URL: http://svn.apache.org/viewvc?rev=1379077&view=rev
Log:
 RAVE-780: Allow direct linking to subpages on person profile page.  Patch supplied by Erin Noe-Payne

Modified:
    rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js

Modified: rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js?rev=1379077&r1=1379076&r2=1379077&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js (original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js Thu Aug 30 19:24:08 2012
@@ -19,32 +19,53 @@
 
 var rave = rave || {};
 rave.personprofile = rave.personprofile || (function() {
-    // map of [subpage id, boolean] tracking whether or not a sub page has been viewed at least once
-    var subPagesViewedStatus = {};
+     // map of {subpage name, boolean} tracking whether or not a sub page has been viewed at least once
+     var subPagesViewedStatus = {};
      function initSubPages() {
-        //Make first tab active (Twitter Bootstrap)
-        $('.nav-tabs a:first').tab('show');
-        $('#personProfileSubPages a[data-toggle="tab"]').on('shown', function(event, ui) {
+         var $tabs = $('#personProfileSubPages a[data-toggle="tab"]');
+         //If the implementation does not use bootstrap tabs / subpages, skip this method
+         if($tabs.length == 0){
+             return;
+         }
+         
+        //Make the tab identified by hash url active, defaulting to the first tab (Twitter Bootstrap)
+         var activeSubPage = decodeURIComponent(location.hash).slice(1);
+         if (activeSubPage===''){
+             activeSubPage = $tabs.first().text();
+         }
+
+         // build the subPageViewedStatus map to track if a given sub page has been viewed yet to determine if we need
+         // to refresh the widgets upon first viewing to ensure they are sized properly.  Set the default active tab to
+         // true since it will be rendered and sized properly as part of the initial page load
+         $.each($tabs, function(i, el){
+             var $tab = $(el);
+             var page = $tab.text();
+             var isActive =  (page == activeSubPage);
+             subPagesViewedStatus[page] = isActive;
+            //show the initial tab
+             if(isActive){
+                 $tab.tab('show');
+             }
+         });
+
+         $tabs.on('shown', function(event, ui) {
+             //on tab click, change the url hash
+             var page = $(this).text();
+             var target = $(this).attr('href');
+             location.hash = encodeURIComponent(page);
+
             // refresh the widgets on the sub page when selected to ensure proper sizing
-            var subPageId = $( $(this).attr("href") ).attr("id");
-            if (subPagesViewedStatus[subPageId] == false) {
-                $("#" + subPageId + " .widget-wrapper").each(function(){
+            if (subPagesViewedStatus[page] == false) {
+                $(target + " .widget-wrapper").each(function(){
                     var regionWidget = rave.getRegionWidgetById(rave.getObjectIdFromDomId(this.id));
                     regionWidget.restore();
                 });
                 // mark that this sub page has been viewed at least once and there is no need to refresh
                 // the widgets in future views
-                subPagesViewedStatus[subPageId] = true;
+                subPagesViewedStatus[page] = true;
             }
         });
-        // build the subPageViewedStatus map to track if a given sub page has been viewed yet to determine if we need
-        // to refresh the widgets upon first viewing to ensure they are sized properly.  Set the default active tab to
-        // true since it will be rendered and sized properly as part of the initial page load
-        var activeSubPageId = $("#personProfileSubPages .tab-pane.active")[0].id;
-        $("#personProfileSubPages .tab-pane").each(function(){
-            subPagesViewedStatus[this.id] = (this.id == activeSubPageId);
-        });
-    }
+     }
 
      function dealWithUserResults(userResults){
     	 var currentUser = $("#addRemoveFriend").get(0).value;