mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 09:17:59 +01:00
Fix hints with :set usermode. Dont sort location/history/search completions. Highlight via liberator:highlight= attribute rather than by class
This commit is contained in:
@@ -6,13 +6,14 @@
|
||||
]>
|
||||
|
||||
<bindings xmlns="http://www.mozilla.org/xbl"
|
||||
xmlns:liberator="http://vimperator.org/namespaces/liberator"
|
||||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:xbl="http://www.mozilla.org/xbl"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<binding id="frame">
|
||||
<content>
|
||||
<div id="liberator-frame-indicator" style="width: 40px; height: 40px"/>
|
||||
<html:div liberator:highlight="FrameIndicator"/>
|
||||
<children/>
|
||||
</content>
|
||||
</binding>
|
||||
|
||||
@@ -50,8 +50,8 @@ function Bookmarks() //{{{
|
||||
const Keyword = new Struct("keyword", "title", "icon", "url");
|
||||
Bookmark.defaultValue("icon", function () getFavicon(this.url));
|
||||
Bookmark.prototype.__defineGetter__("extra", function () [
|
||||
['keyword', this.keyword, "hl-Keyword"],
|
||||
['tags', this.tags.join(', '), "hl-Tag"]
|
||||
['keyword', this.keyword, "Keyword"],
|
||||
['tags', this.tags.join(', '), "Tag"]
|
||||
].filter(function (item) item[1]));
|
||||
|
||||
const storage = modules.storage;
|
||||
@@ -742,6 +742,8 @@ function History() //{{{
|
||||
let query = historyService.getNewQuery();
|
||||
let options = historyService.getNewQueryOptions();
|
||||
|
||||
if (typeof filter == "string")
|
||||
filter = { searchTerms: filter };
|
||||
for (let [k, v] in Iterator(filter))
|
||||
query[k] = v;
|
||||
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
|
||||
|
||||
@@ -871,6 +871,8 @@ function Buffer() //{{{
|
||||
{
|
||||
case "xhtml":
|
||||
return "http://www.w3.org/1999/xhtml";
|
||||
case "liberator":
|
||||
return NS.uri;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -1243,12 +1245,15 @@ function Buffer() //{{{
|
||||
frames[next].frameElement.scrollIntoView(false);
|
||||
|
||||
// add the frame indicator
|
||||
var doc = frames[next].document;
|
||||
var indicator = util.xmlToDom(<div id="liberator-frame-indicator"/>, doc);
|
||||
let doc = frames[next].document;
|
||||
var indicator = util.xmlToDom(<div highlight="FrameIndicator"/>, doc);
|
||||
doc.body.appendChild(indicator);
|
||||
|
||||
// remove the frame indicator
|
||||
setTimeout(function () { doc.body.removeChild(indicator); }, 500);
|
||||
|
||||
// Doesn't unattach
|
||||
//doc.body.setAttributeNS(NS.uri, "activeframe", "true");
|
||||
//setTimeout(function () { doc.body.removeAttributeNS(NS.uri, "activeframe"); }, 500);
|
||||
},
|
||||
|
||||
// similar to pageInfo
|
||||
|
||||
@@ -150,6 +150,9 @@ CompletionContext.prototype = {
|
||||
|
||||
get caret() (this.editor ? this.editor.selection.getRangeAt(0).startOffset : this.value.length) - this.offset,
|
||||
|
||||
get compare() this._compare || function () 0,
|
||||
set compare(val) this._compare = val,
|
||||
|
||||
get completions() this._completions || [],
|
||||
set completions(items)
|
||||
{
|
||||
@@ -1066,8 +1069,8 @@ function Completion() //{{{
|
||||
liberator.threadYield(true, true);
|
||||
|
||||
let list = template.generic(
|
||||
<div class="hl-Completions">
|
||||
{ template.completionRow(context.title, "hl-CompTitle") }
|
||||
<div highlight="Completions">
|
||||
{ template.completionRow(context.title, "CompTitle") }
|
||||
{ template.map(context.items, function (item) context.createRow(item)) }
|
||||
</div>);
|
||||
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||
@@ -1099,7 +1102,7 @@ function Completion() //{{{
|
||||
context.keys = { text: "text", description: "url", icon: "icon" };
|
||||
let process = context.process[0];
|
||||
context.process = [function ({ text: text, item: item }) <>
|
||||
<span class="hl-Indicator" style="display: inline-block; width: 1.5em; text-align: center">{item.indicator}</span>
|
||||
<span highlight="Indicator" style="display: inline-block; width: 1.5em; text-align: center">{item.indicator}</span>
|
||||
{ process.call(this, { item: item, text: text }) }
|
||||
</>];
|
||||
|
||||
@@ -1275,9 +1278,10 @@ function Completion() //{{{
|
||||
{
|
||||
context.format = history.format;
|
||||
context.title = ["History"]
|
||||
context.compare = null;
|
||||
context.background = true;
|
||||
context.regenerate = true;
|
||||
context.generate = function () history.get({ searchTerms: context.filter });
|
||||
context.generate = function () history.get(context.filter);
|
||||
},
|
||||
|
||||
get javascriptCompleter() javascript,
|
||||
@@ -1293,6 +1297,7 @@ function Completion() //{{{
|
||||
context.incomplete = true;
|
||||
context.hasItems = context.completions.length > 0; // XXX
|
||||
context.filterFunc = null;
|
||||
context.compare = null;
|
||||
let timer = new util.Timer(50, 100, function (result) {
|
||||
context.completions = [
|
||||
[result.getValueAt(i), result.getCommentAt(i), result.getImageAt(i)]
|
||||
@@ -1331,9 +1336,9 @@ function Completion() //{{{
|
||||
let engines = bookmarks.getSearchEngines();
|
||||
|
||||
context.title = ["Search Keywords"];
|
||||
context.keys = { text: 0, description: 1, icon: 2 };
|
||||
context.completions = keywords.concat(engines);
|
||||
context.anchored = true;
|
||||
context.completions = keywords.concat(engines);
|
||||
context.keys = { text: 0, description: 1, icon: 2 };
|
||||
|
||||
if (!space || noSuggest)
|
||||
return;
|
||||
@@ -1346,8 +1351,9 @@ function Completion() //{{{
|
||||
context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) {
|
||||
context.format = history.format;
|
||||
context.title = [keyword + " Quick Search"];
|
||||
context.background = true;
|
||||
context.anchored = true;
|
||||
context.background = true;
|
||||
context.compare = null;
|
||||
context.generate = function () {
|
||||
let [begin, end] = item.url.split("%s");
|
||||
|
||||
@@ -1384,8 +1390,9 @@ function Completion() //{{{
|
||||
let ctxt = context.fork(name, 0);
|
||||
|
||||
ctxt.title = [engine.description + " Suggestions"];
|
||||
ctxt.regenerate = true;
|
||||
ctxt.background = true;
|
||||
ctxt.compare = null;
|
||||
ctxt.regenerate = true;
|
||||
ctxt.generate = function () bookmarks.getSuggestions(name, this.filter);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -218,12 +218,12 @@ function AutoCommands() //{{{
|
||||
|
||||
var list = template.generic(
|
||||
<table>
|
||||
<tr class="hl-Title">
|
||||
<tr highlight="Title">
|
||||
<td colspan="2">----- Auto Commands -----</td>
|
||||
</tr>
|
||||
{
|
||||
template.map(cmds, function ([event, items])
|
||||
<tr class="hl-Title">
|
||||
<tr highlight="Title">
|
||||
<td colspan="2">{event}</td>
|
||||
</tr>
|
||||
+
|
||||
|
||||
@@ -157,10 +157,10 @@ function Search() //{{{
|
||||
|
||||
if (!aWord)
|
||||
{
|
||||
let elems = doc.getElementsByClassName("liberator-search");
|
||||
for (let i = elems.length; --i >= 0;)
|
||||
let elems = highlightObj.getSpans(doc);
|
||||
for (let i = elems.snapshotLength; --i >= 0;)
|
||||
{
|
||||
let elem = elems[i];
|
||||
let elem = elems.snapshotItem(i);
|
||||
let docfrag = doc.createDocumentFragment();
|
||||
let next = elem.nextSibling;
|
||||
let parent = elem.parentNode;
|
||||
@@ -176,7 +176,7 @@ function Search() //{{{
|
||||
return;
|
||||
}
|
||||
|
||||
var baseNode = <span class="liberator-search"/>
|
||||
var baseNode = <span highlight="Search"/>
|
||||
baseNode = util.xmlToDom(baseNode, window.content.document);
|
||||
|
||||
var body = doc.body;
|
||||
@@ -221,7 +221,9 @@ function Search() //{{{
|
||||
aNode.appendChild(docfrag);
|
||||
parent.insertBefore(aNode, before);
|
||||
return aNode;
|
||||
}
|
||||
},
|
||||
|
||||
getSpans: function (doc) buffer.evaluateXPath("//*[liberator:highlight='Search']", doc)
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
@@ -442,7 +444,7 @@ function Search() //{{{
|
||||
return;
|
||||
|
||||
// already highlighted?
|
||||
if (window.content.document.getElementsByClassName("liberator-search").length > 0)
|
||||
if (highlightObj.getSpans(content.document).snapshotLength > 0)
|
||||
return;
|
||||
|
||||
if (!text)
|
||||
|
||||
109
content/hints.js
109
content/hints.js
@@ -32,7 +32,7 @@ function Hints() //{{{
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
const ELEM = 0, TEXT = 1, SPAN = 2, IMGSPAN = 3, BGCOLOR = 4, COLOR = 5;
|
||||
const ELEM = 0, TEXT = 1, SPAN = 2, IMGSPAN = 3;
|
||||
|
||||
var myModes = config.browserModes;
|
||||
|
||||
@@ -112,13 +112,12 @@ function Hints() //{{{
|
||||
var scrollX = doc.defaultView.scrollX;
|
||||
var scrollY = doc.defaultView.scrollY;
|
||||
|
||||
var baseNodeAbsolute = util.xmlToDom(
|
||||
<span class="liberator-hint"/>, doc);
|
||||
var baseNodeAbsolute = util.xmlToDom(<span highlight="Hint"/>, doc);
|
||||
|
||||
var elem, tagname, text, span, rect;
|
||||
var res = buffer.evaluateXPath(hintMode.tags(), doc, null, true);
|
||||
|
||||
var fragment = doc.createDocumentFragment();
|
||||
var fragment = util.xmlToDom(<div highlight="hints"/>, doc);
|
||||
var start = pageHints.length;
|
||||
for (let elem in res)
|
||||
{
|
||||
@@ -171,19 +170,24 @@ function Hints() //{{{
|
||||
{
|
||||
var oldElem = validHints[oldID - 1];
|
||||
if (oldElem)
|
||||
oldElem.style.backgroundColor = options["linkbgcolor"];
|
||||
setClass(newElem, false);
|
||||
|
||||
var newElem = validHints[newID - 1];
|
||||
if (newElem)
|
||||
newElem.style.backgroundColor = options["activelinkbgcolor"];
|
||||
setClass(newElem, true);
|
||||
}
|
||||
|
||||
function setClass(elem, active)
|
||||
{
|
||||
let prefix = (elem.getAttributeNS(NS.uri, "class") || "") + " ";
|
||||
if (active)
|
||||
elem.setAttributeNS(NS.uri, "highlight", prefix + "HintActive");
|
||||
else
|
||||
elem.setAttributeNS(NS.uri, "highlight", prefix + "HintElem");
|
||||
}
|
||||
|
||||
function showHints()
|
||||
{
|
||||
var linkfgcolor = options["linkfgcolor"];
|
||||
var linkbgcolor = options["linkbgcolor"];
|
||||
var activelinkfgcolor = options["activelinkfgcolor"];
|
||||
var activelinkbgcolor = options["activelinkbgcolor"];
|
||||
|
||||
let elem, tagname, text, rect, span, imgspan;
|
||||
let hintnum = 1;
|
||||
@@ -208,9 +212,7 @@ function Hints() //{{{
|
||||
if (imgspan)
|
||||
imgspan.style.display = "none";
|
||||
|
||||
// reset background color
|
||||
elem.style.backgroundColor = hint[BGCOLOR];
|
||||
elem.style.color = hint[COLOR];
|
||||
elem.removeAttributeNS(NS.uri, "highlight");
|
||||
continue inner;
|
||||
}
|
||||
|
||||
@@ -222,61 +224,58 @@ function Hints() //{{{
|
||||
if (!rect)
|
||||
continue;
|
||||
|
||||
imgspan = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
|
||||
imgspan.style.position = "absolute";
|
||||
imgspan.style.opacity = 0.5;
|
||||
imgspan.style.zIndex = "10000000";
|
||||
imgspan = util.xmlToDom(<span highlight="Hint"/>, doc);
|
||||
imgspan.setAttributeNS(NS.uri, "class", "HintImage");
|
||||
imgspan.style.left = (rect.left + scrollX) + "px";
|
||||
imgspan.style.top = (rect.top + scrollY) + "px";
|
||||
imgspan.style.width = (rect.right - rect.left) + "px";
|
||||
imgspan.style.height = (rect.bottom - rect.top) + "px";
|
||||
imgspan.className = "liberator-hint";
|
||||
hint[IMGSPAN] = imgspan;
|
||||
doc.body.appendChild(imgspan);
|
||||
span.parentNode.appendChild(imgspan);
|
||||
}
|
||||
imgspan.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor;
|
||||
imgspan.style.display = "inline";
|
||||
setClass(imgspan, activeHint == hintnum)
|
||||
}
|
||||
|
||||
if (!imgspan)
|
||||
elem.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor;
|
||||
elem.style.color = (activeHint == hintnum) ? activelinkfgcolor : linkfgcolor;
|
||||
span.textContent = String(hintnum++);
|
||||
span.style.display = "inline";
|
||||
span.setAttribute("number", hintnum++);
|
||||
if (imgspan)
|
||||
imgspan.setAttribute("number", hintnum++);
|
||||
else
|
||||
setClass(elem, activeHint == hintnum);
|
||||
validHints.push(elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.usermode)
|
||||
{
|
||||
let css = [];
|
||||
// FIXME: Broken for imgspans.
|
||||
for (let [,{ doc: doc }] in Iterator(docs))
|
||||
{
|
||||
for (let elem in buffer.evaluateXPath("//*[@liberator:highlight and @number]", doc))
|
||||
{
|
||||
let group = elem.getAttributeNS(NS.uri, "highlight");
|
||||
css.push(highlight.selector(group) + "[number='" + elem.getAttribute("number") + "'] { " + elem.style.cssText + " }");
|
||||
}
|
||||
}
|
||||
styles.addSheet("hint-positions", "*", css.join("\n"), true, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function removeHints(timeout)
|
||||
{
|
||||
var firstElem = validHints[0] || null;
|
||||
var firstElemBgColor = "";
|
||||
var firstElemColor = "";
|
||||
|
||||
for (let [,{ doc: doc, start: start, end: end }] in Iterator(docs))
|
||||
{
|
||||
for (let elem in buffer.evaluateXPath("//*[@liberator:highlight='hints']", doc))
|
||||
elem.parentNode.removeChild(elem);
|
||||
for (let i in util.range(start, end + 1))
|
||||
{
|
||||
let hint = pageHints[i];
|
||||
// remove the span for the numeric display part
|
||||
doc.body.removeChild(hint[SPAN]);
|
||||
if (hint[IMGSPAN]) // a transparent span for images
|
||||
doc.body.removeChild(hint[IMGSPAN]);
|
||||
|
||||
if (timeout && firstElem == hint[ELEM])
|
||||
{
|
||||
firstElemBgColor = hint[BGCOLOR];
|
||||
firstElemColor = hint[COLOR];
|
||||
}
|
||||
else
|
||||
{
|
||||
// restore colors
|
||||
var elem = hint[ELEM];
|
||||
elem.style.backgroundColor = hint[BGCOLOR];
|
||||
elem.style.color = hint[COLOR]; }
|
||||
if (!timeout || hint[ELEM] != firstHint)
|
||||
hint[ELEM].removeAttributeNS(NS.uri, "highlight");
|
||||
}
|
||||
|
||||
// animate the disappearance of the first hint
|
||||
@@ -305,12 +304,10 @@ function Hints() //{{{
|
||||
// clearTimeout(id);
|
||||
// }
|
||||
// }, 100);
|
||||
setTimeout(function () {
|
||||
firstElem.style.backgroundColor = firstElemBgColor;
|
||||
firstElem.style.color = firstElemColor;
|
||||
}, timeout);
|
||||
setTimeout(function () { firstElem.removeAttributeNS(NS.uri, "highlight") }, timeout);
|
||||
}
|
||||
}
|
||||
styles.removeSheet("hint-positions", null, null, null, true);
|
||||
|
||||
reset();
|
||||
}
|
||||
@@ -560,22 +557,6 @@ function Hints() //{{{
|
||||
"number", 0,
|
||||
{ validator: function (value) value >= 0 && value < 3 });
|
||||
|
||||
options.add(["linkfgcolor", "lfc"],
|
||||
"Foreground color of a link during hint mode",
|
||||
"string", "black");
|
||||
|
||||
options.add(["linkbgcolor", "lbc"],
|
||||
"Background color of a link during hint mode",
|
||||
"string", "yellow");
|
||||
|
||||
options.add(["activelinkfgcolor", "alfc"],
|
||||
"Foreground color of the current active link during hint mode",
|
||||
"string", "black");
|
||||
|
||||
options.add(["activelinkbgcolor", "albc"],
|
||||
"Background color of the current active link during hint mode",
|
||||
"string", "#88FF00");
|
||||
|
||||
options.add(["hintmatching", "hm"],
|
||||
"How links are matched",
|
||||
"string", "contains",
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
Components.utils.import("resource://liberator/storage.jsm", modules);
|
||||
|
||||
["liberator.js",
|
||||
"config.js",
|
||||
"util.js",
|
||||
"style.js",
|
||||
"config.js",
|
||||
"buffer.js",
|
||||
"commands.js",
|
||||
"completion.js",
|
||||
|
||||
@@ -74,8 +74,8 @@ const liberator = (function () //{{{
|
||||
"boolean", false);
|
||||
|
||||
const tabopts = [
|
||||
["n", "Tab number", null, ".hl-TabNumber"],
|
||||
["N", "Tab number over icon", null, ".hl-TabIconNumber"]
|
||||
["n", "Tab number", null, highlight.selector("TabNumber")],
|
||||
["N", "Tab number over icon", null, highlight.selector("TabIconNumber")]
|
||||
];
|
||||
options.add(["guioptions", "go"],
|
||||
"Show or hide certain GUI elements like the menu or toolbar",
|
||||
@@ -433,7 +433,7 @@ const liberator = (function () //{{{
|
||||
|
||||
var str = template.generic(
|
||||
<table>
|
||||
<tr class="hl-Title" align="left">
|
||||
<tr highlight="Title" align="left">
|
||||
<th colspan="3">Code execution summary</th>
|
||||
</tr>
|
||||
<tr><td>  Executed:</td><td align="right"><span class="times-executed">{count}</span></td><td>times</td></tr>
|
||||
|
||||
@@ -34,6 +34,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
]>
|
||||
|
||||
<overlay id="liberator"
|
||||
xmlns:liberator="http://vimperator.org/namespaces/liberator"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:nc="http://home.netscape.com/NC-rdf#"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
@@ -50,7 +51,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
</keyset>
|
||||
|
||||
<popupset>
|
||||
<panel id="liberator-visualbell"/>
|
||||
<panel id="liberator-visualbell" liberator:highlight="Bell"/>
|
||||
</popupset>
|
||||
|
||||
<!--this notifies us also of focus events in the XUL
|
||||
@@ -78,7 +79,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
onclick="liberator.modules.commandline.onMultilineOutputEvent(event)"/>
|
||||
</vbox>
|
||||
|
||||
<hbox id="liberator-commandline" hidden="false" class="hl-Normal">
|
||||
<hbox id="liberator-commandline" hidden="false" liberator:highlight="Normal">
|
||||
<label class="plain" id="liberator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/>
|
||||
<textbox class="plain" id="liberator-commandline-command" flex="1" type="timed" timeout="100"
|
||||
oninput="liberator.modules.commandline.onEvent(event);"
|
||||
@@ -95,7 +96,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
|
||||
</window>
|
||||
|
||||
<statusbar id="status-bar" class="hl-StatusLine">
|
||||
<statusbar id="status-bar" liberator:highlight="StatusLine">
|
||||
<hbox insertbefore="&liberator.statusBefore;" insertafter="&liberator.statusAfter;"
|
||||
id="liberator-statusline" flex="1" hidden="false" align="center">
|
||||
<textbox class="plain" id="liberator-statusline-field-url" readonly="false" flex="1" crop="end"/>
|
||||
|
||||
@@ -38,9 +38,9 @@ function Highlights(name, store, serial)
|
||||
CompResult width: 45%; overflow: hidden;
|
||||
CompDesc color: gray; width: 50%;
|
||||
CompLess text-align: center; height: .5ex; line-height: .5ex; padding-top: 1ex;
|
||||
CompLess:after content: "\2303" /* Unicode up arrowhead */
|
||||
CompLess::after content: "\2303" /* Unicode up arrowhead */
|
||||
CompMore text-align: center; height: .5ex; line-height: .5ex;
|
||||
CompMore:after content: "\2304" /* Unicode down arrowhead */
|
||||
CompMore::after content: "\2304" /* Unicode down arrowhead */
|
||||
|
||||
Indicator color: blue;
|
||||
Filter font-weight: bold;
|
||||
@@ -70,8 +70,19 @@ function Highlights(name, store, serial)
|
||||
URL text-decoration: none; color: green; background: inherit;
|
||||
URL:hover text-decoration: underline; cursor: pointer;
|
||||
|
||||
Bell,#liberator-visualbell border: none; background-color: black;
|
||||
Hint,.liberator-hint,* {
|
||||
FrameIndicator,,* {
|
||||
background-color: red;
|
||||
opacity: 0.5;
|
||||
z-index: 999;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
Bell border: none; background-color: black;
|
||||
Hint,,* {
|
||||
font-family: monospace;
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
@@ -82,7 +93,12 @@ function Highlights(name, store, serial)
|
||||
border-style: solid;
|
||||
padding: 0px 1px 0px 1px;
|
||||
}
|
||||
Search,.liberator-search,* {
|
||||
Hint::after,,* content: attr(number);
|
||||
HintElem,,* background: yellow; color: black;
|
||||
HintActive,,* background: #88FF00; color: black;
|
||||
HintImage,,* opacity: .5;
|
||||
|
||||
Search,,* {
|
||||
font-size: inherit;
|
||||
padding: 0;
|
||||
color: black;
|
||||
@@ -96,7 +112,7 @@ function Highlights(name, store, serial)
|
||||
|
||||
const Highlight = Struct("class", "selector", "filter", "default", "value");
|
||||
Highlight.defaultValue("filter", function () "chrome://liberator/content/buffer.xhtml" + "," + config.styleableChrome);
|
||||
Highlight.defaultValue("selector", function () ".hl-" + this.class);
|
||||
Highlight.defaultValue("selector", function () self.selector(this.class));
|
||||
Highlight.defaultValue("value", function () this.default);
|
||||
Highlight.prototype.toString = function () "Highlight(" + this.class + ")\n\t" + [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join("\n\t");
|
||||
|
||||
@@ -140,11 +156,17 @@ function Highlights(name, store, serial)
|
||||
highlight[style.class] = style;
|
||||
}
|
||||
|
||||
this.selector = function (class)
|
||||
{
|
||||
let [, hl, rest] = class.match(/^(\w*)(.*)/);
|
||||
return "[liberator|highlight~=" + hl + "]" + rest
|
||||
};
|
||||
|
||||
highlightCSS.replace(/\{((?:.|\n)*?)\}/g, function (_, _1) _1.replace(/\n\s*/g, " "))
|
||||
.split("\n").filter(function (s) /\S/.test(s))
|
||||
.forEach(function (style)
|
||||
{
|
||||
style = Highlight.apply(Highlight, Array.slice(style.match(/^\s*([^,\s]+)(?:,([^,\s]+))?(?:,([^,\s]+))?\s*(.*)$/), 1));
|
||||
style = Highlight.apply(Highlight, Array.slice(style.match(/^\s*([^,\s]+)(?:,([^,\s]+)?)?(?:,([^,\s]+))?\s*(.*)$/), 1));
|
||||
highlight[style.class] = style;
|
||||
self.set(style.class);
|
||||
});
|
||||
@@ -165,9 +187,9 @@ function Styles(name, store, serial)
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
const sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
|
||||
.getService(Components.interfaces.nsIStyleSheetService);
|
||||
const XHTML = "http://www.w3.org/1999/xhtml";
|
||||
const namespace = "@namespace html url(" + XHTML + ");\n" +
|
||||
"@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);\n";
|
||||
const namespace = '@namespace html "' + XHTML + '";\n' +
|
||||
'@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' +
|
||||
'@namespace liberator "' + NS.uri + '";\n';
|
||||
const Sheet = new Struct("name", "sites", "css", "ref");
|
||||
|
||||
let cssUri = function (css) "chrome-data:text/css," + encodeURI(css);
|
||||
@@ -373,13 +395,13 @@ let (array = util.Array)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const styles = storage.newObject("styles", Styles, false);
|
||||
try {
|
||||
const highlight = storage.newObject("highlight", Highlights, false);
|
||||
} catch(e) { liberator.reportError(e) }
|
||||
|
||||
liberator.registerObserver("load_commands", function ()
|
||||
{
|
||||
const highlight = storage.newObject("highlight", Highlights, false);
|
||||
|
||||
// TODO: :colo default needs :hi clear
|
||||
commands.add(["colo[rscheme]"],
|
||||
"Load a color scheme",
|
||||
|
||||
@@ -48,13 +48,13 @@ const template = {
|
||||
var desc = this.process[1].call(this, item, this.getKey(item, "description"));
|
||||
}
|
||||
|
||||
return <div class={class || "hl-CompItem"}>
|
||||
return <div highlight={class || "CompItem"}>
|
||||
<!-- The non-breaking spaces prevent empty elements
|
||||
- from pushing the baseline down and enlarging
|
||||
- the row.
|
||||
-->
|
||||
<li class="hl-CompResult">{text} </li>
|
||||
<li class="hl-CompDesc">{desc} </li>
|
||||
<li highlight="CompResult">{text} </li>
|
||||
<li highlight="CompDesc">{desc} </li>
|
||||
</div>;
|
||||
},
|
||||
|
||||
@@ -62,7 +62,7 @@ const template = {
|
||||
{
|
||||
let extra = this.getKey(item, "extra");
|
||||
return <>
|
||||
<a href="#" class="hl-URL">{text}</a> 
|
||||
<a href="#" highlight="URL">{text}</a> 
|
||||
{
|
||||
!(extra && extra.length) ? "" :
|
||||
<span class="extra-info">
|
||||
@@ -79,10 +79,10 @@ const template = {
|
||||
icon: function (item, text)
|
||||
{
|
||||
let icon = this.getKey(item, "icon");
|
||||
return <><span class="hl-CompIcon">{icon ? <img src={icon}/> : <></>}</span>{text}</>
|
||||
return <><span highlight="CompIcon">{icon ? <img src={icon}/> : <></>}</span>{text}</>
|
||||
},
|
||||
|
||||
filter: function (str) <span class="hl-Filter">{str}</span>,
|
||||
filter: function (str) <span highlight="Filter">{str}</span>,
|
||||
|
||||
// if "processStrings" is true, any passed strings will be surrounded by " and
|
||||
// any line breaks are displayed as \n
|
||||
@@ -95,29 +95,29 @@ const template = {
|
||||
switch (arg == null ? "undefined" : typeof arg)
|
||||
{
|
||||
case "number":
|
||||
return <span class="hl-Number">{str}</span>;
|
||||
return <span highlight="Number">{str}</span>;
|
||||
case "string":
|
||||
if (processStrings)
|
||||
str = str.quote();
|
||||
return <span class="hl-String">{str}</span>;
|
||||
return <span highlight="String">{str}</span>;
|
||||
case "boolean":
|
||||
return <span class="hl-Boolean">{str}</span>;
|
||||
return <span highlight="Boolean">{str}</span>;
|
||||
case "function":
|
||||
// Vim generally doesn't like /foo*/, because */ looks like a comment terminator.
|
||||
// Using /foo*(:?)/ instead.
|
||||
if (processStrings)
|
||||
return <span class="hl-Function">{str.replace(/\{(.|\n)*(?:)/g, "{ ... }")}</span>;
|
||||
return <span highlight="Function">{str.replace(/\{(.|\n)*(?:)/g, "{ ... }")}</span>;
|
||||
return <>{arg}</>;
|
||||
case "undefined":
|
||||
return <span class="hl-Null">{arg}</span>;
|
||||
return <span highlight="Null">{arg}</span>;
|
||||
case "object":
|
||||
// for java packages value.toString() would crash so badly
|
||||
// that we cannot even try/catch it
|
||||
if (/^\[JavaPackage.*\]$/.test(arg))
|
||||
return <>[JavaPackage]</>;
|
||||
if (processStrings && false)
|
||||
str = template.highlightFilter(str, "\n", function () <span class="hl-NonText">^J</span>);
|
||||
return <span class="hl-Object">{str}</span>;
|
||||
str = template.highlightFilter(str, "\n", function () <span highlight="NonText">^J</span>);
|
||||
return <span highlight="Object">{str}</span>;
|
||||
case "xml":
|
||||
return arg;
|
||||
default:
|
||||
@@ -179,7 +179,7 @@ const template = {
|
||||
highlightURL: function highlightURL(str, force)
|
||||
{
|
||||
if (force || /^[a-zA-Z]+:\/\//.test(str))
|
||||
return <a class="hl-URL" href="#">{str}</a>;
|
||||
return <a highlight="URL" href="#">{str}</a>;
|
||||
else
|
||||
return str;
|
||||
},
|
||||
@@ -205,7 +205,7 @@ const template = {
|
||||
{
|
||||
return this.generic(
|
||||
<table>
|
||||
<tr style="text-align: left;" class="hl-Title">
|
||||
<tr style="text-align: left;" highlight="Title">
|
||||
<th colspan="2">jump</th><th>title</th><th>URI</th>
|
||||
</tr>
|
||||
{
|
||||
@@ -214,7 +214,7 @@ const template = {
|
||||
<td class="indicator">{idx == index ? ">" : ""}</td>
|
||||
<td>{Math.abs(idx - index)}</td>
|
||||
<td style="width: 250px; max-width: 500px; overflow: hidden;">{val.title}</td>
|
||||
<td><a href="#" class="hl-URL jump-list">{val.URI.spec}</a></td>
|
||||
<td><a href="#" highlight="URL jump-list">{val.URI.spec}</a></td>
|
||||
</tr>)
|
||||
}
|
||||
</table>);
|
||||
@@ -224,7 +224,7 @@ const template = {
|
||||
{
|
||||
return this.generic(
|
||||
<table>
|
||||
<tr class="hl-Title" align="left">
|
||||
<tr highlight="Title" align="left">
|
||||
<th>--- {title} ---</th>
|
||||
</tr>
|
||||
{
|
||||
@@ -243,7 +243,7 @@ const template = {
|
||||
{
|
||||
let table =
|
||||
<table>
|
||||
<tr class="hl-Title" align="left">
|
||||
<tr highlight="Title" align="left">
|
||||
<th colspan="2">{title}</th>
|
||||
</tr>
|
||||
{
|
||||
@@ -263,7 +263,7 @@ const template = {
|
||||
/* This might be mind-bogglingly slow. We'll see. */
|
||||
return this.generic(
|
||||
<table>
|
||||
<tr class="hl-Title" align="left">
|
||||
<tr highlight="Title" align="left">
|
||||
{
|
||||
this.map(headings, function (h)
|
||||
<th>{h}</th>)
|
||||
@@ -288,7 +288,7 @@ const template = {
|
||||
{
|
||||
this.map(iter, function (item)
|
||||
<tr>
|
||||
<td class="hl-Title" style="padding-right: 20px">{item.name || item.names[0]}</td>
|
||||
<td highlight="Title" style="padding-right: 20px">{item.name || item.names[0]}</td>
|
||||
<td>{item.description}</td>
|
||||
</tr>)
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ function CommandLine() //{{{
|
||||
|
||||
function setHighlightGroup(group)
|
||||
{
|
||||
commandlineWidget.setAttribute("class", group);
|
||||
commandlineWidget.setAttributeNS(NS.uri, "highlight", group);
|
||||
}
|
||||
|
||||
// sets the prompt - for example, : or /
|
||||
@@ -301,7 +301,7 @@ function CommandLine() //{{{
|
||||
{
|
||||
promptWidget.collapsed = true;
|
||||
}
|
||||
promptWidget.setAttribute("class", highlightGroup || commandline.HL_NORMAL);
|
||||
promptWidget.setAttributeNS(NS.uri, "highlight", highlightGroup || commandline.HL_NORMAL);
|
||||
}
|
||||
|
||||
// sets the command - e.g. 'tabopen', 'open http://example.com/'
|
||||
@@ -320,7 +320,7 @@ function CommandLine() //{{{
|
||||
.scrollWidth > commandWidget.inputField.scrollWidth)
|
||||
{
|
||||
setCommand("");
|
||||
setMultiline(<span class="hl-Message">{str}</span>, highlightGroup);
|
||||
setMultiline(<span highlight="Message">{str}</span>, highlightGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,7 +616,7 @@ function CommandLine() //{{{
|
||||
let list = <></>;
|
||||
|
||||
for (let [,message] in Iterator(messageHistory.messages))
|
||||
list += <div class={message.highlight + " hl-Message"}>{message.str}</div>;
|
||||
list += <div highlight={message.highlight + " Message"}>{message.str}</div>;
|
||||
|
||||
liberator.echo(list, commandline.FORCE_MULTILINE);
|
||||
}
|
||||
@@ -629,14 +629,14 @@ function CommandLine() //{{{
|
||||
|
||||
return {
|
||||
|
||||
HL_NORMAL : "hl-Normal",
|
||||
HL_ERRORMSG : "hl-ErrorMsg",
|
||||
HL_MODEMSG : "hl-ModeMsg",
|
||||
HL_MOREMSG : "hl-MoreMsg",
|
||||
HL_QUESTION : "hl-Question",
|
||||
HL_INFOMSG : "hl-InfoMsg",
|
||||
HL_WARNINGMSG : "hl-WarningMsg",
|
||||
HL_LINENR : "hl-LineNr",
|
||||
HL_NORMAL : "Normal",
|
||||
HL_ERRORMSG : "ErrorMsg",
|
||||
HL_MODEMSG : "ModeMsg",
|
||||
HL_MOREMSG : "MoreMsg",
|
||||
HL_QUESTION : "Question",
|
||||
HL_INFOMSG : "InfoMsg",
|
||||
HL_WARNINGMSG : "WarningMsg",
|
||||
HL_LINENR : "LineNr",
|
||||
|
||||
FORCE_MULTILINE : 1 << 0,
|
||||
FORCE_SINGLELINE : 1 << 1,
|
||||
@@ -1047,7 +1047,7 @@ function CommandLine() //{{{
|
||||
|
||||
// TODO: <LeftMouse> on the prompt line should scroll one page
|
||||
case "<LeftMouse>":
|
||||
if (event.originalTarget.className == "hl-URL buffer-list")
|
||||
if (event.originalTarget.getAttributeNS(NS.uri, "highlight") == "URL buffer-list")
|
||||
{
|
||||
tabs.select(parseInt(event.originalTarget.parentNode.parentNode.firstChild.textContent, 10) - 1);
|
||||
closeWindow = true;
|
||||
@@ -1315,13 +1315,13 @@ function ItemList(id) //{{{
|
||||
function init()
|
||||
{
|
||||
div = dom(
|
||||
<div class="ex-command-output hl-Normal" style="white-space: nowrap">
|
||||
<div class="hl-Completions" key="noCompletions"><span class="hl-Title">No Completions</span></div>
|
||||
<div class="ex-command-output" highlight="Normal" style="white-space: nowrap">
|
||||
<div highlight="Completions" key="noCompletions"><span highlight="Title">No Completions</span></div>
|
||||
<div key="completions"/>
|
||||
<div class="hl-Completions">
|
||||
<div highlight="Completions">
|
||||
{
|
||||
template.map(util.range(0, maxItems), function (i)
|
||||
<ul><li class="hl-CompTitle hl-NonText">~</li></ul>)
|
||||
<ul><li highlight="CompTitle NonText">~</li></ul>)
|
||||
}
|
||||
</div>
|
||||
</div>, divNodes);
|
||||
@@ -1333,12 +1333,12 @@ function ItemList(id) //{{{
|
||||
return;
|
||||
context.cache.nodes = [];
|
||||
dom(<div key="root">
|
||||
<div class="hl-Completions">
|
||||
{context.createRow(context.title || [], "hl-CompTitle")}
|
||||
<div highlight="Completions">
|
||||
{context.createRow(context.title || [], "CompTitle")}
|
||||
</div>
|
||||
<div key="up" class="hl-CompLess"/>
|
||||
<div key="items" class="hl-Completions"/>
|
||||
<div key="down" class="hl-CompMore"/>
|
||||
<div key="up" highlight="CompLess"/>
|
||||
<div key="items" highlight="Completions"/>
|
||||
<div key="down" highlight="CompMore"/>
|
||||
</div>, context.cache.nodes);
|
||||
divNodes.completions.appendChild(context.cache.nodes.root);
|
||||
});
|
||||
@@ -1400,7 +1400,7 @@ function ItemList(id) //{{{
|
||||
|
||||
divNodes.noCompletions.style.display = (off > 0) ? "none" : "block";
|
||||
|
||||
completionElements = buffer.evaluateXPath("//*[@class='hl-CompItem' and not(contains(@style, 'none'))]", doc);
|
||||
completionElements = buffer.evaluateXPath("//*[@liberator:highlight='CompItem' and not(contains(@style, 'none'))]", doc);
|
||||
|
||||
autoSize();
|
||||
return true;
|
||||
@@ -1549,7 +1549,7 @@ function StatusLine() //{{{
|
||||
insecure: "StatusLine"
|
||||
};
|
||||
|
||||
statusBar.setAttribute("class", "chromeclass-status hl-" + highlightGroup[type]);
|
||||
statusBar.setAttributeNS(NS.uri, "highlight", highlightGroup[type]);
|
||||
},
|
||||
|
||||
// update all fields of the statusline
|
||||
|
||||
@@ -26,6 +26,10 @@ the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
}}} ***** END LICENSE BLOCK *****/
|
||||
|
||||
const XHTML = "http://www.w3.org/1999/xhtml";
|
||||
const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator");
|
||||
default xml namespace = XHTML;
|
||||
|
||||
const util = { //{{{
|
||||
|
||||
Array: {
|
||||
@@ -331,8 +335,8 @@ const util = { //{{{
|
||||
{
|
||||
obj = "[Object]";
|
||||
}
|
||||
obj = template.highlightFilter(util.clip(obj, 150), "\n", !color ? function () "^J" : function () <span class="hl-NonText">^J</span>);
|
||||
let string = <><span class="hl-Title hl-Object">{obj}</span>::<br/>
</>;
|
||||
obj = template.highlightFilter(util.clip(obj, 150), "\n", !color ? function () "^J" : function () <span highlight="NonText">^J</span>);
|
||||
let string = <><span highlight="Title Object">{obj}</span>::<br/>
</>;
|
||||
|
||||
let keys = [];
|
||||
try // window.content often does not want to be queried with "var i in object"
|
||||
@@ -504,10 +508,9 @@ const util = { //{{{
|
||||
case "text":
|
||||
return doc.createTextNode(node);
|
||||
case "element":
|
||||
// Should use the node's namespace, in the future.
|
||||
let domnode = doc.createElementNS("http://www.w3.org/1999/xhtml", node.localName());
|
||||
let domnode = doc.createElementNS(node.namespace(), node.localName());
|
||||
for each (let attr in node.@*)
|
||||
domnode.setAttribute(attr.name(), String(attr));
|
||||
domnode.setAttributeNS(attr.name() == "highlight" ? NS.uri : attr.namespace(), attr.name(), String(attr));
|
||||
for each (let child in node.*)
|
||||
domnode.appendChild(arguments.callee(child, doc, nodes));
|
||||
if (nodes && node.@key)
|
||||
|
||||
Reference in New Issue
Block a user