forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.js
More file actions
85 lines (72 loc) · 2.3 KB
/
button.js
File metadata and controls
85 lines (72 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* MUI Angular Button Component
* @module angular/button
*/
var jqLite = require('../js/lib/jqLite');
module.exports = angular.module('mui.button', [])
.directive('muiButton', function() {
return {
restrict: 'AE',
scope: {
type: '@?'
},
replace: true,
template: '<button class="mui-btn" type={{type}} mui-ripple ng-transclude></button>',
transclude: true,
link: function(scope, element, attrs) {
var isUndef = angular.isUndefined,
el = element[0];
// disable MUI js
el._muiDropdown = true;
el._muiRipple = true;
// handle disabled attribute
if (!isUndef(attrs.disabled) && isUndef(attrs.ngDisabled)) {
element.prop('disabled', true);
}
// set button styles
angular.forEach(['variant', 'color', 'size'], function(attrName) {
var attrVal = attrs[attrName];
if (attrVal) element.addClass('mui-btn--' + attrVal);
});
}
};
})
.directive('muiRipple', ['$timeout', function($timeout) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var rippleClass = 'mui-ripple-effect';
/**
* onmousedown ripple effect
* @param {event} mousedown event
*/
element.on('mousedown', function(event) {
if (element.prop('disabled')) return;
var offset = jqLite.offset(element[0]),
xPos = event.pageX - offset.left,
yPos = event.pageY - offset.top,
diameter,
radius;
diameter = offset.height;
if (element.hasClass('mui-btn--fab')) diameter = offset.height / 2;
radius = diameter / 2;
// ripple Dom position
var rippleStyle = {
height: diameter + 'px',
width: diameter + 'px',
top: (yPos - radius) + 'px',
left: (xPos - radius) + 'px'
};
var ripple = angular.element('<div></div>').addClass(rippleClass);
for (var style in rippleStyle) {
ripple.css(style, rippleStyle[style]);
}
element.append(ripple);
// remove after delay
$timeout(function() {
ripple.remove();
}, 2000);
});
}
};
}]);