🐛Prevent potential null elements

because {% component_js_dependencies %} loads all the components regardless
This commit is contained in:
KimSia, Sim 2022-07-23 14:42:48 +08:00
parent f5c3f64c86
commit bb256f2ec8
No known key found for this signature in database
GPG key ID: 5C51FB99C703F242
2 changed files with 9 additions and 5 deletions

View file

@ -220,7 +220,9 @@ Then you need a javascript file that specifies how you interact with this compon
```js ```js
/* In a file called [project root]/components/calendar/script.js */ /* In a file called [project root]/components/calendar/script.js */
(function(){ (function(){
document.querySelector(".calendar-component").onclick = function(){ alert("Clicked calendar!") } if (document.querySelector(".calendar-component")) {
document.querySelector(".calendar-component").onclick = function(){ alert("Clicked calendar!"); };
}
})() })()
``` ```

View file

@ -1,3 +1,5 @@
(function(){ (function(){
document.querySelector(".calendar-component").onclick = function(){alert("Clicked calendar!")} if (document.querySelector(".calendar-component")) {
document.querySelector(".calendar-component").onclick = function(){ alert("Clicked calendar!"); };
}
})() })()