Skip to content

Commit f164c99

Browse files
committed
use homemade feature
1 parent a675a09 commit f164c99

3 files changed

Lines changed: 55 additions & 34 deletions

File tree

public/class-hello-asso-public.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public function enqueue_scripts()
9898
* class.
9999
*/
100100

101-
wp_enqueue_script('iframe-resizer', plugin_dir_url(__FILE__) . 'js/iframe-resizer.jquery.js', array('jquery'), $this->version, false);
102101
wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/hello-asso-public.js', array('jquery'), $this->version, false);
103102
}
104103

@@ -113,22 +112,23 @@ function ha_shortcode($atts)
113112
$allowed_styles = array(
114113
'style' => array(
115114
'width' => array(),
116-
'height' => array(),
117-
'border' => array(),
118-
),
115+
'height' => array()
116+
)
119117
);
120118

121119
$pattern = '/^\d+px$/';
122120

121+
$height = "750px";
122+
$width = "100%";
123123
if ($type == "widget-bouton") {
124124
$height = preg_match($pattern, $atts['height'] ?? 0) ? $atts['height'] : "70px";
125-
$styleIframe = 'style="width:200px; height:' . $height . '; border:none;"';
125+
$width = '200px';
126126
} else if ($type == "widget") {
127127
$height = preg_match($pattern, $atts['height'] ?? 0) ? $atts['height'] : "750px";
128-
$styleIframe = 'style="width:100%; height:' . $height . '; border:none;"';
128+
$width = '100%';
129129
} else if ($type == "widget-vignette") {
130130
$height = preg_match($pattern, $atts['height'] ?? 0) ? $atts['height'] : "450px";
131-
$styleIframe = 'style="width:350px; height:' . $height . '; border:none;"';
131+
$width = '350px';
132132
} else {
133133
$type = "";
134134
}
@@ -139,7 +139,15 @@ function ha_shortcode($atts)
139139

140140
ob_start();
141141
?>
142-
<iframe src="<?= esc_url($url); ?><?= esc_html($type); ?>" id="idIframe" <?= wp_kses($styleIframe, $allowed_styles); ?> border="0"></iframe>
142+
<iframe
143+
id="idIframe"
144+
src="<?= esc_url($url); ?><?= esc_html($type); ?>"
145+
<?= wp_kses('height=' . $height . '"', $allowed_styles); ?>
146+
<?= wp_kses('width=' . $width . '"', $allowed_styles); ?>
147+
frameborder="0"
148+
loading="lazy"
149+
allowtransparency="true"
150+
onload="resizeIframeMessage()"></iframe>
143151
<?php
144152
return ob_get_clean();
145153
}

public/js/hello-asso-public.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
1-
'use strict';
2-
31
(function ($) {
4-
setTimeout(function () {
5-
$('#idIframe').iframeResize({
6-
license: 'GPLv3'
2+
'use strict';
3+
4+
/**
5+
* All of the code for your public-facing JavaScript source
6+
* should reside in this file.
7+
*
8+
* Note: It has been assumed you will write jQuery code here, so the
9+
* $ function reference has been prepared for usage within the scope
10+
* of this function.
11+
*
12+
* This enables you to define handlers, for when the DOM is ready:
13+
*
14+
* $(function() {
15+
*
16+
* });
17+
*
18+
* When the window is loaded:
19+
*
20+
* $( window ).load(function() {
21+
*
22+
* });
23+
*
24+
* ...and/or other possibilities.
25+
*
26+
* Ideally, it is not considered best practise to attach more than a
27+
* single DOM-ready or window-load handler for a particular page.
28+
* Although scripts in the WordPress core, Plugins and Themes may be
29+
* practising this, we should strive to set a better example in our own work.
30+
*/
31+
32+
window.resizeIframeMessage = function () {
33+
window.addEventListener('message', e => {
34+
const dataHeight = e.data.height;
35+
const idIframeElement = document.getElementById('idIframe')
36+
37+
if (dataHeight > parseFloat(idIframeElement.height || 0)) {
38+
idIframeElement.height = dataHeight + 'px'
39+
}
740
});
8-
}, 500);
41+
}
942

1043
})(jQuery);

0 commit comments

Comments
 (0)