Monday, 15 April 2013

javascript - Return focus after modal closes -



javascript - Return focus after modal closes -

i using venobox modal , need ada support. i've tweaked few things create work well, need 1 more piece. need focus homecoming element a.venobox opened modal when close button pressed.

in words, if user tabbing through site, opened modal, closed it, , tabbed 1 time again pick left off.

i tried inserting tabindex works first tab, jumps top of page. then, tried adding hold focus homecoming when closed, i'm not best js.

thanks

my current code:

$(document).ready(function(){ $('.venobox').venobox().click(function() { $('.vbox-close').attr('tabindex', '1').attr('title','close modal'); var focusreturn = $(this).focus(); $(".vbox-close").click(function(){ homecoming focusreturn; }); }); });

setting var focusreturn = $(this).focus(); set custom variable homecoming value of focus function (which element called on). additionally, the homecoming value in event handler used prevent default event propagation.

what meant var focusreturn = $(this).focus;, phone call focusreturn(); within click-handler. however, i'd recommend against it's functional approach non-functional problem. , writing functionally in non-functional languages such javascript hard read.

however, there more mutual (and more mutual sense) way this:

// don't need line // var focusreturn = $(this).focus(); $(".vbox-close").click($.proxy(function() { $(this).focus(); }, this));

jquery's proxy function used alter closure context in function executes.

(possibly) way improve place event handler on close event on .vbox-close, i'm not familiar plenty plugin know events supports. it's worth investigating though, dialog box c(sh)ould presumably closed in more ways clicking on close button.

javascript jquery modal-dialog focus

No comments:

Post a Comment