angular.module('MagicSearch', ['ui.bootstrap'])
    .directive('magicOverrides', function() {
        return {
            restrict: 'A',
            controller: function($scope) {
                // showMenu and hideMenu depend on foundation's dropdown. They need
                // to be modified to work with another dropdown implemenation.
                // For bootstrap, they are not needed at all.
                $scope.showMenu = function() {
                    $scope.isMenuOpen = true;
                };
                $scope.hideMenu = function() {
                    $scope.isMenuOpen = false;
                };
                $scope.isMenuOpen = false;

                // remove the following when magic_search.js handles changing the facets/options
                $scope.$watch('facets_json', function(newVal, oldVal) {
                    if (newVal === oldVal) {
                        return;
                    }
                    $scope.facetsJson = $scope.facets_json.replace(/__apos__/g, "\'").replace(/__dquote__/g, '\\"').replace(/__bslash__/g, "\\");
                    $scope.facetsObj = JSON.parse($scope.facetsJson);
                    $scope.resetState();
                });

            }
        };
    });
angular.module('MagicSearch', ['ui.bootstrap'])
    .directive('magicOverrides', function() {
        return {
            restrict: 'A',
            controller: function($scope) {
                // showMenu and hideMenu depend on foundation's dropdown. They need
                // to be modified to work with another dropdown implemenation.
                // For bootstrap, they are not needed at all.
                $scope.showMenu = function() {
                    $scope.isMenuOpen = true;
                };
                $scope.hideMenu = function() {
                    $scope.isMenuOpen = false;
                };
                $scope.isMenuOpen = false;

                // remove the following when magic_search.js handles changing the facets/options
                $scope.$watch('facets_json', function(newVal, oldVal) {
                    if (newVal === oldVal) {
                        return;
                    }
                    $scope.currentSearch = [];
                    $scope.initSearch();
                });

            }
        };
    });
Support facets in the url that don't exist yet
Support facets in the url that don't exist yet

For example, the page first loads with a domain=Vivaldi facet
in the URL. But there is no such domain, because domains are
not loaded for another .1 second. So the facet is in the URL
but not the search bar. With this fix, when domains are
loaded and the facet JSON is updated, the code that
regenerates the facets also rereads from the URL.

This is a revision of my little hack in bootstrap_magic_search.js
to handle options coming in late. It actually feels less
like a hack now, and more like something you might want
to pull in and use.
