mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Make media_player hide image it can't load. (#208)
* Make media_player hide image it can't load. * Add timeout for background image loading.
This commit is contained in:
parent
62aa635390
commit
7c9c03a087
@ -248,8 +248,33 @@ Polymer({
|
|||||||
|
|
||||||
playerObjChanged: function (playerObj) {
|
playerObjChanged: function (playerObj) {
|
||||||
var picture = playerObj.stateObj.attributes.entity_picture;
|
var picture = playerObj.stateObj.attributes.entity_picture;
|
||||||
|
var dummy;
|
||||||
if (picture) {
|
if (picture) {
|
||||||
this.$.cover.style.backgroundImage = 'url(' + picture + ')';
|
dummy = document.createElement('IMG');
|
||||||
|
dummy.onload = function () {
|
||||||
|
this.$.cover.style.backgroundImage = 'url(' + picture + ')';
|
||||||
|
dummy.onerror = dummy.onload = null;
|
||||||
|
dummy.src = '';
|
||||||
|
dummy = null;
|
||||||
|
}.bind(this);
|
||||||
|
dummy.onerror = function () {
|
||||||
|
this.$.cover.style.backgroundImage = '';
|
||||||
|
this.toggleClass('no-cover', true, this.$.cover.parentElement);
|
||||||
|
dummy.onerror = dummy.onload = null;
|
||||||
|
dummy.src = '';
|
||||||
|
dummy = null;
|
||||||
|
}.bind(this);
|
||||||
|
if (this._timeout_id) {
|
||||||
|
clearTimeout(this._timeout_id);
|
||||||
|
}
|
||||||
|
this._timeout_id = setTimeout(function () {
|
||||||
|
if (dummy) {
|
||||||
|
// Background load still inflight. Clear real image.
|
||||||
|
this.$.cover.style.backgroundImage = '';
|
||||||
|
}
|
||||||
|
this._timeout_id = null;
|
||||||
|
}, 5000);
|
||||||
|
dummy.src = picture;
|
||||||
} else {
|
} else {
|
||||||
this.$.cover.style.backgroundImage = '';
|
this.$.cover.style.backgroundImage = '';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user