17 * When false, the image is prevented from loading and any placeholder is
18 * shown. This may be useful when a binding to the src property is known to
19 * be invalid, to prevent 404 requests.
28 * Sets a sizing option for the image. Valid values are `contain` (full
29 * aspect ratio of the image is contained within the element and
30 * letterboxed) or `cover` (image is cropped in order to fully cover the
31 * bounds of the element), or `null` (default: image takes natural size).
40 * When a sizing option is uzed (`cover` or `contain`), this determines
41 * how the image is aligned within the element bounds.
50 * When `true`, any change to the `src` property will cause the `placeholder`
51 * image to be shown until the
60 * This image will be used as a background/placeholder until the src image has
61 * loaded. Use of a data-URI for placeholder is encouraged for instant rendering.
63 * @attribute placeholder
70 * When `preload` is true, setting `fade` to true will cause the image to
80 * Read-only value that tracks the loading state of the image when the `preload`
90 * Can be used to set the width of image (e.g. via binding); size may also be
100 * Can be used to set the height of image (e.g. via binding); size may also be
112 'preload color sizing position src fade': 'update'
115 widthChanged: function() {
116 this.style.width = isNaN(this.width) ? this.width : this.width + 'px';
119 heightChanged: function() {
120 this.style.height = isNaN(this.height) ? this.height : this.height + 'px';
124 this.style.backgroundSize = this.sizing;
125 this.style.backgroundPosition = this.sizing ? this.position : null;
126 this.style.backgroundRepeat = this.sizing ? 'no-repeat' : null;
129 if (!this._placeholderEl) {
130 this._placeholderEl = this.shadowRoot.querySelector('#placeholder');
132 this._placeholderEl.style.backgroundSize = this.sizing;
133 this._placeholderEl.style.backgroundPosition = this.sizing ? this.position : null;
134 this._placeholderEl.style.backgroundRepeat = this.sizing ? 'no-repeat' : null;
135 this._placeholderEl.classList.remove('fadein');
136 this._placeholderEl.style.backgroundImage = (this.load && this.placeholder) ? 'url(' + this.placeholder + ')': null;
138 this._setSrc(this.placeholder);
140 if (this.load && this.src) {
141 var img = new Image();
144 img.onload = function() {
145 this._setSrc(this.src);
146 this.loading = false;
148 this._placeholderEl.classList.add('fadein');
153 this._setSrc(this.src);
157 _setSrc: function(src) {
159 this.style.backgroundImage = src ? 'url(' + src + ')': '';
161 this.$.img.src = src || '';