marchaos/toggle-switch

Transforming a checkbox into toggle-switch more than once should be allowed

ceremcem opened this issue · 1 comments

I'm dynamically modifying the dom with Ractive framework. When the document is modified, I need to transform the checkboxes that are just introduced into the dom. I'm using the following algorithm to perform the transformation:

  1. Find all checkboxes to be transfromed into toggle-switch by their class (eg. class="toggle-switch")
  2. Transform these elements into toggle-switch

If I use the same find-and-transform function for the checkboxes that are recently introduced, the previous toggle-switches are transformed twice, which causes the toggle-buttons look ugly and function in a wrong way.

Proposal:

  1. If checkbox has A_SPECIFIC_CLASS, transformation process will skip the element.
  2. If not skipped, transformation process should add A_SPECIFIC_CLASS to the checkbox.

Couldn't you just do this manually each time you transform the checkboxes?

  1. Find all checkboxes to be transformed into toggle-switch by their class .toggle-switch
  2. Transform these elements into toggle-switch
  3. Add a new class name toggle-switch-transformed.

So the next times, just use the CSS :not() selector.

1'. Find all checkboxes to be transformed into toggle-switch that have not already been transformed .toggle-switch:not(.toggle-switch-transformed)
Repeat steps 2 and 3 from above.