From 944411509bc104e7def3ca0476f163ad794a5b67 Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 11 Jul 2013 18:03:51 +0000 Subject: [PATCH] add pandora.getPart method --- static/js/pandora/utils.js | 55 +++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/static/js/pandora/utils.js b/static/js/pandora/utils.js index 12119ad3..3d06c943 100644 --- a/static/js/pandora/utils.js +++ b/static/js/pandora/utils.js @@ -982,10 +982,63 @@ pandora.getPageTitle = function(stateOrURL) { : null; }; +pandora.getPart = function(state, str, callback) { + if (state.page == 'api') { + pandora.api.api(function(result) { + if (Ox.contains(Object.keys(result.data.actions), str)) { + state.part = str; + } + callback(); + }) + } else if (state.page == 'faq') { + // ... + callback(); + } else if (state.page == 'help') { + if (Ox.getObjectById(pandora.site.help, str)) { + state.part = str; + } + callback(); + } else if (state.page == 'news') { + pandora.api.getNews(function(result) { + if (Ox.getObjectById(result.data.items, str)) { + state.part = str; + } else if (result.data.items.length) { + state.part = result.data.items[0].id; + } + callback(); + }); + } else if (state.page == 'tv') { + var split = str.replace(/%20/g, ' ').split(':'), user, name; + if (split.length >= 2) { + user = split.unshift(); + name = split.join(':'); + pandora.api.findLists({ + keys: ['name', 'user'], + query: { + conditions: [ + {key: 'user', operator: '==', value: user}, + {key: 'name', operator: '==', value: name} + ], + operator: '&' + } + }, function(result) { + if (result.data.items.length) { + state.part = str; + } + callback(); + }); + } else { + callback(); + } + } else { + callback(); + } +}; + pandora.getSortKeyData = function(key) { return Ox.getObjectById(pandora.site.itemKeys, key) || Ox.getObjectById(pandora.site.clipKeys, key); -} +}; pandora.getSortKeys = function() { return pandora.site.itemKeys.filter(function(key) {