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

Commit

Permalink
amend(): fix test problems for themes, fix firefox problems
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Dec 16, 2014
1 parent de58777 commit 7322c5d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
18 changes: 18 additions & 0 deletions config/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ var TestUtil = {

beforeEach(function() {

module('material.core.theming', function($mdThemingProvider) {
// Create a test version of every default palette, using a copy of the below palette.
var defaultPalette = {
'50': 'ffebee', '100': 'ffcdd2', '200': 'ef9a9a', '300': 'e57373',
'400': 'ef5350', '500': 'f44336', '600': 'e53935', '700': 'd32f2f',
'800': 'c62828', '900': 'b71c1c', 'A100': 'ff8a80', 'A200': 'ff5252',
'A400': 'ff1744', 'A700': 'd50000',
'contrastDefaultColor': 'light',
'contrastDarkColors': ['50', '100', '200', '300', '400', 'A100']
};
(
'red pink purple deep-purple indigo blue light-blue cyan teal green light-green lime ' +
'yellow amber orange deep-orange brown grey blue-grey'
).split(' ').forEach(function(themeName) {
$mdThemingProvider.definePalette(themeName, angular.extend({}, defaultPalette));
});
});

this.addMatchers({
// toHaveClass matcher from angularjs test helpers
toHaveClass: function(clazz) {
Expand Down
1 change: 0 additions & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function MdCoreInitialize() {
function MdCoreConfigure($provide, $mdThemingProvider) {
$provide.decorator('$$rAF', ['$delegate', '$rootScope', rAFDecorator]);

// Define a default theme with our newly loaded colors
$mdThemingProvider.theme('default')
.primaryColor('blue')
.accentColor('green')
Expand Down
11 changes: 7 additions & 4 deletions src/core/services/theming/theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict';

angular.module('material.core.theming', [])
.constant('$MD_THEME_CSS', '{}') // This is overwritten when angular-material is built
.directive('mdTheme', ThemingDirective)
.directive('mdThemable', ThemableDirective)
.provider('$mdTheming', ThemingProvider)
Expand Down Expand Up @@ -134,7 +133,8 @@ function ThemingProvider() {
// Get rid of leading and trailing quote
content = content ? content.substring(1,content.length-1) : '{}';

var parsed = JSON.parse(content);
// Remove backslashes that firefox gives
var parsed = JSON.parse(content.replace(/\\/g, ''));
angular.extend(PALETTES, parsed);
document.body.removeChild(element);
}
Expand All @@ -143,6 +143,7 @@ function ThemingProvider() {
function definePalette(name, map) {
map = map || {};
PALETTES[name] = checkPaletteValid(name, map);
return themingProvider;
}

// Returns an new object which is a copy of a given palette `name` with variables from
Expand Down Expand Up @@ -397,15 +398,17 @@ function parseRules(theme, colorType, rules) {
}

// Generate our themes at run time given the state of THEMES and PALETTES
function generateThemes($MD_THEME_CSS) {
function generateThemes($injector) {
var themeCss = $injector.has('$MD_THEME_CSS') ? $injector.get('$MD_THEME_CSS') : '';

// MD_THEME_CSS is a string generated by the build process that includes all the themable
// components as templates

// Expose contrast colors for palettes to ensure that text is always readable
angular.forEach(PALETTES, sanitizePalette);

// Break the CSS into individual rules
var rules = $MD_THEME_CSS.split(/\}(?!(\}|'|"|;))/)
var rules = themeCss.split(/\}(?!(\}|'|"|;))/)
.filter(function(rule) { return rule && rule.length; })
.map(function(rule) { return rule.trim() + '}'; });

Expand Down
1 change: 1 addition & 0 deletions src/core/services/theming/theming.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('$mdThemingProvider', function() {
var startAngular = inject;
function setup() {
module('material.core.theming', function($mdThemingProvider, $provide) {
$provide.value('$MD_THEME_CSS', '{}');
themingProvider = $mdThemingProvider;

testPalette = themingProvider._PALETTES.testPalette = {
Expand Down

0 comments on commit 7322c5d

Please sign in to comment.