Sha256: da0da2eb14c802ebba3742df6261324a1c92db29bfc206d3d4e1780feaa09879

Contents?: true

Size: 1.87 KB

Versions: 23

Compression:

Stored size: 1.87 KB

Contents

//extend ui auto-complete to include categories and errors
$.widget( "custom.catcomplete", $.ui.autocomplete, {
  _renderMenu: function( ul, items ) {
    var self = this, currentCategory = "";
    $.each( items, function( index, item ) {
      if ( item.category != undefined && item.category != currentCategory ) {
        ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
        currentCategory = item.category;
      }
      if ( item.error != undefined ) {
        ul.append( "<li class='ui-autocomplete-error'>" + item.error + "</li>" );
      }
      self._renderItemData( ul, item );
    });
  },
  _renderItem: function( ul, item ) {
    return $( "<li>" )
        .append( "<a> <i class='ui-autocomplete-completed'>" + item.completed + "</i>" + item.part + "</a>" )
        .appendTo( ul );
  }
});


  $.fn.scopedSearch = function(){
    var options = arguments[0] || {};
    $(this).each(function(i,el){
      var target = $(el);

      target.catcomplete({
        source: options.source || function( request, response ) {
          $.getJSON( target.data("url"), { search: request.term }, response );
        },
        minLength: options.minLength || 0,
        delay: options.delay || 100,
        select: function(event, ui) {
          target.val( ui.item.value );
        },
        search: function(event, ui) {
          $(".autocomplete-clear").hide();
        },
        response: function(event, ui) {
          $(".autocomplete-clear").show();
        },
        close: function(event, ui) {
          $(".autocomplete-input:focus").catcomplete( target.attr('id'));
        }
      });

      target.bind("focus", function( event ){
        $(this).catcomplete( target.attr('id'));
      });
      target.after('<a class="autocomplete-clear" tabindex="-1" title="Clear">&times;</a>')
      target.next().on("click",function(){ target.val(''); })
    })
  };

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
scoped_search-4.1.3 app/assets/javascripts/scoped_search.js
scoped_search-4.1.2 app/assets/javascripts/scoped_search.js
scoped_search-4.1.1 app/assets/javascripts/scoped_search.js
scoped_search-4.1.0 app/assets/javascripts/scoped_search.js
scoped_search-4.0.0 app/assets/javascripts/scoped_search.js
scoped_search-3.3.0 app/assets/javascripts/scoped_search.js
scoped_search-3.2.2 app/assets/javascripts/scoped_search.js
scoped_search-3.2.1 app/assets/javascripts/scoped_search.js
scoped_search-3.2.0 app/assets/javascripts/scoped_search.js
scoped_search-3.1.0 app/assets/javascripts/scoped_search.js
scoped_search-3.0.1 app/assets/javascripts/scoped_search.js
scoped_search-3.0.0 app/assets/javascripts/scoped_search.js
scoped_search-2.7.1 app/assets/javascripts/scoped_search.js
scoped_search-2.7.0 app/assets/javascripts/scoped_search.js
scoped_search-2.6.5 app/assets/javascripts/scoped_search.js
scoped_search-2.6.4 app/assets/javascripts/scoped_search.js
scoped_search-2.6.3 app/assets/javascripts/scoped_search.js
scoped_search-2.6.2 app/assets/javascripts/scoped_search.js
scoped_search-2.6.1 app/assets/javascripts/scoped_search.js
scoped_search-2.6.0 app/assets/javascripts/scoped_search.js