diff --git a/src/config/common.config.js b/src/config/common.config.js
index 674aa3434..c00eb7430 100644
--- a/src/config/common.config.js
+++ b/src/config/common.config.js
@@ -176,6 +176,14 @@ define([], function () {
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
},
});
+
+ // array helpers
+ Handlebars.registerHelper({
+ includes(value, arr) {
+ return Array.isArray(arr) && arr.includes(value);
+ },
+ prop: (key, obj) => (typeof obj === 'object' ? obj[key] : undefined),
+ });
});
// set validation callbacks used by authentication and user settings widgets
diff --git a/src/js/widgets/preferences/templates/application.html b/src/js/widgets/preferences/templates/application.html
index a45cf5cf0..faae9a970 100644
--- a/src/js/widgets/preferences/templates/application.html
+++ b/src/js/widgets/preferences/templates/application.html
@@ -1,4 +1,7 @@
-
@@ -10,25 +13,26 @@
-
-
-
- Specifies the number of authors to show under each result before the list is truncated.
-
(
- default: {{numAuthorsDefault}})
-
-
+
+
+
+ Specifies the number of authors to show under each result before the list is truncated.
+
(
+ default: {{numAuthorsDefault}})
+
+
@@ -38,25 +42,26 @@
-
-
-
- Select the default action when opening an external link.
-
(
- default: {{externalLinksDefault}})
-
-
+
+
+
+ Select the default action when opening an external link.
+
(
+ default: {{externalLinksDefault}})
+
+
@@ -66,75 +71,96 @@
-
-
-
- Select the default landing page shown when loading the application or starting a new search.
-
(
- default: {{homePageDefault}})
-
-
+
+
+
+ Select the default landing page shown when loading the application or starting a new search.
+
(
+ default: {{homePageDefault}})
+
+
diff --git a/src/js/widgets/preferences/views/application.js b/src/js/widgets/preferences/views/application.js
index 971720f92..ccdf87389 100644
--- a/src/js/widgets/preferences/views/application.js
+++ b/src/js/widgets/preferences/views/application.js
@@ -18,24 +18,11 @@ define([
initialValue: 'Modern Form',
},
database: {
- initialValue: [
- {
- name: 'Physics',
- value: false,
- },
- {
- name: 'Astronomy',
- value: false,
- },
- {
- name: 'General',
- value: false,
- },
- {
- name: 'Earth Science',
- value: false,
- },
- ],
+ 'All': false,
+ 'Physics': false,
+ 'Astronomy': false,
+ 'General': false,
+ 'Earth Science': false,
},
hideSidebars: {
initialValue: 'Show',
@@ -43,22 +30,60 @@ define([
},
};
+ const isEqualToDefault = (prop, value) => {
+ if (prop === 'numAuthorsSelected') {
+ return value === DEFAULTS.numAuthors.initialValue;
+ }
+ if (prop === 'externalLinksSelected') {
+ return value === DEFAULTS.externalLinks.initialValue;
+ }
+ if (prop === 'homePageSelected') {
+ return value === DEFAULTS.homePage.initialValue;
+ }
+ if (prop === 'hideSideBarsSelected') {
+ return value === DEFAULTS.hideSidebars.initialValue;
+ }
+ if (prop === 'databaseSelected') {
+ return _.isEqual(value, DEFAULTS.database.initialValue);
+ }
+ return false;
+ };
+
+ /**
+ * Incoming database isa an array of objects, we need to transform and merge it to our internal format
+ * @param databases
+ * @returns {*|*[]}
+ */
const mergeDatabases = (databases) => {
if (
!Array.isArray(databases) ||
(Array.isArray(databases) && databases.length === 0)
) {
- return DEFAULTS.database.initialValue;
+ return DEFAULTS.database;
}
- const merged = [];
- DEFAULTS.database.initialValue.forEach((database) => {
- const found = databases.find((d) => d.name === database.name);
- merged.push(found || database);
+ // remove any undefined values
+ const cleanedDbs = databases.filter((d) => !!d);
+
+ const merged = {};
+ Object.keys(DEFAULTS.database).forEach((name) => {
+ const found = cleanedDbs.find((d) => d.name === name);
+ merged[name] = found ? !!found.value : DEFAULTS.database[name];
});
return merged;
};
+ /**
+ * Transform the internal database format to the external format
+ * @param databases
+ */
+ const transformDatabases = (databases) => {
+ return Object.keys(databases).map((name) => ({
+ name,
+ value: databases[name],
+ }));
+ };
+
const watchedProps = [
'numAuthorsSelected',
'externalLinksSelected',
@@ -67,22 +92,21 @@ define([
'hideSideBarsSelected',
];
- var ApplicationView = Marionette.ItemView.extend({
+ const ApplicationView = Marionette.ItemView.extend({
initialize: function () {
// Get the latest value from the incoming model, or just take the default
- var numAuthors =
+ const numAuthors =
this.model.get('minAuthorsPerResult') ||
DEFAULTS.numAuthors.initialValue;
- var externalLinks =
+ const externalLinks =
this.model.get('externalLinkAction') ||
DEFAULTS.externalLinks.initialValue;
- var homePage =
+ const homePage =
this.model.get('homePage') || DEFAULTS.homePage.initialValue;
- var database = mergeDatabases(this.model.get('defaultDatabase'));
- var hideSidebars =
+ const hideSidebars =
this.model.get('defaultHideSidebars') ||
DEFAULTS.hideSidebars.initialValue;
-
+ const databases = mergeDatabases(this.model.get('defaultDatabase'));
// must clone the props that will get mutated
this.model.set({
@@ -92,14 +116,23 @@ define([
externalLinksOptions: DEFAULTS.externalLinks.initialOptions,
externalLinksDefault: DEFAULTS.externalLinks.initialValue,
externalLinksSelected: _.clone(externalLinks),
- databaseSelected: _.cloneDeep(database),
+
+ // remove the 'All' database from the list, so it doesn't get rendered as a button
+ databaseSelected: databases,
+ databaseOptions: Object.keys(databases).filter((name) => name !== 'All'),
homePageOptions: DEFAULTS.homePage.initialOptions,
homePageDefault: DEFAULTS.homePage.initialValue,
homePageSelected: _.clone(homePage),
hideSideBarsDefault: DEFAULTS.hideSidebars.initialValue,
hideSideBarsOptions: DEFAULTS.hideSidebars.initialOptions,
hideSideBarsSelected: _.clone(hideSidebars),
- databaseALLSelected: data,
+
+ modifySections: [
+ // databases section is modified if any of the entries are true
+ ...(Object.keys(databases).some((name) => databases[name])
+ ? ['database']
+ : []),
+ ],
});
this.model.trigger('change');
@@ -111,9 +144,12 @@ define([
className: 'panel panel-default s-form-container',
events: {
- 'change .database-select': 'onDatabaseSelect',
+ 'click .database-select': 'onDatabaseSelect',
'change #database_all': 'onDatabaseALLSelect',
'change select': 'syncModel',
+ 'click .section-modify': 'onModifySection',
+ 'click .section-reset': 'onResetSection',
+ 'click .reset-to-defaults': 'onResetToDefaults',
},
modelEvents: {
@@ -122,33 +158,52 @@ define([
onDatabaseALLSelect: function (e) {
const checked = $(e.currentTarget).prop('checked');
- this.model.set('databaseALLSelected', checked);
- if (checked) {
- this.model.set('databaseSelected', DEFAULTS.database.initialValue);
- }
+
+ this.model.set('databaseSelected', {
+ ...DEFAULTS.database,
+ All: checked,
+ });
+
this.model.trigger('change');
},
onDatabaseSelect: function (e) {
- if (this.model.get('databaseALLSelected')) {
+ const dbState = this.model.get('databaseSelected');
+
+ // if 'ALL' selected, then the other options are disabled
+ if (dbState.All) {
return;
}
- const data = this.model.get('databaseSelected');
- // find the current index of the element
- const idx = $('.database-select', this.el).index(e.currentTarget);
+ const id = $(e.currentTarget).data('id');
+
+ this.model.set('databaseSelected', {
+ ...dbState,
- // grab the object at [idx] and make our change
- const newVal = _.assign({}, data[idx], {
- value: !data[idx].value,
+ // toggle the state of the database entry
+ [id]: !dbState[id],
});
+ this.model.trigger('change');
+ },
- // place our new value in the array
- const newData = data
- .slice(0, idx)
- .concat(newVal)
- .concat(data.slice(idx + 1));
- this.model.set('databaseSelected', newData);
+ onModifySection(e) {
+ const section = $(e.currentTarget).data('section');
+ this.model.set('modifySections', [
+ ...this.model.get('modifySections'),
+ section,
+ ]);
+ },
+
+ onResetSection(e) {
+ const section = $(e.currentTarget).data('section');
+ this.model.set({
+ modifySections: this.model.get('modifySections').filter((s) => s !== section),
+ ...(section === 'database'
+ ? {
+ databaseSelected: DEFAULTS.database,
+ }
+ : {}),
+ });
this.model.trigger('change');
},
@@ -190,12 +245,13 @@ define([
loading: true,
});
this.syncModel();
+
this.trigger('change:applicationSettings', {
minAuthorsPerResult: this._convertToString(
this.model.get('numAuthorsSelected'),
),
externalLinkAction: this.model.get('externalLinksSelected'),
- defaultDatabase: this.model.get('databaseSelected'),
+ defaultDatabase: transformDatabases(this.model.get('databaseSelected')),
defaultHideSidebars: this.model.get('hideSideBarsSelected'),
homePage: this.model.get('homePageSelected'),
});
@@ -280,7 +336,15 @@ define([
});
},
+ _renderCount: 1,
+
onRender: function () {
+ // skip initial x renders, because when we first get data it'll render and detect a change
+ if (this._renderCount > 0) {
+ this._renderCount -= 1;
+ return;
+ }
+
var onSortChange = _.bind(this.onSortChange, this);
setTimeout(() => {
$('#addCustomFormat').sortable({
diff --git a/src/js/widgets/search_bar/search_bar_widget.js b/src/js/widgets/search_bar/search_bar_widget.js
index 5862ad88e..7c4ec6d77 100644
--- a/src/js/widgets/search_bar/search_bar_widget.js
+++ b/src/js/widgets/search_bar/search_bar_widget.js
@@ -20,7 +20,7 @@ define([
'js/components/query_validator',
'select2',
'libs/select2/matcher',
-], function(
+], function (
_,
Marionette,
bowser,
@@ -33,7 +33,7 @@ define([
ApiTargets,
ApiFeedback,
FormatMixin,
- { render: renderAutocomplete, autocompleteSource: autocompleteArray },
+ {render: renderAutocomplete, autocompleteSource: autocompleteArray},
quickFieldDesc,
bootstrap,
jqueryUI,
@@ -41,7 +41,7 @@ define([
analytics,
QueryValidator,
select2,
- oldMatcher
+ oldMatcher,
) {
/**
@@ -51,7 +51,7 @@ define([
const DEFAULT_DATABASES = ['Astronomy', 'Physics'];
var SearchBarModel = Backbone.Model.extend({
- defaults: function() {
+ defaults: function () {
return {
citationCount: undefined,
numFound: undefined,
@@ -78,13 +78,13 @@ define([
className: 's-search-bar-widget',
- initialize: function(options) {
+ initialize: function (options) {
_.bindAll(this, 'fieldInsert');
this.queryValidator = new QueryValidator();
this.defaultDatabases = [];
},
- activate: function(beehive) {
+ activate: function (beehive) {
this.setBeeHive(beehive);
var that = this;
},
@@ -93,7 +93,7 @@ define([
change: 'render',
},
- onRender: function() {
+ onRender: function () {
var that = this;
const $container = this.$('#option-dropdown-container');
/*
@@ -107,32 +107,33 @@ define([
}
return false;
}
+
var $select = this.$('.quick-add-dropdown');
$select
- .select2({
- placeholder: 'All Search Terms',
- matcher: oldMatcher(matchStart),
- })
- .on('change', function(e) {
- var val = e.target.value;
- // prevent infinite loop!
- if (!val) return;
- var $option = $(this).find('option[value="' + e.target.value + '"]');
-
- // Grab any default value that is present on the element
- var defaultValue = $option.data('defaultValue');
- var label = $option.closest('optgroup').attr('label');
- $select.val(null).trigger('change');
- setTimeout(function() {
- that.selectFieldInsert(val, label, defaultValue);
- // not entirely sure why this timeout is necessary...
- // without it, focus is moved from the main query bar
- }, 100);
- })
- // this seems to be necessary to show the placeholder on initial render
- .val(null)
- .trigger('change');
+ .select2({
+ placeholder: 'All Search Terms',
+ matcher: oldMatcher(matchStart),
+ })
+ .on('change', function (e) {
+ var val = e.target.value;
+ // prevent infinite loop!
+ if (!val) return;
+ var $option = $(this).find('option[value="' + e.target.value + '"]');
+
+ // Grab any default value that is present on the element
+ var defaultValue = $option.data('defaultValue');
+ var label = $option.closest('optgroup').attr('label');
+ $select.val(null).trigger('change');
+ setTimeout(function () {
+ that.selectFieldInsert(val, label, defaultValue);
+ // not entirely sure why this timeout is necessary...
+ // without it, focus is moved from the main query bar
+ }, 100);
+ })
+ // this seems to be necessary to show the placeholder on initial render
+ .val(null)
+ .trigger('change');
const $select2Instance = $select.data('select2');
@@ -154,7 +155,7 @@ define([
// hide popovers one open and close, focusing will re-open them after this
$select2Instance.on('open', closeAllPopovers);
- $select2Instance.on('results:focus', ({ data: { id } }) => {
+ $select2Instance.on('results:focus', ({data: {id}}) => {
// hide any opened popovers
closeAllPopovers();
// grab the title/body from our list
@@ -166,21 +167,21 @@ define([
// create the popover
const syntax = data.syntax.map((s) => `
${s}
`).join(', ');
const example = data.example
- .map((e) => `
${e}
`)
- .join(', ');
+ .map((e) => `
${e}
`)
+ .join(', ');
$('.select2-dropdown')
- .popover({
- title: `
${data.title}`,
- content: `${data.description}
Syntax:
${syntax}
Example: ${example}`,
- html: true,
- placement: 'top right',
- trigger: 'manual',
- container: 'body',
- animation: false,
- })
- .data('bs.popover')
- .tip()
- .attr('class', 'search-term-popover popover right in');
+ .popover({
+ title: `
${data.title}`,
+ content: `${data.description}
Syntax:
${syntax}
Example: ${example}`,
+ html: true,
+ placement: 'top right',
+ trigger: 'manual',
+ container: 'body',
+ animation: false,
+ })
+ .data('bs.popover')
+ .tip()
+ .attr('class', 'search-term-popover popover right in');
$('.select2-dropdown').popover('show');
});
@@ -217,20 +218,20 @@ define([
'click .bigquery-close': 'clearBigquery',
},
- toggleClear: function() {
+ toggleClear: function () {
this.$('.icon-clear').toggleClass('hidden', !this.$input.val());
},
- clearInput: function() {
+ clearInput: function () {
this.$input.val('').focus();
this.toggleClear();
},
- getFormVal: function() {
+ getFormVal: function () {
return this.$input.val();
},
- setFormVal: function(v) {
+ setFormVal: function (v) {
/*
bigquery special case: don't show the confusing *:*, just empty bar
*/
@@ -242,7 +243,7 @@ define([
this.toggleClear();
},
- serializeData: function() {
+ serializeData: function () {
var j = this.model.toJSON();
j.numFound = j.numFound ? this.formatNum(j.numFound) : 0;
j.citationCount = j.citationCount
@@ -252,20 +253,20 @@ define([
if (this.model.get('bigquerySource').match(/library/i)) {
this.model.set({
libraryName: this.model
- .get('bigquerySource')
- .match(/library:(.*)/i)[1],
+ .get('bigquerySource')
+ .match(/library:(.*)/i)[1],
});
}
}
return j;
},
- onShowForm: function() {
+ onShowForm: function () {
// show the form
this.specifyFormWidth();
},
- toggleFormSection: function(e) {
+ toggleFormSection: function (e) {
var $p = $(e.target).parent();
$p.next().toggleClass('hide');
$p.toggleClass('search-form-header-active');
@@ -277,7 +278,7 @@ define([
startIndex: 0,
},
- storeCursorInfo: function(e) {
+ storeCursorInfo: function (e) {
var selected = getSelectedText(e.currentTarget);
var startIndex = this.$input.getCursorPosition();
this._cursorInfo = {
@@ -287,7 +288,7 @@ define([
this.toggleClear();
},
- selectFieldInsert: function(val, label, initialValue) {
+ selectFieldInsert: function (val, label, initialValue) {
var newVal;
var specialCharacter;
var highlightedText = this._cursorInfo.selected;
@@ -306,16 +307,15 @@ define([
// newVal = df + ":\"" + selected + "\"";
//
switch (label) {
- case 'fields':
- {
- if (val === 'first-author') {
- val = 'author';
- selected = selected.replace(/"/, '"^');
- } else if (val === 'year') {
- selected = selected.replace(/"/g, '');
- }
- newVal = val + ':' + selected;
+ case 'fields': {
+ if (val === 'first-author') {
+ val = 'author';
+ selected = selected.replace(/"/, '"^');
+ } else if (val === 'year') {
+ selected = selected.replace(/"/g, '');
}
+ newVal = val + ':' + selected;
+ }
break;
case 'operators':
newVal = val + '(' + (selected === '""' ? '' : selected) + ')';
@@ -333,8 +333,8 @@ define([
if (highlightedText.length) {
this.setFormVal(
currentVal.substr(0, startIndex) +
- newVal +
- currentVal.substr(startIndex + selected.length)
+ newVal +
+ currentVal.substr(startIndex + selected.length),
);
} else {
// append to the end
@@ -351,11 +351,11 @@ define([
'event',
'interaction',
'field-insert-dropdown-selected',
- val
+ val,
);
},
- fieldInsert: function(e) {
+ fieldInsert: function (e) {
var newVal;
var operator;
var currentVal = this.getFormVal();
@@ -393,8 +393,8 @@ define([
if (selected) {
this.setFormVal(
currentVal.substr(0, startIndex) +
- newVal +
- currentVal.substr(startIndex + selected.length)
+ newVal +
+ currentVal.substr(startIndex + selected.length),
);
} else {
// append to the end
@@ -413,12 +413,12 @@ define([
'event',
'interaction',
'field-insert-button-pressed',
- df
+ df,
);
return false;
},
- submitQuery: function(e) {
+ submitQuery: function (e) {
var fields;
var fielded;
var query;
@@ -433,7 +433,7 @@ define([
) {
// show a popup to tell the user to type in a query
$input.popover('show');
- $input.on('input change blur', function() {
+ $input.on('input change blur', function () {
$(this).popover('hide');
});
return false;
@@ -441,7 +441,7 @@ define([
$input.popover('hide');
// replace uppercased fields with lowercase
- query = query.replace(/([A-Z])\w+:/g, function(letter) {
+ query = query.replace(/([A-Z])\w+:/g, function (letter) {
return letter.toLowerCase();
});
// store the query in case it gets changed (which happens when there is an object query)
@@ -475,7 +475,7 @@ define([
'
reading our help page.',
type: 'info',
fade: true,
- })
+ }),
);
return false;
}
@@ -483,17 +483,17 @@ define([
// let analytics know what type of query it was
fields = _.chain(autocompleteArray)
- .pluck('value')
- .map(function(b) {
- var m = b.match(/\w+:|\w+\(/);
- if (m && m.length) return m[0];
- })
- .unique()
- .value();
+ .pluck('value')
+ .map(function (b) {
+ var m = b.match(/\w+:|\w+\(/);
+ if (m && m.length) return m[0];
+ })
+ .unique()
+ .value();
fielded = false;
- _.each(fields, function(f) {
+ _.each(fields, function (f) {
if (query.indexOf(f) > -1) {
fielded = true;
}
@@ -505,12 +505,12 @@ define([
'event',
'interaction',
type + '-query-submitted-from-search-bar',
- query
+ query,
);
return false;
},
- clearBigquery: function() {
+ clearBigquery: function () {
this.trigger('clear_big_query');
},
});
@@ -518,21 +518,21 @@ define([
_.extend(SearchBarView.prototype, FormatMixin, Dependon.BeeHive);
var SearchBarWidget = BaseWidget.extend({
- initialize: function(options) {
+ initialize: function (options) {
this.model = new SearchBarModel();
this.view = new SearchBarView({
model: this.model,
});
- this.listenTo(this.view, 'start_search', function(query) {
+ this.listenTo(this.view, 'start_search', function (query) {
this.changeDefaultSort(query);
this.navigate(query);
this.updateState('loading');
this.view.setFormVal(query.get('q'));
});
- this.listenTo(this.view, 'clear_big_query', function(query) {
+ this.listenTo(this.view, 'clear_big_query', function (query) {
var query = this._currentQuery.clone();
// awkward but need to remove qid + provide __clearBigQuery
// for querymediator to do the correct thing
@@ -545,7 +545,7 @@ define([
this.navigate(query);
});
- this.listenTo(this.view, 'render', function() {
+ this.listenTo(this.view, 'render', function () {
var newQueryString = '';
var query = this.getCurrentQuery();
var oldQueryString = query.get('q');
@@ -568,7 +568,7 @@ define([
BaseWidget.prototype.initialize.call(this, options);
},
- activate: function(beehive) {
+ activate: function (beehive) {
this.setBeeHive(beehive);
this.activateWidget();
var pubsub = this.getPubSub();
@@ -580,19 +580,19 @@ define([
this.view.activate(beehive.getHardenedInstance());
pubsub.subscribe(
pubsub.INVITING_REQUEST,
- _.bind(this.dispatchRequest, this)
+ _.bind(this.dispatchRequest, this),
);
pubsub.subscribe(pubsub.DELIVERING_RESPONSE, this.processResponse);
pubsub.subscribe(
pubsub.USER_ANNOUNCEMENT,
- _.bind(this.updateFromUserData, this)
+ _.bind(this.updateFromUserData, this),
);
pubsub.subscribe(pubsub.CUSTOM_EVENT, _.bind(this.onCustomEvent, this));
pubsub.subscribe(pubsub.START_SEARCH, _.bind(this.onStartSearch, this));
this.updateFromUserData();
},
- getUserData: function() {
+ getUserData: function () {
try {
var beehive = _.isFunction(this.getBeeHive) && this.getBeeHive();
var user = _.isFunction(beehive.getObject) && beehive.getObject('User');
@@ -607,11 +607,11 @@ define([
}
},
- onStartSearch: function() {
+ onStartSearch: function () {
this.model.unset('timing');
},
- onCustomEvent: function(event, arg) {
+ onCustomEvent: function (event, arg) {
if (event === 'timing:results-loaded') {
this.model.set('timing', arg / 1000);
} else if (event === 'hotkey/search') {
@@ -630,20 +630,26 @@ define([
}
},
- updateFromUserData: function() {
+ updateFromUserData: function () {
var userData = this.getUserData();
this.defaultDatabases = _.has(userData, 'defaultDatabase')
? _.map(
- _.filter(userData.defaultDatabase, {
- value: true,
- }),
- 'name'
- )
+ _.filter(userData.defaultDatabase, {
+ value: true,
+ }),
+ 'name',
+ )
: this.defaultDatabases;
},
applyDefaultFilters: function (apiQuery) {
const dbfilters = Array.isArray(this.defaultDatabases) && this.defaultDatabases.length > 0 ? this.defaultDatabases : DEFAULT_DATABASES;
+
+ // if the user has selected all databases, don't apply ANY filter
+ if (dbfilters.length > 0 && dbfilters.includes('All')) {
+ return apiQuery;
+ }
+
if (dbfilters.length > 0) {
var fqString = '{!type=aqp v=$fq_database}';
@@ -660,28 +666,28 @@ define([
if (!apiQuery.has('fq_database')) {
var fq_database_string = _.reduce(
dbfilters,
- function(res, db, i) {
+ function (res, db, i) {
var d = db.toLowerCase();
return res.replace(
/(\(.*)(\))/,
i === 0
? '$1database:' + d + '$2'
- : '$1 OR database:' + d + '$2'
+ : '$1 OR database:' + d + '$2',
);
},
- '()'
+ '()',
);
apiQuery.set('fq_database', fq_database_string);
}
// finally add the filters
if (!apiQuery.has('__filter_database_fq_database')) {
- var fq_database_filters = _.map(dbfilters, function(db) {
+ var fq_database_filters = _.map(dbfilters, function (db) {
return 'database:' + db.toLowerCase();
});
apiQuery.set(
'__filter_database_fq_database',
- ['OR'].concat(fq_database_filters)
+ ['OR'].concat(fq_database_filters),
);
}
}
@@ -689,7 +695,7 @@ define([
return apiQuery;
},
- processResponse: function(apiResponse) {
+ processResponse: function (apiResponse) {
var res = apiResponse.toJSON();
var sort = res.responseHeader.params.sort;
if (res.stats && /citation.*/.test(sort)) {
@@ -716,7 +722,7 @@ define([
fl: 'id',
},
- dispatchRequest: function(apiQuery) {
+ dispatchRequest: function (apiQuery) {
var sort = apiQuery.get('sort');
if (/citation_count_norm/i.test(sort)) {
this.defaultQueryArguments = _.extend(this.defaultQueryArguments, {
@@ -742,24 +748,24 @@ define([
* when users return to index page, we should re-focus on the search bar
* */
- focusInput: function() {
+ focusInput: function () {
if (this._onIndexPage()) {
this.clearBigQueryPill();
this.view.clearInput();
}
},
- clearBigQueryPill: function() {
+ clearBigQueryPill: function () {
this.model.unset('bigquerySource');
this.model.unset('bigquery');
},
- onNavigate: function(page) {
+ onNavigate: function (page) {
this.currentPage = page;
this.focusInput(page);
},
- handleFeedback: function(feedback) {
+ handleFeedback: function (feedback) {
if (
feedback.code === ApiFeedback.CODES.SEARCH_CYCLE_STARTED ||
feedback.code === ApiFeedback.CODES.SEARCH_CYCLE_FAILED_TO_START
@@ -788,7 +794,7 @@ define([
}
},
- changeDefaultSort: function(query) {
+ changeDefaultSort: function (query) {
var currentQuery = this.getCurrentQuery();
// make sure not to override an explicit sort if there is one
@@ -821,16 +827,16 @@ define([
}
},
- _onIndexPage: function() {
+ _onIndexPage: function () {
// look out for these names, or that the current page is undefined
return (
/(index-page|SearchWidget)/.test(this.currentPage) || !this.currentPage
);
},
- navigate: function(newQuery) {
+ navigate: function (newQuery) {
var newQ = newQuery.toJSON();
- var oldQ = _.omit(this.getCurrentQuery().toJSON(), function(val, key) {
+ var oldQ = _.omit(this.getCurrentQuery().toJSON(), function (val, key) {
// omit certain fields (highlights, paging)
return (
/^hl.*/.test(key) ||
@@ -862,14 +868,14 @@ define([
});
},
- openQueryAssistant: function(queryString) {
+ openQueryAssistant: function (queryString) {
if (queryString) {
this.view.setFormVal(queryString);
}
this.view.$el.find('.show-form').click();
},
- onShow: function() {
+ onShow: function () {
// only focus on the index-page
if (this._onIndexPage()) {
var $input = this.view.$('input[name=q]');
@@ -886,15 +892,15 @@ define([
}
},
- onDestroy: function() {
+ onDestroy: function () {
this.view.destroy();
},
- onLoading: function() {
+ onLoading: function () {
this.model.set('loading', true);
},
- onIdle: function() {
+ onIdle: function () {
this.model.set('loading', false);
},
});