Skip to content

Commit

Permalink
Fix the Divi tab support
Browse files Browse the repository at this point in the history
  • Loading branch information
mheob committed Jul 26, 2019
1 parent 97cff54 commit 4fb6bde
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/src/class-ifdw-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function render_shortcode( $atts ) {

ob_start();

printf( '<div id="%s" class="include-fussball-de-widgets" data-version="' . esc_html( IFDW_VERSION ) . '\">\n', esc_html( $this->id ) );
printf( '<div id="%s" class="include-fussball-de-widgets" data-version="' . esc_html( IFDW_VERSION ) . "\">\n", esc_html( $this->id ) );
/* translators: %s: the description of the widget */
printf( esc_html__( "... the fussball.de widget with the description \"%s\" is currently loading ...\n", 'include-fussball-de-widgets' ), esc_html( $this->notice ) );
print ( "</div>\n" );
Expand Down
55 changes: 31 additions & 24 deletions app/src/fubade-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,39 @@ window.FussballdeWidgetAPI = () => {
}
};

window.addEventListener('message', eventHandler, false);
window.addEventListener(
'message',
evt => {
const currentIframe = document.querySelector('#' + evt.data.container + ' > iframe');

if ('setHeight' === evt.data.type) {
currentIframe.setAttribute('height', evt.data.value + 'px');
currentIframe.style.height = '';
}

if ('setWidth' === evt.data.type) {
if ('100%' !== currentIframe.getAttribute('width')) {
currentIframe.setAttribute('width', evt.data.value + 'px');
}

currentIframe.style.width = '';
}
},
false
);

// Divi tab support
if (document.body.classList.contains('et_divi_theme')) {
const diviTab = document.querySelector('.et_pb_tabs_controls');
if (diviTab) {
diviTab.addEventListener('click', eventHandler, false);
console.log("Clicked on Divi Tab");
}
const diviTab = document.querySelector('.et_pb_tabs_controls');
if (diviTab) {
diviTab.addEventListener(
'click',
() => {
document.querySelectorAll('.et_pb_tab_content [id^="fubade_"] > iframe').forEach(iframe => {
iframe.src += '';
});
},
false
);
}

return widgetObj;
Expand All @@ -80,20 +104,3 @@ const createIFrame = (parentId, src, isFullWidth) => {
parent.innerHTML = '';
parent.appendChild(iframe);
};

const eventHandler = evt => {
const currentIframe = document.querySelector('#' + evt.data.container + ' iframe');

if ('setHeight' === evt.data.type) {
currentIframe.setAttribute('height', evt.data.value + 'px');
currentIframe.style.height = '';
}

if ('setWidth' === evt.data.type) {
if ('100%' !== currentIframe.getAttribute('width')) {
currentIframe.setAttribute('width', evt.data.value + 'px');
}

currentIframe.style.width = '';
}
};

0 comments on commit 4fb6bde

Please sign in to comment.