2016-06-04 21:49:29 -07:00
|
|
|
|
define(['browser', 'css!./emby-button'], function (browser) {
|
2016-06-04 17:17:35 -07:00
|
|
|
|
|
|
|
|
|
var EmbyButtonPrototype = Object.create(HTMLButtonElement.prototype);
|
|
|
|
|
|
|
|
|
|
function animateButton(e) {
|
|
|
|
|
|
2016-06-04 21:49:29 -07:00
|
|
|
|
var btn = this;
|
2016-06-04 17:17:35 -07:00
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
|
|
|
|
|
div.classList.add('ripple-effect');
|
|
|
|
|
|
|
|
|
|
var offsetX = e.offsetX || 0;
|
|
|
|
|
var offsetY = e.offsetY || 0;
|
|
|
|
|
|
|
|
|
|
if (offsetX > 0 && offsetY > 0) {
|
|
|
|
|
div.style.left = offsetX + 'px';
|
|
|
|
|
div.style.top = offsetY + 'px';
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 21:49:29 -07:00
|
|
|
|
btn.appendChild(div);
|
2016-06-04 17:17:35 -07:00
|
|
|
|
|
2016-06-04 21:49:29 -07:00
|
|
|
|
div.addEventListener("animationend", function () {
|
2016-06-04 17:17:35 -07:00
|
|
|
|
div.parentNode.removeChild(div);
|
2016-06-04 20:50:07 -07:00
|
|
|
|
}, false);
|
2016-06-04 17:17:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onKeyDown(e) {
|
|
|
|
|
|
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
|
animateButton.call(this, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 20:50:07 -07:00
|
|
|
|
function onMouseDown(e) {
|
|
|
|
|
|
|
|
|
|
if (e.button == 0) {
|
|
|
|
|
animateButton.call(this, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 17:17:35 -07:00
|
|
|
|
EmbyButtonPrototype.attachedCallback = function () {
|
|
|
|
|
|
|
|
|
|
if (this.getAttribute('data-embybutton') == 'true') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setAttribute('data-embybutton', 'true');
|
|
|
|
|
|
|
|
|
|
this.addEventListener('keydown', onKeyDown);
|
2016-06-04 21:49:29 -07:00
|
|
|
|
if (browser.safari) {
|
|
|
|
|
this.addEventListener('click', animateButton);
|
|
|
|
|
} else {
|
|
|
|
|
this.addEventListener('mousedown', onMouseDown);
|
|
|
|
|
//this.addEventListener('touchstart', animateButton);
|
|
|
|
|
}
|
2016-06-04 17:17:35 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.registerElement('emby-button', {
|
|
|
|
|
prototype: EmbyButtonPrototype,
|
|
|
|
|
extends: 'button'
|
|
|
|
|
});
|
|
|
|
|
});
|