Skip to content

Commit f50b684

Browse files
committed
[Release] v2.3.0
1 parent 1381b89 commit f50b684

23 files changed

+19238
-2607
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# v2.3.0 (TBD)
1+
# v2.3.0 (May 01, 2020)
22
* Fix: `border-corners` and `border-spacing` now work without `grid` attribute.
3+
* Fix: NPM Module give errors with require/import
4+
* Update: examples
35

46
[![](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)
57

README.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🌉 WebComponent: InstagramWidget
22

3-
[![](https://img.shields.io/badge/version-v2.3.0--nightly.20200430-lightgrey.svg)](https://github.com/ptkdev-components/webcomponent-instagram-widget/releases) [![](https://img.shields.io/npm/v/@ptkdev/webcomponent-instagram-widget.svg)](https://www.npmjs.com/package/@ptkdev/webcomponent-instagram-widget) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/ptkdev-components/webcomponent-instagram-widget/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-instagram-widget/badge.svg)](https://snyk.io/test/github/ptkdev-components/webcomponent-instagram-widget) [![](https://discordapp.com/api/guilds/383373985666301975/embed.png)](http://discord.ptkdev.io)
3+
[![](https://img.shields.io/badge/version-v2.3.0-lightgrey.svg)](https://github.com/ptkdev-components/webcomponent-instagram-widget/releases) [![](https://img.shields.io/npm/v/@ptkdev/webcomponent-instagram-widget.svg)](https://www.npmjs.com/package/@ptkdev/webcomponent-instagram-widget) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/ptkdev-components/webcomponent-instagram-widget/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-instagram-widget/badge.svg)](https://snyk.io/test/github/ptkdev-components/webcomponent-instagram-widget) [![](https://discordapp.com/api/guilds/383373985666301975/embed.png)](http://discord.ptkdev.io)
44

55
> Simple Instagram Widget: Photos Box of your Instagram Profile for your blog or website with this WebComponent.
66
@@ -18,7 +18,7 @@
1818
- 🕹 [Demo](https://codepen.io/ptkdev/pen/WNQOYqy)
1919
- 👔 [Screenshot](#-screenshot)
2020
- 🚀 [How to use](#-installation)
21-
- - 🌎 [Web (Generic)](#-installation-web)
21+
- - 🌎 [Web](#-installation-web)
2222
- - 📦 [Webpack/Browserify](#-installation-npm-module---browserifywebpack)
2323
- - 📖 [Wordpress](#-installation-wordpress)
2424
- - ⚛️ [React](#%EF%B8%8F-installation-react)
@@ -68,8 +68,10 @@ See folder `examples`, run with `npm run example`. Below is available a descript
6868
```javascript
6969
require("@ptkdev/webcomponent-instagram-widget");
7070
```
71-
72-
You can replace `en` in jsdelivr cdn with `it` or `pl` and load different languages or replace `@latest` with specific version, example `@2.0.1`.
71+
or
72+
```javascript
73+
import '@ptkdev/webcomponent-instagram-widget';
74+
```
7375

7476
See folder `examples`, run with `npm run example`. Below is available a description of `options` values and all logger methods.
7577

@@ -89,33 +91,29 @@ You can replace `en` in jsdelivr cdn with `it` or `pl` and load different langua
8991
See folder `examples`, run with `npm run example`. Below is available a description of `options` values and all logger methods.
9092

9193
## ⚛️ Installation (React)
92-
1. Add html code to your `App.js` template (and replace `@ptkdev` with your instagram username):
94+
1. Install npm module with `npm install @ptkdev/webcomponent-instagram-widget@latest --save`:
95+
2. Import module in your `src/App.js` on header:
96+
```javascript
97+
import '@ptkdev/webcomponent-instagram-widget';
98+
```
99+
3. Add html code to your `App.js` template (and replace `@ptkdev` with your instagram username):
93100
```html
94101
<instagram-widget username="@ptkdev" />
95102
```
96103

97-
2. Require javascript in your `public/index.html` (before `</body>`):
98-
```javascript
99-
<script src="https://cdn.jsdelivr.net/npm/@ptkdev/webcomponent-instagram-widget@latest/dist/lib/en/instagram-widget.min.js"></script>
100-
```
101-
102-
You can replace `en` in jsdelivr cdn with `it` or `pl` and load different languages or replace `@latest` with specific version, example `@2.0.1`.
103-
104104
Go to `examples/reactjs` and run `npm run start` in folder for more info. Below is available a description of `options` values and all logger methods.
105105

106106
## 🅰️ Installation (Angular)
107-
1. Add html code to your `app.component.html` (and replace `@ptkdev` with your instagram username):
107+
1. Install npm module with `npm install @ptkdev/webcomponent-instagram-widget@latest --save`:
108+
2. Import module in your `app/app.modules.ts` on header:
109+
```javascript
110+
import '@ptkdev/webcomponent-instagram-widget';
111+
```
112+
3. Add html code to your html component (and replace `@ptkdev` with your instagram username):
108113
```html
109114
<instagram-widget username="@ptkdev" />
110115
```
111116

112-
2. Inlude javascript in your `index.html` (before `</body>`):
113-
```javascript
114-
<script src="https://cdn.jsdelivr.net/npm/@ptkdev/webcomponent-instagram-widget@latest/dist/lib/en/instagram-widget.min.js"></script>
115-
```
116-
117-
You can replace `en` in jsdelivr cdn with `it` or `pl` and load different languages or replace `@latest` with specific version, example `@2.0.1`.
118-
119117
Demo: https://webcomponents-60bc6.firebaseapp.com/instagram-widget
120118

121119
Go to `examples/angular` and run `yarn install` then `yarn start` in folder for more info. Below is available a description of `options` values and all logger methods.

dist/lib/en/instagram-widget.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// WebComponent: InstagramWidget 2.3.0 - Collection of WebComponents by Patryk Rzucidlo [@PTKDev] <support@ptkdev.io>
2+
// https://github.com/ptkdev-components/webcomponent-instagram-widget
3+
(function() { /**
4+
* InstagramWidget WebComponent
5+
* =====================
6+
* Simple Instagram Widget: Photos Box of your Instagram Profile for your blog or website with this WebComponent.
7+
*
8+
* @contributors: Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev)
9+
*
10+
* @license: MIT License
11+
*
12+
*/
13+
class InstagramWidget extends HTMLElement {
14+
constructor() {
15+
super();
16+
17+
const template = document.createElement("template");
18+
template.innerHTML = `<style id="instagram-widget-style">#instagram-widget *{margin:0;padding:0;line-height:0}#instagram-widget .instagram-widget-container{text-align:center;justify-content:center;font-weight:500}#instagram-widget .instagram-widget-photos 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}#instagram-widget .instagram-content ul{list-style-type:none;padding-inline-start:0;width:100%}#instagram-widget .instagram-widget-photos li{list-style-type:none;display:inline}</style><div id="instagram-widget" version="2.3.0">
19+
<div class="instagram-widget-container">
20+
<div class="instagram-widget-content">
21+
<ul class="instagram-widget-photos"></ul>
22+
</div>
23+
</div>
24+
</div>`;
25+
26+
this.attachShadow({mode: "open"});
27+
this.shadowRoot.appendChild(template.content.cloneNode(true));
28+
this.json = null;
29+
this.options_default = {
30+
"username": "@ptkdev",
31+
"items-limit": "9",
32+
"image-width": "100%",
33+
"image-height": "100%",
34+
"grid": "responsive",
35+
"cache": "enabled",
36+
"border-spacing": "2px",
37+
"border-corners": "5"
38+
};
39+
40+
this.options = Object.create(this.options_default);
41+
}
42+
43+
/**
44+
* Build HTML grid
45+
* =====================
46+
*
47+
*/
48+
build_html() {
49+
let data = this.json.graphql.user.edge_owner_to_timeline_media.edges;
50+
51+
let photos = [];
52+
53+
for (let i=0; i<data.length; i++) {
54+
photos.push({
55+
url: `https://www.instagram.com/p/${data[i].node.shortcode}/`,
56+
thumbnail: data[i].node.thumbnail_src,
57+
display_url: data[i].node.display_url !== undefined ? data[i].node.display_url : "",
58+
caption: data[i].node.edge_media_to_caption.edges[0] &&
59+
data[i].node.edge_media_to_caption.edges[0].node.text !== undefined ? data[i].node.edge_media_to_caption.edges[0].node.text : ""
60+
});
61+
}
62+
63+
let html = "";
64+
for (let i = 0; i < photos.length && i < this.options["items-limit"]; i++) {
65+
html += `<li><a href="${photos[i].url}" rel="nofollow external noopener noreferrer" target="_blank" title="${photos[i].caption.substring(0, 100).replace(/"/g, "")}"><img width="${this.options["image-width"]}" height="${this.options["image-height"]}" src="${photos[i].display_url}" alt="${photos[i].caption.substring(0, 100).replace(/"/g, "")}" loading="lazy" /></a></li>`;
66+
}
67+
document.querySelector("instagram-widget").shadowRoot.querySelector(".instagram-widget-photos").innerHTML = html;
68+
69+
if (this.options["grid"] !== "" && this.options["grid"] !== null && this.options["grid"] !== "responsive") {
70+
let grid = this.options["grid"].split("x");
71+
let width = 100 / parseInt(grid[0]);
72+
let images = document.querySelector("instagram-widget").shadowRoot.querySelectorAll(".instagram-widget-photos img");
73+
for (let i=0; i < images.length; i++) {
74+
images[i].removeAttribute("width");
75+
images[i].style.width = `calc(${(width)}% - (${this.options["border-spacing"]} * (${parseInt(grid[0])} * 2)))`;
76+
images[i].style.maxWidth = "none";
77+
images[i].style.maxHeight = "none";
78+
images[i].style.borderRadius = `${this.options["border-corners"]}%`;
79+
images[i].style.margin = this.options["border-spacing"];
80+
}
81+
} else {
82+
let images = document.querySelector("instagram-widget").shadowRoot.querySelectorAll(".instagram-widget-photos img");
83+
for (let i=0; i < images.length; i++) {
84+
images[i].style.borderRadius = `${this.options["border-corners"]}%`;
85+
images[i].style.margin = this.options["border-spacing"];
86+
}
87+
}
88+
}
89+
90+
/**
91+
* Get Photos from fetch request
92+
* =====================
93+
*
94+
*/
95+
api_fetch() {
96+
let self = this;
97+
98+
let url = `https://www.instagram.com/${this.options["username"].replace("@", "")}/?__a=1`;
99+
fetch(url, {"cache": this.options["cache"] === null || this.options["cache"] === "enabled" ? "force-cache" : "default"}).then(function(response) {
100+
if (response.status === 200) {
101+
return response.json();
102+
}
103+
}).then(function(response) {
104+
self.json = response;
105+
self.build_html();
106+
});
107+
}
108+
109+
static get observedAttributes() {
110+
return ["username", "items-limit", "grid", "image-width", "image-height", "border-spacing", "border-corners", "cache"];
111+
}
112+
113+
attributeChangedCallback(name_attribute, old_vale, new_value) {
114+
if (old_vale !== new_value) {
115+
if (new_value === null || new_value === "") {
116+
this.options[name_attribute] = this.options_default[name_attribute];
117+
} else {
118+
this.options[name_attribute] = new_value;
119+
}
120+
121+
switch (name_attribute) {
122+
case "username":
123+
this.api_fetch();
124+
break;
125+
default:
126+
if (this.json !== null) {
127+
this.build_html();
128+
}
129+
}
130+
}
131+
}
132+
}
133+
134+
window.customElements.define("instagram-widget", InstagramWidget);
135+
})();

dist/lib/en/instagram-widget.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)