Skip to content

Instantly share code, notes, and snippets.

@AlexanderOMara
Created November 9, 2015 07:54
Show Gist options
  • Save AlexanderOMara/5e83d11cad11f3968428 to your computer and use it in GitHub Desktop.
Save AlexanderOMara/5e83d11cad11f3968428 to your computer and use it in GitHub Desktop.
Firefox invertIconForLightTheme Addon-SDK polyfill.
/**
* Polyfill for invertIconForLightTheme option missing in Firefox < 43 Add-on SDK.
*
* @copyright Alexander O'Mara
* @license MPL-2.0
*
* Conditionally load this polyfill with the following version detection:
*
* const system = require('sdk/system');
* if (parseInt(system.platformVersion) < 43) {
* require('./inverticon-patch');
* }
*/
'use strict';
const { Tool } = require('dev/toolbox');
const { Cu } = require('chrome');
const { gDevTools } = Cu.import('resource:///modules/devtools/gDevTools.jsm', {});
// A lookup object for patching invertIconForLightTheme.
const patchMap = {};
// If the class requests invertIconForLightTheme, remember the ID for later.
const toolSetup = Tool.prototype.setup;
Tool.prototype.setup = function(o) {
if (
o && (o = o.panels) && (o = o.panel) && (o = o.prototype) &&
o.invertIconForLightTheme && o.id
) {
patchMap[o.id] = true;
}
toolSetup.apply(this, arguments);
};
// If this ID requested invertIconForLightTheme, patch it in.
const gDevToolsRegisterTool = gDevTools.registerTool;
gDevTools.registerTool = function(o) {
if (patchMap[o.id]) {
o.invertIconForLightTheme = true;
}
gDevToolsRegisterTool.apply(this, arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment