Skip to content

Commit

Permalink
using a variable instead..., fixes #211
Browse files Browse the repository at this point in the history
  • Loading branch information
henriyli committed Sep 23, 2015
1 parent 00bdb86 commit 8eb5c23
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions resource/js/docready.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$(function() { // DOCUMENT READY

var spinner = '<div class="loading-spinner"><span class="spinner-text">'+ loading_text + '</span><span class="spinner" /></div>';

var searchString = ''; // stores the search field's value before autocomplete selection changes it
var selectedVocabs = [];
var vocabId;
var vocabSelectionString = getUrlParams().vocabs ? getUrlParams().vocabs.replace(/\+/g,' ') : readCookie('SKOSMOS_SELECTED');
Expand Down Expand Up @@ -488,6 +488,8 @@ $(function() { // DOCUMENT READY
// typeahead selection action
function onSelection($e, datum) {
if ($e.currentTarget.id !== 'parent-limit') {
// restoring the original value
$typeahead.typeahead('val', searchString);
var localname = datum.localname;
var params = {};
if (!localname || encodeURIComponent(localname) !== localname) {
Expand Down Expand Up @@ -637,19 +639,13 @@ $(function() { // DOCUMENT READY
}
});

// storing the search input before autocompletion fires into the local storage cache
// storing the search input before autocompletion changes it
$('#search-field').on('input', function() {
// storing the value for only 2 minutes to prevent surprising behaviour
lscache.set('skosmos-query', $(this).val(), 2);
searchString = $(this).val();
});
// reading the stored input from the local storage cache
if (lscache.get('skosmos-query')) {
$typeahead.typeahead('val', lscache.get('skosmos-query'));
}

$('.clear-search').on('click', function() {
$typeahead.typeahead('val', '');
lscache.remove('skosmos-query');
searchString = '';
$(this).removeClass('clear-search-dark');
});

Expand Down

0 comments on commit 8eb5c23

Please sign in to comment.