@@ -55,14 +55,12 @@ function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdU
55
55
this . lastRipple = null ;
56
56
57
57
$mdUtil . valueOnUse ( this , 'container' , this . createContainer ) ;
58
- $mdUtil . valueOnUse ( this , 'background' , this . getColor , 0.5 ) ;
59
58
60
- this . color = this . getColor ( 1 ) ;
61
59
this . $element . addClass ( 'md-ink-ripple' ) ;
62
60
63
61
// attach method for unit tests
64
62
( $element . controller ( 'mdInkRipple' ) || { } ) . createRipple = angular . bind ( this , this . createRipple ) ;
65
- ( $element . controller ( 'mdInkRipple' ) || { } ) . setColor = angular . bind ( this , this . setColor ) ;
63
+ ( $element . controller ( 'mdInkRipple' ) || { } ) . setColor = angular . bind ( this , this . color ) ;
66
64
67
65
this . bindEvents ( ) ;
68
66
}
@@ -86,20 +84,37 @@ function autoCleanup (self, cleanupFn) {
86
84
* Returns the color that the ripple should be (either based on CSS or hard-coded)
87
85
* @returns {string }
88
86
*/
89
- InkRippleCtrl . prototype . getColor = function ( ) {
90
- return this . _parseColor ( this . $element . attr ( 'md-ink-ripple' ) )
91
- || this . _parseColor ( getElementColor . call ( this ) ) ;
87
+ InkRippleCtrl . prototype . color = function ( value ) {
88
+
89
+ // If assigning a color value, apply it to background and the ripple color
90
+ if ( angular . isDefined ( value ) ) {
91
+ this . _color = this . _parseColor ( value ) ;
92
+ }
93
+
94
+ // If color lookup, use assigned, defined, or inherited
95
+ return this . _color || this . _parseColor ( this . inkRipple ( ) ) || this . _parseColor ( getElementColor ( this ) ) ;
92
96
93
97
/**
94
98
* Finds the color element and returns its text color for use as default ripple color
95
99
* @returns {string }
96
100
*/
97
- function getElementColor ( ) {
98
- var colorElement = this . options . colorElement && this . options . colorElement [ 0 ] ;
99
- colorElement = colorElement || this . $element [ 0 ] ;
100
- return colorElement ? this . $window . getComputedStyle ( colorElement ) . color : 'rgb(0,0,0)' ;
101
+ function getElementColor ( self ) {
102
+ var items = self . options && self . options . colorElement ? self . options . colorElement : [ ] ;
103
+ var elem = items . length ? items [ 0 ] : self . $element [ 0 ] ;
104
+
105
+ return elem ? self . $window . getComputedStyle ( elem ) . color : 'rgb(0,0,0)' ;
101
106
}
102
107
} ;
108
+
109
+ /**
110
+ * Updating the ripple colors based on the current inkRipple value
111
+ * or the element's computed style color
112
+ */
113
+ InkRippleCtrl . prototype . calculateColor = function ( ) {
114
+ return this . color ( ) ;
115
+ } ;
116
+
117
+
103
118
/**
104
119
* Takes a string color and converts it to RGBA format
105
120
* @param color {string}
@@ -161,8 +176,6 @@ InkRippleCtrl.prototype.bindEvents = function () {
161
176
InkRippleCtrl . prototype . handleMousedown = function ( event ) {
162
177
if ( this . mousedown ) return ;
163
178
164
- this . setColor ( window . getComputedStyle ( this . $element [ 0 ] ) [ 'color' ] ) ;
165
-
166
179
// When jQuery is loaded, we have to get the original event
167
180
if ( event . hasOwnProperty ( 'originalEvent' ) ) event = event . originalEvent ;
168
181
this . mousedown = true ;
@@ -229,11 +242,24 @@ InkRippleCtrl.prototype.isRippleAllowed = function () {
229
242
var element = this . $element [ 0 ] ;
230
243
do {
231
244
if ( ! element . tagName || element . tagName === 'BODY' ) break ;
232
- if ( element && element . hasAttribute && element . hasAttribute ( 'disabled' ) ) return false ;
245
+
246
+ if ( element && angular . isFunction ( element . hasAttribute ) ) {
247
+ if ( element . hasAttribute ( 'disabled' ) ) return false ;
248
+ if ( this . inkRipple ( ) === 'false' || this . inkRipple ( ) === '0' ) return false ;
249
+ }
250
+
233
251
} while ( element = element . parentNode ) ;
234
252
return true ;
235
253
} ;
236
254
255
+ /**
256
+ * The attribute `md-ink-ripple` may be a static or interpolated
257
+ * color value OR a boolean indicator (used to disable ripples)
258
+ */
259
+ InkRippleCtrl . prototype . inkRipple = function ( ) {
260
+ return this . $element . attr ( 'md-ink-ripple' ) ;
261
+ } ;
262
+
237
263
/**
238
264
* Creates a new ripple and adds it to the container. Also tracks ripple in `this.ripples`.
239
265
* @param left
@@ -249,15 +275,16 @@ InkRippleCtrl.prototype.createRipple = function (left, top) {
249
275
var x = Math . max ( Math . abs ( width - left ) , left ) * 2 ;
250
276
var y = Math . max ( Math . abs ( height - top ) , top ) * 2 ;
251
277
var size = getSize ( this . options . fitRipple , x , y ) ;
278
+ var color = this . calculateColor ( ) ;
252
279
253
280
ripple . css ( {
254
281
left : left + 'px' ,
255
282
top : top + 'px' ,
256
283
background : 'black' ,
257
284
width : size + 'px' ,
258
285
height : size + 'px' ,
259
- backgroundColor : rgbaToRGB ( this . color ) ,
260
- borderColor : rgbaToRGB ( this . color )
286
+ backgroundColor : rgbaToRGB ( color ) ,
287
+ borderColor : rgbaToRGB ( color )
261
288
} ) ;
262
289
this . lastRipple = ripple ;
263
290
@@ -268,7 +295,7 @@ InkRippleCtrl.prototype.createRipple = function (left, top) {
268
295
if ( ! ctrl . mousedown ) ctrl . fadeInComplete ( ripple ) ;
269
296
} , DURATION * 0.35 , false ) ;
270
297
271
- if ( this . options . dimBackground ) this . container . css ( { backgroundColor : this . background } ) ;
298
+ if ( this . options . dimBackground ) this . container . css ( { backgroundColor : color } ) ;
272
299
this . container . append ( ripple ) ;
273
300
this . ripples . push ( ripple ) ;
274
301
ripple . addClass ( 'md-ripple-placed' ) ;
@@ -295,9 +322,7 @@ InkRippleCtrl.prototype.createRipple = function (left, top) {
295
322
}
296
323
} ;
297
324
298
- InkRippleCtrl . prototype . setColor = function ( color ) {
299
- this . color = this . _parseColor ( color ) ;
300
- } ;
325
+
301
326
302
327
/**
303
328
* After fadeIn finishes, either kicks off the fade-out animation or queues the element for removal on mouseup
0 commit comments