|
101 | 101 |
|
102 | 102 | // Register other, special directive functions for the Layout features:
|
103 | 103 | 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')) |
106 | 123 |
|
107 | 124 | .directive('layoutWrap' , attributeWithoutValue('layout-wrap'))
|
108 | 125 | .directive('layoutNowrap' , attributeWithoutValue('layout-nowrap'))
|
|
126 | 143 | .directive('hideLtMd' , warnAttrNotSupported('hide-lt-md'))
|
127 | 144 | .directive('hideLtLg' , warnAttrNotSupported('hide-lt-lg'))
|
128 | 145 | .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 ); |
130 | 150 |
|
131 | 151 | /**
|
132 | 152 | * Converts snake_case to camelCase.
|
|
143 | 163 |
|
144 | 164 | }
|
145 | 165 |
|
| 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 | + |
146 | 181 | /**
|
147 | 182 | * Special directive that will disable ALL Layout conversions of layout
|
148 | 183 | * attribute(s) to classname(s).
|
|
164 | 199 | *
|
165 | 200 | */
|
166 | 201 | function disableLayoutDirective() {
|
| 202 | + // Return a 1x-only, first-match attribute directive |
| 203 | + config.enabled = false; |
| 204 | + |
167 | 205 | return {
|
168 | 206 | restrict : 'A',
|
169 |
| - priority : '900', |
170 |
| - compile : function(element, attr) { |
171 |
| - config.enabled = false; |
172 |
| - return angular.noop; |
173 |
| - } |
| 207 | + priority : '900' |
174 | 208 | };
|
175 | 209 | }
|
176 | 210 |
|
|
0 commit comments