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