pawelgrzybek / siema

Siema - Lightweight and simple carousel in pure JavaScript
https://pawelgrzybek.github.io/siema/
Other
3.49k stars 408 forks source link

Custom settings via data attributes #55

Open adaniello opened 7 years ago

adaniello commented 7 years ago

This is only an idea, something as follow

<div class="siema" data-loop="true" data-duration="500">
  <div>Hi, I'm slide 1</div>
  <div>Hi, I'm slide 2</div>
  <div>Hi, I'm slide 3</div>
  <div>Hi, I'm slide 4</div>
</div>

Normally, this is how works a good jQuery plugin by using $.extend() but it's good also for a pure Javascript as Siema is 😄

pawelgrzybek commented 7 years ago

Hi @adaniello

Thanks for amazing suggestion. I will do my research and check how much code does it require to add on top of current code base. If it won't break my mental rule of "lightweight and simple carousel" I will add it :-)

Thanks again and have a great day 🥑

adaniello commented 7 years ago

@pawelgrzybek in my opinion best way should be something as follow:

  1. remove mergeSettings()
  2. add a extend()
  3. get this.config in constructor as extend() of default settings, custom options and data attributes.

With

function extend() {
    for(var i=1; i<arguments.length; i++)
        for(var key in arguments[i])
            if(arguments[i].hasOwnProperty(key))
                arguments[0][key] = arguments[i][key];
    return arguments[0];
}

Another way, faster should be adding another "for" cycle in mergeSettings in settings to check if data attribute exists and isn't empty (!this.selector.getAttribute(attrname)) and so set this value in settings object.

These are only ideas.

Thanks

pawelgrzybek commented 7 years ago

Great ideas! I'll check all available options, I'll do a research how people smarter than myself do it and then I will come back to you. I'll try to do it this week. Thanks again for great suggestion.

adaniello commented 7 years ago

Thank you for your great project!

pawelgrzybek commented 7 years ago

No problemmooo! I'm glad that you found it useful :)