Changeset 3147699
- Timestamp:
- 09/06/2024 04:18:16 PM (19 months ago)
- Location:
- farmtab-products-shortcode/trunk
- Files:
-
- 3 edited
-
js/productpage-iframe.js (modified) (1 diff)
-
productpage-iframe.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
farmtab-products-shortcode/trunk/js/productpage-iframe.js
r3147589 r3147699 4 4 * This script handles the resizing of the iframe and ensures that links within the iframe open in the parent window. 5 5 * 6 * @version 1.0 6 * @version 1.0.3 7 7 * @author FarmersTable LLC, FarmTab 8 8 */ 9 9 10 function resizeIframe(iframe) { 11 function adjustHeight() { 12 iframe.style.height = iframe.contentWindow.document.documentElement.scrollHeight + "px"; 10 // Create IE + others compatible event handler 11 var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; 12 var eventer = window[eventMethod]; 13 var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; 14 15 // Listen to message from child window 16 eventer(messageEvent, function(e) { 17 if (e.data.type === 'resize') { 18 console.log('parent received resize message: ', e.data.height); 19 var iframe = document.getElementById('productpage-iframe'); 20 iframe.style.height = e.data.height + 'px'; 21 } else if (e.data.type === 'navigate') { 22 console.log('parent received navigate message: ', e.data.url); 23 window.open(e.data.url, '_parent'); 13 24 } 14 iframe.contentWindow.addEventListener("load", adjustHeight); 15 iframe.contentWindow.addEventListener("resize", adjustHeight); 16 iframe.contentWindow.addEventListener("DOMContentLoaded", adjustHeight); 17 adjustHeight(); 18 19 // Ensure links open in the parent window 20 var links = iframe.contentWindow.document.querySelectorAll("a"); 21 links.forEach(function(link) { 22 link.setAttribute("target", "_parent"); 23 }); 24 } 25 }, false); 25 26 26 27 document.addEventListener("DOMContentLoaded", function() { 27 var iframe = document.getElementById("productpage-iframe"); 28 iframe.onload = function() { 29 resizeIframe(iframe); 30 }; 31 window.addEventListener("resize", function() { 32 resizeIframe(iframe); 33 }); 28 window.addEventListener("message", function(e) { 29 if (e.data.type === 'navigate') { 30 window.open(e.data.url, '_parent'); 31 } 32 }, false); 34 33 }); -
farmtab-products-shortcode/trunk/productpage-iframe.php
r3147600 r3147699 5 5 Plugin Name: FarmTab Products Shortcode 6 6 Description: A plugin to display FarmTab products using a shortcode. 7 Version: 1.0. 27 Version: 1.0.3 8 8 Author: FarmersTable LLC, FarmTab 9 9 License: GPLv2 or later … … 40 40 adjustHeight(); 41 41 42 // Ensure links open in a newwindow42 // Ensure links open in the parent window 43 43 var links = iframe.contentWindow.document.querySelectorAll("a"); 44 44 links.forEach(function(link) { 45 link.setAttribute("target", "_blank"); 45 link.addEventListener("click", function(event) { 46 event.preventDefault(); 47 window.parent.postMessage({ type: "navigate", url: link.href }, "*"); 48 }); 46 49 }); 47 50 } … … 54 57 resizeIframe(iframe); 55 58 }); 56 57 // Listen for messages from the iframe58 window.addEventListener("message", function(event) {59 if (event.origin !== "https://www.farmtab.com") {60 return;61 }62 if (event.data.type === "resize") {63 iframe.style.height = event.data.height + "px";64 }65 });66 59 }); 67 60 '; -
farmtab-products-shortcode/trunk/readme.txt
r3147600 r3147699 4 4 Requires at least: 5.0 5 5 Tested up to: 6.6 6 Stable tag: 1.0. 26 Stable tag: 1.0.3 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.