Skip to content

Commit c79e422

Browse files
committed
[Release] v1.1.0
1 parent 37b3a6b commit c79e422

File tree

14 files changed

+131
-98
lines changed

14 files changed

+131
-98
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# v1.0.0 (May 02, 2020)
2-
* First Release.
1+
# v1.1.0 (May 04, 2020)
2+
* Fix: now you can use multiple webcomponents in the same html page
3+
* NOTE: better to use the full close tag `<patreon-box></patreon-box>` than short `/>`
4+
5+
[![](https://img.shields.io/badge/donate-paypal-005EA6.svg?logo=paypal)](https://www.paypal.me/ptkdev) [![](https://img.shields.io/badge/donate-patreon-F87668.svg?logo=patreon)](https://www.patreon.com/ptkdev) [![](https://img.shields.io/badge/donate-sponsors-ea4aaa.svg?logo=github)](https://github.com/sponsors/ptkdev/) [![](https://img.shields.io/badge/donate-ko--fi-29abe0.svg?logo=ko-fi)](https://ko-fi.com/ptkdev)
36

4-
[![](https://img.shields.io/badge/donate-paypal-005EA6.svg?logo=paypal)](https://www.paypal.me/ptkdev) [![](https://img.shields.io/badge/donate-patreon-F87668.svg?logo=patreon)](https://www.patreon.com/ptkdev) [![](https://img.shields.io/badge/donate-sponsors-ea4aaa.svg?logo=github)](https://github.com/sponsors/ptkdev/) [![](https://img.shields.io/badge/donate-ko--fi-29abe0.svg?logo=ko-fi)](https://ko-fi.com/ptkdev)
7+
8+
# v1.0.0 (May 02, 2020)
9+
* First Release.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🎁 WebComponent: Patreon Box
22

3-
[![](https://img.shields.io/badge/version-v1.0.0-lightgrey.svg)](https://github.com/ptkdev-components/webcomponent-patreon-box/releases) [![](https://img.shields.io/npm/v/@ptkdev/webcomponent-patreon-box.svg)](https://www.npmjs.com/package/@ptkdev/webcomponent-patreon-box) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/ptkdev-components/webcomponent-patreon-box/blob/master/LICENSE.md) [![](https://img.shields.io/badge/ES-9-F7DF1E.svg)](https://wikipedia.org/wiki/ECMAScript) [![](https://snyk.io/test/github/ptkdev-components/webcomponent-patreon-box/badge.svg)](https://snyk.io/test/github/ptkdev-components/webcomponent-patreon-box) [![](https://discordapp.com/api/guilds/383373985666301975/embed.png)](http://discord.ptkdev.io)
3+
[![](https://img.shields.io/badge/version-v1.1.0-lightgrey.svg)](https://github.com/ptkdev-components/webcomponent-patreon-box/releases) [![](https://img.shields.io/npm/v/@ptkdev/webcomponent-patreon-box.svg)](https://www.npmjs.com/package/@ptkdev/webcomponent-patreon-box) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/ptkdev-components/webcomponent-patreon-box/blob/master/LICENSE.md) [![](https://img.shields.io/badge/ES-9-F7DF1E.svg)](https://wikipedia.org/wiki/ECMAScript) [![](https://snyk.io/test/github/ptkdev-components/webcomponent-patreon-box/badge.svg)](https://snyk.io/test/github/ptkdev-components/webcomponent-patreon-box) [![](https://discordapp.com/api/guilds/383373985666301975/embed.png)](http://discord.ptkdev.io)
44

55
> My Patreon Tier Box with avatars and link from rest/json api.
66
@@ -47,7 +47,7 @@ See [Demo here](https://codepen.io/ptkdev/pen/abvLgOE). Photos from ptkdev's pat
4747
## 🚀 Installation (Web)
4848
1. Add html code to your page (and replace `api` with your endpoint):
4949
```html
50-
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px" />
50+
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px"></patreon-box>
5151
```
5252
2. Require javascript in yourpage (before `</body>`):
5353
```html
@@ -62,7 +62,7 @@ See folder `examples`, run with `npm run example`. Below is available a descript
6262
1. Install npm module: `npm install @ptkdev/webcomponent-patreon-box --save`
6363
2. Add html code to your page (and replace `api` with your endpoint):
6464
```html
65-
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px" />
65+
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px"></patreon-box>
6666
```
6767
3. Require javascript in your app:
6868
```javascript
@@ -79,7 +79,7 @@ See folder `examples`, run with `npm run example`. Below is available a descript
7979
1. Download [wordpress-plugin](https://github.com/ptkdev-components/webcomponent-patreon-box/raw/nightly/dist/wordpress/patreon-box-wordpress-plugin.zip) and install it.
8080
1. Add code to your html widget, example: `Appearance` --> `Widget` --> insert `HTML Widget` and paste html code (and replace `api` with your endpoint):
8181
```html
82-
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px" />
82+
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px"></patreon-box>
8383
```
8484

8585
You can insert this html code in posts, widget, html box or theme. Where you want see patreon photos box.
@@ -92,7 +92,7 @@ import '@ptkdev/webcomponent-patreon-box';
9292
```
9393
3. Add html code to your `App.js` template (and replace `api` with your endpoint):
9494
```html
95-
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px" />
95+
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px"></patreon-box>
9696
```
9797

9898
Below is available a description of `options` values and all logger methods.
@@ -105,7 +105,7 @@ import '@ptkdev/webcomponent-patreon-box';
105105
```
106106
3. Add html code to your html component (and replace `api` with your endpoint):
107107
```html
108-
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px" />
108+
<patreon-box api="https://api.ptkdev.io/backers/" image-width="80px" image-height="80px"></patreon-box>
109109
```
110110

111111
Below is available a description of `options` values and all logger methods.
@@ -114,7 +114,7 @@ Below is available a description of `options` values and all logger methods.
114114

115115
| Parameter | Description | Values | Default value | Available since |
116116
| --- | --- | --- | --- | --- |
117-
| api | REST Api url | `https://api.ptkdev.io/backers/` | v1.0.0 |
117+
| api | REST Api url | `URI` / `URL` of endpoint | `https://api.ptkdev.io/backers/` | v1.0.0 |
118118
| items-limit | Set the max number of pictures | number: from `0` to `100` | `100` | v1.0.0 |
119119
| grid | Set grid aspect ratio | `1x1`, `2x2`, `3x3`, etc... or `responsive` | `responsive` | v1.0.0 |
120120
| image-width | Set width of images (NOTE: grid different than `responsive` overwrite this value) | length units: `100%`, `100px`, `100pt` | `100%` | v1.0.0 |

dist/lib/en/patreon-box.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// WebComponent: PatreonBox 1.0.0 - Collection of WebComponents by Patryk Rzucidlo [@PTKDev] <[email protected]>
1+
// WebComponent: PatreonBox 1.1.0 - Collection of WebComponents by Patryk Rzucidlo [@PTKDev] <[email protected]>
22
// https://github.com/ptkdev-components/webcomponent-patreon-box
33
(function() { /**
44
* PatreonBox WebComponent
@@ -15,7 +15,7 @@ class PatreonBox extends HTMLElement {
1515
super();
1616

1717
const template = document.createElement("template");
18-
template.innerHTML = `<style id="patreon-box-style">#patreon-box *{margin:0;padding:0;line-height:0}#patreon-box .patreon-box-container{background-color:rgba(249,103,83,.9);border-radius:25px;padding:15px;text-align:center;justify-content:center;font-weight:500}#patreon-box .patreon-box-title p{line-height:normal;padding-bottom:10px;color:#052a49}#patreon-box .patreon-box-subtitle p{line-height:normal;padding-top:10px;color:#052a49}#patreon-box .patreon-box-backers li img{border-radius:5%;background-color:#f8f8ff;object-fit:cover;object-position:50% 50%;max-width:300px;max-height:300px;min-width:80px;min-height:80px;margin:2px}#patreon-box .patreon-content ul{list-style-type:none;padding-inline-start:0;width:100%}#patreon-box .patreon-box-backers li{list-style-type:none;display:inline}</style><div id="patreon-box" version="1.0.0">
18+
template.innerHTML = `<style id="patreon-box-style">#patreon-box *{margin:0;padding:0;line-height:0}#patreon-box .patreon-box-container{background-color:rgba(249,103,83,.9);border-radius:25px;padding:15px;text-align:center;justify-content:center;font-weight:500}#patreon-box .patreon-box-title p{line-height:normal;padding-bottom:10px;color:#052a49}#patreon-box .patreon-box-subtitle p{line-height:normal;padding-top:10px;color:#052a49}#patreon-box .patreon-box-backers li img{border-radius:5%;background-color:#f8f8ff;object-fit:cover;object-position:50% 50%;max-width:300px;max-height:300px;min-width:80px;min-height:80px;margin:2px}#patreon-box .patreon-content ul{list-style-type:none;padding-inline-start:0;width:100%}#patreon-box .patreon-box-backers li{list-style-type:none;display:inline}</style><div id="patreon-box" version="1.1.0">
1919
<div class="patreon-box-container">
2020
<div class="patreon-box-title"><p>Thanks to those who support me on Patreon ❤️</p></div>
2121
<div class="patreon-box-content">
@@ -64,12 +64,12 @@ class PatreonBox extends HTMLElement {
6464
for (let i = 0; i < photos.length && i < this.options["items-limit"]; i++) {
6565
html += `<li><a href="${photos[i].url}" rel="nofollow external noopener noreferrer" target="_blank" ><img width="${this.options["image-width"]}" height="${this.options["image-height"]}" src="${photos[i].pic}" alt="Backer" loading="lazy" /></a></li>`;
6666
}
67-
document.querySelector("patreon-box").shadowRoot.querySelector(".patreon-box-backers").innerHTML = html;
67+
this.shadowRoot.querySelector(".patreon-box-backers").innerHTML = html;
6868

6969
if (this.options["grid"] !== "" && this.options["grid"] !== null && this.options["grid"] !== "responsive") {
7070
let grid = this.options["grid"].split("x");
7171
let width = 100 / parseInt(grid[0]);
72-
let images = document.querySelector("patreon-box").shadowRoot.querySelectorAll(".patreon-box-backers img");
72+
let images = this.shadowRoot.querySelectorAll(".patreon-box-backers img");
7373
for (let i=0; i < images.length; i++) {
7474
images[i].removeAttribute("width");
7575
images[i].style.width = `calc(${(width)}% - (${this.options["border-spacing"]} * (${parseInt(grid[0])} * 2)))`;
@@ -80,48 +80,55 @@ class PatreonBox extends HTMLElement {
8080

8181
if (this.options["force-square"] === "yes") {
8282
images[i].removeAttribute("height");
83-
images[i].style.height = `${document.querySelector("patreon-box").shadowRoot.querySelector(".patreon-box-backers img").clientWidth}px`;
83+
images[i].style.height = `${this.shadowRoot.querySelector(".patreon-box-backers img").clientWidth}px`;
8484
}
8585
}
8686
} else {
87-
let images = document.querySelector("patreon-box").shadowRoot.querySelectorAll(".patreon-box-backers img");
87+
let images = this.shadowRoot.querySelectorAll(".patreon-box-backers img");
8888
for (let i=0; i < images.length; i++) {
8989
images[i].style.borderRadius = `${this.options["border-corners"]}%`;
9090
images[i].style.margin = this.options["border-spacing"];
9191

9292
if (this.options["force-square"] === "yes") {
9393
images[i].removeAttribute("height");
9494
images[i].style.maxHeight = "none";
95-
images[i].style.height = `${document.querySelector("patreon-box").shadowRoot.querySelector(".patreon-box-backers img").clientWidth}px`;
95+
images[i].style.height = `${this.shadowRoot.querySelector(".patreon-box-backers img").clientWidth}px`;
9696
}
9797
}
9898
}
9999
}
100100

101+
/**
102+
* Fix responsive
103+
* =====================
104+
*
105+
*/
106+
resize() {
107+
let images = this.shadowRoot.querySelectorAll(".patreon-box-backers img");
108+
for (let i=0; i < images.length; i++) {
109+
if (this.options["force-square"] === "yes") {
110+
images[i].style.height = `${this.shadowRoot.querySelector(".patreon-box-backers img").clientWidth}px`;
111+
}
112+
}
113+
}
114+
101115
/**
102116
* Get Photos from fetch request
103117
* =====================
104118
*
105119
*/
106120
api_fetch() {
107-
let self = this;
108-
109121
fetch(this.options["api"], {"cache": this.options["cache"] === null || this.options["cache"] === "enabled" ? "force-cache" : "default"}).then(function(response) {
110122
if (response.status === 200) {
111123
return response.json();
112124
}
113125
}).then(function(response) {
114-
self.json = response;
115-
self.build_html();
116-
window.onresize = () => {
117-
let images = document.querySelector("patreon-box").shadowRoot.querySelectorAll(".patreon-box-backers img");
118-
for (let i=0; i < images.length; i++) {
119-
if (self.options["force-square"] === "yes") {
120-
images[i].style.height = `${document.querySelector("patreon-box").shadowRoot.querySelector(".patreon-box-backers img").clientWidth}px`;
121-
}
122-
}
123-
};
124-
});
126+
this.json = response;
127+
this.build_html();
128+
window.addEventListener("resize", function(event) {
129+
this.resize(event);
130+
}.bind(this), false);
131+
}.bind(this), false);
125132
}
126133

127134
static get observedAttributes() {

0 commit comments

Comments
 (0)