diff --git a/CHANGELOG.md b/CHANGELOG.md index 0170279fa..d5ab5ff14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - The `u` option can now be used in the `manual` extension to specify a URL when triggering events. - Delete a site and all related data through the Sites API - Subscribed users can see their Paddle invoices from the last 12 months under the user settings +- Allow custom styles to be passed to embedded iframe plausible/analytics#1522 ### Fixed - UI fix where multi-line text in pills would not be underlined properly on small screens. diff --git a/assets/css/app.css b/assets/css/app.css index 3fc139768..c492847be 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -326,3 +326,7 @@ iframe[hidden] { } } + +/* This class is used for styling embedded dashboards. Do not remove. */ +/* stylelint-disable */ +.date-option-group { } diff --git a/assets/js/dashboard/datepicker.js b/assets/js/dashboard/datepicker.js index 5c046f9d1..d83f88667 100644 --- a/assets/js/dashboard/datepicker.js +++ b/assets/js/dashboard/datepicker.js @@ -319,29 +319,25 @@ class DatePicker extends React.Component { >
-
+
{this.renderLink("day", "Today")} {this.renderLink("realtime", "Realtime")}
-
-
+
{this.renderLink("7d", "Last 7 days")} {this.renderLink("30d", "Last 30 days")}
-
-
+
{ this.renderLink('month', 'Month to Date') } { this.renderLink('month', 'Last month', {date: lastMonth(this.props.site)}) }
-
-
+
{this.renderLink("6mo", "Last 6 months")} {this.renderLink("12mo", "Last 12 months")}
-
-
+
this.setState({mode: 'calendar'}, this.openCalendar)} onKeyPress={() => this.setState({mode: 'calendar'}, this.openCalendar)} diff --git a/assets/js/embed.content.js b/assets/js/embed.content.js index 7f22b3e89..32e50f7c6 100644 --- a/assets/js/embed.content.js +++ b/assets/js/embed.content.js @@ -1 +1,16 @@ import 'iframe-resizer/js/iframeResizer.contentWindow' + +window.iFrameResizer = { + onMessage: function(msg) { + if (msg.type === 'load-custom-styles') { + addCustomStyles(msg.opts) + } + } +} + +function addCustomStyles(opts) { + var style = document.createElement('style'); + style.innerHTML = opts.styles + + document.head.appendChild(style); +} diff --git a/assets/js/embed.host.js b/assets/js/embed.host.js index 1d366566d..37d493b53 100644 --- a/assets/js/embed.host.js +++ b/assets/js/embed.host.js @@ -1,3 +1,20 @@ import iframeResize from 'iframe-resizer/js/iframeResizer' -iframeResize({heightCalculationMethod: 'taggedElement'}, '[plausible-embed]') +var iframes = iframeResize({ + heightCalculationMethod: 'taggedElement', + onInit: onInit +}, '[plausible-embed]') + +function onInit() { + var iframe = iframes[0] + var styles = iframe.getAttribute('styles') + + if (styles) { + iframe.iFrameResizer.sendMessage({ + type: 'load-custom-styles', + opts: { + styles: styles + } + }) + } +}