totality
Total from subtotals, automatically updating with mutation observer
Last updated 8 months ago by entozoon .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install totality 
SYNC missed versions from official npm registry.

Totality

Total from subtotals, automatically updating in your DOM with mutation observations.

Installation

npm i totality

Usage

Create a [data-totality] element, which will sum up all the items pointed to by its data attribute, e.g.

<div class="subtotal">£1.99</div>
<div class="subtotal">£2.99</div>
<div class="subtotal">£3.99</div>
<div data-totality=".subtotal"></div>
import Totality from "totality";

// Spin up instances for any [data-totality] elements
const totalityElements = document.querySelectorAll("[data-totality]");
if (totalityElements) {
  const totalities = [...totalityElements].map(
    element => new Totality({ element, currency: "£" })
  );
}

And it will populate the total with £8.97.

Updating

It observes mutations within the given subtotal elements, so if you've got other scripts wrangling prices, we good.

Current Tags

  • 1.0.2                                ...           latest (8 months ago)

3 Versions

  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |