Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 1057346 - Support for relative style URL
Browse files Browse the repository at this point in the history
  • Loading branch information
janodvarko committed Dec 16, 2014
1 parent a9dd3c7 commit fca2f57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 5 additions & 7 deletions examples/theme/lib/main.js
Expand Up @@ -3,23 +3,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

const self = require("sdk/self");

const { Tool } = require("dev/toolbox");
const { Class } = require("sdk/core/heritage");
const { Style } = require("sdk/stylesheet/style");
const { onEnable, onDisable } = require("dev/theme/hooks");
const { Theme, LightTheme } = require("dev/theme");

/**
* This object represents a new theme registered within the Toolbox
* You can activate it by clicking on "My Light Theme" in the Options
* panel. The theme derives styles from built-in Light theme.
* This object represents a new theme registered within the Toolbox.
* You can activate it by clicking on "My Light Theme" theme option
* in the Options panel.
* Note that the new theme derives styles from built-in Light theme.
*/
const MyTheme = Theme({
name: "mytheme",
label: "My Light Theme",
styles: [LightTheme, self.data.url("theme.css")],
styles: [LightTheme, "./theme.css"],

onEnable: function(window, oldTheme) {
console.log("myTheme.onEnable; method override " +
Expand Down
11 changes: 7 additions & 4 deletions lib/dev/theme.js
Expand Up @@ -8,16 +8,16 @@ module.metadata = {
"stability": "experimental"
};

const { Cu } = require("chrome");
const { Class } = require("../sdk/core/heritage");
const { EventTarget } = require("../sdk/event/target");
const { Disposable, setup, dispose } = require("../sdk/core/disposable");
const { contract, validate } = require("../sdk/util/contract");
const { id: addonID } = require("../sdk/self");
const { onEnable, onDisable } = require("dev/theme/hooks");
const { Style } = require("sdk/stylesheet/style");
const { isString, instanceOf, isFunction } = require("sdk/lang/type");
const { add } = require("sdk/util/array");
const { data } = require("../sdk/self");
const { isLocalURL } = require("../sdk/url");

const makeID = name =>
("dev-theme-" + addonID + (name ? "-" + name : "")).
Expand Down Expand Up @@ -55,9 +55,12 @@ const Theme = Class({
let result = [];
for (let style of this.styles) {
if (isString(style)) {
if (isLocalURL(style)) {
style = data.url(style);
}
add(result, style);
} else if (instanceOf(style, Theme)) {
result = result.concat(style.getStyles())
result = result.concat(style.getStyles());
}
}
return result;
Expand All @@ -66,7 +69,7 @@ const Theme = Class({
let result = [];
for (let style of this.styles) {
if (instanceOf(style, Theme)) {
result = result.concat(style.getClassList())
result = result.concat(style.getClassList());
}
}

Expand Down

0 comments on commit fca2f57

Please sign in to comment.