On Safari 10 constructor check is broken (#237)

* On Safari 10 constructor check is broken.

* Move useragent check

* Make custom element load unconditionally

* Update state-card-content.html
This commit is contained in:
Andrey 2017-03-15 06:57:11 +02:00 committed by Paulus Schoutsen
parent de1b20b70a
commit 215217f652

View File

@ -35,26 +35,14 @@ Polymer({
'inputChanged(hass, inDialog, stateObj)',
],
_isLoaded: function (name) {
var elem = document.createElement(name);
// If Polymer was already loaded for <name> - it replaced the constructor.
return (elem.constructor !== HTMLElement);
},
_maybeLoadCustomUi: function (stateType) {
var isLoaded = this._isLoaded('STATE-CARD-' + stateType.toUpperCase());
// If Polymer component for the required element is not loaded try to load it.
// Don't try to load unconditionally because it cause onflict between vulcanized
// and non-vulacanized versions.
if (!isLoaded) {
this.importHref(
'/local/custom_ui/state-card-' + stateType + '.html',
function () {},
/* eslint-disable no-console */
function () { console.error('Error loading %s from /local/custom_ui/state-card-%s.html', stateType, stateType); },
/* eslint-enable no-console */
true);
}
_ensureCustomUILoaded: function (stateType) {
this.importHref(
'/local/custom_ui/state-card-' + stateType + '.html',
function () {},
/* eslint-disable no-console */
function () { console.error('Error loading %s from /local/custom_ui/state-card-%s.html', stateType, stateType); },
/* eslint-enable no-console */
true);
},
inputChanged: function (hass, inDialog, stateObj) {
@ -62,7 +50,7 @@ Polymer({
if (!stateObj || !hass) return;
if (stateObj.state !== 'unavailable' && 'custom_ui_state_card' in stateObj.attributes) {
stateCardType = stateObj.attributes.custom_ui_state_card;
this._maybeLoadCustomUi(stateCardType);
this._ensureCustomUILoaded(stateCardType);
} else {
stateCardType = window.hassUtil.stateCardType(hass, stateObj);
}