1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 14:12:27 +01:00

Add -append options to :hi and :sty. Fix some bugs (no, I don't know which bugs)

This commit is contained in:
Kris Maglione
2008-11-01 02:04:42 +00:00
parent c5ec767aa5
commit b904f580bb
7 changed files with 71 additions and 173 deletions

View File

@@ -41,7 +41,11 @@ function Command(specs, description, action, extraInfo) //{{{
// 'abc', 'abcdef' // 'abc', 'abcdef'
function parseSpecs(specs) function parseSpecs(specs)
{ {
let shortNames = longNames = names = []; // Whoever wrote the following should be ashamed. :(
// let shortNames = longNames = names = [];
let names = [];
let longNames = [];
let shortNames = [];
for (let [,spec] in Iterator(specs)) for (let [,spec] in Iterator(specs))
{ {
@@ -247,15 +251,12 @@ function Commands() //{{{
if (!command) if (!command)
return false; return false;
for (let i = 0; i < exCommands.length; i++) if (exCommands.some(function (c) c.name == command.name))
{
if (exCommands[i].name == command.name)
{ {
// never replace for now // never replace for now
liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1); liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1);
return false; return false;
} }
}
exCommands.push(command); exCommands.push(command);
return true; return true;

View File

@@ -82,26 +82,22 @@ const liberator = (function () //{{{
{ {
setter: function (value) setter: function (value)
{ {
var guioptions = config.guioptions || {}; for (let [opt, ids] in Iterator(config.guioptions || {}))
for (let option in guioptions)
{ {
if (option in guioptions) ids.forEach(function (id)
{ {
guioptions[option].forEach(function (elem) {
try try
{ {
document.getElementById(elem).collapsed = (value.indexOf(option.toString()) < 0); document.getElementById(id).collapsed = (value.indexOf(opt) < 0);
} }
catch (e) {} catch (e) {}
}); });
} }
}
let classes = tabopts.filter(function (o) value.indexOf(o[0]) == -1) let classes = tabopts.filter(function (o) value.indexOf(o[0]) == -1)
.map(function (a) a[3]) .map(function (a) a[3])
if (!classes.length) if (!classes.length)
{ {
storage.styles.removeSheet("taboptions", null, null, null, true); styles.removeSheet("taboptions", null, null, null, true);
} }
else else
{ {
@@ -652,7 +648,7 @@ const liberator = (function () //{{{
message = util.objectToString(message); message = util.objectToString(message);
else else
message += "\n"; message += "\n";
dump(config.name.toLowerCase() + ": " + message); dump(("config" in modules && config.name.toLowerCase()) + ": " + message);
}, },
dumpStack: function (msg) dumpStack: function (msg)

View File

@@ -170,7 +170,7 @@ function Mappings() //{{{
{ {
flags: Mappings.flags.COUNT, flags: Mappings.flags.COUNT,
rhs: rhs, rhs: rhs,
noremap: noremap, noremap: !!noremap,
silent: "<silent>" in args silent: "<silent>" in args
}); });
} }

View File

@@ -86,22 +86,24 @@ function Highlights(name, store, serial)
Highlight.defaultValue("value", function () this.default); Highlight.defaultValue("value", function () this.default);
Highlight.prototype.toString = function () [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join(", "); Highlight.prototype.toString = function () [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join(", ");
this.__iterator__ = function () (v for ([k,v] in Iterator(highlight))); function keys() [k for ([k, v] in Iterator(highlight))].sort();
this.__iterator__ = function () (highlight[v] for ([k,v] in Iterator(keys())));
this.get = function (k) highlight[k]; this.get = function (k) highlight[k];
this.set = function (key, newStyle, force) this.set = function (key, newStyle, force, append)
{ {
let [, class, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/); let [, class, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/);
if (!(class in highlight)) if (!(class in highlight))
return "Unknown highlight keyword"; return "Unknown highlight keyword";
let style = highlight[key] || new Highlight(key);
styles.removeSheet(style.selector, null, null, null, true);
if (append)
newStyle = (style.value || "").replace(/;?\s*$/, "; " + newStyle);
if (/^\s*$/.test(newStyle)) if (/^\s*$/.test(newStyle))
newStyle = null; newStyle = null;
let style = highlight[key] || new Highlight(key);
styles.removeSheet(style.selector, null, null, true);
if (newStyle == null) if (newStyle == null)
{ {
if (style.default == null) if (style.default == null)
@@ -175,7 +177,7 @@ function Styles(name, store, serial)
let sheet = sheets.filter(function (s) s.sites.join(",") == filter && s.css == css)[0]; let sheet = sheets.filter(function (s) s.sites.join(",") == filter && s.css == css)[0];
if (!sheet) if (!sheet)
sheet = new Sheet(name, filter.split(","), css, null); sheet = new Sheet(name, filter.split(",").filter(function (s) s), css, null);
if (sheet.ref == null) // Not registered yet if (sheet.ref == null) // Not registered yet
{ {
@@ -204,7 +206,7 @@ function Styles(name, store, serial)
let names = system ? systemNames : userNames; let names = system ? systemNames : userNames;
// Grossly inefficient. // Grossly inefficient.
let matches = [k for ([k, v] in sheets)]; let matches = [k for ([k, v] in Iterator(sheets))];
if (index) if (index)
matches = String(index).split(",").filter(function (i) i in sheets); matches = String(index).split(",").filter(function (i) i in sheets);
if (name) if (name)
@@ -213,8 +215,8 @@ function Styles(name, store, serial)
matches = matches.filter(function (i) sheets[i].css == css); matches = matches.filter(function (i) sheets[i].css == css);
if (filter) if (filter)
matches = matches.filter(function (i) sheets[i].sites.indexOf(filter) >= 0); matches = matches.filter(function (i) sheets[i].sites.indexOf(filter) >= 0);
return matches; return matches.map(function (i) [i, sheets[i]]);
}, };
this.removeSheet = function (name, filter, css, index, system) this.removeSheet = function (name, filter, css, index, system)
{ {
@@ -233,9 +235,8 @@ function Styles(name, store, serial)
if (matches.length == 0) if (matches.length == 0)
return; return;
for (let [,i] in Iterator(matches.reverse())) for (let [,[i, sheet]] in Iterator(matches.reverse()))
{ {
let sheet = sheets[i];
if (name) if (name)
{ {
sheet.ref.splice(sheet.ref.indexOf(name)); sheet.ref.splice(sheet.ref.indexOf(name));
@@ -247,6 +248,7 @@ function Styles(name, store, serial)
this.unregisterSheet(cssUri(wrapCSS(sheet))); this.unregisterSheet(cssUri(wrapCSS(sheet)));
} }
// Filter out the given site, and re-add if there are any left // Filter out the given site, and re-add if there are any left
// This could have unintended consequences
if (filter) if (filter)
{ {
let sites = sheet.sites.filter(function (f) f != filter); let sites = sheet.sites.filter(function (f) f != filter);
@@ -381,6 +383,15 @@ liberator.registerObserver("load_commands", function ()
} }
else else
{ {
if ("-append" in args)
{
let sheet = styles.findSheets(name, null, null, null, false)[0];
if (sheet)
{
filter = sheet[1].sites.concat(filter).join(",");
css = sheet[1].css.replace(/;?\s*$/, "; " + css);
}
}
let err = styles.addSheet(name, filter, css, false, special); let err = styles.addSheet(name, filter, css, false, special);
if (err) if (err)
liberator.echoerr(err); liberator.echoerr(err);
@@ -402,7 +413,8 @@ liberator.registerObserver("load_commands", function ()
bang: true, bang: true,
hereDoc: true, hereDoc: true,
literal: true, literal: true,
options: [[["-name", "-n"], commands.OPTION_STRING]], options: [[["-name", "-n"], commands.OPTION_STRING],
[["-append", "-a"], commands.OPTION_NOARG]],
serial: function () [ serial: function () [
{ {
command: this.name, command: this.name,
@@ -437,6 +449,7 @@ liberator.registerObserver("load_commands", function ()
function (args, special) function (args, special)
{ {
let style = <![CDATA[ let style = <![CDATA[
;
display: inline-block !important; display: inline-block !important;
position: static !important; position: static !important;
width: 3em !important; min-width: 3em !important; max-width: 3em !important; width: 3em !important; min-width: 3em !important; max-width: 3em !important;
@@ -458,7 +471,7 @@ liberator.registerObserver("load_commands", function ()
commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
return; return;
} }
let error = highlight.set(key, css, special); let error = highlight.set(key, css, special, "-append" in args);
if (error) if (error)
liberator.echoerr(error); liberator.echoerr(error);
}, },
@@ -472,6 +485,7 @@ liberator.registerObserver("load_commands", function ()
bang: true, bang: true,
hereDoc: true, hereDoc: true,
literal: true, literal: true,
options: [[["-append", "-a"], commands.OPTION_NOARG]],
serial: function () [ serial: function () [
{ {
command: this.name, command: this.name,

View File

@@ -494,11 +494,11 @@ function Struct()
ConStructor.defaultValue = function (key, val) ConStructor.defaultValue = function (key, val)
{ {
let i = args.indexOf(key); let i = args.indexOf(key);
let _i = "_" + i;
ConStructor.prototype.__defineGetter__(i, val); ConStructor.prototype.__defineGetter__(i, val);
ConStructor.prototype.__defineSetter__(i, function (val) { ConStructor.prototype.__defineSetter__(i, function (val) {
this.__defineGetter__(i, function () this[_i]); let value = val;
this[_i] = val; this.__defineGetter__(i, function () value);
this.__defineSetter__(i, function (val) { value = val });
}); });
}; };
return self.constructor = ConStructor; return self.constructor = ConStructor;

View File

@@ -8,12 +8,13 @@ via the [c]:style[c] command, most Vimperator elements can be styled with the
[c]:highlight[c] command, for convenience. [c]:highlight[c] command, for convenience.
|:hi| |:highlight| + |:hi| |:highlight| +
||:hi[light][!] {group}[{selector}] [{css}]|| + ||:hi[light][!] [-append] {group}[{selector}] [{css}]|| +
________________________________________________________________________________ ________________________________________________________________________________
Highlight {group} with {css}. Normally, {css} is checked for valid syntax Highlight {group} with {css}. Normally, {css} is checked for
before it's applied. Once you're certain it's valid, [!] will override the valid syntax before it's applied. Once you're certain it's
check, to speed Vimperator startup. {selector} can be any valid CSS selector, valid, [!] will override the check, to speed Vimperator startup.
such as {:hover}, and if provided will restrict the match to matching elements. {selector} can be any valid CSS selector, such as [c]:hover[c], and
if provided will restrict the match to matching elements.
Valid groups are: Valid groups are:
`------------------`----------------------------------- `------------------`-----------------------------------
@@ -49,20 +50,24 @@ Valid groups are:
*WarningMsg* A warning message *WarningMsg* A warning message
------------------------------------------------------- -------------------------------------------------------
Every invocation completely replaces the styling of any previous invocation. If Every invocation completely replaces the styling of any previous invocation,
{css} is not provided and [!] is, any styles matching {group} are listed. If unless [-append] (short option: -a) is provided, in which case, {css} is
neither {css} nor [!] is provided, the style for {group} is reset to its appended to its current value. If {css} is not provided and [!] is, any
default value. styles matching {group} are listed. If neither {css} nor [!] is provided, the
style for {group} is reset to its default value.
________________________________________________________________________________ ________________________________________________________________________________
|:sty| |:style| + |:sty| |:style| +
||:sty[le][!] [-name={name}] {filter} [{css}]|| + ||:sty[le][!] [-name={name}] [-append] {filter} [{css}]|| +
________________________________________________________________________________ ________________________________________________________________________________
Add CSS styles to the browser or to web pages. {filter} is a comma separated Add CSS styles to the browser or to web pages. {filter} is a
list of URLs to match. URLs ending with [c]*[c] are matched as prefixes, URLs comma separated list of URLs to match. URLs ending with [c]*[c]
not containing any [c]:[c] or [c]/[c] characters are matched as domains. If are matched as prefixes, URLs not containing any [c]:[c] or
{name} (short option: [c]-n[c]) is provided, any existing style with the same [c]/[c] characters are matched as domains. If {name} (short
name is overridden, and the style may later be deleted using {name}. option: [c]-n[c]) is provided, any existing style with the same
name is overridden, and the style may later be deleted using
{name}. If -append (short option: -a) is provided along with -name,
{css} and {filter} are appended to its current value.
If {css} isn't provided, matching styles are listed. If {css} isn't provided, matching styles are listed.
________________________________________________________________________________ ________________________________________________________________________________

View File

@@ -42,30 +42,6 @@ the terms of any one of the MPL, the GPL or the LGPL.
right: 0; right: 0;
} }
.__liberator-search {
display: inline;
font-size: inherit;
padding: 0;
color: black;
background-color: yellow;
padding: 0;
display: inline;
}
.liberator-hint {
z-index: 5000;
font-family: monospace;
font-size: 10px;
font-weight: bold;
color: white;
background-color: red;
border-color: ButtonShadow;
border-width: 0px;
border-style: solid;
padding: 0px 1px 0px 1px;
position: absolute;
}
/* Applied only to completion buffer and MOW */ /* Applied only to completion buffer and MOW */
@-moz-document @-moz-document
url-prefix(chrome://liberator/) { url-prefix(chrome://liberator/) {
@@ -100,20 +76,6 @@ the terms of any one of the MPL, the GPL or the LGPL.
.indicator { color: blue; } .indicator { color: blue; }
.hl-Number { color: red; }
.hl-String { color: green; }
.hl-Boolean { color: blue; }
.hl-Null { color: blue; }
.hl-Object { color: maroon; }
.hl-Function{ color: navy; }
.hl-Keyword { color: red; }
.hl-Tag { color: blue; }
.hl-NonText { color: blue; }
.hl-Filter { font-weight: bold !important; }
} }
/* Applied to completion buffer, MOW, browser window */ /* Applied to completion buffer, MOW, browser window */
@@ -124,20 +86,6 @@ the terms of any one of the MPL, the GPL or the LGPL.
-moz-binding: url(chrome://liberator/content/bindings.xml#tab); -moz-binding: url(chrome://liberator/content/bindings.xml#tab);
} }
.hl-TabIconNumber {
font-weight: bold;
text-shadow: black -1px 0 1px, black 0 1px 1px, black 1px 0 1px, black 0 -1px 1px;
text-align: center;
color: white;
}
.hl-TabNumber {
font-weight: bold;
padding-right: .3ex;
margin-left: 0px;
margin-right: 0px;
}
#liberator-container { #liberator-container {
font-family: monospace; font-family: monospace;
} }
@@ -208,72 +156,6 @@ the terms of any one of the MPL, the GPL or the LGPL.
min-width: 10% !important; min-width: 10% !important;
} }
/* highlight groups */
.hl-Normal {
background-color: white;
color: black;
}
.hl-ErrorMsg {
background-color: red;
color: white;
font-weight: bold;
}
.hl-InfoMsg {
background-color: white;
color: black;
}
.hl-ModeMsg {
background-color: white;
color: black;
}
.hl-LineNr {
background-color: white;
color: orange;
}
.hl-MoreMsg {
background-color: white;
color: green;
}
.hl-Question {
background-color: white;
color: green;
}
.hl-Title {
background-color: white;
color: magenta;
font-weight: bold !important;
}
.hl-WarningMsg {
background-color: white;
color: red;
}
.hl-StatusLine {
background: none !important;
background-color: black !important;
color: white !important;
}
.hl-StatusLineSecure {
background: none !important;
background-color: #B0FF00 !important; /* light green */
color: black !important;
}
.hl-StatusLineBroken {
background: none !important;
background-color: #FF6060 !important; /* light red */
color: black !important;
}
.hl-URL {
background-color: inherit;
color: green;
text-decoration: none;
}
/* NOTE: .aClass:hover not supported in quirks mode: http://developer.mozilla.org/en/docs/Mozilla_Quirks_Mode_Behavior */
a.hl-URL:hover {
text-decoration: underline;
cursor: pointer;
}
/* MOW */ /* MOW */
#liberator-completions, #liberator-multiline-output { #liberator-completions, #liberator-multiline-output {