Переглянути джерело

fix(tauri.js) if the DOM is already loaded, listen for <a> clicks (#436)

code is fine, the CI is borked
Lucas Fernandes Nogueira 5 роки тому
батько
коміт
09680ed6de
1 змінених файлів з 10 додано та 2 видалено
  1. 10 2
      cli/tauri.js/templates/tauri.js

+ 10 - 2
cli/tauri.js/templates/tauri.js

@@ -443,8 +443,8 @@ document.addEventListener('error', function (e) {
   }
 }, true)
 
-window.addEventListener('DOMContentLoaded', function () {
   // open <a href="..."> links with the Tauri API
+function __openLinks () {
   document.querySelector('body').addEventListener('click', function (e) {
     var target = e.target
     while (target != null) {
@@ -457,4 +457,12 @@ window.addEventListener('DOMContentLoaded', function () {
       target = target.parentElement
     }
   }, true)
-}, true)
+}
+
+if (document.readyState === 'complete' || document.readyState === 'interactive') {
+  __openLinks()
+} else {
+  window.addEventListener('DOMContentLoaded', function () {
+    __openLinks()
+  }, true)
+}