(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')]; } return [hint.Type]; } function search() { var self = this; self.showSearchPanel = function () { var viewMenuSearch = $('.viewMenuSearch'); viewMenuSearch.removeClass('hide'); $('.headerSearchInput').focus(); }; } 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: "square", lazy: true, overlayText: false, showTitle: true, coverImage: true, centerImage: true, textLines: getAdditionalTextLines, cardLayout: true }); $('.itemsContainer', elem).html(html).lazyChildren(); } 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) { var elem = $('.searchResultsOverlay'); if (createIfNeeded && !elem.length) { var html = '