Sha256: 48986df6c0d5dbc8495bfb5454e4d98a01a4f4f51424ab576670848e22d83569

Contents?: true

Size: 1.87 KB

Versions: 14

Compression:

Stored size: 1.87 KB

Contents

$(window).ready ->
#navbox mod
  $('._navbox').autocomplete {
    html: 'html',
    source: navbox_results,
    select: navbox_select
# autoFocus: true,
# this makes it so the first option ("search") is pre-selected.
# sadly, it also causes odd navbox behavior, resetting the search term
  }

#navbox mod
reqIndex = 0 #prevents race conditions

navbox_results = (request, response) ->
  f = this.element.closest 'form'
  formData = f.serialize() + '&view=complete'

  this.xhr = $.ajax {
    url: decko.prepUrl decko.rootPath + '/:search.json'
    data: formData
    dataType: "json"
    wagReq: ++reqIndex
    success: ( data, status ) ->
      response navboxize(request.term, data) if this.wagReq == reqIndex
    error: ->
      response [] if this.wagReq == reqIndex
  }

navboxize = (term, results) ->
  items = []

  $.each ['search', 'add', 'new'], (index, key) ->
    if val = results[key]
      i = {
        value: term,
        prefix: key,
        icon: 'add',
        label: '<strong class="highlight">' + term + '</strong>'
      }
      if key == 'search'
        i.icon = key
        i.term = term
      else if key == 'add'
        i.href = '/card/new?card[name]=' + encodeURIComponent(val)
      else if key == 'new'
        i.type = 'add' # for icon
        i.href = '/new/' + val[1]

      items.push i

  $.each results['goto'], (index, val) ->
    items.push {
      icon: 'arrow_forward', prefix: 'go to', value: val[0], label: val[1],
      href: '/' + val[2]
    }

  $.each items, (index, i) ->
    i.label =
      '<i class="material-icons">' + i.icon + '</i>' +
      '<span class="navbox-item-label">' + i.prefix + ':</span> ' +
      '<span class="navbox-item-value">' + i.label + '</span>'

  items

navbox_select = (event, ui) ->
  if ui.item.term
    $(this).closest('form').submit()
  else
    window.location = decko.rootPath + ui.item.href

  $(this).attr('disabled', 'disabled')

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
card-1.93.9 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.8 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.7 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.6 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.5 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.4 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.3 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.2 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.1 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.93.0 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.92.2 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.92.1 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.92 mod/machines/lib/javascript/decko_navbox.js.coffee
card-1.91 mod/machines/lib/javascript/decko_navbox.js.coffee