question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass options through data- attributes

See original GitHub issue

Hi,

I love the plugin and started using it in my project, but I have to use wrap it’s usage in another plugin.

/**!
     * Tooltips
     * Wraps the call to load jquery.tooltipster.js
     * so that we can pass special configs on a case by case basis
     */
    $.fn.tooltips = function() {
        // To chain body plugins
        return this.each(function() {

            $('.tooltip').each(function(){
                var $el = $(this);

                $el.tooltipster({
                    speed:          $el.data('tooltipspeed') || 0,
                    position:       $el.data('tooltipposition') || 'top',
                    trigger:        $el.data('tooltiptrigger') || 'hover',
                    contentAsHTML:  $el.data('tooltiphtml') || false,
                    interactive:    $el.data('tooltipinteractive') || false,
                    delay:          0,
                    theme:          'tooltipster-light'
                });
            });

        });
    };

Any plans to allow setting options through data attributes so they can be set on a case by case basis? Thanks

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11

github_iconTop GitHub Comments

2reactions
louisamelinecommented, May 4, 2016

Although this will not be included in Tootlipster directly, there is nothing easier than to implement it. I’ve even included an example of it in the documentation of V4 (on the v4 branch) and it will also be available as a plugin for Tooltipster. Here is the snippet for V4:

// HTML: <span class="tooltip" data-tooltipster='{"side":"left","animation":"slide"}'></span>

$('.tooltip').tooltipster({
    functionInit: function(instance, helper){

        var $origin = $(helper.origin),
            dataOptions = $origin.attr('data-tooltipster');

        if(dataOptions){

            dataOptions = JSON.parse(dataOptions);

            $.each(dataOptions, function(name, option){
                instance.option(name, option);
            });
        }
    }
});

and for v3 (not tested, let me know if it’s ok):

$('.tooltip').tooltipster({
    functionInit: function(origin)
        var dataOptions = origin.attr('data-tooltipster');

        if(dataOptions){

            dataOptions = JSON.parse(dataOptions);

            $.each(dataOptions, function(name, option){
                origin.tooltipster('option', name, option);
            });
        }
    }
});
0reactions
mplattnercommented, May 4, 2016

+1

Do you know a good alternative tooltip plugin with this feature?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing selected option to method and access data attributes
Wiring up an event handler and getting the user's selection and even accessing the data attributes within the event handler is fine. <script>...
Read more >
Using data attributes - Learn web development | MDN
To get a data attribute through the dataset object, get the property by the part of the attribute name after data- (note that...
Read more >
HTML option data-* Attribute - Dofactory
An <option> element can have any number of data-* attributes, each with their own name. Using data-* attributes reduces the need for requests...
Read more >
A Complete Guide to Data Attributes | CSS-Tricks
Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.
Read more >
data-* attributes - The jQuery replacement for select boxes
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and pagination (infinite scrolling) of results.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found