Sha256: b41ee492e49daf60e45e43fdbad75986f921892e19a9d5020321a6df784249e3
Contents?: true
Size: 1.88 KB
Versions: 13
Compression:
Stored size: 1.88 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: wagn.prepUrl wagn.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: 'plus', 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: 'share-alt', prefix: 'go to', value: val[0], label: val[1], href: '/' + val[2] } $.each items, (index, i) -> i.label = '<span class="glyphicon glyphicon-' + i.icon + '"></span>' + '<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 = wagn.rootPath + ui.item.href $(this).attr('disabled', 'disabled')
Version data entries
13 entries across 13 versions & 1 rubygems