Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/aardvark.js

Issue 5684127030312960: Issue 1091 - Implement a better templating approach for Element Hiding Helper (Closed)
Patch Set: Switched to a functional approach Created Sept. 11, 2014, 4:50 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/content/overlay.xul ('k') | lib/main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/aardvark.js
===================================================================
--- a/lib/aardvark.js
+++ b/lib/aardvark.js
@@ -7,16 +7,32 @@
let {Prefs} = require("prefs");
// Make sure to stop selection when we are uninstalled
onShutdown.add(function() Aardvark.quit());
// To be replaced when selection starts
function E(id) {return null;}
+/*********************************
+ * Minimal element creation code *
+ *********************************/
+
+function createElement(doc, tagName, attrs, children)
+{
+ let el = doc.createElement(tagName);
+ if (attrs)
+ for (let key in attrs)
+ el.setAttribute(key, attrs[key]);
+ if (children)
+ for (let child of children)
+ el.appendChild(child)
+ return el;
+};
+
/**********************************
* General element selection code *
**********************************/
let Aardvark = exports.Aardvark =
{
window: null,
browser: null,
@@ -51,17 +67,24 @@ let Aardvark = exports.Aardvark =
this.browser.addEventListener("keypress", this.onKeyPress, true);
this.browser.addEventListener("mousemove", this.onMouseMove, true);
this.browser.addEventListener("select", this.quit, false);
this.browser.contentWindow.addEventListener("pagehide", this.onPageHide, true);
this.browser.contentWindow.focus();
let doc = this.browser.contentDocument;
- this.boxElem = doc.importNode(E("ehh-elementmarker").firstElementChild.cloneNode(true), true);
+ let {elementMarkerClass} = require("main");
+ this.boxElem = createElement(doc, "div", {"class": elementMarkerClass}, [
+ createElement(doc, "div", {"class": "ehh-border"}),
+ createElement(doc, "div", {"class": "ehh-label"}, [
+ createElement(doc, "span", {"class": "ehh-labelTag"}),
+ createElement(doc, "span", {"class": "ehh-labelAddition"})
+ ])
+ ]);
this.initHelpBox();
if (Prefs.showhelp)
this.showMenu();
// Make sure to select some element immeditely (whichever is in the center of the browser window)
let [wndWidth, wndHeight] = this.getWindowSize(doc.defaultView);
« no previous file with comments | « chrome/content/overlay.xul ('k') | lib/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld