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

Commit

Permalink
feat(theme): allow global disable of theming generation
Browse files Browse the repository at this point in the history
Support config-time disabling of Theming which in turn prevents
dynamic theme css generation and stylesheet injections.

```js
angular
   .module('myApp',['ngMaterial'])
   .config(['$mdThemingProvider', function($mdThemingProvider ){
      $mdThemingProvider.disableTheming();
   }]);
```

Refs #943. Closes #7959.
  • Loading branch information
ThomasBurleson committed Apr 11, 2016
1 parent 57ab6d9 commit cb69404
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/services/theming/theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ var generateOnDemand = false;

// Nonce to be added as an attribute to the generated themes style tags.
var nonce = null;
var disableTheming = false;

function ThemingProvider($mdColorPalette) {
PALETTES = { };
Expand All @@ -153,6 +154,15 @@ function ThemingProvider($mdColorPalette) {
extendPalette: extendPalette,
theme: registerTheme,

/**
* Easy way to disable theming without having to use
* `.constant("$MD_THEME_CSS","");` This disables
* all dynamic theme style sheet generations and injections...
*/
disableTheming: function() {
disableTheming = true;

This comment has been minimized.

Copy link
@iamaaron

iamaaron Apr 11, 2016

Thanks so much!

},

setNonce: function(nonceValue) {
nonce = nonceValue;
},
Expand Down Expand Up @@ -487,7 +497,7 @@ var rulesByType = {};
function generateAllThemes($injector) {
var head = document.head;
var firstChild = head ? head.firstElementChild : null;
var themeCss = $injector.has('$MD_THEME_CSS') ? $injector.get('$MD_THEME_CSS') : '';
var themeCss = !disableTheming && $injector.has('$MD_THEME_CSS') ? $injector.get('$MD_THEME_CSS') : '';

if ( !firstChild ) return;
if (themeCss.length === 0) return; // no rules, so no point in running this expensive task
Expand Down

0 comments on commit cb69404

Please sign in to comment.