Permalink
Browse files

Adding vs.searchBox.selected() as a convenience method to show which …

…facets are selected or being edited.
  • Loading branch information...
samuelclay committed Sep 21, 2012
1 parent 1f608fe commit 3dc33eb9f548fe69dba44be8208f93384b83302f
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Binary file not shown.
View
@@ -75,6 +75,7 @@
};
})();
+
(function() {
var $ = jQuery; // Handle namespaced jQuery
@@ -143,6 +144,19 @@ VS.ui.SearchBox = Backbone.View.extend({
return _.compact(query).join(' ');
},
+
+ // Returns any facet views that are currently selected. Useful for changing the value
+ // callbacks based on what else is in the search box and which facet is being edited.
+ selected: function() {
+ return _.select(this.facetViews, function(view) {
+ return view.modes.editing == 'is' || view.modes.selected == 'is';
+ });
+ },
+
+ // Similar to `this.selected`, returns any facet models that are currently selected.
+ selectedModels: function() {
+ return _.pluck(this.selected(), 'model');
+ },
// Takes a query string and uses the SearchParser to parse and render it. Note that
// `VS.app.SearchParser` refreshes the `VS.app.searchQuery` collection, which is bound
@@ -578,9 +592,9 @@ VS.ui.SearchFacet = Backbone.View.extend({
var originalValue = this.model.get('value');
this.set(ui.item.value);
if (originalValue != ui.item.value || this.box.val() != ui.item.value) {
- if (this.options.app.options.autosearch) {
- this.search(e);
- }
+ if (this.options.app.options.autosearch) {
+ this.search(e);
+ }
}
return false;
}, this),
@@ -1557,9 +1571,7 @@ $.fn.extend({
return this.filter(':visible').each(function() {
if (this.setSelectionRange) { // FF/Webkit
this.focus();
- if ($(this).is(":visible")) {
- this.setSelectionRange(start, end);
- }
+ this.setSelectionRange(start, end);
} else if (this.createTextRange) { // IE
var range = this.createTextRange();
range.collapse(true);
@@ -1810,7 +1822,7 @@ VS.model.SearchQuery = Backbone.Collection.extend({
// Model holds the category and value of the facet.
model : VS.model.SearchFacet,
-
+
// Turns all of the facets into a single serialized string.
serialize : function() {
return this.map(function(facet){ return facet.serialize(); }).join(' ');
@@ -1876,4 +1888,4 @@ window.JST = window.JST || {};
window.JST['search_box'] = _.template('<div class="VS-search">\n <div class="VS-search-box-wrapper VS-search-box">\n <div class="VS-icon VS-icon-search"></div>\n <div class="VS-search-inner"></div>\n <div class="VS-icon VS-icon-cancel VS-cancel-search-box" title="clear search"></div>\n </div>\n</div>');
window.JST['search_facet'] = _.template('<% if (model.has(\'category\')) { %>\n <div class="category"><%= model.get(\'category\') %>:</div>\n<% } %>\n\n<div class="search_facet_input_container">\n <input type="text" class="search_facet_input VS-interface" value="" />\n</div>\n\n<div class="search_facet_remove VS-icon VS-icon-cancel"></div>');
window.JST['search_input'] = _.template('<input type="text" />');
-})();
+})();
@@ -8,7 +8,7 @@ VS.model.SearchQuery = Backbone.Collection.extend({
// Model holds the category and value of the facet.
model : VS.model.SearchFacet,
-
+
// Turns all of the facets into a single serialized string.
serialize : function() {
return this.map(function(facet){ return facet.serialize(); }).join(' ');
View
@@ -66,6 +66,19 @@ VS.ui.SearchBox = Backbone.View.extend({
return _.compact(query).join(' ');
},
+
+ // Returns any facet views that are currently selected. Useful for changing the value
+ // callbacks based on what else is in the search box and which facet is being edited.
+ selected: function() {
+ return _.select(this.facetViews, function(view) {
+ return view.modes.editing == 'is' || view.modes.selected == 'is';
+ });
+ },
+
+ // Similar to `this.selected`, returns any facet models that are currently selected.
+ selectedModels: function() {
+ return _.pluck(this.selected(), 'model');
+ },
// Takes a query string and uses the SearchParser to parse and render it. Note that
// `VS.app.SearchParser` refreshes the `VS.app.searchQuery` collection, which is bound

0 comments on commit 3dc33eb

Please sign in to comment.