From ebdc2b705796b8d6658c6745a0cf6b52043a668b Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 22 Feb 2013 09:46:58 +0530 Subject: [PATCH] post JSON messages, relay theme change to same-domain iframe --- static/js/pandora.js | 13 +++++++++---- static/js/pandora/mainMenu.js | 10 ++++++++++ static/js/pandora/textPanel.js | 18 +++++++++--------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/static/js/pandora.js b/static/js/pandora.js index 2eb500dac..9bed338ee 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -315,10 +315,15 @@ appPanel if (isEmbed) { pandora.$ui.embedPanel = pandora.ui.embedPanel().display(); window.addEventListener('message', function(e) { - var url = e.data; - if (pandora.isEmbedURL(url)) { - pandora.URL.push(url); - } + var data; + try { + data = JSON.parse(e.data); + if (Ox.contains(pandora.site.themes, data.theme)) { + Ox.Theme(data.theme); + } else if (pandora.isEmbedURL(data.url)) { + pandora.URL.push(data.url); + } + } catch() {} }); } else { pandora.$ui.appPanel = pandora.ui.appPanel().display(); diff --git a/static/js/pandora/mainMenu.js b/static/js/pandora/mainMenu.js index ea4dd86fa..f83b40bdb 100644 --- a/static/js/pandora/mainMenu.js +++ b/static/js/pandora/mainMenu.js @@ -227,8 +227,18 @@ pandora.ui.mainMenu = function() { filters[index].sort[0].operator = operator; pandora.UI.set({filters: filters}); } else if (data.id == 'settheme') { + var iframe, src; Ox.Theme(value); pandora.UI.set('theme', value); + iframe = $('#embed')[0]; + if (iframe) { + src = $(iframe).attr('src'); + if (src && Ox.parseURL(src).hostname == document.location.hostname) { + iframe.contentWindow.postMessage(JSON.stringify({ + {theme: value} + }), '*'); + } + } } else if (data.id == 'showsiteposters') { pandora.UI.set('showSitePosters', data.checked) } else if (Ox.startsWith(data.id, 'sortfilter')) { diff --git a/static/js/pandora/textPanel.js b/static/js/pandora/textPanel.js index 89f8a1d55..65a7b33e3 100644 --- a/static/js/pandora/textPanel.js +++ b/static/js/pandora/textPanel.js @@ -21,7 +21,7 @@ pandora.ui.textPanel = function() { embedURLs = text.type == 'html' ? getEmbedURLs(text.text) : []; - selected = embedURLs.length ? 0 : -1; + selected = -1; var $toolbar = Ox.Bar({size: 24}), @@ -104,7 +104,7 @@ pandora.ui.textPanel = function() { : pandora.ui.textPDF(text) }, { - element: pandora.$ui.textEmbed = pandora.ui.textEmbed(embedURLs[selected]), + element: pandora.$ui.textEmbed = pandora.ui.textEmbed(), size: pandora.user.ui.embedSize, resizable: true, resize: [192, 256, 320, 384, 448, 512] @@ -157,6 +157,8 @@ pandora.ui.textPanel = function() { that.replaceElement(1, $panel); that.replaceElement(2, $statusbar); + embedURLs.length && that.selectEmbed(0); + }); function getEmbedURLs(text) { @@ -317,7 +319,7 @@ pandora.ui.textPDF = function(text) { }; -pandora.ui.textEmbed = function(url) { +pandora.ui.textEmbed = function() { var that = Ox.Element() .bindEvent({ @@ -342,6 +344,7 @@ pandora.ui.textEmbed = function(url) { $iframe = $('