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

Commit ea43da3

Browse files
feat(theme,layout): support disabling of themes and layouts globally
* use `md-themes-disabled` attribute directive to disable themes: stylesheet generation and DOM in injection * use `md-layouts-disabled` attribute directive to disable layouts: attribute-to-classname conversions are not performed * update(layout, theme): use querySelector to find first only
1 parent 4236a20 commit ea43da3

File tree

4 files changed

+481
-300
lines changed

4 files changed

+481
-300
lines changed

src/core/services/layout/layout.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,25 @@
101101

102102
// Register other, special directive functions for the Layout features:
103103
module
104-
.directive('mdLayoutCss' , disableLayoutDirective )
105-
.directive('ngCloak' , buildCloakInterceptor('ng-cloak'))
104+
105+
.provider('$$mdLayout' , function() {
106+
// Publish internal service for Layouts
107+
return {
108+
$get : angular.noop,
109+
validateAttributeValue : validateAttributeValue,
110+
validateAttributeUsage : validateAttributeUsage,
111+
/**
112+
* Easy way to disable/enable the Layout API.
113+
* When disabled, this stops all attribute-to-classname generations
114+
*/
115+
disableLayouts : function(isDisabled) {
116+
config.enabled = (isDisabled !== true);
117+
}
118+
};
119+
})
120+
121+
.directive('mdLayoutCss' , disableLayoutDirective )
122+
.directive('ngCloak' , buildCloakInterceptor('ng-cloak'))
106123

107124
.directive('layoutWrap' , attributeWithoutValue('layout-wrap'))
108125
.directive('layoutNowrap' , attributeWithoutValue('layout-nowrap'))
@@ -126,7 +143,10 @@
126143
.directive('hideLtMd' , warnAttrNotSupported('hide-lt-md'))
127144
.directive('hideLtLg' , warnAttrNotSupported('hide-lt-lg'))
128145
.directive('showLtMd' , warnAttrNotSupported('show-lt-md'))
129-
.directive('showLtLg' , warnAttrNotSupported('show-lt-lg'));
146+
.directive('showLtLg' , warnAttrNotSupported('show-lt-lg'))
147+
148+
// Determine if
149+
.config( detectDisabledLayouts );
130150

131151
/**
132152
* Converts snake_case to camelCase.
@@ -143,6 +163,21 @@
143163

144164
}
145165

166+
167+
/**
168+
* Detect if any of the HTML tags has a [md-layouts-disabled] attribute;
169+
* If yes, then immediately disable all layout API features
170+
*
171+
* Note: this attribute should be specified on either the HTML or BODY tags
172+
*/
173+
/**
174+
* @ngInject
175+
*/
176+
function detectDisabledLayouts() {
177+
var isDisabled = !!document.querySelector('[md-layouts-disabled]');
178+
config.enabled = !isDisabled;
179+
}
180+
146181
/**
147182
* Special directive that will disable ALL Layout conversions of layout
148183
* attribute(s) to classname(s).
@@ -164,13 +199,12 @@
164199
*
165200
*/
166201
function disableLayoutDirective() {
202+
// Return a 1x-only, first-match attribute directive
203+
config.enabled = false;
204+
167205
return {
168206
restrict : 'A',
169-
priority : '900',
170-
compile : function(element, attr) {
171-
config.enabled = false;
172-
return angular.noop;
173-
}
207+
priority : '900'
174208
};
175209
}
176210

0 commit comments

Comments
 (0)