Skip to content

Commit

Permalink
Merge branch 'master' of github.com:documentcloud/visualsearch
Browse files Browse the repository at this point in the history
# By José Luis Di Biase
# Via José Luis Di Biase (1) and Samuel Clay (1)
* 'master' of github.com:documentcloud/visualsearch:
  Adding support for managing options on views according newer bb versions
  whitespaces
  • Loading branch information
samuelclay committed Feb 9, 2014
2 parents c56f040 + 4857547 commit b173f7d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
19 changes: 11 additions & 8 deletions lib/js/views/search_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 || '',
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -362,7 +365,7 @@ VS.ui.SearchBox = Backbone.View.extend({
}
if (options.selectText) view.selectText();
this.resizeFacets();

return true;
},

Expand Down
9 changes: 6 additions & 3 deletions lib/js/views/search_facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ VS.ui.SearchFacet = Backbone.View.extend({
},

initialize : function(options) {
if(options)
this.options = options;

this.flags = {
canClose : false
};
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -171,7 +174,7 @@ VS.ui.SearchFacet = Backbone.View.extend({
});
}
}

if (options.preserveOrder) {
resp(matches);
} else {
Expand Down
15 changes: 9 additions & 6 deletions lib/js/views/search_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,13 +80,13 @@ VS.ui.SearchInput = Backbone.View.extend({
ul.append('<li class="ui-autocomplete-category">'+item.category+'</li>');
category = item.category;
}

if(this._renderItemData) {
this._renderItemData(ul, item);
} else {
this._renderItem(ul, item);
}

}, this));
};

Expand Down Expand Up @@ -166,7 +169,7 @@ VS.ui.SearchInput = Backbone.View.extend({
addTextFacetRemainder : function(facetValue) {
var boxValue = this.box.val();
var lastWord = boxValue.match(/\b(\w+)$/);

if (!lastWord) {
return '';
}
Expand All @@ -176,11 +179,11 @@ VS.ui.SearchInput = Backbone.View.extend({
boxValue = boxValue.replace(/\b(\w+)$/, '');
}
boxValue = boxValue.replace('^\s+|\s+$', '');

if (boxValue) {
this.app.searchBox.addFacet(this.app.options.remainder, boxValue, this.options.position);
}

return boxValue;
},

Expand Down

0 comments on commit b173f7d

Please sign in to comment.