@@ -51,18 +51,29 @@ function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdU
5151 this . options = rippleOptions ;
5252 this . mousedown = false ;
5353 this . ripples = [ ] ;
54- this . container = null ;
55- this . color = null ;
56- this . background = null ;
5754 this . timeout = null ; // Stores a reference to the most-recent ripple timeout
5855 this . lastRipple = null ;
5956
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+
6061 // attach method for unit tests
6162 ( $element . controller ( 'mdInkRipple' ) || { } ) . createRipple = angular . bind ( this , this . createRipple ) ;
6263
6364 this . bindEvents ( ) ;
6465}
6566
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+
6677/**
6778 * Returns the color that the ripple should be (either based on CSS or hard-coded)
6879 * @returns {string }
@@ -189,10 +200,6 @@ InkRippleCtrl.prototype.clearTimeout = function () {
189200 * @param top
190201 */
191202InkRippleCtrl . 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-
196203 var ctrl = this ;
197204 var ripple = angular . element ( '<div class="md-ripple"></div>' ) ;
198205 var width = this . $element . prop ( 'clientWidth' ) ;
0 commit comments