Skip to content

Commit

Permalink
Merge pull request #803 from GrabarzUndPartner/feature/speedkit-pictu…
Browse files Browse the repository at this point in the history
…re-prop-sort-sources

fix(speedkit-picture): added prop for disable source sorting
  • Loading branch information
ThornWalli committed May 2, 2023
2 parents e85f8c3 + fa73be1 commit 54f56f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/content/3.guide/5.components/speedkit-picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ If not set, the global crossorigin is used `this.$speedkit.crossorigin`.

[MDN - HTML.Attributes.crossorigin](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin)

### `sortSources`

- Type: `Boolean`
- Default: `true`

If set, the sources are sorted by the `media` properties.

This is made possible by [`sort-css-media-queries`](https://www.npmjs.com/package/sort-css-media-queries).

### `critical`

- Type: `Boolean`
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/components/SpeedkitPicture/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export default {
return this.$speedkit.crossorigin;
},
validator: val => ['anonymous', 'use-credentials', '', true, false].includes(val)
},
sortSources: {
type: Boolean,
default: true
}
},
Expand Down Expand Up @@ -92,7 +97,7 @@ export default {
computed: {
sourceList () {
return SourceList.create(this.sources);
return SourceList.create(this.sources, { sort: this.sortSources });
},
formatSources () {
Expand Down
11 changes: 9 additions & 2 deletions src/runtime/components/SpeedkitPicture/classes/SourceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ const sortByMediaQueries = createSort();

export default class SourceList {
#list = [];
#sort = false;

constructor (list) {
constructor (list, options = {}) {
options = options || {};
this.#sort = options.sort || false;
this.#list = this.#list.concat(Array.from(list || this.#list).map(item => new Source(item)));
}

Expand All @@ -20,7 +23,11 @@ export default class SourceList {
get list () { return this.#list; }

get sorted () {
return this.#list.sort((a, b) => sortByMediaQueries(a.media, b.media));
if (this.#sort) {
return this.#list.sort((a, b) => sortByMediaQueries(a.media, b.media));
} else {
return this.#list;
}
}

get style () {
Expand Down

0 comments on commit 54f56f8

Please sign in to comment.