WordPress.org

Ready to get started?Download WordPress

Forums

WP Slimstat
[resolved] firing on links that have jQuery .click() actions (6 posts)

  1. freerange
    Member
    Posted 3 years ago #

    Here is what happens:

    Slimstat checks at install time for onClick before attaching to the click event of <a> elements. This means that any click event handlers added by other code after slimstat installs get missed. When the user clicks the link the new event handler runs and calls .preventDefault() which should stop the link from being followed but instead slimstat_track_link() simulates the click anyway leading to unpredictable results. This is particularly a problem with jQuery because it tends to bind .click() late due to the use of .ready()

    The fix is probably to check for the presence of other click handlers in slimstat_track_link() and bail if you find more than one total.

    Click the 'RepostUs' button on this page to see this happening http://juliasherred.com/2011/05/dan-freeman-interview/

  2. camu
    Member
    Plugin Author

    Posted 3 years ago #

    Hi there,

    Unfortunately I don't think there's a way to do that in JavaScript (I'm not using jquery). But you can add class=noslimstat to the links you want to "protect". Wp slimstat will just skip them

    Camu

  3. freerange
    Member
    Posted 3 years ago #

    Doh! You're right - I get so used to jQuery I forget you can't do some things generically.

    Do you check for .noslimstat at runtime or only when you install the event handler ?

  4. camu
    Member
    Plugin Author

    Posted 3 years ago #

    Runtime :) when users click, the event handler will check for that class and if it exists, will not disturb the other handlers installed (append)

    Camu

  5. freerange
    Member
    Posted 3 years ago #

    I fixed it another way - the href is really only a fallback in case the JS fails so when I attach the click event in jQuery I now replace the href with a javascript:void(0); which seems to do the trick and should work for anybody else doing similar things.

    Thanks for your help.

  6. camu
    Member
    Plugin Author

    Posted 3 years ago #

    Okay, but I guess the class is easier for people who don't have this kind of skills ;) Not everybody is a javascript "guru" :D

    Camu

    PS: a vote for my plugin would be greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic