Tweak search on mobile, fixes #432

This commit is contained in:
Stéphane Goetz 2017-01-23 23:09:27 +01:00
parent f3a134cf84
commit f6237b7ddb
2 changed files with 47 additions and 18 deletions

View File

@ -5,6 +5,10 @@ Tipue Search is released under the MIT License
http://www.tipue.com/search http://www.tipue.com/search
*/ */
body.with-search {
overflow: hidden;
}
/* bootstrap overrides the search field so let's undo that */ /* bootstrap overrides the search field so let's undo that */
input[type="search"] { input[type="search"] {
-webkit-appearance: searchfield; -webkit-appearance: searchfield;
@ -28,8 +32,7 @@ input[type="search"]::-webkit-search-cancel-button {
z-index: 100; z-index: 100;
position:absolute; position:absolute;
top: 50px; top: 50px;
left: 50%; left: 0;
margin-left: -300px;
bottom: 0; bottom: 0;
overflow: auto; overflow: auto;
@ -73,6 +76,18 @@ input[type="search"]::-webkit-search-cancel-button {
color: #555; color: #555;
} }
.tipue_close {
border: 0 transparent solid;
background: none;
float: right;
font-size: 2em;
cursor: pointer;
padding: 0;
margin: 0;
line-height: .8em;
}
.tipue_search_content_title { .tipue_search_content_title {
font-weight:300; font-weight:300;
font-size:21px; font-size:21px;
@ -197,6 +212,14 @@ input[type="search"]::-webkit-search-cancel-button {
} }
} }
@media (min-width: 650px) {
#tipue_search_content {
width: 650px;
left: 50%;
margin-left: -325px;
}
}

View File

@ -8,6 +8,8 @@
(function ($) { (function ($) {
var originalTitle = document.title;
// Stop words (list from http://www.ranks.nl/stopwords) // Stop words (list from http://www.ranks.nl/stopwords)
var tipuesearch_stop_words = ["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can't", "cannot", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't", "down", "during", "each", "few", "for", "from", "further", "had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't", "it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't", "my", "myself", "no", "nor", "not", "of", "off", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same", "shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll", "we're", "we've", "were", "weren't", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "who's", "whom", "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves"]; var tipuesearch_stop_words = ["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can't", "cannot", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't", "down", "during", "each", "few", "for", "from", "further", "had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't", "it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't", "my", "myself", "no", "nor", "not", "of", "off", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same", "shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll", "we're", "we've", "were", "weren't", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "who's", "whom", "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves"];
@ -37,13 +39,20 @@
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null; return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
} }
function closeContainer(e) { function closeSearch() {
if (e.which == 27) { //escape document.title = originalTitle;
$(document).off("keyup", closeContainer);
$(document).off("keyup", keyUpHandler);
$("body").removeClass("with-search");
tipue_container.hide(); tipue_container.hide();
tipue_backdrop.hide(); tipue_backdrop.hide();
} }
function keyUpHandler(e) {
if (e.which == 27) { //escape
closeSearch();
}
} }
var tipue_container, tipue_backdrop; var tipue_container, tipue_backdrop;
@ -71,8 +80,6 @@
pages: [] pages: []
}; };
var tipuesearch_t_c = 0;
$.ajax( $.ajax(
{ {
dataType: "json", dataType: "json",
@ -99,17 +106,15 @@
function getTipueSearch(start, replace) { function getTipueSearch(start, replace) {
$('#tipue_search_content').hide();
$('#tipue_search_content').html('<div class="tipue_search_spinner"><div class="tipue_search_rect1"></div><div class="tipue_search_rect2"></div><div class="rect3"></div></div>'); $('#tipue_search_content').html('<div class="tipue_search_spinner"><div class="tipue_search_rect1"></div><div class="tipue_search_rect2"></div><div class="rect3"></div></div>');
$('#tipue_search_content').show();
var out = ''; var out = '<button class=tipue_close>&times;</button>';
var results = ''; var results = '';
var show_replace = false; var show_replace = false;
var show_stop = false; var show_stop = false;
var standard = true; var standard = true;
var c = 0; var c = 0;
found = []; var found = [];
var d = set.field.val().toLowerCase(); var d = set.field.val().toLowerCase();
d = $.trim(d); d = $.trim(d);
@ -277,10 +282,8 @@
} }
if (c != 0) { if (c != 0) {
if (set.showTitleCount && tipuesearch_t_c == 0) { if (set.showTitleCount) {
var title = document.title; document.title = '(' + c + ') ' + originalTitle;
document.title = '(' + c + ') ' + title;
tipuesearch_t_c++;
} }
if (show_replace == 1) { if (show_replace == 1) {
@ -403,10 +406,13 @@
document.body.appendChild(tipue_backdrop.get(0)); document.body.appendChild(tipue_backdrop.get(0));
} }
$("body").addClass("with-search").scrollTop(0);
tipue_backdrop.show(); tipue_backdrop.show();
tipue_container.scrollTop(0); tipue_container.scrollTop(0);
tipue_container.show().html(out); tipue_container.show().html(out);
tipue_container.find('.tipue_close').on('click', closeSearch);
$('#tipue_search_replaced').click( $('#tipue_search_replaced').click(
function () { function () {
getTipueSearch(0, false); getTipueSearch(0, false);
@ -422,7 +428,7 @@
tipue_container.scrollTop(0); tipue_container.scrollTop(0);
}); });
$(document).keyup(closeContainer); $(document).keyup(keyUpHandler);
} }
}; };