Skip to content

Commit

Permalink
Merge pull request #92 from alyuev/Save-search-query-string
Browse files Browse the repository at this point in the history
Search history #20
  • Loading branch information
tigran123 committed Apr 12, 2019
2 parents c6e976c + 10386ed commit 595a338
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 18 deletions.
44 changes: 31 additions & 13 deletions css/ubex.css
Expand Up @@ -6,6 +6,7 @@ body { font-family: 'Trebuchet MS', Tahoma, Verdana, Arial, Helvetica, sans-seri
.ui-tabs .ui-tabs-panel { padding: 0.7em 0em 0.5em 0em; }
.loading { background: white url('../img/ui-anim_basic_16x16.gif') right center no-repeat; }
.sc {text-transform: uppercase;}
.ui-autocomplete { max-height: 300px; overflow-y: scroll; overflow-x: hidden;}

.pictures {
max-width: 100%;
Expand All @@ -15,7 +16,7 @@ body { font-family: 'Trebuchet MS', Tahoma, Verdana, Arial, Helvetica, sans-seri
figure { margin: 2px; }

#search_text {
margin: 0px 0px 0px 10px;
margin: 0px 30px 0px 10px;
height: 20px;
width: 250px;
}
Expand All @@ -24,25 +25,25 @@ figure { margin: 2px; }
.hit { font-family: 'Arial Narrow', Arial; color: red; }

#help {
position: absolute;
left: 300px;
top: 200px;
padding: 1.2em;
font-size: 14px;
position: absolute;
left: 300px;
top: 200px;
padding: 1.2em;
font-size: 14px;
}

.ui-tooltip { text-align: center; }

.toc li {
line-height: 140%;
padding-bottom: 7px;
}
line-height: 140%;
padding-bottom: 7px;
}

.toc_container {
font-family: 'Arial Narrow', Arial;
padding: 0px;
font-size: 14px;
overflow-y: scroll;
font-family: 'Arial Narrow', Arial;
padding: 0px;
font-size: 14px;
overflow-y: scroll;
}

legend { font-weight: bold; }
Expand Down Expand Up @@ -99,3 +100,20 @@ legend { font-weight: bold; }
a: { color: blue; }
a:hover, a:focus { color: #018fe2; }
a, a:hover, a:active, a:focus { text-decoration: none; }

.custom-combobox {
position: relative;
display: inline-block;
}
.custom-combobox-toggle {
position: absolute;
top: 0;
bottom: 0;
margin-left: -30px;
padding: 0;
}
.custom-combobox-input {
margin: 0;
padding: 5px 10px;
}

3 changes: 2 additions & 1 deletion header.php
Expand Up @@ -4,7 +4,7 @@
$lang = $_COOKIE['lang'];
else {
$ip = get_client_ip();
$country = trim(file_get_contents("http://ipinfo.io/{$ip}/country"));
$country = $ip=='127.0.0.1' ? 'EN' : trim(file_get_contents("http://ipinfo.io/{$ip}/country"));

switch($country) {
case 'UA':
Expand Down Expand Up @@ -78,6 +78,7 @@
<script src='jquery/jquery.mark.min.js' charset='UTF-8'></script>
<script src='jquery/cookieBubble.min.js'></script>
<script src='jquery/jquery.scrollSync.js'></script>
<script type='text/javascript'>var INPUT_SEARCH_STRING = '".$INPUT_SEARCH_STRING."';</script>
<script src='js/index.js'></script>
</body></html>";

Expand Down
2 changes: 1 addition & 1 deletion index.php
Expand Up @@ -141,7 +141,7 @@
<option value=2>$TITLES_ONLY</option>
</select>
<button class='buttons' type='button' id='clear' title='$CLEAR_SEARCH_STRING'><span class='ui-icon ui-icon-close'></span></button>
<input placeholder='$INPUT_SEARCH_STRING' type='text' autofocus id='search_text'>
<select id='combobox'></select>
<button class='buttons' type='button' id='search' title='$START_SEARCH'><span class='ui-icon ui-icon-arrowrefresh-1-n' id='search_status'></span></button>
<button class='buttons' type='button' id='ic' title='$IGNORE_CASE'><span id='ic_lab'>a = A</span></button>
</fieldset>
Expand Down
138 changes: 135 additions & 3 deletions js/index.js
Expand Up @@ -112,6 +112,24 @@ $('.coltxt').each(function() {
});
});


Storage.prototype.setObj = function(key, obj) {
return this.setItem(key, JSON.stringify(obj))
}
Storage.prototype.getObj = function(key, default_val) {
var JSONparce = JSON.parse(this.getItem(key));
return typeof default_val !== 'undefined' ? (JSONparce == null ? default_val : JSONparce) : JSONparce;
}

function getSearchHistory(){
return localStorage.getObj('_searches',[]);
};

var availableHistory = getSearchHistory();
$('#combobox').empty();
availableHistory.map(function(value){$(new Option(value)).appendTo($('#combobox'));});


$('#search_part').selectmenu({change: function() { $('#search_text').focus(); }, width: 120});
$('#search_mode').selectmenu({change: function() { $('#search_text').focus(); }, width: 140});
$('#search_range').selectmenu({change: function() { $('#search_text').focus(); }, width: 180});
Expand Down Expand Up @@ -297,6 +315,18 @@ $('#search').click(function(event) {
var html = $('#search_text').val().trim(); /* may contain html tags */
var text = $('<div/>').html(html).text(); /* strip html tags, if any */
if (!text) return;
var availableHistory = getSearchHistory();
if (!availableHistory.includes(text)) {
availableHistory.unshift(text);
availableHistory = availableHistory.slice(0, 40); //Ограничиваю 40-ка последними значениями
} else {
var itemIndex = availableHistory.indexOf(text);
availableHistory.unshift(availableHistory.splice(itemIndex, 1)[0]);
}
localStorage.setObj('_searches',availableHistory);
availableHistory = getSearchHistory();
$('#combobox').empty();
availableHistory.map(function(value){$(new Option(value)).appendTo($('#combobox'));});
var mod_idx = $('#' + active_column + 'mod').val();
var srt = /(\d{1,3}):(\d{1,2}).?(\d{1,3})?/; /* SRT ref 'Paper:Section.Paragraph' */
var ref = srt.exec(text);
Expand Down Expand Up @@ -419,9 +449,10 @@ $(document).keydown(function(event) {
});

function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
var value = '; ' + document.cookie;
var parts = value.split('; ' + name + '=');
if (parts.length == 2) return parts.pop().split(';').shift();
return "";
}

function toggle_active_column(col) {
Expand Down Expand Up @@ -482,4 +513,105 @@ function ContentLoaded() {
}
}

$.widget('custom.combobox', {
_create: function() {
this.wrapper = $('<span>')
.addClass('custom-combobox')
.insertAfter(this.element);

this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
},

_createAutocomplete: function() {
var selected = this.element.children(':selected'),
value = selected.val() ? selected.text() : '';

this.input = $('<input>')
.appendTo(this.wrapper)
.val(value)
.attr('title','')
.attr('id','search_text')
.attr('placeholder',INPUT_SEARCH_STRING)
//.addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
.autocomplete({
delay: 0,
minLength: 0,
source: $.proxy(this,'_source')
})
.tooltip({
classes: {
'ui-tooltip': 'ui-state-highlight'
}
});

this._on(this.input, {
autocompleteselect: function(event,ui) {
ui.item.option.selected = true;
this._trigger('select',event, {
item: ui.item.option
});
},

});
},

_createShowAllButton: function() {
var input = this.input,
wasOpen = false;

$('<a>')
.attr('tabIndex', -1 )
.attr('title','Show All Items')
.tooltip()
.appendTo(this.wrapper)
.button({
icons: {
primary: 'ui-icon-triangle-1-s'
},
text: false
})
.removeClass('ui-corner-all')
.addClass('custom-combobox-toggle ui-corner-right')
.on('mousedown', function() {
wasOpen = input.autocomplete('widget').is(':visible');
})
.on('click', function() {
input.trigger('focus');

// Close if already visible
if (wasOpen) {
return;
}

// Pass empty string as value to search for, displaying all results
input.autocomplete('search','');
});
},

_source: function(request,response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term),'i');
response(this.element.children('option').map(function() {
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text)) )
return {
label: text,
value: text,
option: this
};
}) );
},

_destroy: function() {
this.wrapper.remove();
this.element.show();
}
});

$('#combobox').combobox();
$('#toggle').on('click', function() {
$('combobox').toggle();
});

setTimeout(ContentLoaded,1500);

0 comments on commit 595a338

Please sign in to comment.