vuetify
Version:
Vue.js 2 Semantic Component Framework
157 lines (131 loc) • 4.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function style(el, value) {
el.style['transform'] = value;
el.style['webkitTransform'] = value;
}
var RippleDataAttribute = 'data-ripple';
var ripple = {
/**
* @param {Event} e
* @param {Element} el
* @param {{ class?: string, center?: boolean }} [value={}]
*/
show: function show(e, el, _ref) {
var _ref$value = _ref.value,
value = _ref$value === undefined ? {} : _ref$value;
if (el.getAttribute(RippleDataAttribute) !== 'true') {
return;
}
var container = document.createElement('span');
var animation = document.createElement('span');
container.appendChild(animation);
container.className = 'ripple__container';
if (value.class) {
container.className += ' ' + value.class;
}
var size = el.clientWidth > el.clientHeight ? el.clientWidth : el.clientHeight;
animation.className = 'ripple__animation';
animation.style.width = size * (value.center ? 1 : 2) + 'px';
animation.style.height = animation.style.width;
el.appendChild(container);
var computed = window.getComputedStyle(el);
if (computed.position !== 'absolute' && computed.position !== 'fixed') el.style.position = 'relative';
var offset = el.getBoundingClientRect();
var x = value.center ? '50%' : e.clientX - offset.left + 'px';
var y = value.center ? '50%' : e.clientY - offset.top + 'px';
animation.classList.add('ripple__animation--enter');
animation.classList.add('ripple__animation--visible');
style(animation, 'translate(-50%, -50%) translate(' + x + ', ' + y + ') scale3d(0.01,0.01,0.01)');
animation.dataset.activated = Date.now();
setTimeout(function () {
animation.classList.remove('ripple__animation--enter');
style(animation, 'translate(-50%, -50%) translate(' + x + ', ' + y + ') scale3d(0.99,0.99,0.99)');
}, 0);
},
hide: function hide(el) {
if (el.getAttribute(RippleDataAttribute) !== 'true') {
return;
}
var ripples = el.getElementsByClassName('ripple__animation');
if (ripples.length === 0) return;
var animation = ripples[ripples.length - 1];
var diff = Date.now() - Number(animation.dataset.activated);
var delay = 400 - diff;
delay = delay < 0 ? 0 : delay;
setTimeout(function () {
animation.classList.remove('ripple__animation--visible');
setTimeout(function () {
// Need to figure out a new way to do this
try {
if (ripples.length < 1) el.style.position = null;
animation.parentNode && el.removeChild(animation.parentNode);
} catch (e) {}
}, 300);
}, delay);
}
};
function isRippleEnabled(binding) {
return typeof binding.value === 'undefined' || !!binding.value;
}
function directive(el, binding) {
el.setAttribute(RippleDataAttribute, isRippleEnabled(binding));
if ('ontouchstart' in window) {
el.addEventListener('touchend', function () {
return ripple.hide(el);
}, false);
el.addEventListener('touchcancel', function () {
return ripple.hide(el);
}, false);
}
el.addEventListener('mousedown', function (e) {
return ripple.show(e, el, binding);
}, false);
el.addEventListener('mouseup', function () {
return ripple.hide(el);
}, false);
el.addEventListener('mouseleave', function () {
return ripple.hide(el);
}, false);
// Anchor tags can be dragged, causes other hides to fail - #1537
el.addEventListener('dragstart', function () {
return ripple.hide(el);
}, false);
}
function unbind(el, binding) {
el.removeEventListener('touchstart', function (e) {
return ripple.show(e, el, binding);
}, false);
el.removeEventListener('mousedown', function (e) {
return ripple.show(e, el, binding);
}, false);
el.removeEventListener('touchend', function () {
return ripple.hide(el);
}, false);
el.removeEventListener('touchcancel', function () {
return ripple.hide(el);
}, false);
el.removeEventListener('mouseup', function () {
return ripple.hide(el);
}, false);
el.removeEventListener('mouseleave', function () {
return ripple.hide(el);
}, false);
el.removeEventListener('dragstart', function () {
return ripple.hide(el);
}, false);
}
function update(el, binding) {
if (binding.value === binding.oldValue) {
return;
}
el.setAttribute(RippleDataAttribute, isRippleEnabled(binding));
}
exports.default = {
name: 'ripple',
bind: directive,
unbind: unbind,
update: update
};