         e.stopImmediatePropagation()
         # close only topmost dialog
         currentDialogPr?.reject()
+      if e.which == 9  # Tab
+        lockDialogFocus(e)
 
   currentDialogPr = null
   openedClass = 'uploadcare--page'
+  originalFocusedElement = null
+  focusableElements = null
 
   ns.isDialogOpened = ->
     currentDialogPr != null


uploadcare.namespace '', (ns) ->

  lockScroll = (el, toTop) ->
    top = el.scrollTop()
    left = el.scrollLeft()

    dialog.addClass('uploadcare--dialog_status_active')
    dialogPr.dialogElement = dialog

    focusableElements = dialog.find('select, input, textarea, button, a[href]')
    focusableElements.first().focus()

    cancelLock = lockScroll($(window), dialog.css('position') is 'absolute')
    $('html, body').addClass(openedClass)

