Sha256: 3fdaeb179b5802dbe5ed5b579a0e58ebc7e9c00415f1df8e6d20fb7bc706d60b

Contents?: true

Size: 1.08 KB

Versions: 24

Compression:

Stored size: 1.08 KB

Contents

import { Controller } from '@hotwired/stimulus';
class AccumulatorController extends Controller {
    connect() {
        this.accumulate();
    }
    accumulate() {
        let sum = 0;
        for (const i in this.sumTargets) {
            const target = this.sumTargets[i];
            const value = Number(target.getAttribute(this.sumAttrValue));
            if (!isNaN(value)) {
                sum += value;
            }
        }
        this.setAttributesTo(sum);
    }
    setAttributesTo(sum) {
        for (const i in this.syncAttrsValue) {
            const attr = this.syncAttrsValue[i];
            this.accumulator.setAttribute(attr, sum.toString());
        }
    }
    get accumulator() {
        var _a;
        return (_a = this.accumulatorTarget) !== null && _a !== void 0 ? _a : this.element;
    }
}
AccumulatorController.targets = ['sum', 'accumulator'];
AccumulatorController.values = {
    syncAttrs: {
        type: Array,
        default: ['aria-valuenow'],
    },
    sumAttr: {
        type: 'string',
        default: 'data-value',
    },
};
export default AccumulatorController;

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.59-x64-mingw-ucrt app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.59-aarch64-linux app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.59-x86_64-darwin app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.59-x86_64-linux app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.59-arm64-darwin app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.59 app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.58-x86_64-darwin app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.58-aarch64-linux app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.58-arm64-darwin app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.58-x64-mingw-ucrt app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.58 app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.58-x86_64-linux app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.57-arm64-darwin app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.57-aarch64-linux app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.57-x86_64-darwin app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.57-x86_64-linux app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.57-x64-mingw-ucrt app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.57 app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.55-x86_64-linux app/components/ariadne/accumulator_controller/accumulator_controller.js
ariadne_view_components-0.0.55-arm64-darwin app/components/ariadne/accumulator_controller/accumulator_controller.js