stevenbenner / jquery-powertip

:speech_balloon: A jQuery plugin that creates hover tooltips.
https://stevenbenner.github.io/jquery-powertip/
MIT License
821 stars 137 forks source link

Homepage example incorrect #108

Closed AntoDRFC closed 10 years ago

AntoDRFC commented 10 years ago

The example on the homepage for the manual click of the powertips is incorrect

The current code:

// run PowerTip - but disable the default event hooks
$('.tooltips').powerTip({ manual: true });

// hook custom onclick function
$('.tooltips').on('click', function() {
    // hide any open tooltips
    // this is optional, but recommended in case we optimize away the sanity
    // checks in the API at some point.
    $.powerTip.hide();

    // show the tooltip for the element that received the click event
    $.powerTip.show(this);
});

Claims: This code will open a tooltip when the element is clicked and close it when the element is clicked again, or when another of the .tooltips elements gets clicked

Infact, when the powertip is clicked again, it simply hides, and then reshows it. The code below is how I got it to behave as the above is intended.

    // run PowerTip - but disable the default event hooks
    $('.tooltips').powerTip({ manual: true, placement: 'w', smartPlacement: true });

    var currentlyOpenPowerTip = '';
    // hook custom onclick function
    $('.tooltips').on('click', function() {
        var clickedPowerTip = $(this).data('powertiptarget');

        $.powerTip.hide();
        if(currentlyOpenPowerTip != clickedPowerTip) {
            $.powerTip.show(this);
            currentlyOpenPowerTip = clickedPowerTip;
        } else {
            currentlyOpenPowerTip = '';
        }
    });

Thanks Anto

stevenbenner commented 10 years ago

Well, that's embarrassing. I don't know how I let that slip by. I'll have to fix, change, or remove that example.

The next release will include options for the open and close events so that use case will be deprecated anyway. Lets see if I can come up with a better example for custom integration.

stevenbenner commented 10 years ago

I've changed the example to simply use the toggle() API method in commit 2a313c61abad2bbd304009f5ce60ab288a79db41. The code example also includes a note that the openEvents and closeEvents options would be the best tool for that particular job.