Sha256: 36c672401b269ac31713eadbbc4e3d85d0d61d97f59fbed92f972940e1378a92

Contents?: true

Size: 1.48 KB

Versions: 72

Compression:

Stored size: 1.48 KB

Contents

(function($) {
  $.fn.udongo_tagbox = function(options) {
    var settings = $.extend({
      items: 'items-path',
      limit: null,
      minLength: 2,
      on_add: function(tag, input) {},
      on_remove: function(tag, input) {}
    }, options);

    return this.each(function() {
      var input = $(this);

      if(typeof settings.items == 'string'){
        $.ajax({
          type: 'GET',
          url: input.data(settings.items)
        }).done(function(data){
          settings.items = data;
          return tagit(input, settings.items);
        });
      } else {
        return tagit(input, settings.items);
      }

      function tagit(input, items) {
        input.tagit({
          autocomplete: {
            minLength: settings.minLength,
            source: function(request, response) {
              response($.ui.autocomplete.filter(settings.items, request.term));
            }
          },
          allowSpaces: true,
          caseSensitive: false,
          removeConfirmation: true,
          tagLimit: settings.limit,
          beforeTagAdded: function(event, ui) {
            if($.isFunction(settings.on_add)){
              settings.on_add.call(this, ui.tag.find('.tagit-label').text(), input);
            }
          },
          afterTagRemoved: function(event, ui) {
            if($.isFunction(settings.on_remove)){
              settings.on_remove.call(this, ui.tag.find('.tagit-label').text(), input);
            }
          }
        });
      }
    });
  };
}(jQuery));

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
udongo-7.9.0 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.8.1 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.8.0 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.7.2 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.7.1 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.7.0 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.6.2 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.6.1 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.6.0 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.5.1 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.5.0 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.4.2 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.4.1 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.4.0 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.3.5 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.3.4 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.3.3 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.3.2 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.3.1 app/assets/javascripts/backend/plugins/tagbox.js
udongo-7.2.1 app/assets/javascripts/backend/plugins/tagbox.js