dimanche 12 juin 2016

jQuery: Lightbox close event handling

I have a simple lightbox on the page, where the close icon has some class .closeIt. When user clicks the close icon, I want to shift the focus back to the link element, which triggered the lightbox.

I tried adding some function which takes input of the triggering link and the closing icon class name.

 function focusBack(triggeringLinkId,closingLinkClass){
     $(closingLinkClass).click(function () {
        $(triggeringLinkId).focus();
     });
  }

and for each lightbox, I manually called the function back like this:

 focusBack('#someLink','.closeIt')

this approach works fine if I only have one lightbox on the page, but if I have more than one lightboxes, it starts binding it to the last called function, and now whatever lightbox I close, the focus goes back to the triggering link for which I last called the focusBack function.

What's the best approach to deal with this kind of situation?

Aucun commentaire:

Enregistrer un commentaire