forked from 0x2620/pandora
post JSON messages, relay theme change to same-domain iframe
This commit is contained in:
parent
699f0b64a5
commit
ebdc2b7057
3 changed files with 28 additions and 13 deletions
|
@ -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();
|
||||
|
|
|
@ -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')) {
|
||||
|
|
|
@ -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 = $('<iframe>')
|
||||
.attr({
|
||||
height: '100%',
|
||||
id: 'embed',
|
||||
frameborder: 0,
|
||||
src: '',
|
||||
width: '100%',
|
||||
|
@ -374,10 +377,9 @@ pandora.ui.textEmbed = function(url) {
|
|||
&& parsed.url.protocol == parsed.src.protocol
|
||||
&& parsed.url.hostname == parsed.src.hostname
|
||||
) {
|
||||
$iframe[0].contentWindow.postMessage(
|
||||
parsed.url.pathname + parsed.url.search + parsed.url.hash,
|
||||
'*'
|
||||
);
|
||||
$iframe[0].contentWindow.postMessage(JSON.stringify({
|
||||
url: parsed.url.pathname + parsed.url.search + parsed.url.hash
|
||||
}), '*');
|
||||
} else {
|
||||
$iframe.attr({src: url});
|
||||
}
|
||||
|
@ -390,8 +392,6 @@ pandora.ui.textEmbed = function(url) {
|
|||
return that;
|
||||
};
|
||||
|
||||
that.update(url);
|
||||
|
||||
return that;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue