npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

way2web-clone

v1.0.1

Published

Clone an element.

Downloads

122

Readme

Clone

Clone an element.

NPM version Downloads

With this package you can clone elements on page.

Add this to your javascript file:

new Clone(element).init();

Example html:

<div class="js-clone">
    <input class="js-clone-count" name="counter" type="hidden" value="1">
    <form>
        <div class="js-remove-target">
            <button type="button" name="remove-target" class="js-clone-delete">
                Delete
            </button>
            <input name="test[0][id]" type="hidden" value="1">
        </div>

        <div class="js-clone-target"></div>
    </form>

    <div class="is-hidden | js-remove-target js-clone-template">
        <button type="button" name="remove-target" class="js-clone-delete">
            Delete
        </button>
        <input name="test[{key}][id]" type="hidden" value="{key}">
    </div>

    <button class="btn btn--filled | js-add-clone-button">Add delivery address</button>
</div>

Default elements:

{
    toggle:      '.js-add-clone-button',
    remove:      '.js-clone-delete',
    target:      '.js-clone-target',
    template:    '.js-clone-template',
    counter:     '.js-clone-count',
    removeClone: '.js-remove-target'
}

You can overrule this with: .setElements({ ... })

Default classes:

{
    hidden: 'is-hidden'
}

You can overrule this with: .setClasses({ ... })

When a element is cloned or removed an event is triggered. You can set functions to call when the element is cloned or removed. The events are clone and remove.

You can overrule this with: .setEvents({ ... })

e.g.

new Clone(element)
    .setEvents({
        clone: testFunction
    })
    .init();

functions

init

Get all parameters, and merge it with the default values. Check the click events.

return {object}

scope

The element used for the clone.

clone

Clone the element. This function is called if you click on the clone button.

remove

When triggered, remove the target element. This function is called if you click on the remove button of an item.

setElements

Overrule the default elements.

param {object} customElements

return {object}

setClasses

Overrule the default classes.

@param {object} customClasses

@return {object}

setEvents

Overrule the default events.

@param {object} customEvents

@return {object}

setCountOnRemove

If true, the count will be the amount of items. The counter will change if you delete an item. By default the value is false, so it can be used as an unique id.

@param {boolean} customCountOnRemove

@return {object}

getItems

Get all item elements.

return {object}

getTemplate

Get the template element.

@return {object}

getItemCount

Get the total of items.

@return {integer}

version

Get the version of the package.

NPM

Install using npm:

$ npm install --save way2web-clone

Test the package.

To test the package, clone the package to your system. Than run this command.

npm run build

This will copy the test files to the dist, and also build the package files include the dependencies.

When this script is complete without errors, you can open dist/test/index.html in your browser. Open the dev tools, tab console, and you see all the results of the tests.

If you only want to check the eslint rules, just run.

npm run lint