mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-19 23:07:58 +01:00
DOM#highlight magic. Provide 'this' object for DOM#filter.
This commit is contained in:
@@ -850,6 +850,7 @@ var Events = Module("events", {
|
||||
return;
|
||||
|
||||
if (isinstance(elem, [HTMLEmbedElement, HTMLEmbedElement])) {
|
||||
if (!modes.main.passthrough && modes.main != modes.EMBED)
|
||||
modes.push(modes.EMBED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ var Modes = Module("modes", {
|
||||
|
||||
this.addMode("EMBED", {
|
||||
description: "Active when an <embed> or <object> element is focused",
|
||||
bases: [modes.MAIN],
|
||||
insert: true,
|
||||
ownsFocus: true,
|
||||
passthrough: true
|
||||
@@ -308,6 +309,7 @@ var Modes = Module("modes", {
|
||||
},
|
||||
|
||||
removeMode: function removeMode(mode) {
|
||||
this.remove(mode);
|
||||
if (this[mode.name] == mode)
|
||||
delete this[mode.name];
|
||||
if (this._modeMap[mode.name] == mode)
|
||||
|
||||
@@ -177,8 +177,9 @@ var DOM = Class("DOM", {
|
||||
val = this.matcher(val);
|
||||
|
||||
this.constructor(Array.filter(this, val, self || this));
|
||||
let obj = self || this.Empty();
|
||||
for (let i = 0; i < this.length; i++)
|
||||
if (val.call(self, this[i], i))
|
||||
if (val.call(self || update(obj, [this[i]]), this[i], i))
|
||||
res[res.length++] = this[i];
|
||||
|
||||
return res;
|
||||
@@ -292,25 +293,28 @@ var DOM = Class("DOM", {
|
||||
get highlight() let (self = this) ({
|
||||
toString: function () self.attrNS(NS, "highlight") || "",
|
||||
|
||||
get list() this.toString().trim().split(/\s+/),
|
||||
set list(val) self.attrNS(NS, "highlight", val.join(" ")),
|
||||
get list() let (s = this.toString().trim()) s ? s.split(/\s+/) : [],
|
||||
set list(val) {
|
||||
let str = array.uniq(val).join(" ").trim();
|
||||
self.attrNS(NS, "highlight", str || null);
|
||||
},
|
||||
|
||||
has: function has(hl) ~this.list.indexOf(hl),
|
||||
|
||||
add: function add(hl) self.each(function () {
|
||||
highlight.loaded[hl] = true;
|
||||
this.attrNS(NS, "highlight",
|
||||
array.uniq(this.highlight.list.concat(hl)).join(" "));
|
||||
this.highlight.list = this.highlight.list.concat(hl);
|
||||
}),
|
||||
|
||||
remove: function remove(hl) self.each(function () {
|
||||
this.attrNS(NS, "highlight",
|
||||
this.highlight.list.filter(function (h) h != hl));
|
||||
this.highlight.list = this.highlight.list.filter(function (h) h != hl);
|
||||
}),
|
||||
|
||||
toggle: function toggle(hl, val) self.each(function () {
|
||||
toggle: function toggle(hl, val, thisObj) self.each(function (elem, i) {
|
||||
let { highlight } = this;
|
||||
highlight[val == null ? highlight.has(hl) : val ? "remove" : "add"](hl)
|
||||
let v = callable(val) ? val.call(thisObj || this, elem, i) : val;
|
||||
|
||||
highlight[(v == null ? highlight.has(hl) : !v) ? "remove" : "add"](hl)
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user