2016-05-28 11:03:38 -07:00
|
|
|
|
define(['layoutManager', 'browser', 'css!./emby-input'], function (layoutManager, browser) {
|
|
|
|
|
|
|
|
|
|
var EmbyInputPrototype = Object.create(HTMLInputElement.prototype);
|
|
|
|
|
|
2016-06-03 12:32:10 -07:00
|
|
|
|
var inputId = 0;
|
|
|
|
|
|
2016-06-04 17:17:35 -07:00
|
|
|
|
if (Object.getOwnPropertyDescriptor && Object.defineProperty) {
|
|
|
|
|
|
|
|
|
|
var descriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
|
|
|
|
|
|
2016-06-04 21:49:29 -07:00
|
|
|
|
if (descriptor.configurable) {
|
|
|
|
|
var baseSetMethod = descriptor.set;
|
|
|
|
|
descriptor.set = function (value) {
|
|
|
|
|
baseSetMethod.call(this, value);
|
|
|
|
|
this.dispatchEvent(new CustomEvent('valueset', {
|
|
|
|
|
bubbles: false,
|
|
|
|
|
cancelable: false
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(HTMLInputElement.prototype, 'value', descriptor);
|
2016-06-04 17:17:35 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-28 11:03:38 -07:00
|
|
|
|
EmbyInputPrototype.createdCallback = function () {
|
|
|
|
|
|
|
|
|
|
if (!this.id) {
|
2016-06-03 12:32:10 -07:00
|
|
|
|
this.id = 'embyinput' + inputId;
|
|
|
|
|
inputId++;
|
2016-05-28 11:03:38 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EmbyInputPrototype.attachedCallback = function () {
|
|
|
|
|
|
2016-05-29 11:42:03 -07:00
|
|
|
|
if (this.getAttribute('data-embyinput') == 'true') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-05-28 11:03:38 -07:00
|
|
|
|
|
2016-05-29 11:42:03 -07:00
|
|
|
|
this.setAttribute('data-embyinput', 'true');
|
|
|
|
|
|
|
|
|
|
var parentNode = this.parentNode;
|
|
|
|
|
var label = this.ownerDocument.createElement('label');
|
|
|
|
|
label.innerHTML = this.getAttribute('label') || '';
|
|
|
|
|
label.classList.add('inputLabel');
|
2016-05-28 11:03:38 -07:00
|
|
|
|
|
2016-05-29 11:42:03 -07:00
|
|
|
|
label.htmlFor = this.id;
|
|
|
|
|
parentNode.insertBefore(label, this);
|
|
|
|
|
|
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.classList.add('emby-input-selectionbar');
|
|
|
|
|
parentNode.insertBefore(div, this.nextSibling);
|
|
|
|
|
|
|
|
|
|
function onChange() {
|
|
|
|
|
if (this.value) {
|
|
|
|
|
label.classList.remove('blank');
|
|
|
|
|
} else {
|
|
|
|
|
label.classList.add('blank');
|
|
|
|
|
}
|
2016-05-28 11:03:38 -07:00
|
|
|
|
}
|
2016-05-29 11:42:03 -07:00
|
|
|
|
|
|
|
|
|
this.addEventListener('focus', function () {
|
|
|
|
|
onChange.call(this);
|
2016-05-30 09:09:47 -07:00
|
|
|
|
label.classList.add('focused');
|
2016-05-29 11:42:03 -07:00
|
|
|
|
});
|
|
|
|
|
this.addEventListener('blur', function () {
|
2016-06-04 17:17:35 -07:00
|
|
|
|
onChange.call(this);
|
2016-05-30 09:09:47 -07:00
|
|
|
|
label.classList.remove('focused');
|
2016-05-29 11:42:03 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.addEventListener('change', onChange);
|
2016-06-03 21:57:46 -07:00
|
|
|
|
this.addEventListener('input', onChange);
|
2016-06-04 17:17:35 -07:00
|
|
|
|
this.addEventListener('valueset', onChange);
|
2016-05-29 11:42:03 -07:00
|
|
|
|
|
|
|
|
|
onChange.call(this);
|
2016-05-29 12:41:39 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EmbyInputPrototype.detachedCallback = function () {
|
|
|
|
|
|
|
|
|
|
var observer = this.observer;
|
|
|
|
|
if (observer) {
|
|
|
|
|
observer.disconnect();
|
|
|
|
|
this.observer = null;
|
|
|
|
|
}
|
2016-05-28 11:03:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.registerElement('emby-input', {
|
|
|
|
|
prototype: EmbyInputPrototype,
|
|
|
|
|
extends: 'input'
|
|
|
|
|
});
|
|
|
|
|
});
|