@@ -51,18 +51,29 @@ function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdU
51
51
this . options = rippleOptions ;
52
52
this . mousedown = false ;
53
53
this . ripples = [ ] ;
54
- this . container = null ;
55
- this . color = null ;
56
- this . background = null ;
57
54
this . timeout = null ; // Stores a reference to the most-recent ripple timeout
58
55
this . lastRipple = null ;
59
56
57
+ this . valueOnUse ( 'container' , angular . bind ( this , this . createContainer ) ) ;
58
+ this . valueOnUse ( 'color' , angular . bind ( this , this . getColor , 1 ) ) ;
59
+ this . valueOnUse ( 'background' , angular . bind ( this , this . getColor , 0.5 ) ) ;
60
+
60
61
// attach method for unit tests
61
62
( $element . controller ( 'mdInkRipple' ) || { } ) . createRipple = angular . bind ( this , this . createRipple ) ;
62
63
63
64
this . bindEvents ( ) ;
64
65
}
65
66
67
+ InkRippleCtrl . prototype . valueOnUse = function ( key , getter ) {
68
+ var value = null ;
69
+ Object . defineProperty ( this , key , {
70
+ get : function ( ) {
71
+ if ( value === null ) value = getter ( ) ;
72
+ return value ;
73
+ }
74
+ } ) ;
75
+ } ;
76
+
66
77
/**
67
78
* Returns the color that the ripple should be (either based on CSS or hard-coded)
68
79
* @returns {string }
@@ -189,10 +200,6 @@ InkRippleCtrl.prototype.clearTimeout = function () {
189
200
* @param top
190
201
*/
191
202
InkRippleCtrl . prototype . createRipple = function ( left , top ) {
192
- if ( ! this . container ) this . container = this . createContainer ( ) ;
193
- if ( ! this . color ) this . color = this . getColor ( ) ;
194
- if ( ! this . background ) this . background = this . getColor ( 0.5 ) ;
195
-
196
203
var ctrl = this ;
197
204
var ripple = angular . element ( '<div class="md-ripple"></div>' ) ;
198
205
var width = this . $element . prop ( 'clientWidth' ) ;
0 commit comments