Skip to content

Commit

Permalink
Fix widgetpack rating
Browse files Browse the repository at this point in the history
  • Loading branch information
PaperStrike committed Apr 6, 2021
1 parent 015dd00 commit e0df44d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions layout/_third-party/rating.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{%- if theme.rating.enable %}
<script src="https://embed.widgetpack.com/widget.js" async></script>
{{ next_data('rating', theme.rating) }}
{{ next_js('third-party/rating.js') }}
{%- endif %}
27 changes: 14 additions & 13 deletions source/js/third-party/rating.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/* global NexT, CONFIG, wpac_init */
/* global CONFIG, WPac */

document.addEventListener('page:loaded', () => {
if (!CONFIG.page.isPost) return;
if (!window.wpac_init) window.wpac_init = [];

wpac_init.push({
{
const widgets = [{
widget: 'Rating',
id : CONFIG.rating.id,
el : 'wpac-rating',
color : CONFIG.rating.color
});
}];

document.addEventListener('page:loaded', () => {
if (!CONFIG.page.isPost) return;

const newWidgets = widgets.map(widget => ({...widget}));

if (window.WIDGETPACK_LOADED) return;
window.WIDGETPACK_LOADED = true;
NexT.utils.getScriptPromise('//embed.widgetpack.com/widget.js', {
attributes: {
async: true
if (window.WPac) {
WPac.init(newWidgets);
} else {
window.wpac_init = newWidgets;
}
});
});
}

0 comments on commit e0df44d

Please sign in to comment.