Skip to content

Commit 0efb7d0

Browse files
authored
Allow script tags to be defined in plugin settings (#4797) (#5361)
* Allow script tags to be defined in plugin settings (#4797) * Fix for IE11 * Wrap NodeList in an Array. * NodeList.forEach method is not supported on IE11, Use forEach method from Array * More information: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach\#Browser_Compatibility
1 parent 53f742d commit 0efb7d0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

server/webapp/WEB-INF/rails/webpack/views/shared/angular_plugin.js.msx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,38 @@ function onUpdate(scope, args) {
110110
};
111111
}
112112

113+
const oncreate = function (vnode) {
114+
vnode.children.forEach((elem) => {
115+
if (!(elem.dom instanceof Element)) {
116+
return;
117+
}
118+
119+
Array.from(elem.dom.querySelectorAll("script")).forEach((script) => {
120+
const newScript = document.createElement('script');
121+
newScript.innerHTML = script.innerHTML;
122+
script.parentNode.replaceChild(newScript, script);
123+
});
124+
});
125+
};
126+
113127
const AngularPlugin = {
114-
template (template) {
128+
template(template) {
115129
return $('<div></div>').html(template.replace(/GOINPUTNAME\[([^\]]*)\]/g, (_match, name) => {
116130
return `GOINPUTNAME['${name}']`;
117131
})).html();
118132
},
119133

120-
oninit () {
134+
oninit() {
121135
this.$scope = Stream();
122136
},
123137

124-
view (vnode) {
138+
view(vnode) {
125139
return (
126140
<div class='plugin-view'
127141
ng-controller={controllerName(vnode.attrs.configuration())}
128142
oncreate={onCreate(vnode.state.$scope, vnode.attrs)}
129143
onupdate={onUpdate(vnode.state.$scope, vnode.attrs)}>
130-
{pluginTemplate(vnode.attrs.pluginInfoSettings())}
144+
{m.fragment({oncreate}, [pluginTemplate(vnode.attrs.pluginInfoSettings())])}
131145
</div>
132146
);
133147
}

0 commit comments

Comments
 (0)