(function ($, document, window, clearTimeout, setTimeout) { var searchHintTimeout; function clearSearchHintTimeout() { if (searchHintTimeout) { clearTimeout(searchHintTimeout); searchHintTimeout = null; } } 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')]; } else if (hint.Type == "BoxSet") { return [Globalize.translate('LabelCollection')]; } else if (hint.ChannelName) { return [hint.ChannelName]; } return [hint.Type]; } function search() { var self = this; self.showSearchPanel = function () { showSearchMenu(); }; } window.Search = new search(); 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: "auto", lazy: true, overlayText: false, showTitle: true, centerImage: true, centerText: true, textLines: getAdditionalTextLines }); var itemsContainer = elem.querySelector('.itemsContainer'); itemsContainer.innerHTML = html; ImageLoader.lazyChildren(itemsContainer); } function requestSearchHintsForOverlay(elem, searchTerm) { var currentTimeout = searchHintTimeout; Dashboard.showLoadingMsg(); ApiClient.getSearchHints({ userId: Dashboard.getCurrentUserId(), searchTerm: searchTerm, limit: 30 }).done(function (result) { if (currentTimeout == searchHintTimeout) { renderSearchResultsInOverlay(elem, result.SearchHints); } Dashboard.hideLoadingMsg(); }).fail(function () { Dashboard.hideLoadingMsg(); }); } function updateSearchOverlay(elem, searchTerm) { if (!searchTerm) { $('.itemsContainer', elem).empty(); clearSearchHintTimeout(); return; } clearSearchHintTimeout(); searchHintTimeout = setTimeout(function () { requestSearchHintsForOverlay(elem, searchTerm); }, 300); } function getSearchOverlay(createIfNeeded) { var elem = document.querySelector('.searchResultsOverlay'); if (createIfNeeded && !elem) { var html = '