commit
733a8da0b7
|
@ -1,2 +0,0 @@
|
||||||
dev
|
|
||||||
dist
|
|
|
@ -0,0 +1 @@
|
||||||
|
./.gitignore
|
|
@ -1,13 +1,29 @@
|
||||||
{
|
{
|
||||||
"root": true,
|
"root": true,
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true
|
||||||
"es6": true,
|
},
|
||||||
"node": true
|
"extends": ["eslint:recommended", "plugin:unicorn/recommended", "prettier"],
|
||||||
|
"rules": {
|
||||||
|
"unicorn/no-for-loop": 0
|
||||||
},
|
},
|
||||||
"extends": ["airbnb-base", "prettier"],
|
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2020,
|
"ecmaVersion": "latest",
|
||||||
"sourceType": "module"
|
"sourceType": "module"
|
||||||
}
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["postcss.config.js", "vite.config.js"],
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"browser": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["postcss.config.js"],
|
||||||
|
"rules": {
|
||||||
|
"unicorn/prefer-module": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
"build:js": "vite build",
|
"build:js": "vite build",
|
||||||
"build:css": "postcss src/shareon.css -o dist/shareon.min.css --map",
|
"build:css": "postcss src/shareon.css -o dist/shareon.min.css --map",
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"lint": "prettier --check . && eslint src/*.js",
|
"lint": "prettier --check . && eslint .",
|
||||||
"size": "size-limit",
|
"size": "size-limit",
|
||||||
"test": "pnpm run lint && pnpm run build && pnpm run size",
|
"test": "pnpm run lint && pnpm run build && pnpm run size",
|
||||||
"postversion": "pnpm run build"
|
"postversion": "pnpm run build"
|
||||||
|
@ -49,9 +49,8 @@
|
||||||
"autoprefixer": "^10.4.2",
|
"autoprefixer": "^10.4.2",
|
||||||
"cssnano": "^5.0.16",
|
"cssnano": "^5.0.16",
|
||||||
"eslint": "^8.8.0",
|
"eslint": "^8.8.0",
|
||||||
"eslint-config-airbnb-base": "^15.0.0",
|
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-plugin-import": "^2.25.4",
|
"eslint-plugin-unicorn": "^40.1.0",
|
||||||
"postcss": "^8.4.6",
|
"postcss": "^8.4.6",
|
||||||
"postcss-banner": "^4.0.1",
|
"postcss-banner": "^4.0.1",
|
||||||
"postcss-calc": "^8.2.3",
|
"postcss-calc": "^8.2.3",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const pkg = require("./package.json");
|
const package_ = require("./package.json");
|
||||||
const bannerText = `${pkg.name} v${pkg.version}`;
|
const bannerText = `${package_.name} v${package_.version}`;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
map: {
|
map: {
|
||||||
|
|
|
@ -6,4 +6,4 @@ if (s && s.hasAttribute("init")) {
|
||||||
initializeShareon();
|
initializeShareon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default initializeShareon;
|
export { default } from "./shareon";
|
||||||
|
|
|
@ -30,18 +30,30 @@ const urlBuilderMap = {
|
||||||
whatsapp: (d) => `https://wa.me/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`,
|
whatsapp: (d) => `https://wa.me/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openUrl = (buttonUrl) => () => {
|
||||||
|
window.open(buttonUrl, "_blank", "noopener,noreferrer");
|
||||||
|
};
|
||||||
|
|
||||||
const initializeShareon = () => {
|
const initializeShareon = () => {
|
||||||
const shareonContainers = document.getElementsByClassName("shareon");
|
const shareonContainers = document.querySelectorAll(".shareon");
|
||||||
|
|
||||||
// iterate over <div class="shareon">
|
// iterate over <div class="shareon">
|
||||||
for (let i = 0; i < shareonContainers.length; i += 1) {
|
for (
|
||||||
|
let containerIndex = 0;
|
||||||
|
containerIndex < shareonContainers.length;
|
||||||
|
containerIndex += 1
|
||||||
|
) {
|
||||||
/** @type Element */
|
/** @type Element */
|
||||||
const container = shareonContainers[i];
|
const container = shareonContainers[containerIndex];
|
||||||
|
|
||||||
// iterate over children of <div class="shareon">
|
// iterate over children of <div class="shareon">
|
||||||
for (let j = 0; j < container.children.length; j += 1) {
|
for (
|
||||||
|
let childIndex = 0;
|
||||||
|
childIndex < container.children.length;
|
||||||
|
childIndex += 1
|
||||||
|
) {
|
||||||
/** @type Element */
|
/** @type Element */
|
||||||
const child = container.children[j];
|
const child = container.children[childIndex];
|
||||||
|
|
||||||
if (child) {
|
if (child) {
|
||||||
const classListLength = child.classList.length;
|
const classListLength = child.classList.length;
|
||||||
|
@ -81,11 +93,7 @@ const initializeShareon = () => {
|
||||||
child.setAttribute("rel", "noopener noreferrer");
|
child.setAttribute("rel", "noopener noreferrer");
|
||||||
child.setAttribute("target", "_blank");
|
child.setAttribute("target", "_blank");
|
||||||
} else {
|
} else {
|
||||||
const getButtonListener = (buttonUrl) => () => {
|
child.addEventListener("click", openUrl(url));
|
||||||
window.open(buttonUrl, "_blank", "noopener,noreferrer");
|
|
||||||
};
|
|
||||||
|
|
||||||
child.addEventListener("click", getButtonListener(url));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break; // once a network is detected we don't want to check further
|
break; // once a network is detected we don't want to check further
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import * as path from "path";
|
import * as path from "node:path";
|
||||||
import pkg from "./package.json";
|
import package_ from "./package.json";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
esbuild: {
|
esbuild: {
|
||||||
|
@ -17,7 +17,7 @@ export default defineConfig({
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
banner: `/*! ${pkg.name} v${pkg.version} */`,
|
banner: `/*! ${package_.name} v${package_.version} */`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue