-
-
Save vitorspencer/742e4143290ba75ab3a0ef1900d97d96 to your computer and use it in GitHub Desktop.
Revisions
-
vitorspencer revised this gist
Apr 8, 2020 . 1 changed file with 37 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,43 @@ $.fn.select2.amd.define('select2/data/extended-ajax',['./ajax','./tags','../utils','module','jquery'], function(AjaxAdapter, Tags, Utils, module, $){ function ExtendedAjaxAdapter ($element,options) { //we need explicitly process minimumInputLength value //to decide should we use AjaxAdapter or return defaultResults, //so it is impossible to use MinimumLength decorator here this.minimumInputLength = options.get('minimumInputLength'); this.defaultResults = options.get('defaultResults'); ExtendedAjaxAdapter.__super__.constructor.call(this,$element,options); } Utils.Extend(ExtendedAjaxAdapter,AjaxAdapter); //override original query function to support default results var originQuery = AjaxAdapter.prototype.query; ExtendedAjaxAdapter.prototype.query = function (params, callback) { var defaultResults = (typeof this.defaultResults == 'function') ? this.defaultResults.call(this) : this.defaultResults; if (defaultResults && defaultResults.length && (!params.term || params.term.length < this.minimumInputLength)){ var data = { results: defaultResults }; var processedResults = this.processResults(data, params); callback(processedResults); } else if (params.term && params.term.length >= this.minimumInputLength) { originQuery.call(this, params, callback); } else { this.trigger('results:message', { message: 'inputTooShort', args: { minimum: this.minimumInputLength, input: '', params: params } }); } }; if (module.config().tags) { return Utils.Decorate(ExtendedAjaxAdapter, Tags); } else { return ExtendedAjaxAdapter; } }); -
Stanislav E. Govorov revised this gist
May 19, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,8 +18,8 @@ $.fn.select2.amd.define('select2/data/extended-ajax',['./ajax','../utils','jquer ExtendedAjaxAdapter.prototype.query = function (params, callback) { var defaultResults = (typeof this.defaultResults == 'function') ? this.defaultResults.call(this) : this.defaultResults; if (defaultResults && defaultResults.length && (!params.term || params.term.length < this.minimumInputLength)){ var processedResults = this.processResults(defaultResults,params.term); callback(processedResults); } else { originQuery.call(this, params, callback); -
Stanislav revised this gist
May 19, 2016 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,8 +6,6 @@ $.fn.select2.amd.define('select2/data/extended-ajax',['./ajax','../utils','jquer //so it is impossible to use MinimumLength decorator here this.minimumInputLength = options.get('minimumInputLength'); this.defaultResults = options.get('defaultResults'); ExtendedAjaxAdapter.__super__.constructor.call(this,$element,options); } -
Stanislav revised this gist
May 19, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ $.fn.select2.amd.define('select2/data/extended-ajax',['./ajax','../utils','jquer ExtendedAjaxAdapter.prototype.query = function (params, callback) { var defaultResults = (typeof this.defaultResults == 'function') ? this.defaultResults.call(this) : this.defaultResults; if (defaultResults && defaultResults.length && (!params.term || params.term.length < this.minimumInputLength)){ //no need to use processResults, pass them directly to callback callback({results:defaultResults}); } -
Stanislav created this gist
May 19, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ $.fn.select2.amd.define('select2/data/extended-ajax',['./ajax','../utils','jquery'], function(AjaxAdapter, Utils, $){ function ExtendedAjaxAdapter ($element,options) { //we need explicitly process minimumInputLength value //to decide should we use AjaxAdapter or return defaultResults, //so it is impossible to use MinimumLength decorator here this.minimumInputLength = options.get('minimumInputLength'); this.defaultResults = options.get('defaultResults'); this.$element = $element; this.options = options; ExtendedAjaxAdapter.__super__.constructor.call(this,$element,options); } Utils.Extend(ExtendedAjaxAdapter,AjaxAdapter); //override original query function to support default results var originQuery = AjaxAdapter.prototype.query; ExtendedAjaxAdapter.prototype.query = function (params, callback) { var defaultResults = (typeof this.defaultResults == 'function') ? this.defaultResults.call(this) : this.defaultResults; if (defaultResults && defaultResults.length && (!params.term || params.term.length < this.minimumInputength)){ //no need to use processResults, pass them directly to callback callback({results:defaultResults}); } else { originQuery.call(this, params, callback); } }; return ExtendedAjaxAdapter; });