feat: prima versione del plugin, blocco e shortcode con iframe stampato lato server
This commit is contained in:
commit
5c73bbc2b8
20 changed files with 1562 additions and 0 deletions
44
assets/js/resize.js
Normal file
44
assets/js/resize.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Keeps the widget as tall as its content.
|
||||
*
|
||||
* The framed page posts its height whenever it changes; we accept the message
|
||||
* only when it comes from the Piazza in Festa origin and from a window that is
|
||||
* one of our own iframes, then set the height. Nothing else leaves or enters
|
||||
* the page.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var cfg = window.pinfestaCfg || {};
|
||||
var origin = cfg.origin || '';
|
||||
|
||||
if (!origin) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('message', function (event) {
|
||||
if (event.origin !== origin) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = event.data;
|
||||
|
||||
if (!data || data.tipo !== 'piazzainfesta:altezza') {
|
||||
return;
|
||||
}
|
||||
|
||||
var altezza = parseInt(data.altezza, 10);
|
||||
|
||||
if (!altezza || altezza < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var frames = document.querySelectorAll('iframe.pinfesta-embed');
|
||||
|
||||
for (var i = 0; i < frames.length; i++) {
|
||||
if (frames[i].contentWindow === event.source) {
|
||||
frames[i].style.height = altezza + 2 + 'px';
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue