2 * Angular Material Design
3 * https://github.com/angular/material
7 goog.provide('ngmaterial.components.button');
8 goog.require('ngmaterial.core');
11 * @name material.components.button
16 MdButtonDirective['$inject'] = ["$mdButtonInkRipple", "$mdTheming", "$mdAria", "$mdInteraction"];
17 MdAnchorDirective['$inject'] = ["$mdTheming"];
19 .module('material.components.button', [ 'material.core' ])
20 .directive('mdButton', MdButtonDirective)
21 .directive('a', MdAnchorDirective);
29 * `a` is an anchor directive used to inherit theme colors for md-primary, md-accent, etc.
34 * <md-content md-theme="myTheme">
35 * <a href="#chapter1" class="md-accent"></a>
39 function MdAnchorDirective($mdTheming) {
42 link : function postLink(scope, element) {
43 // Make sure to inherit theme so stand-alone anchors
44 // support theme colors for md-primary, md-accent, etc.
54 * @module material.components.button
59 * `<md-button>` is a button directive with optional ink ripples (default enabled).
61 * If you supply a `href` or `ng-href` attribute, it will become an `<a>` element. Otherwise, it
62 * will become a `<button>` element. As per the
63 * [Material Design specifications](https://material.google.com/style/color.html#color-color-palette)
64 * the FAB button background is filled with the accent color [by default]. The primary color palette
65 * may be used with the `md-primary` class.
67 * Developers can also change the color palette of the button, by using the following classes
75 * <md-button class="md-primary">Primary Button</md-button>
78 * Button can be also raised, which means that they will use the current color palette to fill the button.
81 * <md-button class="md-accent md-raised">Raised and Accent Button</md-button>
84 * It is also possible to disable the focus effect on the button, by using the following markup.
87 * <md-button class="md-no-focus">No Focus Style</md-button>
90 * @param {boolean=} md-no-ink If present, disable ripple ink effects.
91 * @param {expression=} ng-disabled En/Disable based on the expression
92 * @param {string=} md-ripple-size Overrides the default ripple size logic. Options: `full`, `partial`, `auto`
93 * @param {string=} aria-label Adds alternative text to button for accessibility, useful for icon buttons.
94 * If no default text is found, a warning will be logged.
101 * <md-button> Flat Button </md-button>
102 * <md-button href="http://google.com"> Flat link </md-button>
103 * <md-button class="md-raised"> Raised Button </md-button>
104 * <md-button ng-disabled="true"> Disabled Button </md-button>
106 * <md-icon md-svg-src="your/icon.svg"></md-icon>
114 * <md-button class="md-fab" aria-label="FAB">
115 * <md-icon md-svg-src="your/icon.svg"></md-icon>
118 * <md-button class="md-fab md-mini" aria-label="Mini FAB">
119 * <md-icon md-svg-src="your/icon.svg"></md-icon>
121 * <!-- Button with SVG Icon -->
122 * <md-button class="md-icon-button" aria-label="Custom Icon Button">
123 * <md-icon md-svg-icon="path/to/your.svg"></md-icon>
127 function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $mdInteraction) {
133 template: getTemplate,
137 function isAnchor(attr) {
138 return angular.isDefined(attr.href) || angular.isDefined(attr.ngHref) || angular.isDefined(attr.ngLink) || angular.isDefined(attr.uiSref);
141 function getTemplate(element, attr) {
142 if (isAnchor(attr)) {
143 return '<a class="md-button" ng-transclude></a>';
145 //If buttons don't have type="button", they will submit forms automatically.
146 var btnType = (typeof attr.type === 'undefined') ? 'button' : attr.type;
147 return '<button class="md-button" type="' + btnType + '" ng-transclude></button>';
151 function postLink(scope, element, attr) {
153 $mdButtonInkRipple.attach(scope, element);
155 // Use async expect to support possible bindings in the button label
156 $mdAria.expectWithoutText(element, 'aria-label');
158 // For anchor elements, we have to set tabindex manually when the
159 // element is disabled
160 if (isAnchor(attr) && angular.isDefined(attr.ngDisabled) ) {
161 scope.$watch(attr.ngDisabled, function(isDisabled) {
162 element.attr('tabindex', isDisabled ? -1 : 0);
166 // disabling click event when disabled is true
167 element.on('click', function(e){
168 if (attr.disabled === true) {
170 e.stopImmediatePropagation();
174 if (!element.hasClass('md-no-focus')) {
176 element.on('focus', function() {
178 // Only show the focus effect when being focused through keyboard interaction or programmatically
179 if (!$mdInteraction.isUserInvoked() || $mdInteraction.getLastInteractionType() === 'keyboard') {
180 element.addClass('md-focused');
185 element.on('blur', function() {
186 element.removeClass('md-focused');
194 ngmaterial.components.button = angular.module("material.components.button");