emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 07/15] xwidget: Add function to find element by CSS selector


From: Ricardo Wurmus
Subject: [PATCH 07/15] xwidget: Add function to find element by CSS selector
Date: Mon, 24 Oct 2016 18:40:53 +0200

* lisp/xwidget.el (xwidget-webkit-show-element): New procedure.
---
 lisp/xwidget.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index e54d1f8..d7ef44d 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -334,6 +334,23 @@ XW is the xwidget identifier, TEXT is retrieved from the 
webkit."
   ;;TODO convert linefeed to \n
   )
 
+(defun xwidget-webkit-show-element (xw element-selector)
+  "Make webkit xwidget XW show a named element ELEMENT-SELECTOR.
+The ELEMENT-SELECTOR must be a valid CSS selector.  For example,
+use this to display an anchor."
+  (interactive (list (xwidget-webkit-current-session)
+                     (read-string "Element selector: ")))
+  (xwidget-webkit-execute-script
+   xw
+   (format "
+(function (query) {
+  var el = document.querySelector(query);
+  if (el !== null) {
+    window.scrollTo(0, el.offsetTop);
+  }
+})('%s');"
+    element-selector)))
+
 (defun xwidget-webkit-show-named-element (xw element-name)
   "Make webkit xwidget XW show a named element ELEMENT-NAME.
 For example, use this to display an anchor."
-- 
2.10.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]