diff --git a/package.json b/package.json index b4d190e..80890d7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "a web frontend for ScreenInvader", "dependencies": { "screeninvader.js": "screeninvader/screeninvader.js", - "underscore": "~1.8.2" + "underscore": "~1.8.2", + "underscore.string": "^3.0.3" }, "devDependencies": { "babelify": "~5.0.4", diff --git a/src/search.js b/src/search.js index 924a7e9..bde1516 100644 --- a/src/search.js +++ b/src/search.js @@ -2,6 +2,7 @@ import _ from 'underscore'; import {loadTemplate, fetchJSON, bindEvent, bindEvents} from './utils'; import config from './config'; import api from './api'; +import {startsWith} from 'underscore.string'; var searchProviders = { @@ -89,7 +90,7 @@ class Search { let term = ev.target.value; this.submit.disabled = true; if (term.length > 0) { - if (term.startsWith('http')) { + if (startsWith(term, 'http')) { this.submit.disabled = false; } else { this.doSearch(term); @@ -101,7 +102,7 @@ class Search { submitHandler(ev) { ev.preventDefault(); - if (this.input.value.startsWith('http')) { + if (startsWith(this.input.value, 'http')) { api.showUrl(this.input.value); } } @@ -126,8 +127,8 @@ class Search { console.log('alias, terms', providerAlias, terms); let matchingProviders = _.filter(searchProviders, (provider, name) => { - return (provider.alias.startsWith(providerAlias) || - name.startsWith(providerAlias)); + return (startsWith(provider.alias, providerAlias) || + startsWith(name, providerAlias)); }); if (terms.length === 0) {