+
+
@@ -10,17 +10,16 @@
{{ facet.label[0] }}:{{ facet.label[1] }}
-
+
-
+
{{ facetSelected.label[0] }}:
-
diff --git a/xstatic/pkg/magic_search/data/magic_search.js b/xstatic/pkg/magic_search/data/magic_search.js
index 943eda9..347bb33 100755
--- a/xstatic/pkg/magic_search/data/magic_search.js
+++ b/xstatic/pkg/magic_search/data/magic_search.js
@@ -16,7 +16,7 @@ angular.module('MagicSearch')
return {
restrict: 'E',
scope: {
- facets_json: '@facets',
+ facets_param: '@facets',
filter_keys: '=filterKeys',
strings: '=strings'
},
@@ -24,11 +24,22 @@ angular.module('MagicSearch')
return elem.template;
},
controller: function ($scope, $timeout) {
+ $scope.promptString = $scope.strings['prompt'];
$scope.currentSearch = [];
$scope.initSearch = function() {
- // Parse facets JSON and convert to a list of facets.
- $scope.facetsJson = $scope.facets_json.replace(/__apos__/g, "\'").replace(/__dquote__/g, '\\"').replace(/__bslash__/g, "\\");
- $scope.facetsObj = JSON.parse($scope.facetsJson);
+ if (typeof $scope.facets_param === 'string') {
+ // Parse facets JSON and convert to a list of facets.
+ var tmp = $scope.facets_param.replace(/__apos__/g, "\'").replace(/__dquote__/g, '\\"').replace(/__bslash__/g, "\\");
+ $scope.facetsObj = JSON.parse(tmp);
+ }
+ else {
+ // Assume this is a usable javascript object
+ $scope.facetsObj = $scope.facets_param;
+ }
+ $scope.facetsSave = $scope.copyFacets($scope.facetsObj);
+ $scope.initFacets();
+ };
+ $scope.initFacets = function() {
// set facets selected and remove them from facetsObj
var initialFacets = window.location.search;
if (initialFacets.indexOf('?') === 0) {
@@ -52,25 +63,47 @@ angular.module('MagicSearch')
angular.forEach(value.options, function(option, idx) {
if (option.key == facetParts[1]) {
$scope.currentSearch.push({'name':facet, 'label':[value.label, option.label]});
- $scope.deleteFacetSelection(facetParts);
+ if (value.singleton === true) {
+ $scope.deleteFacetEntirely(facetParts);
+ }
+ else {
+ $scope.deleteFacetSelection(facetParts);
+ }
}
});
}
}
});
});
+ if ($scope.textSearch !== undefined) {
+ $scope.currentSearch.push({'name':'text='+$scope.textSearch, 'label':[$scope.strings['text'], $scope.textSearch]});
+ }
$scope.filteredObj = $scope.facetsObj;
};
+ $scope.copyFacets = function(facets) {
+ var ret = []
+ for (var i=0; i
-1) {
- label = [facet.label.substring(0, idx), facet.label.substring(idx, idx + search_val.length), facet.label.substring(idx + search_val.length)];
+ label = [facet.label.substring(0, idx), facet.label.substring(idx, idx + searchVal.length), facet.label.substring(idx + searchVal.length)];
filtered.push({'name':facet.name, 'label':label, 'options':facet.options});
}
}
@@ -195,7 +241,7 @@ angular.module('MagicSearch')
}, 0.1);
}
else {
- $scope.$emit('textSearch', search_val, $scope.filter_keys);
+ $scope.$emit('textSearch', searchVal, $scope.filter_keys);
$scope.hideMenu();
}
}
@@ -206,9 +252,9 @@ angular.module('MagicSearch')
}
for (i=0; i<$scope.filteredOptions.length; i++) {
var option = $scope.filteredOptions[i];
- idx = option.label.toLowerCase().indexOf(search_val);
+ idx = option.label.toLowerCase().indexOf(searchVal);
if (idx > -1) {
- label = [option.label.substring(0, idx), option.label.substring(idx, idx + search_val.length), option.label.substring(idx + search_val.length)];
+ label = [option.label.substring(0, idx), option.label.substring(idx, idx + searchVal.length), option.label.substring(idx + searchVal.length)];
filtered.push({'key':option.key, 'label':label});
}
}
@@ -221,8 +267,8 @@ angular.module('MagicSearch')
}
};
// enable text entry when mouse clicked anywhere in search box
- $('#search-main-area').on("click", function($event) {
- $('#search-input').trigger("focus");
+ $('.search-main-area').on("click", function($event) {
+ $('.search-input').trigger("focus");
if ($scope.facetSelected === undefined) {
$scope.showMenu();
}
@@ -241,11 +287,11 @@ angular.module('MagicSearch')
$scope.showMenu();
}
$timeout(function() {
- $('#search-input').val('');
+ $('.search-input').val('');
});
$scope.strings['prompt'] = '';
$timeout(function() {
- $('#search-input').focus();
+ $('.search-input').focus();
});
};
// when option clicked, complete facet and send event
@@ -273,12 +319,23 @@ angular.module('MagicSearch')
}
if (removed !== undefined && removed.indexOf('text') === 0) {
$scope.$emit('textSearch', '', $scope.filter_keys);
+ $scope.textSearch = undefined
}
else {
$scope.$emit('searchUpdated', query);
if ($scope.currentSearch.length > 0) {
var newFacet = $scope.currentSearch[$scope.currentSearch.length-1].name;
- $scope.deleteFacetSelection(newFacet.split('='));
+ var facetParts = newFacet.split('=');
+ angular.forEach($scope.facetsSave, function(facet, idx) {
+ if (facet.name == facetParts[0]) {
+ if (facet.singleton === true) {
+ $scope.deleteFacetEntirely(facetParts);
+ }
+ else {
+ $scope.deleteFacetSelection(facetParts);
+ }
+ }
+ });
}
}
};
@@ -291,25 +348,32 @@ angular.module('MagicSearch')
}
else {
$scope.resetState();
- $('#search-input').val('');
+ $('.search-input').val('');
}
- // facet re-enabled by reload
+ if ($scope.currentSearch.length == 0) {
+ $scope.strings['prompt'] = $scope.promptString;
+ }
+ // re-init to restore facets cleanly
+ $scope.facetsObj = $scope.copyFacets($scope.facetsSave);
+ $scope.currentSearch = [];
+ $scope.initFacets();
};
// clear entire searchbar
$scope.clearSearch = function() {
if ($scope.currentSearch.length > 0) {
$scope.currentSearch = [];
- $scope.facetsObj = JSON.parse($scope.facetsJson);
+ $scope.facetsObj = $scope.copyFacets($scope.facetsSave);
$scope.resetState();
$scope.$emit('searchUpdated', '');
$scope.$emit('textSearch', '', $scope.filter_keys);
+ $scope.strings['prompt'] = $scope.promptString;
}
};
$scope.isMatchLabel = function(label) {
return Array.isArray(label);
};
$scope.resetState = function() {
- $('#search-input').val('');
+ $('.search-input').val('');
$scope.filteredObj = $scope.facetsObj;
$scope.facetSelected = undefined;
$scope.facetOptions = undefined;
@@ -320,7 +384,7 @@ angular.module('MagicSearch')
$scope.showMenu = function() {
$timeout(function() {
if ($('#facet-drop').hasClass('open') === false) {
- $('#search-input').trigger('click');
+ $('.search-input').trigger('click');
}
});
};
diff --git a/xstatic/pkg/magic_search/data/magic_search.scss b/xstatic/pkg/magic_search/data/magic_search.scss
old mode 100755
new mode 100644
index 4993fe3..b25cf3a
--- a/xstatic/pkg/magic_search/data/magic_search.scss
+++ b/xstatic/pkg/magic_search/data/magic_search.scss
@@ -39,11 +39,8 @@ $itembackground: #e6e7e8;
position: absolute;
top: 0.5rem;
left: 0.65rem;
- //&.has-items {
- // margin-top: 6px;
- //}
}
- #search-main-area {
+ .search-main-area {
position: relative;
margin-left: 1.65rem;
margin-right: 1.65rem;
@@ -53,24 +50,24 @@ $itembackground: #e6e7e8;
.item-list {
margin-bottom: 2px;
}
- #search-selected {
+ .search-selected {
background-color: $background;
color: $textcolor;
}
- #search-entry {
+ .search-entry {
display: inline-block;
height: 1.5rem;
}
- #search-input {
+ .search-input {
width: 220px;
border: 0;
box-shadow: none;
height: 1.5rem;
padding: 3px;
background-color: $background;
- //&.has-items {
- // margin-top: 6px;
- //}
+ &:focus {
+ box-shadow: none;
+ }
}
.match {
font-weight: bold;
diff --git a/xstatic/pkg/magic_search/data/magic_search_bootstrap.html b/xstatic/pkg/magic_search/data/magic_search_bootstrap.html
deleted file mode 100755
index b8639b0..0000000
--- a/xstatic/pkg/magic_search/data/magic_search_bootstrap.html
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
-
- {{ facet.label[0] }}:{{ facet.label[1] }}
-
-
-
-
-
-
-
- {{ facetSelected.label[0] }}:
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/xstatic/pkg/magic_search/data/magic_search_bootstrap.js b/xstatic/pkg/magic_search/data/magic_search_bootstrap.js
deleted file mode 100755
index 69810fe..0000000
--- a/xstatic/pkg/magic_search/data/magic_search_bootstrap.js
+++ /dev/null
@@ -1,28 +0,0 @@
-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();
- });
-
- }
- };
- });
\ No newline at end of file