siema icon indicating copy to clipboard operation
siema copied to clipboard

Custom settings via data attributes

Open adaniello opened this issue 7 years ago • 5 comments

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 😄

adaniello avatar May 02 '17 09:05 adaniello

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 🥑

pawelgrzybek avatar May 02 '17 13:05 pawelgrzybek

@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

adaniello avatar May 02 '17 14:05 adaniello

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.

pawelgrzybek avatar May 02 '17 14:05 pawelgrzybek

Thank you for your great project!

adaniello avatar May 02 '17 15:05 adaniello

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

pawelgrzybek avatar May 02 '17 15:05 pawelgrzybek