2013-04-27 06:05:33 -07:00
|
|
|
|
(function ($, document, window, clearTimeout, setTimeout) {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
var searchHintTimeout;
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
function clearSearchHintTimeout() {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
if (searchHintTimeout) {
|
|
|
|
|
|
|
|
|
|
clearTimeout(searchHintTimeout);
|
|
|
|
|
searchHintTimeout = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
function updateSearchHints(page, searchTerm) {
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
|
|
|
|
if (!searchTerm) {
|
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
$('#searchHints', page).empty();
|
2013-04-27 06:05:33 -07:00
|
|
|
|
clearSearchHintTimeout();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearSearchHintTimeout();
|
|
|
|
|
|
|
|
|
|
searchHintTimeout = setTimeout(function () {
|
|
|
|
|
|
|
|
|
|
requestSearchHints(page, searchTerm);
|
|
|
|
|
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
function requestSearchHints(page, searchTerm) {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
var currentTimeout = searchHintTimeout;
|
|
|
|
|
|
2013-04-28 13:23:37 -07:00
|
|
|
|
ApiClient.getSearchHints({ userId: Dashboard.getCurrentUserId(), searchTerm: searchTerm, limit: 10 }).done(function (result) {
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
|
|
|
|
if (currentTimeout != searchHintTimeout) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
renderSearchHintResult(page, result.SearchHints);
|
2013-04-26 13:53:54 -07:00
|
|
|
|
});
|
2013-04-27 06:05:33 -07:00
|
|
|
|
}
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
function preg_quote(str, delimiter) {
|
|
|
|
|
// http://kevin.vanzonneveld.net
|
|
|
|
|
// + original by: booeyOH
|
|
|
|
|
// + improved by: Ates Goral (http://magnetiq.com)
|
|
|
|
|
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
|
|
|
|
|
// + bugfixed by: Onno Marsman
|
|
|
|
|
// + improved by: Brett Zamir (http://brett-zamir.me)
|
|
|
|
|
// * example 1: preg_quote("$40");
|
|
|
|
|
// * returns 1: '\$40'
|
|
|
|
|
// * example 2: preg_quote("*RRRING* Hello?");
|
|
|
|
|
// * returns 2: '\*RRRING\* Hello\?'
|
|
|
|
|
// * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:");
|
|
|
|
|
// * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:'
|
|
|
|
|
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
|
|
|
|
|
}
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
function getHintDisplayName(data, term) {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
var regexp = new RegExp("(" + preg_quote(term) + ")", 'gi');
|
|
|
|
|
|
|
|
|
|
return data.replace(regexp, "<b>$1</b>");
|
2013-04-26 13:53:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 23:34:50 -07:00
|
|
|
|
function getAdditionalTextLines(hint) {
|
|
|
|
|
|
|
|
|
|
if (hint.Type == "Audio") {
|
|
|
|
|
|
|
|
|
|
return [[hint.AlbumArtist, hint.Album].join(" - ")];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicAlbum") {
|
|
|
|
|
|
|
|
|
|
return [hint.AlbumArtist];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicArtist") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelArtist')];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Movie") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelMovie')];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicVideo") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelMusicVideo')];
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Episode") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelEpisode')];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Series") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelSeries')];
|
|
|
|
|
}
|
2015-01-25 12:13:04 -07:00
|
|
|
|
else if (hint.Type == "BoxSet") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelCollection')];
|
|
|
|
|
}
|
2015-01-24 23:34:50 -07:00
|
|
|
|
|
|
|
|
|
return [hint.Type];
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
function getSearchHintHtml(hint) {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
var html = '';
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<a class="searchHint" href="' + LibraryBrowser.getHref(hint, null, '') + '">';
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
|
|
|
|
var imgUrl;
|
|
|
|
|
|
|
|
|
|
if (hint.PrimaryImageTag) {
|
|
|
|
|
|
|
|
|
|
hint.ImageTags = { Primary: hint.PrimaryImageTag };
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
|
|
|
|
imgUrl = ApiClient.getImageUrl(hint.ItemId, {
|
|
|
|
|
type: "Primary",
|
|
|
|
|
maxWidth: 150,
|
|
|
|
|
maxHeight: 150,
|
|
|
|
|
tag: hint.PrimaryImageTag
|
|
|
|
|
});
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.MediaType == "Game") {
|
|
|
|
|
|
2013-12-27 09:31:45 -07:00
|
|
|
|
imgUrl = "css/images/items/searchhintsv2/game.png";
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Episode" || hint.Type == "Season" || hint.Type == "Series") {
|
|
|
|
|
|
2013-12-27 09:31:45 -07:00
|
|
|
|
imgUrl = "css/images/items/searchhintsv2/tv.png";
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
|
else if (hint.Type == "Audio" || hint.Type == "MusicAlbum" || hint.Type == "MusicArtist") {
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
2013-12-27 09:31:45 -07:00
|
|
|
|
imgUrl = "css/images/items/searchhintsv2/music.png";
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Person") {
|
|
|
|
|
|
2013-12-27 09:31:45 -07:00
|
|
|
|
imgUrl = "css/images/items/searchhintsv2/person.png";
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
2013-12-27 09:31:45 -07:00
|
|
|
|
imgUrl = "css/images/items/searchhintsv2/film.png";
|
2013-04-27 06:05:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '<img class="searchHintImage" src="' + imgUrl + '" />';
|
|
|
|
|
|
|
|
|
|
html += '<div class="searchHintContent"><div class="searchHintContentInner">';
|
|
|
|
|
|
|
|
|
|
html += '<div class="searchHintName">' + getHintDisplayName(hint.Name, hint.MatchedTerm) + '</div>';
|
|
|
|
|
|
|
|
|
|
if (hint.Type == "Audio") {
|
|
|
|
|
|
|
|
|
|
html += '<div class="searchHintSecondaryText">' + [hint.AlbumArtist, hint.Album].join(" - ") + '</div>';
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicAlbum") {
|
|
|
|
|
|
|
|
|
|
html += '<div class="searchHintSecondaryText">' + hint.AlbumArtist + '</div>';
|
|
|
|
|
|
2013-12-07 08:52:38 -07:00
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicArtist") {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
html += '<div class="searchHintSecondaryText">' + Globalize.translate('LabelArtist') + '</div>';
|
2013-12-07 08:52:38 -07:00
|
|
|
|
|
2013-05-18 10:07:20 -07:00
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Movie") {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
html += '<div class="searchHintSecondaryText">' + Globalize.translate('LabelMovie') + '</div>';
|
2013-05-18 10:07:20 -07:00
|
|
|
|
|
2013-05-27 18:59:26 -07:00
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicVideo") {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
html += '<div class="searchHintSecondaryText">' + Globalize.translate('LabelMusicVideo') + '</div>';
|
2013-05-27 18:59:26 -07:00
|
|
|
|
|
2013-05-18 10:07:20 -07:00
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Episode") {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
html += '<div class="searchHintSecondaryText">' + Globalize.translate('LabelEpisode') + '</div>';
|
2013-05-18 10:07:20 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Series") {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
html += '<div class="searchHintSecondaryText">' + Globalize.translate('LabelSeries') + '</div>';
|
2013-05-18 10:07:20 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-10-01 08:16:38 -07:00
|
|
|
|
html += '<div class="searchHintSecondaryText">' + (hint.Type) + '</div>';
|
2013-04-27 06:05:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var text;
|
|
|
|
|
|
|
|
|
|
if (hint.EpisodeCount) {
|
|
|
|
|
|
|
|
|
|
text = hint.EpisodeCount == 1 ? "1 Episode" : hint.EpisodeCount + " Episodes";
|
|
|
|
|
|
|
|
|
|
html += '<div class="searchHintSecondaryText">' + text + '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (hint.SongCount) {
|
|
|
|
|
|
|
|
|
|
text = hint.SongCount == 1 ? "1 Song" : hint.SongCount + " Songs";
|
|
|
|
|
|
|
|
|
|
html += '<div class="searchHintSecondaryText">' + text + '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 10:12:23 -07:00
|
|
|
|
else if (hint.ProductionYear && hint.MediaType != "Audio" && hint.Type != "Episode") {
|
|
|
|
|
html += '<div class="searchHintSecondaryText">' + hint.ProductionYear + '</div>';
|
|
|
|
|
}
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
else if (hint.RunTimeTicks) {
|
2013-06-07 10:29:33 -07:00
|
|
|
|
html += '<div class="searchHintSecondaryText">' + Dashboard.getDisplayTime(hint.RunTimeTicks) + '</div>';
|
2013-04-27 06:05:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '</div></div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
html += '</a>';
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderSearchHintResult(page, hints) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = hints.length; i < length; i++) {
|
|
|
|
|
html += getSearchHintHtml(hints[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#searchHints', page).html(html);
|
2013-04-26 13:53:54 -07:00
|
|
|
|
}
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
function getSearchPanel(page) {
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
var panel = $('#searchPanel', page);
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
if (!panel.length) {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
var html = '';
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
html += '<div data-role="panel" id="searchPanel" class="searchPanel" data-position="right" data-display="overlay" data-position-fixed="true" data-theme="b">';
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
html += '<h3>';
|
2014-05-30 12:23:56 -07:00
|
|
|
|
html += Globalize.translate('HeaderSearch');
|
2013-12-27 09:18:42 -07:00
|
|
|
|
html += '</h3>';
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
html += '<input id="txtSearch" class="txtSearch" type="search" data-theme="a" />';
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
html += '<div id="searchHints" class="searchHints"></div>';
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
html += '</div>';
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
$(page).append(html);
|
2013-04-27 06:05:33 -07:00
|
|
|
|
|
2014-11-09 21:20:11 -07:00
|
|
|
|
panel = $('#searchPanel', page).panel({}).trigger('create');
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
$('#txtSearch', panel).on("keyup", function (e) {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
// Down
|
|
|
|
|
if (e.keyCode == 40) {
|
|
|
|
|
|
|
|
|
|
var first = $('.searchHint', panel)[0];
|
|
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
|
first.focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).on("keyup", function (e) {
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
if (e.keyCode != 40) {
|
|
|
|
|
var value = this.value;
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-12-27 09:18:42 -07:00
|
|
|
|
updateSearchHints(panel, value);
|
|
|
|
|
}
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
|
|
|
|
});
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2013-12-27 10:12:23 -07:00
|
|
|
|
$('#searchHints', page).on("keydown", '.searchHint', function (e) {
|
2013-05-21 14:13:57 -07:00
|
|
|
|
|
|
|
|
|
// Down
|
|
|
|
|
if (e.keyCode == 40) {
|
|
|
|
|
|
|
|
|
|
var next = $(this).next()[0];
|
|
|
|
|
|
|
|
|
|
if (next) {
|
|
|
|
|
next.focus();
|
|
|
|
|
}
|
2013-05-21 20:42:25 -07:00
|
|
|
|
return false;
|
2013-05-21 14:13:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Up
|
|
|
|
|
if (e.keyCode == 38) {
|
|
|
|
|
|
|
|
|
|
var prev = $(this).prev()[0];
|
|
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
|
prev.focus();
|
|
|
|
|
} else {
|
2013-12-27 10:12:23 -07:00
|
|
|
|
$('#txtSearch', page)[0].focus();
|
2013-05-21 14:13:57 -07:00
|
|
|
|
}
|
2013-05-21 20:42:25 -07:00
|
|
|
|
return false;
|
2013-05-21 14:13:57 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-12-27 10:12:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return panel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function search() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.showSearchPanel = function (page) {
|
|
|
|
|
|
|
|
|
|
var panel = getSearchPanel(page);
|
2013-05-21 14:13:57 -07:00
|
|
|
|
|
2013-12-27 10:12:23 -07:00
|
|
|
|
$(panel).panel('toggle');
|
2014-03-02 22:46:04 -07:00
|
|
|
|
|
|
|
|
|
$('#txtSearch').focus();
|
2013-04-26 13:53:54 -07:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
window.Search = new search();
|
2013-04-28 10:21:56 -07:00
|
|
|
|
|
2015-01-21 12:21:19 -07:00
|
|
|
|
function renderSearchResultsInOverlay(elem, hints) {
|
|
|
|
|
|
|
|
|
|
// Massage the objects to look like regular items
|
|
|
|
|
hints = hints.map(function (i) {
|
|
|
|
|
|
|
|
|
|
i.Id = i.ItemId;
|
|
|
|
|
i.ImageTags = {};
|
|
|
|
|
i.UserData = {};
|
|
|
|
|
|
|
|
|
|
if (i.PrimaryImageTag) {
|
|
|
|
|
i.ImageTags.Primary = i.PrimaryImageTag;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: hints,
|
|
|
|
|
shape: "square",
|
2015-01-22 23:15:15 -07:00
|
|
|
|
lazy: true,
|
2015-01-21 12:21:19 -07:00
|
|
|
|
overlayText: false,
|
2015-01-24 12:03:55 -07:00
|
|
|
|
showTitle: true,
|
2015-01-24 23:34:50 -07:00
|
|
|
|
coverImage: true,
|
2015-01-26 23:50:40 -07:00
|
|
|
|
centerImage: true,
|
2015-01-24 23:34:50 -07:00
|
|
|
|
textLines: getAdditionalTextLines
|
2015-01-21 12:21:19 -07:00
|
|
|
|
});
|
2015-01-22 23:15:15 -07:00
|
|
|
|
$('.itemsContainer', elem).html(html).lazyChildren();
|
2015-01-21 12:21:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function requestSearchHintsForOverlay(elem, searchTerm) {
|
|
|
|
|
|
|
|
|
|
var currentTimeout = searchHintTimeout;
|
|
|
|
|
|
|
|
|
|
ApiClient.getSearchHints({ userId: Dashboard.getCurrentUserId(), searchTerm: searchTerm, limit: 30 }).done(function (result) {
|
|
|
|
|
|
|
|
|
|
if (currentTimeout != searchHintTimeout) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderSearchResultsInOverlay(elem, result.SearchHints);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateSearchOverlay(elem, searchTerm) {
|
|
|
|
|
|
|
|
|
|
if (!searchTerm) {
|
|
|
|
|
|
|
|
|
|
$('.itemsContainer', elem).empty();
|
|
|
|
|
clearSearchHintTimeout();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearSearchHintTimeout();
|
|
|
|
|
|
|
|
|
|
searchHintTimeout = setTimeout(function () {
|
|
|
|
|
|
|
|
|
|
requestSearchHintsForOverlay(elem, searchTerm);
|
|
|
|
|
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSearchOverlay(createIfNeeded) {
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
|
|
|
|
var elem = $('.searchResultsOverlay');
|
|
|
|
|
|
2015-01-21 12:21:19 -07:00
|
|
|
|
if (createIfNeeded && !elem.length) {
|
2015-01-22 23:15:15 -07:00
|
|
|
|
|
2015-01-23 21:50:45 -07:00
|
|
|
|
var html = '<div class="searchResultsOverlay ui-page-theme-b">';
|
2015-01-22 23:15:15 -07:00
|
|
|
|
|
|
|
|
|
html += '<div class="searchResultsContainer"><div class="itemsContainer"></div></div></div>';
|
|
|
|
|
|
|
|
|
|
elem = $(html).appendTo(document.body).hide().trigger('create');
|
|
|
|
|
|
|
|
|
|
elem.createCardMenus();
|
2015-01-20 23:26:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onHeaderSearchChange(val) {
|
|
|
|
|
|
|
|
|
|
if (val) {
|
2015-01-23 21:50:45 -07:00
|
|
|
|
$('.btnCloseSearch').show();
|
2015-01-21 12:21:19 -07:00
|
|
|
|
updateSearchOverlay(getSearchOverlay(true).fadeIn('fast'), val);
|
2015-01-26 23:50:40 -07:00
|
|
|
|
$(document.body).addClass('bodyWithPopupOpen');
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2015-01-23 21:50:45 -07:00
|
|
|
|
$('.btnCloseSearch').hide();
|
2015-01-21 12:21:19 -07:00
|
|
|
|
updateSearchOverlay(getSearchOverlay(false).fadeOut('fast'), val);
|
2015-01-26 23:50:40 -07:00
|
|
|
|
$(document.body).removeClass('bodyWithPopupOpen');
|
2015-01-20 23:26:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 12:21:19 -07:00
|
|
|
|
function bindSearchEvents() {
|
2013-04-27 07:00:22 -07:00
|
|
|
|
|
2015-01-21 12:21:19 -07:00
|
|
|
|
$('.headerSearchInput').on("keyup", function (e) {
|
2013-04-27 07:00:22 -07:00
|
|
|
|
|
2015-01-21 12:21:19 -07:00
|
|
|
|
// Down key
|
|
|
|
|
if (e.keyCode == 40) {
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2015-01-22 09:41:34 -07:00
|
|
|
|
//var first = $('.card', panel)[0];
|
2015-01-21 12:21:19 -07:00
|
|
|
|
|
|
|
|
|
//if (first) {
|
|
|
|
|
// first.focus();
|
|
|
|
|
//}
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2015-01-21 12:21:19 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
} else {
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
|
|
|
|
onHeaderSearchChange(this.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).on("search", function (e) {
|
|
|
|
|
|
|
|
|
|
if (!this.value) {
|
|
|
|
|
|
|
|
|
|
onHeaderSearchChange('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2015-01-23 21:50:45 -07:00
|
|
|
|
|
2015-01-24 12:03:55 -07:00
|
|
|
|
$('.btnCloseSearch').on('click', closeSearchOverlay);
|
2015-02-14 12:36:40 -07:00
|
|
|
|
|
|
|
|
|
$('.viewMenuSearchForm').on('submit', function () {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2015-01-24 12:03:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeSearchOverlay() {
|
|
|
|
|
$('.headerSearchInput').val('');
|
|
|
|
|
onHeaderSearchChange('');
|
2015-01-21 12:21:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('pagehide', ".libraryPage", function () {
|
|
|
|
|
|
|
|
|
|
$('#txtSearch', this).val('');
|
|
|
|
|
$('#searchHints', this).empty();
|
|
|
|
|
|
2015-01-24 12:03:55 -07:00
|
|
|
|
}).on('pagecontainerbeforehide', closeSearchOverlay);
|
2015-01-21 12:21:19 -07:00
|
|
|
|
|
|
|
|
|
$(document).on('headercreated', function () {
|
2015-01-20 23:26:16 -07:00
|
|
|
|
|
2015-01-21 12:21:19 -07:00
|
|
|
|
bindSearchEvents();
|
2015-01-20 23:26:16 -07:00
|
|
|
|
});
|
2013-04-26 13:53:54 -07:00
|
|
|
|
|
2013-04-27 06:05:33 -07:00
|
|
|
|
})(jQuery, document, window, clearTimeout, setTimeout);
|