summaryrefslogtreecommitdiff
path: root/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/userstyles.js
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@gnu.org>2015-11-28 15:24:36 -0600
committerRuben Rodriguez <ruben@gnu.org>2015-11-28 16:27:06 -0600
commite4a3586a14996bbece3b26c9e3b7704ea6af8615 (patch)
tree499bdd16b3a90c30b01e4b47a5882d13b4800f50 /data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/userstyles.js
parent4dbc2fae927bb02ef243c87938e638af9afee8fa (diff)
LibreJS upgraded to 6.0.10
Diffstat (limited to 'data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/userstyles.js')
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/userstyles.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/userstyles.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/userstyles.js
new file mode 100644
index 0000000..0cc3414
--- /dev/null
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/userstyles.js
@@ -0,0 +1,72 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+'use strict';
+
+const { Cc, Ci } = require("chrome");
+const { unload } = require('./addon/unload');
+
+const sss = Cc["@mozilla.org/content/style-sheet-service;1"]
+ .getService(Ci.nsIStyleSheetService);
+
+function getURI(aURL) Cc["@mozilla.org/network/io-service;1"]
+ .getService(Ci.nsIIOService).newURI(aURL, null, null);
+
+function setOptions(url, options) {
+ let newOptions = {};
+ options = options || {};
+
+ newOptions.uri = getURI(url);
+ newOptions.type = (options.type || 'user').toLowerCase();
+ newOptions.type = (newOptions.type == 'agent') ? sss.AGENT_SHEET : sss.USER_SHEET;
+
+ return newOptions;
+};
+
+// capture the unload callbacks for removing the unload function from
+// the queue as they are no longer needed when a URL is unregistered manually
+var unloaders = {};
+
+function removeUnload(url) {
+ if (typeof unloaders[url] === "function") {
+ unloaders[url].call(null);
+ delete unloaders[url];
+ }
+}
+
+/**
+ * Load various packaged styles for the add-on and undo on unload
+ *
+ * @usage load(aURL): Load specified style
+ * @param [string] aURL: Style file to load
+ * @param [object] options:
+ */
+const loadSS = exports.load = function loadSS(url, options) {
+ let { uri, type } = setOptions(url, options);
+
+ // load the stylesheet
+ sss.loadAndRegisterSheet(uri, type);
+
+ // remove the unloader for this URL if it exists
+ removeUnload(url);
+
+ // unload the stylesheet on unload
+ unloaders[url] = unload(unregisterSS.bind(null, url, options));
+};
+
+const registeredSS = exports.registered = function registeredSS(url, options) {
+ let { uri, type } = setOptions(url, options);
+
+ // check that the stylesheet is registered
+ return !!sss.sheetRegistered(uri, type);
+};
+
+const unregisterSS = exports.unload = function unregisterSS(url, options) {
+ let { uri, type } = setOptions(url, options);
+
+ // remove the unloader our load function setup if it exists
+ removeUnload(url);
+
+ // unregister the stylesheet
+ sss.unregisterSheet(uri, type);
+};