Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
998fe31
commit 76d87f4
Showing
4 changed files
with
98 additions
and
112 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,85 @@ | ||
(function() { | ||
(function($) { | ||
if ($ == null) { | ||
$ = jQuery; | ||
} | ||
return $.fn.ajaxChosen = function(settings, callback) { | ||
var chosenXhr, defaultOptions, options, select; | ||
if (settings == null) { | ||
settings = {}; | ||
|
||
(function($) { | ||
if ($ == null) $ = jQuery; | ||
return $.fn.ajaxChosen = function(settings, callback) { | ||
var chosenXhr, defaultOptions, options, select; | ||
if (settings == null) settings = {}; | ||
if (callback == null) callback = function() {}; | ||
defaultOptions = { | ||
minTermLength: 3, | ||
afterTypeDelay: 500, | ||
jsonTermKey: "term" | ||
}; | ||
select = this; | ||
chosenXhr = null; | ||
options = $.extend({}, defaultOptions, settings); | ||
this.chosen(); | ||
this.next('.chzn-container').find(".search-field > input").bind('keyup', function() { | ||
var field, msg, val; | ||
val = $.trim($(this).attr('value')); | ||
msg = val.length < options.minTermLength ? "Keep typing..." : "Looking for '" + val + "'"; | ||
select.next('.chzn-container').find('.no-results').text(msg); | ||
if (val.length < options.minTermLength || val === $(this).data('prevVal')) { | ||
return false; | ||
} | ||
if (callback == null) { | ||
callback = function() {}; | ||
if (this.timer) clearTimeout(this.timer); | ||
$(this).data('prevVal', val); | ||
field = $(this); | ||
if (!(options.data != null)) options.data = {}; | ||
options.data[options.jsonTermKey] = val; | ||
if (typeof success === "undefined" || success === null) { | ||
success = options.success; | ||
} | ||
defaultOptions = { | ||
minTermLength: 3, | ||
afterTypeDelay: 500, | ||
jsonTermKey: "term" | ||
options.success = function(data) { | ||
var items; | ||
if (!(data != null)) return; | ||
select.find('option').each(function() { | ||
if (!$(this).is(":selected")) return $(this).remove(); | ||
}); | ||
items = callback(data); | ||
$.each(items, function(value, text) { | ||
return $("<option />").attr('value', value).html(text).appendTo(select); | ||
}); | ||
select.trigger("liszt:updated"); | ||
if (typeof success !== "undefined" && success !== null) success(); | ||
field.attr('value', val); | ||
return field.css('width', 'auto'); | ||
}; | ||
select = this; | ||
chosenXhr = null; | ||
options = $.extend({}, defaultOptions, settings); | ||
this.chosen(); | ||
this.next('.chzn-container').find(".search-field > input").bind('keyup', function() { | ||
var field, msg, val; | ||
val = $.trim($(this).attr('value')); | ||
msg = val.length < options.minTermLength ? "Keep typing..." : "Looking for '" + val + "'"; | ||
select.next('.chzn-container').find('.no-results').text(msg); | ||
if (val.length < options.minTermLength || val === $(this).data('prevVal')) { | ||
return false; | ||
} | ||
if (this.timer) { | ||
clearTimeout(this.timer); | ||
} | ||
$(this).data('prevVal', val); | ||
field = $(this); | ||
if (!(options.data != null)) { | ||
options.data = {}; | ||
} | ||
options.data[options.jsonTermKey] = val; | ||
if (typeof success === "undefined" || success === null) { | ||
success = options.success; | ||
} | ||
options.success = function(data) { | ||
var items; | ||
if (!(data != null)) { | ||
return; | ||
} | ||
select.find('option').each(function() { | ||
if (!$(this).is(":selected")) { | ||
return $(this).remove(); | ||
} | ||
}); | ||
items = callback(data); | ||
$.each(items, function(value, text) { | ||
return $("<option />").attr('value', value).html(text).appendTo(select); | ||
}); | ||
select.trigger("liszt:updated"); | ||
if (typeof success !== "undefined" && success !== null) { | ||
success(); | ||
} | ||
field.attr('value', val); | ||
return field.css('width', 'auto'); | ||
}; | ||
return this.timer = setTimeout(function() { | ||
if (chosenXhr) { | ||
chosenXhr.abort(); | ||
} | ||
return chosenXhr = $.ajax(options); | ||
}, options.afterTypeDelay); | ||
}); | ||
return this.next('.chzn-container').find(".chzn-search > input").bind('keyup', function() { | ||
var field, val; | ||
val = $.trim($(this).attr('value')); | ||
if (val.length < options.minTermLength || val === $(this).data('prevVal')) { | ||
return false; | ||
} | ||
field = $(this); | ||
options.data = {}; | ||
options.data[options.jsonTermKey] = val; | ||
if (typeof success === "undefined" || success === null) { | ||
success = options.success; | ||
} | ||
options.success = function(data) { | ||
var items; | ||
if (!(data != null)) { | ||
return; | ||
} | ||
select.find('option').each(function() { | ||
return $(this).remove(); | ||
}); | ||
items = callback(data); | ||
$.each(items, function(value, text) { | ||
return $("<option />").attr('value', value).html(text).appendTo(select); | ||
}); | ||
select.trigger("liszt:updated"); | ||
field.attr('value', val); | ||
if (typeof success !== "undefined" && success !== null) { | ||
return success(); | ||
} | ||
}; | ||
return this.timer = setTimeout(function() { | ||
if (chosenXhr) { | ||
chosenXhr.abort(); | ||
} | ||
return chosenXhr = $.ajax(options); | ||
}, options.afterTypeDelay); | ||
}); | ||
}; | ||
})($); | ||
}).call(this); | ||
return this.timer = setTimeout(function() { | ||
if (chosenXhr) chosenXhr.abort(); | ||
return chosenXhr = $.ajax(options); | ||
}, options.afterTypeDelay); | ||
}); | ||
return this.next('.chzn-container').find(".chzn-search > input").bind('keyup', function() { | ||
var field, val; | ||
val = $.trim($(this).attr('value')); | ||
if (val.length < options.minTermLength || val === $(this).data('prevVal')) { | ||
return false; | ||
} | ||
field = $(this); | ||
options.data = {}; | ||
options.data[options.jsonTermKey] = val; | ||
if (typeof success === "undefined" || success === null) { | ||
success = options.success; | ||
} | ||
options.success = function(data) { | ||
var items; | ||
if (!(data != null)) return; | ||
select.find('option').each(function() { | ||
return $(this).remove(); | ||
}); | ||
items = callback(data); | ||
$.each(items, function(value, text) { | ||
return $("<option />").attr('value', value).html(text).appendTo(select); | ||
}); | ||
select.trigger("liszt:updated"); | ||
field.attr('value', val); | ||
if (typeof success !== "undefined" && success !== null) return success(); | ||
}; | ||
return this.timer = setTimeout(function() { | ||
if (chosenXhr) chosenXhr.abort(); | ||
return chosenXhr = $.ajax(options); | ||
}, options.afterTypeDelay); | ||
}); | ||
}; | ||
})($); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.