jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/emby-button/paper-icon-button-light.js

82 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-12-14 13:58:55 -07:00
define(['browser', 'dom', 'layoutManager', 'css!./emby-button', 'registerElement'], function (browser, dom, layoutManager) {
2016-10-03 22:15:39 -07:00
'use strict';
2016-06-05 13:46:19 -07:00
var EmbyButtonPrototype = Object.create(HTMLButtonElement.prototype);
2016-06-25 13:18:23 -07:00
function enableAnimation() {
if (browser.tv) {
// too slow
return false;
}
return true;
}
2016-06-05 13:46:19 -07:00
function animateButtonInternal(e, btn) {
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-05 13:46:19 -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';
}
btn.appendChild(div);
2016-11-26 22:00:20 -07:00
div.addEventListener(dom.whichAnimationEvent(), function () {
2016-06-05 13:46:19 -07:00
div.parentNode.removeChild(div);
}, false);
}
2016-10-05 21:28:10 -07:00
function animateButton(e, btn) {
2016-06-05 13:46:19 -07:00
requestAnimationFrame(function () {
animateButtonInternal(e, btn);
});
}
function onKeyDown(e) {
2016-10-03 22:15:39 -07:00
if (e.keyCode === 13) {
2016-10-05 21:28:10 -07:00
animateButton(e, this);
2016-06-05 13:46:19 -07:00
}
}
2016-10-05 21:28:10 -07:00
function onClick(e) {
animateButton(e, this);
}
2016-08-22 11:28:24 -07:00
EmbyButtonPrototype.createdCallback = function () {
2016-06-05 13:46:19 -07:00
2016-08-04 19:03:15 -07:00
if (this.classList.contains('paper-icon-button-light')) {
2016-06-05 13:46:19 -07:00
return;
}
2016-08-04 19:03:15 -07:00
this.classList.add('paper-icon-button-light');
2016-06-05 13:46:19 -07:00
2016-12-14 13:58:55 -07:00
if (layoutManager.tv) {
this.classList.add('icon-button-focusscale');
}
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-10-05 21:28:10 -07:00
dom.addEventListener(this, 'click', onClick, {
2016-08-07 12:43:52 -07:00
passive: true
});
2016-06-25 13:18:23 -07:00
}
2016-06-05 13:46:19 -07:00
};
document.registerElement('paper-icon-button-light', {
prototype: EmbyButtonPrototype,
extends: 'button'
});
});