Hi Dato,
I wrote a simple plugin long time ago to display a custom button for our preview feature. Recently It has stopped working and I don’t know why since It has been working for a long time before. Not sure if you guys changed any thing on the API?
Basically, the function call on the init function has never been called. Seems like the promise has neer been resolve. Any idea?
See the gif for more detail.
DatoCmsPlugin.init(function(plugin) {
const getButton = () => document.getElementById("previewButton")
const setButtonUrl = (button, url) => button.setAttribute("href", url)
const setButtonText = (button, text) => button.textContent = text
const setButtonVisible = (button) => button.style.visibility = "visible"
const init = () => {
var label = plugin.parameters.instance.label;
//blog or caseStudy
var dataSource = plugin.parameters.instance.previewType || "blog";
let slug = plugin.getFieldValue("slug");
let url = `source=${dataSource}&slug=${slug}`;
var button = getButton();
setButtonText(button, label);
setButtonVisible(button);
setButtonUrl(button, 'https://www.nugit.co/blog-preview/?' + url);
};
const initPlugin = () => {
init();
plugin.startAutoResizer();
};
initPlugin();
});
And this the HTML, I took it from the template.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link href="https://unpkg.com/datocms-plugins-sdk/dist/sdk.css" media="all" rel="stylesheet" />
<script src="https://unpkg.com/datocms-plugins-sdk"></script>
<script src="preview.js"></script>
<style type="text/css">
.fullwidth-button {
width: 100%;
text-align: center;
}
</style>
</head>
<body>
<a id="previewButton" class="DatoCMS-button--primary fullwidth-button" target="_blank" style="visibility:hidden"></a>
</body>
</html>