]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/content/mow.js
Imported Upstream version 1.1+hg7904
[dactyl.git] / common / content / mow.js
index 770929dd5fb580df96979c5d50810aa2b7bfb297..e2ad98f5d459f512954d8da5ee283f9509e991da 100644 (file)
@@ -1,10 +1,10 @@
 // Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
 // Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
 
 var MOW = Module("mow", {
     init: function init() {
@@ -41,38 +41,28 @@ var MOW = Module("mow", {
                            html|html > xul|scrollbar { visibility: collapse !important; }",
                           true);
 
-        XML.ignoreWhitespace = true;
         overlay.overlayWindow(window, {
             objects: {
                 eventTarget: this
             },
-            append: <e4x xmlns={XUL} xmlns:dactyl={NS}>
-                <window id={document.documentElement.id}>
-                    <popupset>
-                        <menupopup id="dactyl-contextmenu" highlight="Events" events="contextEvents">
-                            <menuitem id="dactyl-context-copylink"
-                                      label={_("mow.contextMenu.copyLink")} dactyl:group="link"
-                                      oncommand="goDoCommand('cmd_copyLink');"/>
-                            <menuitem id="dactyl-context-copypath"
-                                      label={_("mow.contextMenu.copyPath")} dactyl:group="link path"
-                                      oncommand="dactyl.clipboardWrite(document.popupNode.getAttribute('path'));"/>
-                            <menuitem id="dactyl-context-copy"
-                                      label={_("mow.contextMenu.copy")} dactyl:group="selection"
-                                      command="cmd_copy"/>
-                            <menuitem id="dactyl-context-selectall"
-                                      label={_("mow.contextMenu.selectAll")}
-                                      command="cmd_selectAll"/>
-                        </menupopup>
-                    </popupset>
-                </window>
-                <vbox id={config.ids.commandContainer}>
-                    <vbox class="dactyl-container" id="dactyl-multiline-output-container" hidden="false" collapsed="true">
-                        <iframe id="dactyl-multiline-output" src="dactyl://content/buffer.xhtml"
-                                flex="1" hidden="false" collapsed="false" contextmenu="dactyl-contextmenu"
-                                highlight="Events" />
-                    </vbox>
-                </vbox>
-            </e4x>
+            append: [
+                ["window", { id: document.documentElement.id, xmlns: "xul" },
+                    ["popupset", {},
+                        ["menupopup", { id: "dactyl-contextmenu", highlight: "Events", events: "contextEvents" },
+                            ["menuitem", { id: "dactyl-context-copylink", label: _("mow.contextMenu.copyLink"),
+                                           "dactyl:group": "link",      oncommand: "goDoCommand('cmd_copyLink');" }],
+                            ["menuitem", { id: "dactyl-context-copypath", label: _("mow.contextMenu.copyPath"),
+                                           "dactyl:group": "link path", oncommand: "dactyl.clipboardWrite(document.popupNode.getAttribute('path'));" }],
+                            ["menuitem", { id: "dactyl-context-copy", label: _("mow.contextMenu.copy"),
+                                           "dactyl:group": "selection", command: "cmd_copy" }],
+                            ["menuitem", { id: "dactyl-context-selectall", label: _("mow.contextMenu.selectAll"),
+                                           command: "cmd_selectAll" }]]]],
+
+                ["vbox", { id: config.ids.commandContainer, xmlns: "xul" },
+                    ["vbox", { class: "dactyl-container", id: "dactyl-multiline-output-container", hidden: "false", collapsed: "true" },
+                        ["iframe", { id: "dactyl-multiline-output", src: "dactyl://content/buffer.xhtml",
+                                     flex: "1", hidden: "false", collapsed: "false",
+                                     contextmenu: "dactyl-contextmenu", highlight: "Events" }]]]]
         });
     },
 
@@ -100,32 +90,26 @@ var MOW = Module("mow", {
 
         if (modes.main != modes.OUTPUT_MULTILINE) {
             modes.push(modes.OUTPUT_MULTILINE, null, {
-                onKeyPress: this.closure.onKeyPress,
+                onKeyPress: this.bound.onKeyPress,
 
-                leave: this.closure(function leave(stack) {
+                leave: stack => {
                     if (stack.pop)
                         for (let message in values(this.messages))
                             if (message.leave)
                                 message.leave(stack);
-                }),
+                },
 
                 window: this.window
             });
             this.messages = [];
         }
 
-        // If it's already XML, assume it knows what it's doing.
-        // Otherwise, white space is significant.
-        // The problem elsewhere is that E4X tends to insert new lines
-        // after interpolated data.
-        XML.ignoreWhitespace = XML.prettyPrinting = false;
-
         highlightGroup = "CommandOutput " + (highlightGroup || "");
 
-        if (isObject(data) && !isinstance(data, _)) {
+        if (isObject(data) && !isinstance(data, _) && !DOM.isJSONXML(data)) {
             this.lastOutput = null;
 
-            var output = DOM(<div style="white-space: nowrap" highlight={highlightGroup}/>,
+            var output = DOM(["div", { style: "white-space: nowrap", highlight: highlightGroup }],
                              this.document);
             data.document = this.document;
             try {
@@ -139,7 +123,8 @@ var MOW = Module("mow", {
         }
         else {
             let style = isString(data) ? "pre-wrap" : "nowrap";
-            this.lastOutput = <div style={"white-space: " + style} highlight={highlightGroup}>{data}</div>;
+            this.lastOutput = ["div", { style: "white-space: " + style, highlight: highlightGroup },
+                               data];
 
             var output = DOM(this.lastOutput, this.document);
         }
@@ -164,7 +149,7 @@ var MOW = Module("mow", {
 
     events: {
         click: function onClick(event) {
-            if (event.getPreventDefault())
+            if (event.defaultPrevented)
                 return;
 
             const openLink = function openLink(where) {
@@ -172,7 +157,7 @@ var MOW = Module("mow", {
                 dactyl.open(event.target.href, where);
             };
 
-            if (event.target instanceof HTMLAnchorElement)
+            if (event.target instanceof Ci.nsIDOMHTMLAnchorElement)
                 switch (DOM.Event.stringify(event)) {
                 case "<LeftMouse>":
                     openLink(dactyl.CURRENT_TAB);
@@ -207,14 +192,14 @@ var MOW = Module("mow", {
         popupshowing: function onPopupShowing(event) {
             let menu = commandline.widgets.contextMenu;
             let enabled = {
-                link: window.document.popupNode instanceof HTMLAnchorElement,
+                link: window.document.popupNode instanceof Ci.nsIDOMHTMLAnchorElement,
                 path: window.document.popupNode.hasAttribute("path"),
                 selection: !window.document.commandDispatcher.focusedWindow.getSelection().isCollapsed
             };
 
             for (let node in array.iterValues(menu.children)) {
                 let group = node.getAttributeNS(NS, "group");
-                node.hidden = group && !group.split(/\s+/).every(function (g) enabled[g]);
+                node.hidden = group && !group.split(/\s+/).every(g => enabled[g]);
             }
         }
     },
@@ -361,36 +346,36 @@ var MOW = Module("mow", {
 
         bind(["j", "<C-e>", "<Down>"], "Scroll down one line",
              function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
-             function () mow.canScroll(1), BEEP);
+             () => mow.canScroll(1), BEEP);
 
         bind(["k", "<C-y>", "<Up>"], "Scroll up one line",
              function ({ count }) { mow.scrollVertical("lines", -1 * (count || 1)); },
-             function () mow.canScroll(-1), BEEP);
+             () => mow.canScroll(-1), BEEP);
 
         bind(["<C-j>", "<C-m>", "<Return>"], "Scroll down one line, exit on last line",
              function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
-             function () mow.canScroll(1), DROP);
+             () => mow.canScroll(1), DROP);
 
         // half page down
         bind(["<C-d>"], "Scroll down half a page",
              function ({ count }) { mow.scrollVertical("pages", .5 * (count || 1)); },
-             function () mow.canScroll(1), BEEP);
+             () => mow.canScroll(1), BEEP);
 
         bind(["<C-f>", "<PageDown>"], "Scroll down one page",
              function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
-             function () mow.canScroll(1), BEEP);
+             () => mow.canScroll(1), BEEP);
 
         bind(["<Space>"], "Scroll down one page",
              function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
-             function () mow.canScroll(1), DROP);
+             () => mow.canScroll(1), DROP);
 
         bind(["<C-u>"], "Scroll up half a page",
              function ({ count }) { mow.scrollVertical("pages", -.5 * (count || 1)); },
-             function () mow.canScroll(-1), BEEP);
+             () => mow.canScroll(-1), BEEP);
 
         bind(["<C-b>", "<PageUp>"], "Scroll up half a page",
              function ({ count }) { mow.scrollVertical("pages", -1 * (count || 1)); },
-             function () mow.canScroll(-1), BEEP);
+             () => mow.canScroll(-1), BEEP);
 
         bind(["gg"], "Scroll to the beginning of output",
              function () { mow.scrollToPercent(null, 0); });
@@ -400,12 +385,12 @@ var MOW = Module("mow", {
 
         // copy text to clipboard
         bind(["<C-y>"], "Yank selection to clipboard",
-             function () { dactyl.clipboardWrite(buffer.getCurrentWord(mow.window)); });
+             function () { dactyl.clipboardWrite(Buffer.currentWord(mow.window)); });
 
         // close the window
         bind(["q"], "Close the output window",
              function () {},
-             function () false, DROP);
+             () => false, DROP);
     },
     options: function initOptions() {
         options.add(["more"],
@@ -414,4 +399,4 @@ var MOW = Module("mow", {
     }
 });
 
-// vim: set fdm=marker sw=4 ts=4 et:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et: