Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(ripple): add the ability to disable ripples globally
Browse files Browse the repository at this point in the history
Exposes the `$mdInkRippleProvider` during app config and allows the user to disable ripples globally via the `disableInkRipple` method.

Fixes #5669.

Closes #8191
  • Loading branch information
crisbeto authored and ThomasBurleson committed May 11, 2016
1 parent 918e335 commit 86bb3f7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 25 deletions.
78 changes: 53 additions & 25 deletions src/core/services/ripple/ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Ripple
*/
angular.module('material.core')
.factory('$mdInkRipple', InkRippleService)
.provider('$mdInkRipple', InkRippleProvider)
.directive('mdInkRipple', InkRippleDirective)
.directive('mdNoInk', attrNoDirective)
.directive('mdNoBar', attrNoDirective)
Expand Down Expand Up @@ -84,32 +84,60 @@ function InkRippleDirective ($mdButtonInkRipple, $mdCheckboxInkRipple) {
* }
* });
* </hljs>
*/

/**
* @ngdoc method
* @name $mdInkRipple#attach
*
* @description
* Attaching given scope, element and options to inkRipple controller
* ### Disabling ripples globally
* If you want to disable ink ripples globally, for all components, you can call the
* `disableInkRipple` method in your app's config.
*
* @param {object=} scope Scope within the current context
* @param {object=} element The element the ripple effect should be applied to
* @param {object=} options (Optional) Configuration options to override the defaultRipple configuration
* * `center` - Whether the ripple should start from the center of the container element
* * `dimBackground` - Whether the background should be dimmed with the ripple color
* * `colorElement` - The element the ripple should take its color from, defined by css property `color`
* * `fitRipple` - Whether the ripple should fill the element
* <hljs lang="js">
* app.config(function ($mdInkRippleProvider) {
* $mdInkRippleProvider.disableInkRipple();
* });
*/
function InkRippleService ($injector) {
return { attach: attach };
function attach (scope, element, options) {
if (element.controller('mdNoInk')) return angular.noop;
return $injector.instantiate(InkRippleCtrl, {
$scope: scope,
$element: element,
rippleOptions: options
});

function InkRippleProvider () {
var isDisabledGlobally = false;

return {
disableInkRipple: disableInkRipple,
$get: function($injector) {
return { attach: attach };

/**
* @ngdoc method
* @name $mdInkRipple#attach
*
* @description
* Attaching given scope, element and options to inkRipple controller
*
* @param {object=} scope Scope within the current context
* @param {object=} element The element the ripple effect should be applied to
* @param {object=} options (Optional) Configuration options to override the defaultRipple configuration
* * `center` - Whether the ripple should start from the center of the container element
* * `dimBackground` - Whether the background should be dimmed with the ripple color
* * `colorElement` - The element the ripple should take its color from, defined by css property `color`
* * `fitRipple` - Whether the ripple should fill the element
*/
function attach (scope, element, options) {
if (isDisabledGlobally || element.controller('mdNoInk')) return angular.noop;
return $injector.instantiate(InkRippleCtrl, {
$scope: scope,
$element: element,
rippleOptions: options
});
}
}
};

/**
* @ngdoc method
* @name $mdInkRipple#disableInkRipple
*
* @description
* A config-time method that, when called, disables ripples globally.
*/
function disableInkRipple () {
isDisabledGlobally = true;
}
}

Expand Down Expand Up @@ -202,7 +230,7 @@ InkRippleCtrl.prototype.calculateColor = function () {
InkRippleCtrl.prototype._parseColor = function parseColor (color, multiplier) {
multiplier = multiplier || 1;
var colorUtil = this.$mdColorUtil;

if (!color) return;
if (color.indexOf('rgba') === 0) return color.replace(/\d?\.?\d*\s*\)\s*$/, (0.1 * multiplier).toString() + ')');
if (color.indexOf('rgb') === 0) return colorUtil.rgbToRgba(color);
Expand Down
14 changes: 14 additions & 0 deletions src/core/services/ripple/ripple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,17 @@ describe('mdInkRipple directive', function() {
}));
});
});

describe('disabling ripples globally', function() {
beforeEach(function() {
module('material.core', function($mdInkRippleProvider) {
$mdInkRippleProvider.disableInkRipple();
});
});

it('should not instantiate the ripple controller', inject(function ($compile, $rootScope) {
var elem = $compile('<div md-ink-ripple="true"></div>')($rootScope.$new());
var controller = elem.controller('mdInkRipple');
expect(Object.keys(controller).length).toBe(0);
}));
});

0 comments on commit 86bb3f7

Please sign in to comment.