(js, css) Improve sg-ripple-click directive

This commit is contained in:
Francis Lachapelle
2016-08-01 12:13:11 -04:00
parent 0ec79e0411
commit 8389ec5f40
2 changed files with 27 additions and 12 deletions
@@ -70,27 +70,42 @@
element.on('click', listener);
function listener(event) {
var coordinates;
if (element[0].hasAttribute('disabled')) {
return;
}
if (event.pageX && event.pageY) {
// Event is a mouse click
coordinates = { left: event.pageX, top: event.pageY };
}
else {
// Event is a form submit; target is the submit button
coordinates = event.target.getBoundingClientRect();
}
if (content.classList.contains('ng-hide')) {
// Show ripple
angular.element(container).css({ 'overflow': 'hidden' });
content.classList.remove('ng-hide');
angular.element(content).css({ top: container.scrollTop + 'px' });
ripple.css({
'top': (event.pageY - container.offsetTop + container.scrollTop) + 'px',
'left': (event.pageX - container.offsetLeft) + 'px',
'width': '400vmin',
'height': '400vmin'
});
$timeout(function() {
// Wait until next digest for CSS animation to work
ripple.css({
'top': (coordinates.top - container.offsetTop + container.scrollTop) + 'px',
'left': (coordinates.left - container.offsetLeft) + 'px',
'height': '400vmin',
'width': '400vmin'
});
// Show ripple content
content.classList.remove('ng-hide');
});
}
else {
// Hide ripple layer
ripple.css({
'top': (event.pageY - container.offsetTop + container.scrollTop) + 'px',
'left': (event.pageX - container.offsetLeft) + 'px',
'top': (coordinates.top - container.offsetTop + container.scrollTop) + 'px',
'left': (coordinates.left - container.offsetLeft) + 'px',
'height': '0px',
'width': '0px'
});