Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #131 from PolymerElements/auto-cleanup
Browse files Browse the repository at this point in the history
Automatic format!
  • Loading branch information
e111077 authored Apr 10, 2018
2 parents ebc4e5c + 74ef571 commit d8c9e7f
Show file tree
Hide file tree
Showing 7 changed files with 1,872 additions and 442 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ before_script:
npm run update-types && git diff --exit-code || (echo -e
'\n\033[31mERROR:\033[0m Typings are stale. Please run "npm run
update-types".' && false)
- >-
npm run format && git diff --exit-code || (echo -e '\n\033[31mERROR:\033[0m
Project is not formatted. Please run "npm run format".' && false)
env:
global:
- secure: >-
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<script>
function load(id) {
document.getElementById(id).src = "./polymer.svg?" + Math.random();
document.getElementById(id).src = './polymer.svg?' + Math.random();
}
</script>

Expand Down
24 changes: 13 additions & 11 deletions iron-image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ interface IronImageElement extends Polymer.Element {
alt: string|null|undefined;

/**
* CORS enabled images support: https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
* CORS enabled images support:
* https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
*/
crossorigin: string|null|undefined;

Expand All @@ -102,14 +103,15 @@ interface IronImageElement extends Polymer.Element {
position: string|null|undefined;

/**
* When `true`, any change to the `src` property will cause the `placeholder`
* image to be shown until the new image has loaded.
* When `true`, any change to the `src` property will cause the
* `placeholder` image to be shown until the new image has loaded.
*/
preload: boolean|null|undefined;

/**
* This image will be used as a background/placeholder until the src image has
* loaded. Use of a data-URI for placeholder is encouraged for instant rendering.
* This image will be used as a background/placeholder until the src image
* has loaded. Use of a data-URI for placeholder is encouraged for instant
* rendering.
*/
placeholder: string|null|undefined;

Expand All @@ -125,8 +127,8 @@ interface IronImageElement extends Polymer.Element {
readonly loaded: boolean|null|undefined;

/**
* Read-only value that tracks the loading state of the image when the `preload`
* option is used.
* Read-only value that tracks the loading state of the image when the
* `preload` option is used.
*/
readonly loading: boolean|null|undefined;

Expand All @@ -136,14 +138,14 @@ interface IronImageElement extends Polymer.Element {
readonly error: boolean|null|undefined;

/**
* Can be used to set the width of image (e.g. via binding); size may also be
* set via CSS.
* Can be used to set the width of image (e.g. via binding); size may also
* be set via CSS.
*/
width: number|null|undefined;

/**
* Can be used to set the height of image (e.g. via binding); size may also be
* set via CSS.
* Can be used to set the height of image (e.g. via binding); size may also
* be set via CSS.
*/
height: number|null|undefined;
created(): void;
Expand Down
134 changes: 43 additions & 91 deletions iron-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,140 +149,90 @@
/**
* The URL of an image.
*/
src: {
type: String,
value: ''
},
src: {type: String, value: ''},

/**
* A short text alternative for the image.
*/
alt: {
type: String,
value: null
},
alt: {type: String, value: null},

/**
* CORS enabled images support: https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
* CORS enabled images support:
* https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
*/
crossorigin: {
type: String,
value: null
},
crossorigin: {type: String, value: null},

/**
* When true, the image is prevented from loading and any placeholder is
* shown. This may be useful when a binding to the src property is known to
* be invalid, to prevent 404 requests.
*/
preventLoad: {
type: Boolean,
value: false
},
preventLoad: {type: Boolean, value: false},

/**
* Sets a sizing option for the image. Valid values are `contain` (full
* aspect ratio of the image is contained within the element and
* letterboxed) or `cover` (image is cropped in order to fully cover the
* bounds of the element), or `null` (default: image takes natural size).
*/
sizing: {
type: String,
value: null,
reflectToAttribute: true
},
sizing: {type: String, value: null, reflectToAttribute: true},

/**
* When a sizing option is used (`cover` or `contain`), this determines
* how the image is aligned within the element bounds.
*/
position: {
type: String,
value: 'center'
},
position: {type: String, value: 'center'},

/**
* When `true`, any change to the `src` property will cause the `placeholder`
* image to be shown until the new image has loaded.
* When `true`, any change to the `src` property will cause the
* `placeholder` image to be shown until the new image has loaded.
*/
preload: {
type: Boolean,
value: false
},
preload: {type: Boolean, value: false},

/**
* This image will be used as a background/placeholder until the src image has
* loaded. Use of a data-URI for placeholder is encouraged for instant rendering.
* This image will be used as a background/placeholder until the src image
* has loaded. Use of a data-URI for placeholder is encouraged for instant
* rendering.
*/
placeholder: {
type: String,
value: null,
observer: '_placeholderChanged'
},
placeholder: {type: String, value: null, observer: '_placeholderChanged'},

/**
* When `preload` is true, setting `fade` to true will cause the image to
* fade into place.
*/
fade: {
type: Boolean,
value: false
},
fade: {type: Boolean, value: false},

/**
* Read-only value that is true when the image is loaded.
*/
loaded: {
notify: true,
readOnly: true,
type: Boolean,
value: false
},
loaded: {notify: true, readOnly: true, type: Boolean, value: false},

/**
* Read-only value that tracks the loading state of the image when the `preload`
* option is used.
* Read-only value that tracks the loading state of the image when the
* `preload` option is used.
*/
loading: {
notify: true,
readOnly: true,
type: Boolean,
value: false
},
loading: {notify: true, readOnly: true, type: Boolean, value: false},

/**
* Read-only value that indicates that the last set `src` failed to load.
*/
error: {
notify: true,
readOnly: true,
type: Boolean,
value: false
},
error: {notify: true, readOnly: true, type: Boolean, value: false},

/**
* Can be used to set the width of image (e.g. via binding); size may also be
* set via CSS.
* Can be used to set the width of image (e.g. via binding); size may also
* be set via CSS.
*/
width: {
observer: '_widthChanged',
type: Number,
value: null
},
width: {observer: '_widthChanged', type: Number, value: null},

/**
* Can be used to set the height of image (e.g. via binding); size may also be
* set via CSS.
* Can be used to set the height of image (e.g. via binding); size may also
* be set via CSS.
*
* @attribute height
* @type number
* @default null
*/
height: {
observer: '_heightChanged',
type: Number,
value: null
},
height: {observer: '_heightChanged', type: Number, value: null},
},

observers: [
Expand Down Expand Up @@ -322,7 +272,9 @@
},

_computePlaceholderClassName: function() {
return (this.preload && this.fade && !this.loading && this.loaded) ? 'faded-out' : '';
return (this.preload && this.fade && !this.loading && this.loaded) ?
'faded-out' :
'';
},

_computeImgDivHidden: function() {
Expand Down Expand Up @@ -381,7 +333,8 @@
} else {
this._resolvedSrc = newResolvedSrc;
this.$.img.src = this._resolvedSrc;
this.$.sizedImgDiv.style.backgroundImage = 'url("' + this._resolvedSrc + '")';
this.$.sizedImgDiv.style.backgroundImage =
'url("' + this._resolvedSrc + '")';

this._setLoading(true);
this._setLoaded(false);
Expand All @@ -391,35 +344,34 @@

_placeholderChanged: function() {
this.$.placeholder.style.backgroundImage =
this.placeholder ? 'url("' + this.placeholder + '")' : '';
this.placeholder ? 'url("' + this.placeholder + '")' : '';
},

_transformChanged: function() {
var sizedImgDivStyle = this.$.sizedImgDiv.style;
var placeholderStyle = this.$.placeholder.style;

sizedImgDivStyle.backgroundSize =
placeholderStyle.backgroundSize =
this.sizing;
sizedImgDivStyle.backgroundSize = placeholderStyle.backgroundSize =
this.sizing;

sizedImgDivStyle.backgroundPosition =
placeholderStyle.backgroundPosition =
this.sizing ? this.position : '';
sizedImgDivStyle.backgroundPosition = placeholderStyle.backgroundPosition =
this.sizing ? this.position : '';

sizedImgDivStyle.backgroundRepeat =
placeholderStyle.backgroundRepeat =
this.sizing ? 'no-repeat' : '';
sizedImgDivStyle.backgroundRepeat = placeholderStyle.backgroundRepeat =
this.sizing ? 'no-repeat' : '';
},

_resolveSrc: function(testSrc) {
var resolved = Polymer.ResolveUrl.resolveUrl(testSrc, this.$.baseURIAnchor.href);
var resolved =
Polymer.ResolveUrl.resolveUrl(testSrc, this.$.baseURIAnchor.href);
// NOTE: Use of `URL` was removed here because IE11 doesn't support
// constructing it. If this ends up being problematic, we should
// consider reverting and adding the URL polyfill as a dev dependency.
if (resolved[0] === '/') {
// In IE location.origin might not work
// https://connect.microsoft.com/IE/feedback/details/1763802/location-origin-is-undefined-in-ie-11-on-windows-10-but-works-on-windows-7
resolved = (location.origin || location.protocol + '//' + location.host) + resolved;
resolved = (location.origin || location.protocol + '//' + location.host) +
resolved;
}
return resolved;
}
Expand Down
Loading

0 comments on commit d8c9e7f

Please sign in to comment.