diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 4df9f34..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Node.js CI - -on: - push: - branches: - - main - - v* - pull_request: - branches: - - main - -jobs: - lint: - name: Lint package - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Setup Node - uses: actions/setup-node@v2 - with: - node-version: "16" - - uses: pnpm/action-setup@v2.0.1 - with: - version: 6.0.2 - - name: Install dependencies - run: pnpm i - - name: Lint - run: pnpm run lint - - build-docs: - name: Build and test package and deploy docs - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Setup Node - uses: actions/setup-node@v2 - with: - node-version: "16" - - uses: pnpm/action-setup@v2.0.1 - with: - version: 6.0.2 - - name: Install dependencies - run: pnpm i - - name: Test package - run: pnpm run test - - - name: Copy built files to docs - run: cp ./dist/shareon.min.* ./docs - if: ${{ github.ref == 'refs/heads/main' }} - - name: Deploy to GitHub Pages - uses: crazy-max/ghaction-github-pages@v2 - with: - keep_history: true - build_dir: docs - fqdn: shareon.js.org - jekyll: false - if: ${{ github.ref == 'refs/heads/main' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a38c82..9a52376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,13 +19,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ``` -or install it via NPM use it in a JS file that you will bundle: +- `defer` makes sure Shareon is loaded after HTML is parsed +- `init` will automatically initialize Shareon buttons -```sh -npm install shareon -# or -yarn add shareon -``` +### Do not auto-initialize -```js -const shareon = require("shareon"); -// or -import shareon from "shareon"; -``` - -## Initialization - -By default, shareon will initialize every button after page load. It also -exports the `shareon` function, that will let you repopulate your buttons with -updated information (for example, if you changed the page title): - -```js -// shareon auto-initializes - -window.title = "Cool new window title"; -shareon(); -``` - -If you want to postpone the initialization, you can import the `noinit`-version -of the package. You'll need to manually call the `shareon` function when you -want the buttons to be initialized: +Remove the `init` attribute and initialize Shareon when you need it: ```html - - - ``` -or, if you're using Node: +### Use ESM build + +There is also a ESM build for the browsers, which doesn't support +auto-initialization: + +```html + +``` + +### Bundle with Node + +You can also install Shareon using your favourite package manager and include it +in your source files: + +```sh +pnpm add shareon # or `npm install`, or `yarn add` +``` ```js -const shareon = require("shareon/dist/noinit/shareon"); -// or -import shareon from "shareon/dist/noinit/shareon"; +import { init } from "shareon"; +import "shareon/css"; // most bundlers will transpile this CSS -// do something important -shareon(); +init(); +``` + +CommonJS imports are also supported: + +```js +const Shareon = require("shareon"); +require("shareon/css"); // most bundlers will transpile this CSS + +Shareon.init(); ``` ## Usage -> shareon was heavily inspired by [Likely](https://ilyabirman.net/projects/likely/), -> and has a backwards-compatible API (excluding themes and sizes). - -Create a container with class `shareon` and populate it with elements, whose -classes match the names of social networks: +Create a container with class `shareon` and populate it with elements, class +names of which match the names of the social networks: ```html
``` -If you use ``, the buttons will get a `href`-attribute to them. In other cases -they will get a listener on `click` event, so you can use `