Skip to content

Commit

Permalink
[Release] v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ptkdev committed Apr 30, 2020
1 parent 1381b89 commit f50b684
Show file tree
Hide file tree
Showing 23 changed files with 19,238 additions and 2,607 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,7 @@
# v2.3.0 (TBD)
# v2.3.0 (May 01, 2020)
* Fix: `border-corners` and `border-spacing` now work without `grid` attribute.
* Fix: NPM Module give errors with require/import
* Update: examples

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

Expand Down
38 changes: 18 additions & 20 deletions README.md
@@ -1,6 +1,6 @@
# 🌉 WebComponent: InstagramWidget

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

> Simple Instagram Widget: Photos Box of your Instagram Profile for your blog or website with this WebComponent.
Expand All @@ -18,7 +18,7 @@
- 🕹 [Demo](https://codepen.io/ptkdev/pen/WNQOYqy)
- 👔 [Screenshot](#-screenshot)
- 🚀 [How to use](#-installation)
- - 🌎 [Web (Generic)](#-installation-web)
- - 🌎 [Web](#-installation-web)
- - 📦 [Webpack/Browserify](#-installation-npm-module---browserifywebpack)
- - 📖 [Wordpress](#-installation-wordpress)
- - ⚛️ [React](#%EF%B8%8F-installation-react)
Expand Down Expand Up @@ -68,8 +68,10 @@ See folder `examples`, run with `npm run example`. Below is available a descript
```javascript
require("@ptkdev/webcomponent-instagram-widget");
```

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`.
or
```javascript
import '@ptkdev/webcomponent-instagram-widget';
```

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

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

## ⚛️ Installation (React)
1. Add html code to your `App.js` template (and replace `@ptkdev` with your instagram username):
1. Install npm module with `npm install @ptkdev/webcomponent-instagram-widget@latest --save`:
2. Import module in your `src/App.js` on header:
```javascript
import '@ptkdev/webcomponent-instagram-widget';
```
3. Add html code to your `App.js` template (and replace `@ptkdev` with your instagram username):
```html
<instagram-widget username="@ptkdev" />
```

2. Require javascript in your `public/index.html` (before `</body>`):
```javascript
<script src="https://cdn.jsdelivr.net/npm/@ptkdev/webcomponent-instagram-widget@latest/dist/lib/en/instagram-widget.min.js"></script>
```

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`.

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.

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

2. Inlude javascript in your `index.html` (before `</body>`):
```javascript
<script src="https://cdn.jsdelivr.net/npm/@ptkdev/webcomponent-instagram-widget@latest/dist/lib/en/instagram-widget.min.js"></script>
```

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`.

Demo: https://webcomponents-60bc6.firebaseapp.com/instagram-widget

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.
Expand Down
135 changes: 135 additions & 0 deletions dist/lib/en/instagram-widget.js
@@ -0,0 +1,135 @@
// WebComponent: InstagramWidget 2.3.0 - Collection of WebComponents by Patryk Rzucidlo [@PTKDev] <support@ptkdev.io>
// https://github.com/ptkdev-components/webcomponent-instagram-widget
(function() { /**
* InstagramWidget WebComponent
* =====================
* Simple Instagram Widget: Photos Box of your Instagram Profile for your blog or website with this WebComponent.
*
* @contributors: Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev)
*
* @license: MIT License
*
*/
class InstagramWidget extends HTMLElement {
constructor() {
super();

const template = document.createElement("template");
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">
<div class="instagram-widget-container">
<div class="instagram-widget-content">
<ul class="instagram-widget-photos"></ul>
</div>
</div>
</div>`;

this.attachShadow({mode: "open"});
this.shadowRoot.appendChild(template.content.cloneNode(true));
this.json = null;
this.options_default = {
"username": "@ptkdev",
"items-limit": "9",
"image-width": "100%",
"image-height": "100%",
"grid": "responsive",
"cache": "enabled",
"border-spacing": "2px",
"border-corners": "5"
};

this.options = Object.create(this.options_default);
}

/**
* Build HTML grid
* =====================
*
*/
build_html() {
let data = this.json.graphql.user.edge_owner_to_timeline_media.edges;

let photos = [];

for (let i=0; i<data.length; i++) {
photos.push({
url: `https://www.instagram.com/p/${data[i].node.shortcode}/`,
thumbnail: data[i].node.thumbnail_src,
display_url: data[i].node.display_url !== undefined ? data[i].node.display_url : "",
caption: data[i].node.edge_media_to_caption.edges[0] &&
data[i].node.edge_media_to_caption.edges[0].node.text !== undefined ? data[i].node.edge_media_to_caption.edges[0].node.text : ""
});
}

let html = "";
for (let i = 0; i < photos.length && i < this.options["items-limit"]; i++) {
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>`;
}
document.querySelector("instagram-widget").shadowRoot.querySelector(".instagram-widget-photos").innerHTML = html;

if (this.options["grid"] !== "" && this.options["grid"] !== null && this.options["grid"] !== "responsive") {
let grid = this.options["grid"].split("x");
let width = 100 / parseInt(grid[0]);
let images = document.querySelector("instagram-widget").shadowRoot.querySelectorAll(".instagram-widget-photos img");
for (let i=0; i < images.length; i++) {
images[i].removeAttribute("width");
images[i].style.width = `calc(${(width)}% - (${this.options["border-spacing"]} * (${parseInt(grid[0])} * 2)))`;
images[i].style.maxWidth = "none";
images[i].style.maxHeight = "none";
images[i].style.borderRadius = `${this.options["border-corners"]}%`;
images[i].style.margin = this.options["border-spacing"];
}
} else {
let images = document.querySelector("instagram-widget").shadowRoot.querySelectorAll(".instagram-widget-photos img");
for (let i=0; i < images.length; i++) {
images[i].style.borderRadius = `${this.options["border-corners"]}%`;
images[i].style.margin = this.options["border-spacing"];
}
}
}

/**
* Get Photos from fetch request
* =====================
*
*/
api_fetch() {
let self = this;

let url = `https://www.instagram.com/${this.options["username"].replace("@", "")}/?__a=1`;
fetch(url, {"cache": this.options["cache"] === null || this.options["cache"] === "enabled" ? "force-cache" : "default"}).then(function(response) {
if (response.status === 200) {
return response.json();
}
}).then(function(response) {
self.json = response;
self.build_html();
});
}

static get observedAttributes() {
return ["username", "items-limit", "grid", "image-width", "image-height", "border-spacing", "border-corners", "cache"];
}

attributeChangedCallback(name_attribute, old_vale, new_value) {
if (old_vale !== new_value) {
if (new_value === null || new_value === "") {
this.options[name_attribute] = this.options_default[name_attribute];
} else {
this.options[name_attribute] = new_value;
}

switch (name_attribute) {
case "username":
this.api_fetch();
break;
default:
if (this.json !== null) {
this.build_html();
}
}
}
}
}

window.customElements.define("instagram-widget", InstagramWidget);
})();
4 changes: 2 additions & 2 deletions dist/lib/en/instagram-widget.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f50b684

Please sign in to comment.