text: this.ckan.module('autocomplete',function(jQuery,_){return{options:{tags:false,items:10,source:null,interval:1000,dropdownClass:'',containerClass:'',i18n:{noMatches:_('No matches found'),emptySearch:_('Start typing…'),inputTooShort:function(data){return _('Input is too short, must be at least one character').ifPlural(data.min,'Input is too short, must be at least %(min)d characters');}}},initialize:function(){jQuery.proxyAll(this,/_on/,/format/);this.setupAutoComplete();},setupAutoComplete:function(){var settings={width:'resolve',formatResult:this.formatResult,formatNoMatches:this.formatNoMatches,formatInputTooShort:this.formatInputTooShort,dropdownCssClass:this.options.dropdownClass,containerCssClass:this.options.containerClass};if(!this.el.is('select')){if(this.options.tags){settings.tags=this._onQuery;}else{settings.query=this._onQuery;settings.createSearchChoice=this.formatTerm;}
  settings.initSelection=this.formatInitialValue;}
  var select2=this.el.select2(settings).data('select2');if(this.options.tags&&select2&&select2.search){select2.search.on('keydown',this._onKeydown);}},getCompletions:function(string,fn){var parts=this.options.source.split('?');var end=parts.pop();var source=parts.join('?')+encodeURIComponent(string)+end;var client=this.sandbox.client;var options={format:client.parseCompletionsForPlugin};return client.getCompletions(source,options,fn);},lookup:function(string,fn){var module=this;this._lastTerm=string;if(string){if(!this._debounced){this._debounced=setTimeout(function(){var term=module._lastTerm;delete module._debounced;if(module._last){module._last.abort();}
  module._last=module.getCompletions(term,function(terms){fn(module._lastResults=terms);});},this.options.interval);}else{fn(this._lastResults||{results:[]});}}else{fn({results:[]});}},formatResult:function(state,container,query){var term=this._lastTerm||null;if(container){container.attr('data-value',state.id);}
  return state.text.split(term).join(term&&term.bold());},formatNoMatches:function(term){return!term?this.i18n('emptySearch'):this.i18n('noMatches');},formatInputTooShort:function(term,min){return this.i18n('inputTooShort',{min:min});},formatTerm:function(term){term=jQuery.trim(term||'');return{id:term.replace(/,/g,'\u002C'),text:term};},formatInitialValue:function(element,callback){var value=jQuery.trim(element.val()||'');var formatted;if(this.options.tags){formatted=jQuery.map(value.split(","),this.formatTerm);}else{formatted=this.formatTerm(value);}
  if(typeof callback==='function'){callback(formatted);}
  return formatted;},_onQuery:function(options){if(options){this.lookup(options.term,options.callback);}},_onKeydown:function(event){if(event.which===188){event.preventDefault();setTimeout(function(){var e=jQuery.Event("keydown",{which:13});jQuery(event.target).trigger(e);},10);}}};});