diff --git a/README.md b/README.md index e832bd8..79b0125 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # eveeno WordPress Plugin -[![Aktuelle Version](https://img.shields.io/badge/Version-2.0-brightgreen)](https://github.com/cassandre/eveeno-wp) +[![Aktuelle Version](https://img.shields.io/badge/Version-2.1-brightgreen)](https://github.com/cassandre/eveeno-wp) [![Release Version](https://img.shields.io/github/v/release/cassandre/eveeno-wp?label=Release+Version)](https://github.com/cassandre/eveeno-wp/releases/) [![GitHub License](https://img.shields.io/github/license/cassandre/eveeno-wp)](https://github.com/cassandre/eveeno-wp) [![GitHub issues](https://img.shields.io/github/issues/cassandre/eveeno-wp)](https://github.com/cassandre/eveeno-wp/issues) diff --git a/assets/js/embed.js b/assets/js/embed.js index 282bdf9..a10a8ce 100644 --- a/assets/js/embed.js +++ b/assets/js/embed.js @@ -3,10 +3,10 @@ * uses the iframeResizer tool to adapt iframe size to the content * and to communicate between iframe parent and child * -* last change: 2024-12-22 +* last change: 2025-01-15 */ -var SCRIPT_VERSION = '1.1'; +var SCRIPT_VERSION = '1.2'; /*! iFrame Resizer (iframeSizer.min.js ) - v4.3.9 - 2023-11-10 @@ -23,7 +23,7 @@ var SCRIPT_VERSION = '1.1'; */ window.onload = function() { - //logconsole.log('script version ' + SCRIPT_VERSION); + //console.log('script version ' + SCRIPT_VERSION); evInitializeWidgets(); }; @@ -43,35 +43,38 @@ function evCreateWidget(widget, i) { //console.log('evCreateWidget', i, widget); // read parameters - + var data = widget.dataset; var apikey = data.apikey; var event = data.event; var lang = data.lang; + var notterm = data.notterm; + var period = data.period; var scope = data.scope; var server = data.server; var style = data.style; + var term = data.term; var type = data.type; var user = data.user; var version = data.version || 'none'; - var wp_plugin_version = data.wp_plugin_version || 'none'; - + var wppluginversion = data.wppluginversion || 'none'; + // overwrite some by fallbacks for WP plugin version < 1.8 - + if (data.show) { if (data.show == 'form') { type = 'booking'; } else if (data.show == 'grid' || data.show == 'table' || data.show == 'list') { - type = 'booking'; style = data.show; + type = 'calendar'; style = data.show; } } if (data.eventid) event = data.eventid; if (data.userid) user = data.userid; - + // build widget url - + switch (server) { case 'dev': var serverurl = 'http://localhost'; break; case 'tst': var serverurl = 'https://tst.eveeno.com'; break; @@ -80,10 +83,10 @@ function evCreateWidget(widget, i) { } switch (type) { - + case 'booking': - - if (!event) { + + if (!event) { evWidgetShowError(widget, "Für das widget 'booking' ist der parameter 'event' Pflicht"); return; } @@ -92,13 +95,13 @@ function evCreateWidget(widget, i) { case 'calendar': - if (!user) { + if (!user) { evWidgetShowError(widget, "Für das widget 'calendar' ist der parameter 'user' Pflicht"); return; } var url = new URL(serverurl + '/de/event-cal/' + user); break; - + default: evWidgetShowError(widget, "Der Widget-Typ 'type' fehlt oder ist falsch"); @@ -110,21 +113,23 @@ function evCreateWidget(widget, i) { if (apikey) url.searchParams.append('apikey', apikey); if (event) url.searchParams.append('eventid', event); if (lang) url.searchParams.append('lang', lang); + if (notterm) url.searchParams.append('notterm', notterm); + if (period) url.searchParams.append('period', period); if (scope) url.searchParams.append('scope', scope); if (style) url.searchParams.append('style', style); + if (term) url.searchParams.append('term', term); if (user) url.searchParams.append('userid', user); - if (apikey) url.searchParams.append('apikey', apikey); url.searchParams.append('format', 'embedded'); url.searchParams.append('version', SCRIPT_VERSION); - url.searchParams.append('wp_plugin_version', wp_plugin_version); + url.searchParams.append('wppluginversion', wppluginversion); // create iframe - - let widgetId = 'evFrame'+i; + + let widgetId = 'evFrame'+i; const iframe = document.createElement('iframe'); - + iframe.setAttribute('id', widgetId); iframe.setAttribute('src', url.href); iframe.setAttribute('width', '100%'); @@ -135,9 +140,9 @@ function evCreateWidget(widget, i) { widget.replaceWith(iframe); // create resizer for the iframe - + iFrameResize({ - + log: false, checkOrigin: false, heightCalculationMethod: 'taggedElement', @@ -145,36 +150,40 @@ function evCreateWidget(widget, i) { onMessage: function(data){ //console.log('Message received', data); - + // receive commands from the iframed page - + if (!data.message.cmd) return; switch(data.message.cmd) { - - case 'forceReload': + + case 'forceReload': + location.reload(true); break; - + case 'scrollTo': + if (data.message.pos) { + + // window.pageYOffset => whole page's scroll offset ( page is at 500px scrolled down ) + // document.getElementById(widgetId).getBoundingClientRect().top => current element's top relative to viewport + // ( form's top is hidden as currently you are watching bottom part of form : top is at -200px relative to viewport ) + // above 1 + 2 => 500 + -200 => 300 => top position of iframe in given page + // ( top of iframe is at 300px relative to whole page ) + + // add to this : given field's pos from data.message.pos and it'll scroll to `iframe + given field` + window.scrollTo({ - top: document.getElementById(widgetId).offsetTop + data.message.pos - 10, + top: ( window.pageYOffset + document.getElementById(widgetId).getBoundingClientRect().top ) + data.message.pos - 10, left: 0, behavior: "smooth", }); } - /* - if (data.message.msg) { - setTimeout(function() { - alert(data.message.msg); - }, 10); // TBD: replace setTimeout with a better solution - } - */ break; } }, - + },'#'+widgetId); } @@ -183,5 +192,5 @@ function evWidgetShowError(widget, msg) { html += '

'; html += msg; widget.innerHTML = html; - widget.setAttribute('style', 'background-color:#FAEAE9; color: #D9534F; text-align: center; padding: 20px;'); + widget.setAttribute('style', 'background-color:#FAEAE9; color: #D9534F; text-align: center; padding: 20px;'); } diff --git a/assets/js/embed.min.js b/assets/js/embed.min.js index ef33615..f68e0ab 100644 --- a/assets/js/embed.min.js +++ b/assets/js/embed.min.js @@ -1,7 +1,7 @@ -var SCRIPT_VERSION="1.1"; +var SCRIPT_VERSION="1.2"; /*! iFrame Resizer (iframeSizer.min.js ) - v4.3.9 - 2023-11-10 * Desc: Force cross domain iframes to size to content. * Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame. * Copyright: (c) 2023 David J. Bradshaw - dave@bradshaw.net * License: MIT - */function evInitializeWidgets(){document.querySelectorAll(".eveenoWidget").forEach(evCreateWidget)}function evCreateWidget(e,n){var t=e.dataset,i=t.apikey,o=t.event,r=t.lang,a=t.scope,s=t.server,d=t.style,c=t.type,l=t.user,u=(t.version,t.wp_plugin_version||"none");switch(t.show&&("form"==t.show?c="booking":"grid"!=t.show&&"table"!=t.show&&"list"!=t.show||(c="booking",d=t.show)),t.eventid&&(o=t.eventid),t.userid&&(l=t.userid),s){case"dev":var f="http://localhost";break;case"tst":f="https://tst.eveeno.com";break;case"int":f="https://int.eveeno.com";break;default:f="https://eveeno.com"}switch(c){case"booking":if(!o)return void evWidgetShowError(e,"Für das widget 'booking' ist der parameter 'event' Pflicht");var m=new URL(f+"/"+o);break;case"calendar":if(!l)return void evWidgetShowError(e,"Für das widget 'calendar' ist der parameter 'user' Pflicht");m=new URL(f+"/de/event-cal/"+l);break;default:return void evWidgetShowError(e,"Der Widget-Typ 'type' fehlt oder ist falsch")}i&&m.searchParams.append("apikey",i),o&&m.searchParams.append("eventid",o),r&&m.searchParams.append("lang",r),a&&m.searchParams.append("scope",a),d&&m.searchParams.append("style",d),l&&m.searchParams.append("userid",l),i&&m.searchParams.append("apikey",i),m.searchParams.append("format","embedded"),m.searchParams.append("version",SCRIPT_VERSION),m.searchParams.append("wp_plugin_version",u);let g="evFrame"+n;const h=document.createElement("iframe");h.setAttribute("id",g),h.setAttribute("src",m.href),h.setAttribute("width","100%"),h.setAttribute("minWidth","100%"),h.setAttribute("scrolling","no"),h.setAttribute("frameborder","0"),e.replaceWith(h),iFrameResize({log:!1,checkOrigin:!1,heightCalculationMethod:"taggedElement",onMessage:function(e){if(e.message.cmd)switch(e.message.cmd){case"forceReload":location.reload(!0);break;case"scrollTo":e.message.pos&&window.scrollTo({top:document.getElementById(g).offsetTop+e.message.pos-10,left:0,behavior:"smooth"})}}},"#"+g)}function evWidgetShowError(e,n){html="Fehler in diesem Widget, bitte überprüfen Sie die Parameter:",html+="

",html+=n,e.innerHTML=html,e.setAttribute("style","background-color:#FAEAE9; color: #D9534F; text-align: center; padding: 20px;")}!function(e){var n,t,i,o,r,a,s,d,c,l,u,f,m;function g(){return window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver}function h(e,n,t){e.addEventListener(n,t,!1)}function p(e,n,t){e.removeEventListener(n,t,!1)}function w(e){return l[e]?l[e].log:t}function b(e,n){k("log",e,n,w(e))}function y(e,n){k("info",e,n,w(e))}function v(e,n){k("warn",e,n,!0)}function k(e,n,t,i){!0===i&&"object"==typeof window.console&&console[e](function(e){return r+"["+(n="Host page: "+e,(n=window.top!==window.self?window.parentIFrame&&window.parentIFrame.getId?window.parentIFrame.getId()+": "+e:"Nested host page: "+e:n)+"]");var n}(n),t)}function I(e){function n(){t("Height"),t("Width"),W((function(){T(C),E(A),k("onResized",C)}),C,"init")}function t(e){var n=Number(l[A]["max"+e]),t=Number(l[A]["min"+e]),i=(e=e.toLowerCase(),Number(C[e]));b(A,"Checking "+e+" is in range "+t+"-"+n),il[a]["max"+e])throw new Error("Value for min"+e+" can not be greater than max"+e)}}function C(e,n){null===u&&(u=setTimeout((function(){u=null,e()}),n))}function A(){"hidden"!==document.visibilityState&&(b("document","Trigger event: Visibility change"),C((function(){j("Tab Visible","resize")}),16))}function j(e,n){Object.keys(l).forEach((function(t){var i;l[i=t]&&"parent"===l[i].resizeFrom&&l[i].autoResize&&!l[i].firstRun&&S(e,n,l[t].iframe,t)}))}function H(){h(window,"message",I),h(window,"resize",(function(){b("window","Trigger event: "+"resize"),C((function(){j("Window resize","resize")}),16)})),h(document,"visibilitychange",A),h(document,"-webkit-visibilitychange",A)}function L(){function n(e,n){if(n){if(!n.tagName)throw new TypeError("Object is not a valid DOM element");if("IFRAME"!==n.tagName.toUpperCase())throw new TypeError("Expected