edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Kevin Carhart <kevin@carhart.net>
To: Edbrowse-dev@lists.the-brannons.com
Subject: [Edbrowse-dev] [PATCH] attributes, Event, item, var s
Date: Mon, 04 Sep 2017 22:30:40 -0700	[thread overview]
Message-ID: <20170804223040.kevin@carhart.net > (raw)

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

>From 7efbfa49404222d6c7614385a02f9b7c8057a796 Mon Sep 17 00:00:00 2001
From: Kevin Carhart <kevin@carhart.net>
Date: Mon, 4 Sep 2017 22:19:41 -0700
Subject: [PATCH] Flesh out a few things in the DOM.  Add the Event object and
 pump it in to the addEventHandler and attachEvent.  Turn s into a local
 variable in getComputedStyle to avoid collisions

---
 src/startwindow.js | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/startwindow.js b/src/startwindow.js
index 9dcdd77..e246600 100644
--- a/src/startwindow.js
+++ b/src/startwindow.js
@@ -773,6 +773,7 @@ Document = function(){}
 CSSStyleDeclaration = function(){
         this.element = null;
         this.style = this;
+	 this.attributes = new Array;
 };
 
 CSSStyleDeclaration.prototype.getPropertyValue = function(p) {
@@ -787,7 +788,7 @@ document.style.bgcolor = "white";
 
 getComputedStyle = function(e,pe) {
 	// disregarding pseudoelements for now
-s = new CSSStyleDeclaration;
+var s = new CSSStyleDeclaration;
 s.element = e;
 // This is a rather inefficient use of cssApply, but it is hardly ever called.
 cssApply(e, s);
@@ -1122,6 +1123,23 @@ c.nodeType = 8;
 return c;
 }
 
+Event = function(options){
+    // event state is kept read-only by forcing
+    // a new object for each event.  This may not
+    // be appropriate in the long run and we'll
+    // have to decide if we simply dont adhere to
+    // the read-only restriction of the specification
+    this._bubbles = true;
+    this._cancelable = true;
+    this._cancelled = false;
+    this._currentTarget = null;
+    this._target = null;
+    this._eventPhase = Event.AT_TARGET;
+    this._timeStamp = new Date().getTime();
+    this._preventDefault = false;
+    this._stopPropagation = false;
+};
+
 /*********************************************************************
 This is our addEventListener function.
 It is bound to window, which is ok because window has such a function
@@ -1136,6 +1154,7 @@ Third arg is not used cause I don't understand it.
 
 function addEventListener(ev, handler, notused)
 {
+ev_before_changes = ev;
 ev = "on" + ev;
 var evarray = ev + "$$array"; // array of handlers
 var evorig = ev + "$$orig"; // original handler from html
@@ -1149,7 +1168,7 @@ this[ev] = undefined;
 }
 this[evarray] = a;
 eval(
-'this.' + ev + ' = function(){ var a = this.' + evarray + '; if(this.' + evorig + ') this.' + evorig + '(); for(var i = 0; i<a.length; ++i) {a[i]();} };');
+'this.' + ev + ' = function(){ var a = this.' + evarray + '; if(this.' + evorig + ') this.' + evorig + '(); for(var i = 0; i<a.length; ++i) {var tempEvent = new Event;tempEvent.type = "' + ev_before_changes + '";a[i](tempEvent);} };');
 }
 this[evarray].push(handler);
 }
@@ -1198,7 +1217,7 @@ this[ev] = undefined;
 }
 this[evarray] = a;
 eval(
-'this.' + ev + ' = function(){ var a = this.' + evarray + '; if(this.' + evorig + ') this.' + evorig + '(); for(var i = 0; i<a.length; ++i) a[i](); };');
+'this.' + ev + ' = function(){ var a = this.' + evarray + '; if(this.' + evorig + ') this.' + evorig + '(); for(var i = 0; i<a.length; ++i) {var tempEvent = new Event;tempEvent.type = "' + ev + '";a[i](tempEvent);} };');
 }
 this[evarray].push(handler);
 }
@@ -1363,12 +1382,13 @@ Object.defineProperty(Array.prototype, "firstChild", { get: function() { return
 Object.defineProperty(Array.prototype, "lastChild", { get: function() { return this[this.length-1]; } });
 Object.defineProperty(Array.prototype, "nextSibling", { get: function() { return eb$getSibling(this,"next"); } });
 Object.defineProperty(Array.prototype, "previousSibling", { get: function() { return eb$getSibling(this,"previous"); } });
+
 Array.prototype.getAttribute = document.getAttribute;
 Array.prototype.setAttribute = document.setAttribute;
 Array.prototype.hasAttribute = document.hasAttribute;
 Array.prototype.removeAttribute = document.removeAttribute;
 Array.prototype.getAttributeNode = document.getAttributeNode;
-
+Array.prototype.item = function(x) { return this[x] };
 /*********************************************************************
 The rest of this file contains open source software form third parties.
 These functions are useful to edbrowse, particularly in the area
-- 
1.8.3.2



                 reply	other threads:[~2017-09-05  5:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20170804223040.kevin@carhart.net ' \
    --to=kevin@carhart.net \
    --cc=Edbrowse-dev@lists.the-brannons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).