laterpay/laterpay-wordpress-plugin — pull request #444 by jdelic (2014-10-29 15:55:53+00:00)
Title: Fix click delegation logic

Make sure that we always delegate the click event even if there is no
purchase link on the page currently. We then don't call attachToLinks
anymore, as we want to check whether we're in preview mode before
we call LaterPay's DialogManager.

@drdla: Please check that my changes now reflect the desired behavior. The initial problem was that the old code `return`ed when there was no $purchaseLink to be found, which of course happened if there was no post loaded (because we load them via ajax). Therefor `dm.attachToLinks` was never called. Also, the preview mode delegation never worked, because that also relied on $purchaseLink being `truish`. I now sidestep `dm.attachToLinks` completely and always attach a delegate event handler for `.lp_js_do-purchase`.