2016-06-09 23:54:03 -07:00
|
|
|
|
define(['browser', 'css!./emby-button', 'registerElement'], function (browser) {
|
2016-06-04 17:17:35 -07:00
|
|
|
|
|
|
|
|
|
var EmbyButtonPrototype = Object.create(HTMLButtonElement.prototype);
|
|
|
|
|
|
2016-06-05 13:46:19 -07:00
|
|
|
|
function animateButtonInternal(e, btn) {
|
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
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 13:46:19 -07:00
|
|
|
|
function animateButton(e) {
|
|
|
|
|
|
|
|
|
|
var btn = this;
|
|
|
|
|
requestAnimationFrame(function () {
|
|
|
|
|
animateButtonInternal(e, btn);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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-25 13:18:23 -07:00
|
|
|
|
function enableAnimation() {
|
|
|
|
|
if (browser.tv) {
|
|
|
|
|
// too slow
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 17:17:35 -07:00
|
|
|
|
EmbyButtonPrototype.attachedCallback = function () {
|
|
|
|
|
|
2016-08-04 23:10:24 -07:00
|
|
|
|
if (this.classList.contains('emby-button')) {
|
2016-06-04 17:17:35 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-04 23:10:24 -07:00
|
|
|
|
this.classList.add('emby-button');
|
2016-06-04 17:17:35 -07:00
|
|
|
|
|
2016-06-15 09:45:45 -07:00
|
|
|
|
if (browser.safari || browser.firefox || browser.noFlex) {
|
2016-08-04 23:10:24 -07:00
|
|
|
|
this.classList.add('emby-button-noflex');
|
2016-06-06 14:12:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-25 13:18:23 -07:00
|
|
|
|
if (enableAnimation()) {
|
|
|
|
|
this.addEventListener('keydown', onKeyDown);
|
|
|
|
|
if (browser.safari) {
|
|
|
|
|
this.addEventListener('click', animateButton);
|
|
|
|
|
} else {
|
|
|
|
|
this.addEventListener('mousedown', onMouseDown);
|
|
|
|
|
//this.addEventListener('touchstart', animateButton);
|
|
|
|
|
}
|
2016-06-04 21:49:29 -07:00
|
|
|
|
}
|
2016-06-04 17:17:35 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.registerElement('emby-button', {
|
|
|
|
|
prototype: EmbyButtonPrototype,
|
|
|
|
|
extends: 'button'
|
|
|
|
|
});
|
|
|
|
|
});
|