浏览代码

chore(entry) move <a> handling code from q-app (#21)

Lucas Fernandes Nogueira 6 年之前
父节点
当前提交
88f01efbe5
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      lib/tauri.js

+ 12 - 0
lib/tauri.js

@@ -11,6 +11,18 @@
  *
  **/
 
+// open <a href="..."> links with the Tauri API
+document.querySelector('body').addEventListener('click', e => {
+  let target = e.target
+  while (target != null) {
+    if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
+      tauri.open(target.href)
+      break
+    }
+    target = target.parentElement
+  }
+}, true)
+
 /**
  * @module tauri
  * @description This API interface makes powerful interactions available