diff --git a/lib/js/views/search_box.js b/lib/js/views/search_box.js index c5506be..9c15c60 100644 --- a/lib/js/views/search_box.js +++ b/lib/js/views/search_box.js @@ -16,7 +16,10 @@ VS.ui.SearchBox = Backbone.View.extend({ // Creating a new SearchBox registers handlers for re-rendering facets when necessary, // as well as handling typing when a facet is selected. - initialize : function() { + initialize : function(options) { + if(options) + this.options = options; + this.app = this.options.app; this.flags = { allSelected : false @@ -66,15 +69,15 @@ 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 _.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'); @@ -112,7 +115,7 @@ VS.ui.SearchBox = Backbone.View.extend({ category = VS.utils.inflector.trim(category); initialQuery = VS.utils.inflector.trim(initialQuery || ''); if (!category) return; - + var model = new VS.model.SearchFacet({ category : category, value : initialQuery || '', @@ -184,14 +187,14 @@ VS.ui.SearchBox = Backbone.View.extend({ // Render a single input, used to create and autocomplete facets renderSearchInput : function() { var input = new VS.ui.SearchInput({ - position: this.inputViews.length, + position: this.inputViews.length, app: this.app, showFacets: this.options.showFacets }); this.$('.VS-search-inner').append(input.render().el); this.inputViews.push(input); }, - + // Handles showing/hiding the placeholder text renderPlaceholder : function() { var $placeholder = this.$('.VS-placeholder'); @@ -362,7 +365,7 @@ VS.ui.SearchBox = Backbone.View.extend({ } if (options.selectText) view.selectText(); this.resizeFacets(); - + return true; }, diff --git a/lib/js/views/search_facet.js b/lib/js/views/search_facet.js index d9ae3bb..606db13 100644 --- a/lib/js/views/search_facet.js +++ b/lib/js/views/search_facet.js @@ -20,6 +20,9 @@ VS.ui.SearchFacet = Backbone.View.extend({ }, initialize : function(options) { + if(options) + this.options = options; + this.flags = { canClose : false }; @@ -147,7 +150,7 @@ VS.ui.SearchFacet = Backbone.View.extend({ // Search terms used in the autocomplete menu. These are specific to the facet, // and only match for the facet's category. The values are then matched on the // first letter of any word in matches, and finally sorted according to the - // value's own category. You can pass `preserveOrder` as an option in the + // value's own category. You can pass `preserveOrder` as an option in the // `facetMatches` callback to skip any further ordering done client-side. autocompleteValues : function(req, resp) { var category = this.model.get('category'); @@ -157,7 +160,7 @@ VS.ui.SearchFacet = Backbone.View.extend({ this.options.app.options.callbacks.valueMatches(category, searchTerm, function(matches, options) { options = options || {}; matches = matches || []; - + if (searchTerm && value != searchTerm) { if (options.preserveMatches) { resp(matches); @@ -171,7 +174,7 @@ VS.ui.SearchFacet = Backbone.View.extend({ }); } } - + if (options.preserveOrder) { resp(matches); } else { diff --git a/lib/js/views/search_input.js b/lib/js/views/search_input.js index 61eccc9..9f36cb8 100644 --- a/lib/js/views/search_input.js +++ b/lib/js/views/search_input.js @@ -17,7 +17,10 @@ VS.ui.SearchInput = Backbone.View.extend({ 'dblclick input' : 'startTripleClickTimer' }, - initialize : function() { + initialize : function(options) { + if(options) + this.options = options; + this.app = this.options.app; this.flags = { canClose : false @@ -77,13 +80,13 @@ VS.ui.SearchInput = Backbone.View.extend({ ul.append('