[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 22/483: View source commands implemented

David Prévot taffit at moszumanska.debian.org
Thu Jan 22 21:41:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.

commit eb45dc3b8468f8ec3a6017e38cefe92dd6628e21
Author: Wladimir Palant <trev at gtchat.de>
Date:   Tue Jan 9 19:25:03 2007 +0000

    View source commands implemented
    
    --HG--
    extra : convert_revision : svn%3Ad8bf93c1-8190-44a8-bb31-1ea94378a4df/trunk%40619
---
 chrome/content/aardvark.js            | 211 ++++++++++++++++++++++------------
 chrome/content/overlay.js             |   1 +
 chrome/content/overlay.xul            |   3 +-
 chrome/locale/en-US/global.properties |   2 +
 chrome/skin/classic/overlay.css       |  59 +++++++++-
 5 files changed, 195 insertions(+), 81 deletions(-)

diff --git a/chrome/content/aardvark.js b/chrome/content/aardvark.js
index 47a0cae..355527e 100644
--- a/chrome/content/aardvark.js
+++ b/chrome/content/aardvark.js
@@ -30,6 +30,7 @@
 var ehhAardvark = {
   wnd: null,
   selectedElem: null,
+  commentElem : null,
   mouseX: -1,
   mouseY: -1,
   commandLabelTimeout: 0
@@ -39,6 +40,29 @@ ehhAardvark.start = function(wnd) {
   if (!wnd || !(wnd.document instanceof HTMLDocument) || !wnd.document.body || wnd.location.href == "about:blank" || wnd.location.hostname == "")
     return;
 
+  if (!("viewSourceURL" in this)) {
+    // Firefox/Thunderbird and SeaMonkey have different viewPartialSource URLs
+    var urls = [
+      "chrome://global/content/viewPartialSource.xul",
+      "chrome://navigator/content/viewPartialSource.xul"
+    ];
+    this.viewSourceURL = null;
+    for (var i = 0; i < urls.length && !this.viewSourceURL; i++) {
+      var request = new XMLHttpRequest();
+      request.open("GET", urls[i], false);
+      try {
+        request.send(null);
+        this.viewSourceURL = urls[i];
+      } catch (e) {}
+    }
+
+    if (!this.viewSourceURL) {
+      for (i = 0; i < this.commands.length; i++)
+        if (this.commands[i] == "viewSourceWindow")
+          this.commands.splice(i--, 1);
+    }
+  }
+
   wnd.addEventListener("click", this.mouseClick, false);
   wnd.addEventListener("mouseover", this.mouseOver, false);
   wnd.addEventListener("keypress", this.keyPress, false);
@@ -147,6 +171,14 @@ ehhAardvark.generateEventHandlers = function(handlers) {
 }
 ehhAardvark.generateEventHandlers(["mouseClick", "mouseOver", "keyPress", "pageHide", "mouseMove"]);
 
+ehhAardvark.appendDescription = function(node, value, className) {
+  var descr = document.createElement("description");
+  descr.setAttribute("value", value);
+  if (className)
+    descr.setAttribute("class", className);
+  node.appendChild(descr);
+}
+
 /***************************
  * Highlight frame display *
  ***************************/
@@ -345,7 +377,8 @@ ehhAardvark.commands = [
   "narrower",
   "quit",
   "blinkElement",
-  //"viewSource",
+  "viewSource",
+  "viewSourceWindow",
   "showMenu"
 ];
 
@@ -399,7 +432,7 @@ ehhAardvark.quit = function ()
     return false;
 
   this.clearBox();
-  document.getElementById("ehh-helpbox").hidePopup();
+  ehhHideTooltips();
   
   this.wnd.removeEventListener("click", this.mouseClick, false);
   this.wnd.removeEventListener("mouseover", this.mouseOver, false);
@@ -409,6 +442,7 @@ ehhAardvark.quit = function ()
 
   this.selectedElem = null;
   this.wnd = null;
+  this.commentElem = null;
   delete this.widerStack;
   delete this.borderElems;
   delete this.labelElem;
@@ -462,91 +496,116 @@ ehhAardvark.viewSource = function (elem)
   if (!elem)
     return false;
 
-  var dbox = new DBox ("#fff", true);
-  dbox.innerContainer.innerHTML = this.getOuterHtmlFormatted(elem);
-  dbox.show ();
+  var sourceBox = document.getElementById("ehh-viewsource");
+  if (sourceBox.getAttribute("_moz-menuactive") == "true" && this.commentElem == elem) {
+    sourceBox.hidePopup();
+    return true;
+  }
+  sourceBox.hidePopup();
+
+  while (sourceBox.firstChild)
+    sourceBox.removeChild(sourceBox.firstChild);
+  this.getOuterHtmlFormatted(elem, sourceBox);
+  this.commentElem = elem;
+
+  var x = this.mouseX;
+  var y = this.mouseY;
+  var browser = getBrowser();
+  setTimeout(function() {
+    sourceBox.showPopup(browser, x, y, "tooltip", "topleft", "topleft");
+  }, 500);
   return true;
 }
 
 //--------------------------------------------------------
-ehhAardvark.getOuterHtmlFormatted = function (node)
-{
-  var str = "";
-  
-  if (document.all)
-  {
-    return "<textarea style='width:100%; height:100%'>" + node.outerHTML + "</textarea>"; 
-  }
+ehhAardvark.viewSourceWindow = function(elem) {
+  if (!elem || !this.viewSourceURL)
+    return false;
 
-  switch (node.nodeType)
-  {
-    case 1: // ELEMENT_NODE
-    {
-      if (node.style.display == 'none')
-        break;
-      var isLeaf = (node.childNodes.length == 0 && leafElems[node.nodeName]);
-      var isTbody = (node.nodeName == "TBODY" && node.attributes.length == 0);
-      
-      if (isTbody)
-      {
-        for (var i=0; i<node.childNodes.length; i++)
-          str += this.getOuterHtmlFormatted(node.childNodes.item(i));
-      }
-      else
-      {
-        if (!isLeaf)
-          str += "<div style='border: 1px solid #cccccc; border-right: 0;" +
-            "margin-left: 10px; margin-right: 0; overflow: hidden'>";
-        str += "<<span style='color:red;font-weight:bold'>" +
-              node.nodeName.toLowerCase() + "</span>";
-        for (var i=0; i<node.attributes.length; i++) 
-        {
-          if (node.attributes.item(i).nodeValue != null &&
-            node.attributes.item(i).nodeValue != '')
-          {
-            str += " <span style='color:green;'>"
-            str += node.attributes.item(i).nodeName;
-            str += "</span>='<span style='color:blue;'>";
-            str += node.attributes.item(i).nodeValue;
-            str += "</span>'";
-          }
-        }
-        if (isLeaf)
-          str += " /><br>";
-        else 
-        {
-          str += "><br>";
-          
-          for (var i=0; i<node.childNodes.length; i++)
-            str += this.getOuterHtmlFormatted(node.childNodes.item(i));
-          
-          str += "</<span style='color:red;font-weight:bold'>" +
-            node.nodeName.toLowerCase() + "</span>></div>"
+  var range = elem.ownerDocument.createRange();
+  range.selectNodeContents(elem);
+  var selection = {rangeCount: 1, getRangeAt: function() {return range}};
+
+  // SeaMonkey uses a different 
+  window.openDialog(this.viewSourceURL, "_blank", "scrollbars,resizable,chrome,dialog=no",
+                    null, null, selection, "selection");
+  return true;
+}
+
+//--------------------------------------------------------
+ehhAardvark.getOuterHtmlFormatted = function (node, container)
+{
+  var type = null;
+  switch (node.nodeType) {
+    case node.ELEMENT_NODE:
+      var box = document.createElement("vbox");
+      box.className = "elementBox";
+
+      var startTag = document.createElement("hbox");
+      startTag.className = "elementStartTag";
+      if (!node.firstChild);
+        startTag.className += "elementEndTag";
+
+      this.appendDescription(startTag, "<", null);
+      this.appendDescription(startTag, node.tagName, "tagName");
+
+      for (var i = 0; i < node.attributes.length; i++) {
+        var attr = node.attributes[i];
+        this.appendDescription(startTag, attr.name, "attrName");
+        if (attr.value != "") {
+          this.appendDescription(startTag, "=", null);
+          this.appendDescription(startTag, '"' + attr.value.replace(/"/, """) + '"', "attrValue");
         }
       }
-    }
-    break;
-        
-    case 3: //TEXT_NODE
-      if (node.nodeValue != '' && node.nodeValue != '\n' 
-          && node.nodeValue != '\r\n' && node.nodeValue != ' ')
-        str += node.nodeValue + "<br>";
-      break;
-      
-    case 4: // CDATA_SECTION_NODE
-      str += "<![CDATA[" + node.nodeValue + "]]><br>";
+
+      this.appendDescription(startTag, node.firstChild ? ">" : " />", null);
+      box.appendChild(startTag);
+
+      if (node.firstChild) {
+        for (var child = node.firstChild; child; child = child.nextSibling)
+          this.getOuterHtmlFormatted(child, box);
+
+        var endTag = document.createElement("hbox");
+        endTag.className = "elementEndTag";
+        this.appendDescription(endTag, "<", null);
+        this.appendDescription(endTag, "/" + node.tagName, "tagName");
+        this.appendDescription(endTag, ">", null);
+        box.appendChild(endTag);
+      }
+      container.appendChild(box);
+      return;
+
+    case node.TEXT_NODE:
+      type = "text";
       break;
-          
-    case 5: // ENTITY_REFERENCE_NODE
-      str += "&" + node.nodeName + ";<br>"
+    case node.CDATA_SECTION_NODE:
+      type = "cdata";
       break;
-  
-    case 8: // COMMENT_NODE
-      str += "<!--" + node.nodeValue + "--><br>"
+    case node.COMMENT_NODE:
+      type = "comment";
       break;
+    default:
+      return;
   }
-  
-  return str;
+
+  var text = node.nodeValue.replace(/\r/g, '').replace(/^\s+/, '').replace(/\s+$/, '');
+  if (text == "")
+    return;
+
+  if (type != "cdata") {
+    text = text.replace(/&/g, "&")
+               .replace(/</g, "<")
+               .replace(/>/g, ">")
+  }
+  text = text.replace(/\t/g, "  ");
+  if (type == "cdata")
+    text = "<![CDATA[" + text + "]]>";
+  else if (type == "comment")
+    text = "<!--" + text + "-->";
+
+  var lines = text.split("\n");
+  for (var i = 0; i < lines.length; i++)
+    this.appendDescription(container, lines[i].replace(/^\s+/, '').replace(/\s+$/, ''), type);
 }
 
 //-------------------------------------------------
diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js
index baba9e7..46d517c 100644
--- a/chrome/content/overlay.js
+++ b/chrome/content/overlay.js
@@ -62,6 +62,7 @@ function ehhInit() {
 function ehhHideTooltips() {
   document.getElementById("ehh-helpbox").hidePopup();
   document.getElementById("ehh-commandlabel").hidePopup();
+  document.getElementById("ehh-viewsource").hidePopup();
 }
 
 function ehhDisableElement(id, disable) {
diff --git a/chrome/content/overlay.xul b/chrome/content/overlay.xul
index bf9e2fe..c00da95 100644
--- a/chrome/content/overlay.xul
+++ b/chrome/content/overlay.xul
@@ -43,10 +43,11 @@
         <rows id="ehh-helpbox-rows"/>
       </grid>
     </tooltip>
-    <tooltip id="ehh-commandlabel" noautohide="true"  orient="horizontal">
+    <tooltip id="ehh-commandlabel" noautohide="true" orient="horizontal">
       <description id="ehh-commandlabel-key"/>
       <description id="ehh-commandlabel-label"/>
     </tooltip>
+    <tooltip id="ehh-viewsource" noautohide="true" orient="vertical"/>
   </popupset>
 
   <popup id="abp-status-popup">
diff --git a/chrome/locale/en-US/global.properties b/chrome/locale/en-US/global.properties
index 220a063..9b98716 100644
--- a/chrome/locale/en-US/global.properties
+++ b/chrome/locale/en-US/global.properties
@@ -10,5 +10,7 @@ command.blinkElement.key=b
 command.blinkElement.label=blink element
 command.viewSource.key=v
 command.viewSource.label=view source
+command.viewSourceWindow.key=u
+command.viewSourceWindow.label=view source (in separate window)
 command.showMenu.key=h
 command.showMenu.label=show/hide help
diff --git a/chrome/skin/classic/overlay.css b/chrome/skin/classic/overlay.css
index 6809835..dae6707 100644
--- a/chrome/skin/classic/overlay.css
+++ b/chrome/skin/classic/overlay.css
@@ -24,21 +24,72 @@
 
 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
 
-#ehh-helpbox, #ehh-commandlabel {
+#ehh-helpbox, #ehh-commandlabel, #ehh-viewsource
+{
   margin: 10px;
   padding: 5px;
 }
 
-#ehh-helpbox .key {
+#ehh-helpbox .key
+{
   font-weight: bold;
   margin-right: 10px;
 }
 
-#ehh-helpbox-title {
+#ehh-helpbox-title
+{
   font-size: 130%;
   margin-bottom: 10px;
 }
 
-#ehh-commandlabel-key {
+#ehh-commandlabel
+{
+  font-size: 200%;
+}
+
+#ehh-commandlabel-key
+{
   font-weight: bold;
 }
+
+#ehh-viewsource description,
+#ehh-viewsource hbox,
+#ehh-viewsource vbox
+{
+  margin: 0px;
+}
+
+#ehh-viewsource .elementBox
+{
+  border: 1px solid #CCCCCC;
+  margin: 5px;
+}
+
+#ehh-viewsource .text,
+#ehh-viewsource .cdata,
+#ehh-viewsource .comment
+{
+  margin: 0px 5px;
+}
+
+#ehh-viewsource .tagName
+{
+  font-weight: bold;
+  color: #FF0000;
+}
+
+#ehh-viewsource .attrName
+{
+  margin-left: 5px;
+  color: #00FF00;
+}
+
+#ehh-viewsource .attrValue
+{
+  color: #0000FF;
+}
+
+#ehh-viewsource .comment
+{
+  color: #808080;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git



More information about the Pkg-mozext-commits mailing list