Skip to content

Commit 5e794ab

Browse files
committed
replaced substr with substring and minor code improvements
1 parent a569bde commit 5e794ab

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/js/dream_search_widget.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ jQuery(document).ready(function($) {
1616
});
1717
});
1818
window.tryGetFromCache = function(val) {
19-
let ch = val.substr(0, 1).toLowerCase();
19+
val = val.toLowerCase();
20+
let ch = val.substring(0, 1);
2021
if (ch.match(/^[a-z]$/)) {
21-
val = val.toLowerCase();
2222
console.log('keydown triggered, val is: '+val);
23-
if (!window.dreamCache[ch]) {
23+
if (!window.dreamCache[ch]) { // is cache miss ?
2424
window.dreamCache[ch] = true; // set up placeholder
2525
let url = window.urlPrefix+ch+'.json';
2626
console.log('cache miss, downloading '+url);
27-
$.get(url, function(res) {
27+
$.get(url, function(res) { // get /dict/ json
2828
console.log('downloaded '+url);
2929
window.dreamCache[ch] = res; // save to cache
3030
if (val.length > 1)
@@ -39,7 +39,7 @@ window.tryGetFromCache = function(val) {
3939
}
4040
window.hashChange = function(e) {
4141
if (location.hash && location.hash.length > 1) {
42-
let val = decodeURI(location.hash.substr(1));
42+
let val = decodeURI(location.hash.substring(1));
4343
$('#symbol').val(val);
4444
window.tryGetFromCache(val);
4545
}
@@ -48,7 +48,7 @@ $(window).bind('hashchange', window.hashChange);
4848
window.hashChange();
4949
window.updateAutoCompleteWithVal = function() {
5050
if (window.cachedVal) {
51-
let ch = window.cachedVal.substr(0, 1);
51+
let ch = window.cachedVal.substring(0, 1);
5252
if (window.dreamCache[ch]
5353
&& window.dreamCache[ch] !== true) {
5454
window.updateAutoComplete(window.cachedVal);
@@ -57,7 +57,7 @@ window.updateAutoCompleteWithVal = function() {
5757
}
5858
}
5959
window.updateAutoComplete = function(val) {
60-
let ch = val.substr(0, 1), output = '',
60+
let ch = val.substring(0, 1), output = '',
6161
items = window.dreamCache[ch];
6262
if (items === true) {
6363
console.log('Scheduled search');

0 commit comments

Comments
 (0)