diff --git a/common/content/buffer.js b/common/content/buffer.js index c65bf311..b34edbe9 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -565,7 +565,7 @@ function Buffer() //{{{ } }); - commands.add(["pagest[yle]"], + commands.add(["pagest[yle]", "pas"], "Select the author style sheet to apply", function (args) { diff --git a/common/content/editor.js b/common/content/editor.js index 073e88cf..a9e7789a 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -85,10 +85,7 @@ function Editor() //{{{ // Used in addAbbrevation and expandAbbreviation var abbrevmatch = full_id + "|" + end_id + "|" + non_id; - function getEditor() - { - return window.document.commandDispatcher.focusedElement; - } + function getEditor() liberator.focus; function getController() { @@ -606,7 +603,7 @@ function Editor() //{{{ unselectText: function () { - let elem = window.document.commandDispatcher.focusedElement; + let elem = liberator.focus; // A error occurs if the element has been removed when "elem.selectionStart" is executed. try { if (elem && elem.selectionEnd) @@ -630,7 +627,7 @@ function Editor() //{{{ } // FIXME: #93 ( in the bottom of a long textarea bounces up) - let elem = window.document.commandDispatcher.focusedElement; + let elem = liberator.focus; if (elem.setSelectionRange && util.readFromClipboard()) // readFromClipboard would return 'undefined' if not checked @@ -887,7 +884,7 @@ function Editor() //{{{ let textBox = null; if (!(config.isComposeWindow)) - textBox = document.commandDispatcher.focusedElement; + textBox = liberator.focus; let text = ""; // XXX if (textBox) diff --git a/common/content/events.js b/common/content/events.js index 972af6ca..d13fa72a 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -501,7 +501,7 @@ function Events() //{{{ function isFormElemFocused() { - let elem = window.document.commandDispatcher.focusedElement; + let elem = liberator.focus; if (elem == null) return false; @@ -591,7 +591,7 @@ function Events() //{{{ if (options["focuscontent"]) { setTimeout(function () { - let focused = document.commandDispatcher.focusedElement; + let focused = liberator.focus; if (focused && (focused.value !== undefined) && focused.value.length == 0) focused.blur(); }, 100); @@ -963,7 +963,7 @@ function Events() //{{{ shift = (keys[i] >= "A" && keys[i] <= "Z"); } - let elem = window.document.commandDispatcher.focusedElement; + let elem = liberator.focus; if (!elem) elem = window.content; diff --git a/common/content/liberator.js b/common/content/liberator.js index 61c0242a..98b3871f 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -217,16 +217,16 @@ const liberator = (function () //{{{ for (let [,item] in Iterator(node.childNodes)) { if (item.childNodes.length == 0 && item.localName == "menuitem" - && !/rdf:http:/.test(item.label)) // FIXME + && !/rdf:http:/.test(item.getAttribute("label"))) // FIXME { - item.fullMenuPath = parent + item.label; + item.fullMenuPath = parent + item.getAttribute("label"); items.push(item); } else { let path = parent; if (item.localName == "menu") - path += item.label + "."; + path += item.getAttribute("label") + "."; addChildren(item, path); } } @@ -600,6 +600,8 @@ const liberator = (function () //{{{ get menuItems() getMenuItems(), + get focus() document.commandDispatcher.focusedElement, + // Global constants CURRENT_TAB: 1, NEW_TAB: 2, @@ -926,9 +928,9 @@ const liberator = (function () //{{{ } } catch (e) {} - if (clearFocusedElement && document.commandDispatcher.focusedElement) - document.commandDispatcher.focusedElement.blur(); - if (elem && (elem != document.commandDispatcher.focusedElement)) + if (clearFocusedElement && liberator.focus) + liberator.focus.blur(); + if (elem && elem != liberator.focus) elem.focus(); }, diff --git a/common/content/style.js b/common/content/style.js index ba075832..7d701918 100644 --- a/common/content/style.js +++ b/common/content/style.js @@ -257,7 +257,7 @@ function Styles(name, store, serial) const ios = services.get("io"); const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService); const namespace = '@namespace html "' + XHTML + '";\n' + - '@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' + + '@namespace xul "' + XUL + '";\n' + '@namespace liberator "' + NS.uri + '";\n'; const Sheet = new Struct("name", "sites", "css", "ref", "agent"); diff --git a/common/content/util.js b/common/content/util.js index d00cd280..80fc9cf8 100644 --- a/common/content/util.js +++ b/common/content/util.js @@ -28,7 +28,8 @@ the terms of any one of the MPL, the GPL or the LGPL. /** @scope modules */ -const XHTML = "http://www.w3.org/1999/xhtml"; +const XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); +const XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator"); default xml namespace = XHTML; @@ -404,6 +405,32 @@ const util = { //{{{ if (typeof object != "object") return false; + const NAMESPACES = util.Array.toObject([ + [NS, 'liberator'], + [XHTML, 'html'], + [XUL, 'xul'], + ]); + if (object instanceof Node) { + let elem = object; + if (elem.nodeType == elem.TEXT_NODE) + return elem.data; + function namespaced(node) { + var ns = NAMESPACES[node.namespaceURI]; + if (ns) + return ns + ":" + node.localName; + return node.localName.toLowerCase(); + } + let tag = "<" + [namespaced(elem)].concat( + [namespaced(a) + "=" + template.highlight(a.value, true) + for ([i, a] in util.Array.iteritems(elem.attributes))]).join(" "); + + if (!elem.firstChild || /^\s*$/.test(elem.firstChild) && !elem.firstChild.nextSibling) + tag += '/>'; + else + tag += '>...'; + return tag; + } + try { // for window.JSON var obj = String(object); diff --git a/muttator/content/config.js b/muttator/content/config.js index 62bb0a78..7535a64d 100644 --- a/muttator/content/config.js +++ b/muttator/content/config.js @@ -104,8 +104,7 @@ const config = { //{{{ focusChange: function(win) { // we switch to -- MESSAGE -- mode for Muttator, when the main HTML widget gets focus - let elem = window.document.commandDispatcher.focusedElement; - if ((win && win.document && win.document instanceof HTMLDocument) || elem instanceof HTMLAnchorElement) + if (win && win.document instanceof HTMLDocument || liberator.focus instanceof HTMLAnchorElement) { if (config.isComposeWindow) modes.set(modes.INSERT, modes.TEXTAREA);