//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
-"use strict";
+/* use strict */
Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("styles", {
exports: ["Style", "Styles", "styles"],
- require: ["services", "util"],
- use: ["contexts", "messages", "template"]
+ require: ["services", "util"]
}, this);
function cssUri(css) "chrome-data:text/css," + encodeURI(css);
return preamble + css;
let selectors = filter.map(function (part)
- !/^(?:[a-z-]+[:*]|[a-z-.]+$)/i.test(part) ? "regexp(" + (".*(?:" + part + ").*").quote() + ")" :
+ !/^(?:[a-z-]+[:*]|[a-z-.]+$)/i.test(part) ? "regexp(" + Styles.quote(".*(?:" + part + ").*") + ")" :
(/[*]$/.test(part) ? "url-prefix" :
/[\/:]/.test(part) ? "url"
: "domain")
- + '("' + part.replace(/"/g, "%22").replace(/\*$/, "") + '")')
+ + '(' + Styles.quote(part.replace(/\*$/, "")) + ')')
.join(",\n ");
return preamble + "@-moz-document " + selectors + " {\n\n" + css + "\n\n}\n";
get modifiable() this.name !== "system",
addRef: function (obj) {
- this.refs.push(Cu.getWeakReference(obj));
+ this.refs.push(util.weakReference(obj));
this.dropRef(null);
},
dropRef: function (obj) {
this.cleanup();
this.allSheets = {};
- services["dactyl:"].providers["style"] = function styleProvider(uri) {
- let id = /^\/(\d*)/.exec(uri.path)[1];
- if (Set.has(styles.allSheets, id))
- return ["text/css", styles.allSheets[id].fullCSS];
- return null;
- };
+ update(services["dactyl:"].providers, {
+ "style": function styleProvider(uri, path) {
+ let id = parseInt(path);
+ if (Set.has(styles.allSheets, id))
+ return ["text/css", styles.allSheets[id].fullCSS];
+ return null;
+ }
+ });
},
cleanup: function cleanup() {
else
test = function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } };
test.toString = function toString() filter;
+ test.key = filter;
if (arguments.length < 2)
return test;
return test(arguments[1]);
| [^;}\s]+
)
]]>, "gix", this)
- })
+ }),
+
+ /**
+ * Quotes a string for use in CSS stylesheets.
+ *
+ * @param {string} str
+ * @returns {string}
+ */
+ quote: function quote(str) {
+ return '"' + str.replace(/([\\"])/g, "\\$1").replace(/\n/g, "\\00000a") + '"';
+ },
}, {
commands: function (dactyl, modules, window) {
const { commands, contexts, styles } = modules;
command: "style",
arguments: [style.sites.join(",")],
literalArg: style.css,
- options: update(
- hive.name == "user" ? {} : { "-group": hive.name },
- style.name ? { "-name": style.name } : {})
+ options: {
+ "-group": hive.name == "user" ? undefined : hive.name,
+ "-name": style.name || undefined
+ }
})))
.flatten().array
});
}));
},
completion: function (dactyl, modules, window) {
- const names = Array.slice(util.computedStyle(window.document.createElement("div")));
+ const names = Array.slice(DOM(<div/>, window.document).style);
modules.completion.css = function (context) {
context.title = ["CSS Property"];
context.keys = { text: function (p) p + ":", description: function () "" };
};
},
javascript: function (dactyl, modules, window) {
- modules.JavaScript.setCompleter(["get", "add", "remove", "find"].map(function (m) styles.user[m]),
+ modules.JavaScript.setCompleter(["get", "add", "remove", "find"].map(function (m) Hive.prototype[m]),
[ // Prototype: (name, filter, css, index)
function (context, obj, args) this.names,
function (context, obj, args) Styles.completeSite(context, window.content),
template.highlightCSS = function highlightCSS(css) {
XML.prettyPrinting = XML.ignoreWhitespace = false;
- return this.highlightRegexp(css, patterns.property, function (match) <>{
- match.preSpace}{template.filter(match.name)}: {
+ return this.highlightRegexp(css, patterns.property, function (match) {
+ if (!match.length)
+ return <></>;
+ return <>{match.preSpace}{template.filter(match.name)}: {
template.highlightRegexp(match.value, patterns.token, function (match) {
if (match.function)
})
}{ match.postSpace }</>
- )
+ })
}
},
});