Sha256: 8a94553bf7f8367773686f7fce09ba1a28e7a74ad5dcb2d73f28ea63ada03f86
Contents?: true
Size: 1.83 KB
Versions: 77
Compression:
Stored size: 1.83 KB
Contents
unless String::contains String::contains = (args...) -> @indexOf(args...) != -1 KEY = UP: 38 DOWN: 40 ENTER: 13 class StackSearch constructor: (root) -> @$root = $(root) @$root.on('keyup', '.stack-search', @onKeyUp) @$root.on('click', '.show-all-stacks', (event) => @$root.find('.not-matching').removeClass('not-matching') event.preventDefault() ) onKeyUp: (event) => @$items = @$root.find('[data-search]') switch event.keyCode when KEY.ENTER event.preventDefault() @goToSelectedStack() when KEY.UP event.preventDefault() @selectPrevious() when KEY.DOWN event.preventDefault() @selectNext() else @filterResults($.trim($(event.target).val()).toLowerCase()) filterResults: (query) -> if query for item in @$items $item = $(item) $item.toggleClass('not-matching', !$item.attr('data-search').toLowerCase().contains(query)) @selectFirst() else @$items.removeClass('not-matching') selectFirst: -> @$items.removeClass('selected').first(':not(.not-matching)').addClass('selected') selectNext: -> $next = @$items.filter('.selected').removeClass('selected').nextAll(':not(.not-matching)').first() $next = @$items.filter(':not(.not-matching)').first() unless $next.length $next.addClass('selected') selectPrevious: -> $previous = @$items.filter('.selected').removeClass('selected').prevAll(':not(.not-matching)').first() $previous = @$items.filter(':not(.not-matching)').last() unless $previous.length $previous.addClass('selected') goToSelectedStack: -> if stack = @$items.filter('.selected').filter(':not(.not-matching)').find('.commits-path').attr('href') window.location = stack search = new StackSearch(document) jQuery -> $('.stack-search').focus()
Version data entries
77 entries across 77 versions & 1 rubygems