Skip to content

Commit 310c7b0

Browse files
committed
Don't register JS function if already loaded
1 parent 75177fa commit 310c7b0

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

CHANGELOG-1.x.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
1.4.0
1+
1.3.1
22
-----
33

44
* Run CI against PHP 8.2
5+
* Don't register JS function if already loaded (may happen using symfony/ux-turbo)
56

67
1.3.0
78
-----

src/Resources/views/Form/froala_widget.html.twig

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,47 +53,45 @@
5353

5454
{# Load the editor. #}
5555
<script type="text/javascript">
56-
57-
{# Go. #}
58-
const {{ id }}_function = function() {
59-
(function(){
60-
const editInstance = new FroalaEditor( "#{{ id }}",{
61-
{# Add license. #}
62-
{% if froala_serialNumber is defined %}
63-
key : "{{ froala_serialNumber }}",
64-
{% endif %}
65-
{% for option, value in froala_arrOption %}
66-
{{ option }} : {% include "@LeaptFroalaEditor/Form/value.html.twig" %}
67-
{% endfor %}
68-
69-
events: {
70-
'image.error': function ( error ) {
71-
froalaDisplayError( this, error );
72-
},
73-
'imageManager.error': function ( error ) {
74-
froalaDisplayError( this, error );
75-
},
76-
'save.error': function ( error ) {
77-
froalaDisplayError( this, error );
78-
},
79-
'file.error': function ( error, responses ) {
80-
froalaDisplayError( this, error );
81-
},
82-
'video.error': function ( error, responses ) {
83-
froalaDisplayError( this, error );
84-
}
85-
{% for event, func in froala_events %}
86-
,'{{ event }}': {{ func }}
56+
if (typeof {{ id }}_function === 'undefined') {
57+
const {{ id }}_function = function() {
58+
(function(){
59+
const editInstance = new FroalaEditor( "#{{ id }}",{
60+
{# Add license. #}
61+
{% if froala_serialNumber is defined %}
62+
key : "{{ froala_serialNumber }}",
63+
{% endif %}
64+
{% for option, value in froala_arrOption %}
65+
{{ option }} : {% include "@LeaptFroalaEditor/Form/value.html.twig" %}
8766
{% endfor %}
88-
}})
89-
})();
90-
91-
92-
}
9367
94-
document.addEventListener("DOMContentLoaded", {{ id }}_function);
95-
if (document.readyState === "interactive" || document.readyState === "complete" ) {
96-
{{ id }}_function();
68+
events: {
69+
'image.error': function ( error ) {
70+
froalaDisplayError( this, error );
71+
},
72+
'imageManager.error': function ( error ) {
73+
froalaDisplayError( this, error );
74+
},
75+
'save.error': function ( error ) {
76+
froalaDisplayError( this, error );
77+
},
78+
'file.error': function ( error, responses ) {
79+
froalaDisplayError( this, error );
80+
},
81+
'video.error': function ( error, responses ) {
82+
froalaDisplayError( this, error );
83+
}
84+
{% for event, func in froala_events %}
85+
,'{{ event }}': {{ func }}
86+
{% endfor %}
87+
}})
88+
})();
89+
}
90+
91+
document.addEventListener("DOMContentLoaded", {{ id }}_function);
92+
if (document.readyState === "interactive" || document.readyState === "complete" ) {
93+
{{ id }}_function();
94+
}
9795
}
9896
</script>
9997

0 commit comments

Comments
 (0)