/*! * Angular Material Design * https://github.com/angular/material * @license MIT * v1.1.1 */ goog.provide('ngmaterial.components.button'); goog.require('ngmaterial.core'); /** * @ngdoc module * @name material.components.button * @description * * Button */ MdButtonDirective.$inject = ["$mdButtonInkRipple", "$mdTheming", "$mdAria", "$timeout"]; MdAnchorDirective.$inject = ["$mdTheming"]; angular .module('material.components.button', [ 'material.core' ]) .directive('mdButton', MdButtonDirective) .directive('a', MdAnchorDirective); /** * @private * @restrict E * * @description * `a` is an anchor directive used to inherit theme colors for md-primary, md-accent, etc. * * @usage * * * * * * */ function MdAnchorDirective($mdTheming) { return { restrict : 'E', link : function postLink(scope, element) { // Make sure to inherit theme so stand-alone anchors // support theme colors for md-primary, md-accent, etc. $mdTheming(element); } }; } /** * @ngdoc directive * @name mdButton * @module material.components.button * * @restrict E * * @description * `` is a button directive with optional ink ripples (default enabled). * * If you supply a `href` or `ng-href` attribute, it will become an `` element. Otherwise, it * will become a `'; } } function postLink(scope, element, attr) { $mdTheming(element); $mdButtonInkRipple.attach(scope, element); // Use async expect to support possible bindings in the button label $mdAria.expectWithoutText(element, 'aria-label'); // For anchor elements, we have to set tabindex manually when the // element is disabled if (isAnchor(attr) && angular.isDefined(attr.ngDisabled) ) { scope.$watch(attr.ngDisabled, function(isDisabled) { element.attr('tabindex', isDisabled ? -1 : 0); }); } // disabling click event when disabled is true element.on('click', function(e){ if (attr.disabled === true) { e.preventDefault(); e.stopImmediatePropagation(); } }); if (!element.hasClass('md-no-focus')) { // restrict focus styles to the keyboard scope.mouseActive = false; element.on('mousedown', function() { scope.mouseActive = true; $timeout(function(){ scope.mouseActive = false; }, 100); }) .on('focus', function() { if (scope.mouseActive === false) { element.addClass('md-focused'); } }) .on('blur', function(ev) { element.removeClass('md-focused'); }); } } } ngmaterial.components.button = angular.module("material.components.button");