/* 
* 
* Copyright (c) 2012-2014 Adobe Systems Incorporated. All rights reserved.

* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), 
* to deal in the Software without restriction, including without limitation 
* the rights to use, copy, modify, merge, publish, distribute, sublicense, 
* and/or sell copies of the Software, and to permit persons to whom the 
* Software is furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
* DEALINGS IN THE SOFTWARE.
* 
*/

(function(app) {
    app.directive("apiTabs", function() {
        return {
            restrict: "E",
            transclude: true,
            scope: {},
            controller: function($scope) {
                var panes = $scope.panes = [];

                $scope.select = function(pane) {
                    angular.forEach(panes, function(pane) {
                        pane.selected = false;
                    });

                    pane.selected = true;

                    if(pane.hash) {
                        window.location.hash = pane.hash;
                    }                    
                };

                this.addPane = function(pane) {
                    var currHash = window.location.hash;

                    if((!currHash || !pane.hash) && panes.length == 0) {
                        pane.selected = true;
                    };

                    panes.push(pane);
                };

                this.restoreActive = function() {
                    var currHash = window.location.hash;

                    if(!currHash) {
                        return;
                    }

                    angular.forEach(panes, function(pane) {
                        if(!currHash || !pane.hash) {
                            return;
                        }

                        pane.selected = pane.hash == currHash;
                    });
                }
            },
            templateUrl: "/_System/apps/bc-api-discovery/templates/directives/tabs.html"
        };
    });

    app.directive("apiTabPane", function() {
        return {
            require: "^apiTabs",
            restrict: "E",
            transclude: true,
            scope: {
                title: "@",
                hash: "@"
            },
            link: function(scope, element, attrs, tabsCtrl) {
                tabsCtrl.addPane(scope);
                tabsCtrl.restoreActive();
            },
            templateUrl: "/_System/apps/bc-api-discovery/templates/directives/pane.html"
        };
    });

})(DiscoveryApp);
@@ -2179,34 +2179,77 @@
 ow.location.hash
+,%0A                        selected = false;
 ;%0A
-
 %0A               
@@ -2430,32 +2430,83 @@
 %7C !pane.hash) %7B%0A
+                            pane.selected = false;%0A
                 
@@ -2592,16 +2592,33 @@
 ected = 
+currHash.indexOf(
 pane.has
@@ -2622,20 +2622,162 @@
 hash
+)
  == 
-currHash
+0;%0A                    %7D);%0A%0A                    if(selected == false && panes && panes.length %3E 0) %7B%0A                        panes%5B0%5D.selected = true
 ;%0A  
@@ -2795,18 +2795,16 @@
        %7D
-);
 %0A       

Fix a bug in tabs restore selected pane method. Now it works even if no pane can be selected based on its hash.