Sha256: 363f8768f6a6114fd61a07ca55b1352b4cca18703b6cdc4e2d9ce443d6af47e1

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

$ ->
  $menu = $('#iam-menu')
  linkTemplate = $menu.attr 'href'
  inputMode = false
  input = ''

  iamNotice = (notice) ->
    $notice = $("<div class='iam-notice'>#{notice}</div>")
    $('body').append $notice
    $notice.fadeIn(200).delay(1000).fadeOut 600

  log_in_by_link = (link) ->
    $.post link, (data) ->
      $menu.hide()
      window.location.reload()
      iamNotice data.notice

  log_in_by_input = ->
    if inputMode
      if input.match(/^\d+$/)
        link = linkTemplate.replace(/ID/, input)
        log_in_by_link link
      else
        iamNotice "#{input} is invalid id." if input
    input = ''

  $menu.on 'click', 'td', ->
    $tr = $(@).parents 'tr'
    link = $tr.attr 'href'
    if link
      log_in_by_link link
      inputMode = false
      input = ''

  $(document).on 'keypress', (e) ->
    $selectedInput = $(document.getSelection().focusNode).find('input')

    if $selectedInput.length == 0 && (e.keyCode == 96 || e.keyCode == 1105) # '`' || 'ё'
      log_in_by_input()

      inputMode = !inputMode
      $menu.toggle()
    else
      input += String.fromCharCode e.keyCode

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iam-0.1.2 vendor/assets/javascripts/iam.js.coffee
iam-0.1.1 vendor/assets/javascripts/iam.js.coffee