edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [edbrowse-dev] [PATCH] element.dataset and h/w dimension properties added to element prototype
@ 2019-06-17  4:10 Kevin Carhart
  0 siblings, 0 replies; only message in thread
From: Kevin Carhart @ 2019-06-17  4:10 UTC (permalink / raw)
  To: edbrowse-dev

[-- Attachment #1: Type: text/plain, Size: 3469 bytes --]

I can't use edbrowse sm at the moment so in case alpine adds bad 
linefeeds, please refer to the attached

From c5653a8493bf6bf898355431b6fbc1ebcc09e566 Mon Sep 17 00:00:00 2001
From: Kevin Carhart <kevin@carhart.net>
Date: Sun, 16 Jun 2019 19:55:10 -0700
Subject: [PATCH] Makes html data-* attributes available in element.dataset
  object.  Also adds screen dimension properties to element.prototype.

---
  src/decorate.c     | 12 ++++++++++++
  src/jsrt           |  4 +++-
  src/startwindow.js |  8 ++++++++
  3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/decorate.c b/src/decorate.c
index 52e2459..c9ad47a 100644
--- a/src/decorate.c
+++ b/src/decorate.c
@@ -937,6 +937,7 @@ static void domLink(struct htmlTag *t, const char *classname,	/* instantiate thi
  	const char *stylestring = attribVal(t, "style");
  	jsobjtype so = 0;	/* obj.style */
  	jsobjtype ato = 0;	/* obj.attributes */
+	jsobjtype dso = 0;	/* obj.dataset */
  	char upname[MAXTAGNAME];

  	debugPrint(5, "domLink %s.%d name %s",
@@ -1043,6 +1044,8 @@ Don't do any of this if the tag is itself <style>. */
  		ato = instantiate(io, "attributes", "NamedNodeMap");
  		set_property_object(ato, "owner", io);
  		set_property_object(io, "ownerDocument", cf->docobj);
+                dso = instantiate(io, "dataset","Object");
+                set_property_object(io,"dataset",dso);

  // only anchors with href go into links[]
  		if (list && stringEqual(list, "links") &&
@@ -1549,6 +1552,15 @@ static void pushAttributes(const struct htmlTag *t)
  	if (!a)
  		return;
  	for (i = 0; a[i]; ++i) {
+
+// attributes on HTML tags that begin with "data-" should be available under a 
+// "dataset" object in JS
+	if (strncmp(a[i],"data-",5)==0) {
+	jsobjtype dso = get_property_object(t->jv,"dataset");
+	if(dso)
+		set_property_string(dso, a[i]+5, v[i]);
+	}
+
  // There are some exceptions, some attributes that we handle individually.
  		static const char *const exclist[] = {
  			"name", "id", "class",
diff --git a/src/jsrt b/src/jsrt
index 22507f4..4ce72fd 100644
--- a/src/jsrt
+++ b/src/jsrt
@@ -499,7 +499,7 @@ We'll get back to you if we like what you have to say.
  <input type='submit' value='Send Message' name='b1'
  onclick="alert('rock and roll')">
  </form>
-
+<DIV id=tag_with_data_attribute data-blech=abc>ok</DIV>
  <script type=text/javascript language=JavaScript>
  // I'll push the button for you
  document.forms[0].b.onclick();
@@ -892,6 +892,8 @@ if(fn.contentDocument.style.bgcolor !== "white") fail(168);
  if(querySelector(".inject").firstChild.style.display != "round") fail(175);
  if(document.body.style.fly) fail(176);

+var dataset_test = document.getElementById("tag_with_data_attribute");
+if(dataset_test.dataset.blech !== "abc") fail(177);
  </script>

  </body>
diff --git a/src/startwindow.js b/src/startwindow.js
index 5b1d4fc..589622b 100644
--- a/src/startwindow.js
+++ b/src/startwindow.js
@@ -2498,6 +2498,14 @@ set: function(s) { return mw0.newTextUnder(this, s, 1); }});
  Object.defineProperty(c.prototype, "nodeValue", {
  get: function() { return this.nodeType == 3 ? this.data : null;},
  set: function(h) { if(this.nodeType == 3) this.data = h; }});
+c.prototype.clientHeight = 16;
+c.prototype.clientWidth = 120;
+c.prototype.offsetHeight = 16;
+c.prototype.offsetWidth = 120;
+c.prototype.scrollHeight = 16;
+c.prototype.scrollWidth = 120;
+c.prototype.scrollTop = 0;
+c.prototype.scrollLeft = 0;
  }
  })();

-- 
1.8.3.2

[-- Attachment #2: Type: application/zip, Size: 1819 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-17  4:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-17  4:10 [edbrowse-dev] [PATCH] element.dataset and h/w dimension properties added to element prototype Kevin Carhart

edbrowse-dev - development list for edbrowse

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/edbrowse-dev

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 edbrowse-dev edbrowse-dev/ http://inbox.vuxu.org/edbrowse-dev \
		edbrowse-dev@edbrowse.org
	public-inbox-index edbrowse-dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.edbrowse.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git