From 41a15fa8b3ad700b2f69fe9f8047abc30fe6ead1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 18 Aug 2015 11:52:48 -0400 Subject: [PATCH] split live tv scripts --- dashboard-ui/livetv.html | 14 +++--- dashboard-ui/scripts/livetvchannels.js | 58 +++++++--------------- dashboard-ui/scripts/livetvguide.js | 46 +++++++---------- dashboard-ui/scripts/livetvrecordings.js | 20 ++------ dashboard-ui/scripts/livetvseriestimers.js | 53 ++------------------ dashboard-ui/scripts/livetvsuggested.js | 51 +++++++++++++++++-- dashboard-ui/scripts/livetvtimers.js | 19 ++----- 7 files changed, 106 insertions(+), 155 deletions(-) diff --git a/dashboard-ui/livetv.html b/dashboard-ui/livetv.html index 9c13bb2d81..308bc65067 100644 --- a/dashboard-ui/livetv.html +++ b/dashboard-ui/livetv.html @@ -4,7 +4,7 @@ Emby -
+
@@ -29,7 +29,7 @@
-
+

${HeaderWhatsOnTV}

@@ -59,7 +59,7 @@
-
+
@@ -82,7 +82,7 @@
-
+
@@ -91,7 +91,7 @@
-
+
-
+
-
+
diff --git a/dashboard-ui/scripts/livetvchannels.js b/dashboard-ui/scripts/livetvchannels.js index 99e0f16df5..e035074490 100644 --- a/dashboard-ui/scripts/livetvchannels.js +++ b/dashboard-ui/scripts/livetvchannels.js @@ -14,15 +14,6 @@ }); } - function showLoadingMessage(page) { - - Dashboard.showLoadingMsg(); - } - - function hideLoadingMessage(page) { - Dashboard.hideLoadingMsg(); - } - function renderChannels(page, viewPanel, result) { $('.listTopPaging', page).html(LibraryBrowser.getQueryPagingHtml({ @@ -59,13 +50,13 @@ function reloadItems(page, viewPanel) { - showLoadingMessage(page); + Dashboard.showLoadingMsg(); ApiClient.getLiveTvChannels(query).done(function (result) { renderChannels(page, viewPanel, result); - hideLoadingMessage(page); + Dashboard.hideLoadingMsg(); LibraryBrowser.setLastRefreshed(page); }); @@ -79,17 +70,16 @@ $('#selectPageSize', page).val(query.Limit).selectmenu('refresh'); } - $(document).on('pageinitdepends', "#liveTvSuggestedPage", function () { + window.LiveTvPage.initChannelsTab = function (page, tabContent) { - var page = this.querySelector('.channelsTabContent'); - var viewPanel = this.querySelector('.channelViewPanel'); + var viewPanel = page.querySelector('.channelViewPanel'); $('#chkFavorite', viewPanel).on('change', function () { query.StartIndex = 0; query.IsFavorite = this.checked ? true : null; - reloadItems(page, viewPanel); + reloadItems(tabContent, viewPanel); }); @@ -98,7 +88,7 @@ query.StartIndex = 0; query.IsLiked = this.checked ? true : null; - reloadItems(page, viewPanel); + reloadItems(tabContent, viewPanel); }); $('#chkDislikes', viewPanel).on('change', function () { @@ -106,37 +96,27 @@ query.StartIndex = 0; query.IsDisliked = this.checked ? true : null; - reloadItems(page, viewPanel); + reloadItems(tabContent, viewPanel); }); $('#selectPageSize', viewPanel).on('change', function () { query.Limit = parseInt(this.value); query.StartIndex = 0; - reloadItems(page, viewPanel); + reloadItems(tabContent, viewPanel); }); + }; - }); + window.LiveTvPage.renderChannelsTab = function (page, tabContent) { - $(document).on('pageinitdepends', "#liveTvSuggestedPage", function () { + var viewPanel = page.querySelector('.channelViewPanel'); - var page = this; - - $(page.querySelector('neon-animated-pages')).on('tabchange', function () { - - if (parseInt(this.selected) == 2) { - var tabContent = page.querySelector('.channelsTabContent'); - var viewPanel = page.querySelector('.channelViewPanel'); - - if (LibraryBrowser.needsRefresh(tabContent)) { - query.UserId = Dashboard.getCurrentUserId(); - LibraryBrowser.loadSavedQueryValues('movies', query); - query.Limit = query.Limit || LibraryBrowser.getDefaultPageSize(); - reloadItems(tabContent, viewPanel); - updateFilterControls(viewPanel); - } - } - }); - - }); + if (LibraryBrowser.needsRefresh(tabContent)) { + query.UserId = Dashboard.getCurrentUserId(); + LibraryBrowser.loadSavedQueryValues('movies', query); + query.Limit = query.Limit || LibraryBrowser.getDefaultPageSize(); + reloadItems(tabContent, viewPanel); + updateFilterControls(viewPanel); + } + }; })(jQuery, document); \ No newline at end of file diff --git a/dashboard-ui/scripts/livetvguide.js b/dashboard-ui/scripts/livetvguide.js index 320cfd1e7c..49da90f908 100644 --- a/dashboard-ui/scripts/livetvguide.js +++ b/dashboard-ui/scripts/livetvguide.js @@ -446,24 +446,22 @@ }); } - $(document).on('pageinitdepends', "#liveTvSuggestedPage", function () { + window.LiveTvPage.initGuideTab = function (page, tabContent) { - var page = this.querySelector('.guideTabContent'); + Events.on(tabContent.querySelector('.programGrid'), 'scroll', function () { - Events.on(page.querySelector('.programGrid'), 'scroll', function () { - - onProgramGridScroll(page, this); + onProgramGridScroll(tabContent, this); }); if ($.browser.mobile) { - page.querySelector('.tvGuide').classList.add('mobileGuide'); + tabContent.querySelector('.tvGuide').classList.add('mobileGuide'); } else { - page.querySelector('.tvGuide').classList.remove('mobileGuide'); + tabContent.querySelector('.tvGuide').classList.remove('mobileGuide'); - Events.on(page.querySelector('.timeslotHeaders'), 'scroll', function () { + Events.on(tabContent.querySelector('.timeslotHeaders'), 'scroll', function () { - onTimeslotHeadersScroll(page, this); + onTimeslotHeadersScroll(tabContent, this); }); } @@ -471,36 +469,28 @@ requirejs(["thirdparty/headroom"], function () { // construct an instance of Headroom, passing the element - var headroom = new Headroom(page.querySelector('.tvGuideHeader')); + var headroom = new Headroom(tabContent.querySelector('.tvGuideHeader')); // initialise headroom.init(); }); } - $('.btnUnlockGuide', page).on('click', function () { + $('.btnUnlockGuide', tabContent).on('click', function () { - reloadPage(page); + reloadPage(tabContent); }); - $('.btnSelectDate', page).on('click', function () { + $('.btnSelectDate', tabContent).on('click', function () { - selectDate(page); + selectDate(tabContent); }); + }; - }).on('pageinitdepends', "#liveTvSuggestedPage", function () { + window.LiveTvPage.renderGuideTab = function (page, tabContent) { - var page = this; - - $(page.querySelector('neon-animated-pages')).on('tabchange', function () { - - if (parseInt(this.selected) == 1) { - var tabContent = page.querySelector('.guideTabContent'); - - if (LibraryBrowser.needsRefresh(tabContent)) { - reloadPage(tabContent); - } - } - }); - }); + if (LibraryBrowser.needsRefresh(tabContent)) { + reloadPage(tabContent); + } + }; })(jQuery, document); \ No newline at end of file diff --git a/dashboard-ui/scripts/livetvrecordings.js b/dashboard-ui/scripts/livetvrecordings.js index c2223b67e9..1c32c0e42c 100644 --- a/dashboard-ui/scripts/livetvrecordings.js +++ b/dashboard-ui/scripts/livetvrecordings.js @@ -101,21 +101,11 @@ }); } - $(document).on('pageinitdepends', "#liveTvSuggestedPage", function () { + window.LiveTvPage.renderRecordingsTab = function (page, tabContent) { - var page = this; - - $(page.querySelector('neon-animated-pages')).on('tabchange', function () { - - if (parseInt(this.selected) == 3) { - var tabContent = page.querySelector('.recordingsTabContent'); - - if (LibraryBrowser.needsRefresh(tabContent)) { - reload(tabContent); - } - } - }); - - }); + if (LibraryBrowser.needsRefresh(tabContent)) { + reload(tabContent); + } + }; })(jQuery, document); \ No newline at end of file diff --git a/dashboard-ui/scripts/livetvseriestimers.js b/dashboard-ui/scripts/livetvseriestimers.js index d921ca56f9..e9cf6b5033 100644 --- a/dashboard-ui/scripts/livetvseriestimers.js +++ b/dashboard-ui/scripts/livetvseriestimers.js @@ -110,54 +110,11 @@ }); } - function updateFilterControls(page) { + window.LiveTvPage.renderSeriesTimersTab = function (page, tabContent) { - // Reset form values using the last used query - $('.radioSortBy', page).each(function () { - - this.checked = (query.SortBy || '').toLowerCase() == this.getAttribute('data-sortby').toLowerCase(); - - }).checkboxradio('refresh'); - - $('.radioSortOrder', page).each(function () { - - this.checked = (query.SortOrder || '').toLowerCase() == this.getAttribute('data-sortorder').toLowerCase(); - - }).checkboxradio('refresh'); - } - - $(document).on('pageinitdepends', "#liveTvSuggestedPage", function () { - - var page = this; - - $(page.querySelector('neon-animated-pages')).on('tabchange', function () { - - if (parseInt(this.selected) == 5) { - var tabContent = page.querySelector('.seriesTimersTabContent'); - - if (LibraryBrowser.needsRefresh(tabContent)) { - reload(tabContent); - } - } - }); - - }).on('pageinitdepends', "#liveTvSuggestedPage", function () { - - var page = this.querySelector('.seriesTimersTabContent'); - - $('.radioSortBy', page).on('click', function () { - query.StartIndex = 0; - query.SortBy = this.getAttribute('data-sortby'); - reload(page); - }); - - $('.radioSortOrder', page).on('click', function () { - query.StartIndex = 0; - query.SortOrder = this.getAttribute('data-sortorder'); - reload(page); - }); - - updateFilterControls(this); - }); + if (LibraryBrowser.needsRefresh(tabContent)) { + reload(tabContent); + } + }; })(jQuery, document); \ No newline at end of file diff --git a/dashboard-ui/scripts/livetvsuggested.js b/dashboard-ui/scripts/livetvsuggested.js index 02bc414daf..5b55411bdd 100644 --- a/dashboard-ui/scripts/livetvsuggested.js +++ b/dashboard-ui/scripts/livetvsuggested.js @@ -121,9 +121,7 @@ }); } - function loadSuggestedTab(page) { - - var tabContent = page.querySelector('.suggestedTabContent'); + function renderSuggestedTab(page, tabContent) { if (LibraryBrowser.needsRefresh(tabContent)) { reload(tabContent); @@ -132,14 +130,55 @@ function loadTab(page, index) { + var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']'); + var depends = []; + var scope = 'LiveTvPage'; + var renderMethod = ''; + var initMethod = ''; + switch (index) { case 0: - loadSuggestedTab(page); + renderMethod = 'renderSuggestedTab'; + break; + case 1: + depends.push('scripts/registrationservices'); + depends.push('scripts/livetvguide'); + renderMethod = 'renderGuideTab'; + initMethod = 'initGuideTab'; + break; + case 2: + depends.push('scripts/livetvchannels'); + renderMethod = 'renderChannelsTab'; + initMethod = 'initChannelsTab'; + break; + case 3: + depends.push('scripts/livetvrecordings'); + renderMethod = 'renderRecordingsTab'; + break; + case 4: + depends.push('scripts/livetvtimers'); + renderMethod = 'renderTimersTab'; + break; + case 5: + depends.push('scripts/livetvseriestimers'); + renderMethod = 'renderSeriesTimersTab'; break; default: break; } + + require(depends, function () { + + if (initMethod && !tabContent.initComplete) { + + window[scope][initMethod](page, tabContent); + tabContent.initComplete = true; + } + + window[scope][renderMethod](page, tabContent); + + }); } $(document).on('pageinitdepends', "#liveTvSuggestedPage", function () { @@ -173,4 +212,8 @@ }); + window.LiveTvPage = { + renderSuggestedTab: renderSuggestedTab + }; + })(jQuery, document); \ No newline at end of file diff --git a/dashboard-ui/scripts/livetvtimers.js b/dashboard-ui/scripts/livetvtimers.js index f0654e7d0b..ef11e56f42 100644 --- a/dashboard-ui/scripts/livetvtimers.js +++ b/dashboard-ui/scripts/livetvtimers.js @@ -133,20 +133,11 @@ }); } - $(document).on('pageinitdepends', "#liveTvSuggestedPage", function () { + window.LiveTvPage.renderTimersTab = function (page, tabContent) { - var page = this; - - $(page.querySelector('neon-animated-pages')).on('tabchange', function () { - - if (parseInt(this.selected) == 4) { - var tabContent = page.querySelector('.timersTabContent'); - - if (LibraryBrowser.needsRefresh(tabContent)) { - reload(tabContent); - } - } - }); - }); + if (LibraryBrowser.needsRefresh(tabContent)) { + reload(tabContent); + } + }; })(jQuery, document); \ No newline at end of file