2013-04-27 09:05:33 -04:00
|
|
|
|
(function ($, document, window, clearTimeout, setTimeout) {
|
2013-04-26 16:53:54 -04:00
|
|
|
|
|
2013-04-27 09:05:33 -04:00
|
|
|
|
var searchHintTimeout;
|
2013-04-26 16:53:54 -04:00
|
|
|
|
|
2013-04-27 09:05:33 -04:00
|
|
|
|
function clearSearchHintTimeout() {
|
2013-04-26 16:53:54 -04:00
|
|
|
|
|
2013-04-27 09:05:33 -04:00
|
|
|
|
if (searchHintTimeout) {
|
|
|
|
|
|
|
|
|
|
clearTimeout(searchHintTimeout);
|
|
|
|
|
searchHintTimeout = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 01:34:50 -05: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 14:13:04 -05:00
|
|
|
|
else if (hint.Type == "BoxSet") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelCollection')];
|
|
|
|
|
}
|
2015-01-25 01:34:50 -05:00
|
|
|
|
|
|
|
|
|
return [hint.Type];
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 12:12:23 -05:00
|
|
|
|
function search() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.showSearchPanel = function (page) {
|
|
|
|
|
|
2015-05-14 01:42:55 -04:00
|
|
|
|
$('.viewMenuSearch').removeClass('hide').animate({ "left": "0px" }, "fast");
|
|
|
|
|
$('.headerSearchInput').focus();
|
2013-04-26 16:53:54 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
window.Search = new search();
|
2013-04-28 13:21:56 -04:00
|
|
|
|
|
2015-01-21 14:21:19 -05: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-23 01:15:15 -05:00
|
|
|
|
lazy: true,
|
2015-01-21 14:21:19 -05:00
|
|
|
|
overlayText: false,
|
2015-01-24 14:03:55 -05:00
|
|
|
|
showTitle: true,
|
2015-01-25 01:34:50 -05:00
|
|
|
|
coverImage: true,
|
2015-01-27 01:50:40 -05:00
|
|
|
|
centerImage: true,
|
2015-01-25 01:34:50 -05:00
|
|
|
|
textLines: getAdditionalTextLines
|
2015-01-21 14:21:19 -05:00
|
|
|
|
});
|
2015-01-23 01:15:15 -05:00
|
|
|
|
$('.itemsContainer', elem).html(html).lazyChildren();
|
2015-01-21 14:21:19 -05: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-21 01:26:16 -05:00
|
|
|
|
|
|
|
|
|
var elem = $('.searchResultsOverlay');
|
|
|
|
|
|
2015-01-21 14:21:19 -05:00
|
|
|
|
if (createIfNeeded && !elem.length) {
|
2015-01-23 01:15:15 -05:00
|
|
|
|
|
2015-01-23 23:50:45 -05:00
|
|
|
|
var html = '<div class="searchResultsOverlay ui-page-theme-b">';
|
2015-01-23 01:15:15 -05:00
|
|
|
|
|
|
|
|
|
html += '<div class="searchResultsContainer"><div class="itemsContainer"></div></div></div>';
|
|
|
|
|
|
|
|
|
|
elem = $(html).appendTo(document.body).hide().trigger('create');
|
|
|
|
|
|
|
|
|
|
elem.createCardMenus();
|
2015-01-21 01:26:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onHeaderSearchChange(val) {
|
|
|
|
|
|
|
|
|
|
if (val) {
|
2015-01-21 14:21:19 -05:00
|
|
|
|
updateSearchOverlay(getSearchOverlay(true).fadeIn('fast'), val);
|
2015-01-27 01:50:40 -05:00
|
|
|
|
$(document.body).addClass('bodyWithPopupOpen');
|
2015-01-21 01:26:16 -05:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2015-01-21 14:21:19 -05:00
|
|
|
|
updateSearchOverlay(getSearchOverlay(false).fadeOut('fast'), val);
|
2015-01-27 01:50:40 -05:00
|
|
|
|
$(document.body).removeClass('bodyWithPopupOpen');
|
2015-01-21 01:26:16 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 14:21:19 -05:00
|
|
|
|
function bindSearchEvents() {
|
2013-04-27 10:00:22 -04:00
|
|
|
|
|
2015-01-21 14:21:19 -05:00
|
|
|
|
$('.headerSearchInput').on("keyup", function (e) {
|
2013-04-27 10:00:22 -04:00
|
|
|
|
|
2015-01-21 14:21:19 -05:00
|
|
|
|
// Down key
|
|
|
|
|
if (e.keyCode == 40) {
|
2015-01-21 01:26:16 -05:00
|
|
|
|
|
2015-01-22 11:41:34 -05:00
|
|
|
|
//var first = $('.card', panel)[0];
|
2015-01-21 14:21:19 -05:00
|
|
|
|
|
|
|
|
|
//if (first) {
|
|
|
|
|
// first.focus();
|
|
|
|
|
//}
|
2015-01-21 01:26:16 -05:00
|
|
|
|
|
2015-01-21 14:21:19 -05:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
} else {
|
2015-01-21 01:26:16 -05:00
|
|
|
|
|
|
|
|
|
onHeaderSearchChange(this.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).on("search", function (e) {
|
|
|
|
|
|
|
|
|
|
if (!this.value) {
|
|
|
|
|
|
|
|
|
|
onHeaderSearchChange('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2015-01-23 23:50:45 -05:00
|
|
|
|
|
2015-01-24 14:03:55 -05:00
|
|
|
|
$('.btnCloseSearch').on('click', closeSearchOverlay);
|
2015-02-14 14:36:40 -05:00
|
|
|
|
|
|
|
|
|
$('.viewMenuSearchForm').on('submit', function () {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2015-01-24 14:03:55 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeSearchOverlay() {
|
|
|
|
|
$('.headerSearchInput').val('');
|
|
|
|
|
onHeaderSearchChange('');
|
2015-05-14 01:42:55 -04:00
|
|
|
|
$('.viewMenuSearch').addClass('hide');
|
2015-01-21 14:21:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('pagehide', ".libraryPage", function () {
|
|
|
|
|
|
|
|
|
|
$('#txtSearch', this).val('');
|
|
|
|
|
$('#searchHints', this).empty();
|
|
|
|
|
|
2015-01-24 14:03:55 -05:00
|
|
|
|
}).on('pagecontainerbeforehide', closeSearchOverlay);
|
2015-01-21 14:21:19 -05:00
|
|
|
|
|
|
|
|
|
$(document).on('headercreated', function () {
|
2015-01-21 01:26:16 -05:00
|
|
|
|
|
2015-01-21 14:21:19 -05:00
|
|
|
|
bindSearchEvents();
|
2015-01-21 01:26:16 -05:00
|
|
|
|
});
|
2013-04-26 16:53:54 -04:00
|
|
|
|
|
2013-04-27 09:05:33 -04:00
|
|
|
|
})(jQuery, document, window, clearTimeout, setTimeout);
|