Script in component get messed up, any idea?
Question
I created a component like
const TWITTER_TYPE = 'TWITTER';
domc.addType(TWITTER_TYPE, {
model: defaultModel.extend({
defaults: {
...defaultModel.prototype.defaults,
droppable: false,
account: 'OntarioAlliance',
widget_width: 425,
widget_height: 525,
traits: [
{ label: 'Account', name: 'account', changeProp: 1, },
{ label: 'Width', name: 'widget_width', type: 'number', changeProp: 1, },
{ label: 'Height', name: 'widget_height', type: 'number', changeProp: 1, }
],
script: function() {
if(this.innerHTML.length == 0){
this.innerHTML=`<a class="twitter-timeline" data-width="426" data-height="525" data-dnt="true" href="https://twitter.com/{[ account ]}?ref_src=twsrc%5Etfw">Tweets by {[ account ]}</a>`;
if(window.twttr && window.twttr.widgets)
twttr.widgets.load();
else
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)){
twttr.widgets.load();
return;
}
fjs = d.getElementsByTagName(s)[0];
js = d.createElement(s); js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "twitter-widgets"));
}
}
},
}, {
isComponent(el) {
if(el.getAttribute &&
el.getAttribute('data-gjs-type') == TWITTER_TYPE) {
return {
type: TWITTER_TYPE
};
}
but after I put it in page and check the export html, I see code like below
<div id="idtj">
</div>
<script>var items = document.querySelectorAll('#idtj');
for (var i = 0, len = items.length; i < len; i++) {
(function(){
0==this.innerHTML.length&&(this.innerHTML='<a class="twitter-timeline" data-width="426" data-height="525" data-dnt="true" href="https://twitter.com/OntarioAlliance?ref_src=twsrc%5Etfw">Tweets by OntarioAlliance</a>',window.twttr&&window.twttr.widgets?twttr.widgets.load():function(e,t,n){
var a,i=e.getElementsByTagName(t)[0];
if(e.getElementById(n))return void twttr.widgets.load();
i=e.getElementsByTagName(t)[0],a=e.createElement(t),a.id=n,a.src="https://platform.twitter.com/widgets.js",i.parentNode.insertBefore(a,i)}
(document,"script","twitter-widgets"))}
.bind(items[i]))();
}
</script>
See the code after the function(), it messes the page up.
Any idea?Answers (2)
If you use any kind of minifier, the script is affected too. You can set the script as a string if you need to show the complete code to the user
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #845
Impossible to select Iframe
I've created a new type of component an general iframe, avoiding selecting the map, but when I try to select it in canvas so that the setti...
Issue #1959
[Question] Edit innerHTML in a custom button
Hi All, I am trying to change the text in a button component, but I am not able to edit it. I added this type: I included the editable: tru...
Issue #738
image reverted to original size after resized
hi, i got a strange issue with component: i got 2 types, image and icon the issue is when i first drag and drop the image component, i'm ab...
Issue #709
isComponent is not returning trait
Happy new year! I am having an issue with isComponent(). Here is my code: For some reason the only time the trait shows up in component set...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.