Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(theming): fix theming in safari
Browse files Browse the repository at this point in the history
closes #2209, references #2066
  • Loading branch information
JulianWielga authored and rschmukler committed Apr 12, 2015
1 parent 4faa7e8 commit 1ebc42e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/core/services/theming/theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ function parseRules(theme, colorType, rules) {
generatedRules.push(newRule);
});

return generatedRules.join('');
return generatedRules;
}

// Generate our themes at run time given the state of THEMES and PALETTES
Expand Down Expand Up @@ -495,16 +495,17 @@ function generateThemes($injector) {
angular.forEach(THEMES, function(theme) {
if ( !GENERATED[theme.name] ) {

var styleStrings = '';
var style = document.createElement('style');
style.setAttribute('type', 'text/css');

THEME_COLOR_TYPES.forEach(function(colorType) {
styleStrings += parseRules(theme, colorType, rulesByType[colorType] + '');
var styleStrings = parseRules(theme, colorType, rulesByType[colorType]);
while (styleStrings.length) {
var style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.appendChild(document.createTextNode(styleStrings.shift()));
head.insertBefore(style, firstChild);
}
});

style.innerHTML = styleStrings;
head.insertBefore(style, firstChild);

if (theme.colors.primary.name == theme.colors.accent.name) {
console.warn("$mdThemingProvider: Using the same palette for primary and" +
Expand Down
5 changes: 3 additions & 2 deletions src/core/services/theming/theming.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('$mdThemingProvider', function() {

function parse(str) {
return themingProvider._parseRules(testTheme, 'primary', str)
.join('')
.split(/\}(?!(\}|'|"|;))/)
.filter(function(val) { return !!val; })
.map(function(rule) {
Expand All @@ -169,13 +170,13 @@ describe('$mdThemingProvider', function() {
it('errors if given a theme with invalid palettes', function() {
testTheme.primaryPalette('invalidPalette');
expect(function() {
themingProvider._parseRules(testTheme, 'primary', '');
themingProvider._parseRules(testTheme, 'primary', '').join('');
}).toThrow();
});
it('replaces THEME_NAME', function() {
expect(themingProvider._parseRules(
testTheme, 'primary', '.md-THEME_NAME-theme {}'
)).toContain('.md-test-theme {}');
).join('')).toContain('.md-test-theme {}');
});
describe('parses foreground text and shadow', function() {
it('for a light theme', function() {
Expand Down

0 comments on commit 1ebc42e

Please sign in to comment.