2016-08-07 12:43:52 -07:00
|
|
|
|
define(['browser', 'dom', 'css!./emby-button', 'registerElement'], function (browser, dom) {
|
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');
|
|
|
|
|
|
2016-08-14 09:53:23 -07:00
|
|
|
|
for (var i = 0, length = btn.classList.length; i < length; i++) {
|
|
|
|
|
div.classList.add(btn.classList[i] + '-ripple-effect');
|
|
|
|
|
}
|
2016-06-04 17:17:35 -07:00
|
|
|
|
|
|
|
|
|
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-08-14 09:53:23 -07:00
|
|
|
|
var firstChild = btn.firstChild;
|
|
|
|
|
if (firstChild) {
|
|
|
|
|
btn.insertBefore(div, btn.firstChild);
|
|
|
|
|
} else {
|
|
|
|
|
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-08-12 22:49:00 -07:00
|
|
|
|
EmbyButtonPrototype.createdCallback = function () {
|
2016-06-04 17:17:35 -07:00
|
|
|
|
|
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()) {
|
2016-08-07 12:43:52 -07:00
|
|
|
|
dom.addEventListener(this, 'keydown', onKeyDown, {
|
|
|
|
|
passive: true
|
|
|
|
|
});
|
2016-06-25 13:18:23 -07:00
|
|
|
|
if (browser.safari) {
|
2016-08-07 12:43:52 -07:00
|
|
|
|
dom.addEventListener(this, 'click', animateButton, {
|
|
|
|
|
passive: true
|
|
|
|
|
});
|
2016-06-25 13:18:23 -07:00
|
|
|
|
} else {
|
2016-08-07 12:43:52 -07:00
|
|
|
|
dom.addEventListener(this, 'mousedown', onMouseDown, {
|
|
|
|
|
passive: true
|
|
|
|
|
});
|
2016-06-25 13:18:23 -07:00
|
|
|
|
//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'
|
|
|
|
|
});
|
|
|
|
|
});
|