8
8
*/
9
9
angular . module ( 'material.core.theming' , [ 'material.core.theming.palette' , 'material.core.meta' ] )
10
10
. directive ( 'mdTheme' , ThemingDirective )
11
+ . directive ( 'mdDeferredTheme' , ThemingDirective )
11
12
. directive ( 'mdThemable' , ThemableDirective )
12
13
. directive ( 'mdThemesDisabled' , disableThemesDirective )
13
14
. provider ( '$mdTheming' , ThemingProvider )
@@ -552,6 +553,28 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
552
553
applyTheme . registered = registered ;
553
554
applyTheme . defaultTheme = function ( ) { return defaultTheme ; } ;
554
555
applyTheme . generateTheme = function ( name ) { generateTheme ( THEMES [ name ] , name , themeConfig . nonce ) ; } ;
556
+ applyTheme . defineTheme = function ( name , options ) {
557
+ options = options || { } ;
558
+
559
+ var theme = registerTheme ( name ) ;
560
+
561
+ if ( options . primary ) {
562
+ theme . primaryPalette ( options . primary ) ;
563
+ }
564
+ if ( options . accent ) {
565
+ theme . accentPalette ( options . accent ) ;
566
+ }
567
+ if ( options . warn ) {
568
+ theme . warnPalette ( options . warn ) ;
569
+ }
570
+ if ( options . background ) {
571
+ theme . backgroundPalette ( options . background ) ;
572
+ }
573
+
574
+ this . generateTheme ( name ) ;
575
+
576
+ return theme ;
577
+ } ;
555
578
applyTheme . setBrowserColor = enableBrowserColor ;
556
579
557
580
return applyTheme ;
@@ -593,7 +616,7 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
593
616
*/
594
617
function updateThemeClass ( theme ) {
595
618
if ( ! theme ) return ;
596
- if ( ! registered ( theme ) ) {
619
+ if ( ! ctrl . $isDeferredTheme && ! registered ( theme ) ) {
597
620
$log . warn ( 'Attempted to use unregistered theme \'' + theme + '\'. ' +
598
621
'Register it with $mdThemingProvider.theme().' ) ;
599
622
}
@@ -628,6 +651,7 @@ function ThemingDirective($mdTheming, $interpolate, $log) {
628
651
priority : 100 ,
629
652
link : {
630
653
pre : function ( scope , el , attrs ) {
654
+ var isDeferred = attrs . hasOwnProperty ( 'mdDeferredTheme' ) ;
631
655
var registeredCallbacks = [ ] ;
632
656
var ctrl = {
633
657
registerChanges : function ( cb , context ) {
@@ -646,19 +670,21 @@ function ThemingDirective($mdTheming, $interpolate, $log) {
646
670
} ;
647
671
} ,
648
672
$setTheme : function ( theme ) {
649
- if ( ! $mdTheming . registered ( theme ) ) {
673
+ if ( ! isDeferred && ! $mdTheming . registered ( theme ) ) {
650
674
$log . warn ( 'attempted to use unregistered theme \'' + theme + '\'' ) ;
651
675
}
652
676
ctrl . $mdTheme = theme ;
677
+ ctrl . $isDeferredTheme = isDeferred ;
653
678
654
679
registeredCallbacks . forEach ( function ( cb ) {
655
680
cb ( ) ;
656
681
} ) ;
657
682
}
658
683
} ;
659
684
el . data ( '$mdThemeController' , ctrl ) ;
660
- ctrl . $setTheme ( $interpolate ( attrs . mdTheme ) ( scope ) ) ;
661
- attrs . $observe ( 'mdTheme' , ctrl . $setTheme ) ;
685
+ var directiveType = isDeferred ? 'mdDeferredTheme' : 'mdTheme' ;
686
+ ctrl . $setTheme ( $interpolate ( attrs [ directiveType ] ) ( scope ) ) ;
687
+ attrs . $observe ( directiveType , ctrl . $setTheme ) ;
662
688
}
663
689
}
664
690
} ;
0 commit comments