Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge #35 and add a package.json for easy dependency installation

  • Loading branch information...
commit f037ddc37315cf1a2e936791284ccd37f2d65830 1 parent b90301c
@meltingice authored
View
3  .gitignore
@@ -1,2 +1,3 @@
.DS_Store
-sftp-config.json
+sftp-config.json
+node_modules
View
2  Cakefile
@@ -15,7 +15,7 @@ targetCoffee = "#{csSrcDir}/build.coffee"
targetJS = "#{csTargetDir}/#{targetName}.js"
targetMinJS = "#{csTargetDir}/#{targetName}.min.js"
-coffeeOpts = "-b -r coffeescript-growl -j #{targetName}.js -o #{csTargetDir} -c #{targetCoffee}"
+coffeeOpts = "-b -j #{targetName}.js -o #{csTargetDir} -c #{targetCoffee}"
coffeeFiles = [
"ajax-chosen"
View
6 README.md
@@ -99,4 +99,10 @@ $("#example-input").ajaxChosen({
## Developing ajax-chosen
+In order to install development dependencies, you can run in the ajax-chosen directory:
+
+```
+npm install -d
+```
+
ajax-chosen is written in Coffeescript, so there is a Cakefile provided that will perform all necessary tasks for you. Simply run `cake` to see all available commands.
View
9 lib/ajax-chosen.js
@@ -1,3 +1,5 @@
+// Generated by CoffeeScript 1.3.3
+
(function($) {
return $.fn.ajaxChosen = function(settings, callback, chosenOptions) {
var chosenXhr, defaultOptions, options, select;
@@ -21,7 +23,8 @@
this.chosen(chosenOptions ? chosenOptions : {});
return this.each(function() {
return $(this).next('.chzn-container').find(".search-field > input, .chzn-search > input").bind('keyup', function() {
- var field, msg, success, val;
+ var field, msg, success, untrimmed_val, val;
+ untrimmed_val = $(this).attr('value');
val = $.trim($(this).attr('value'));
msg = val.length < options.minTermLength ? "Keep typing..." : "Looking for '" + val + "'";
select.next('.chzn-container').find('.no-results').text(msg);
@@ -78,7 +81,7 @@
if (success != null) {
success(data);
}
- return field.attr('value', val);
+ return field.attr('value', untrimmed_val);
};
return this.timer = setTimeout(function() {
if (chosenXhr) {
@@ -89,4 +92,4 @@
});
});
};
-})(jQuery);
+})(jQuery);
View
16 lib/ajax-chosen.min.js
@@ -1,3 +1,13 @@
-(function(b){return b.fn.ajaxChosen=function(c,h,f){var e,a,g;null==c&&(c={});null==h&&(h={});null==f&&(f=function(){});g=this;e=null;a=b.extend({},{minTermLength:3,afterTypeDelay:500,jsonTermKey:"term"},c);this.chosen(f?f:{});return this.each(function(){return b(this).next(".chzn-container").find(".search-field > input, .chzn-search > input").bind("keyup",function(){var f,c,i,d;d=b.trim(b(this).attr("value"));c=d.length<a.minTermLength?"Keep typing...":"Looking for '"+d+"'";g.next(".chzn-container").find(".no-results").text(c);
-if(d===b(this).data("prevVal"))return!1;b(this).data("prevVal",d);this.timer&&clearTimeout(this.timer);if(d.length<a.minTermLength)return!1;f=b(this);null==a.data&&(a.data={});a.data[a.jsonTermKey]=d;null!=a.dataCallback&&(a.data=a.dataCallback(a.data));i=a.success;a.success=function(a){var c,e;if(a!=null){e=[];g.find("optgroup").each(function(){return b(this).remove()});g.find("option").each(function(){return b(this).is(":selected")?e.push(b(this).val()+"-"+b(this).text()):b(this).remove()});c=h(a);
-b.each(c,function(a,c){var d;if(c.group){d=b("<optgroup />").attr("label",c.text).appendTo(g);return b.each(c.items,function(a,c){if(b.inArray(a+"-"+c,e)===-1)return b("<option />").attr("value",a).html(c).appendTo(d)})}if(b.inArray(a+"-"+c,e)===-1)return b("<option />").attr("value",a).html(c).appendTo(g)});g.trigger("liszt:updated");i!=null&&i(a);return f.attr("value",d)}};return this.timer=setTimeout(function(){e&&e.abort();return e=b.ajax(a)},a.afterTypeDelay)})})}})(jQuery);
+
+(function($){return $.fn.ajaxChosen=function(settings,callback,chosenOptions){var chosenXhr,defaultOptions,options,select;if(settings==null){settings={};}
+if(callback==null){callback={};}
+if(chosenOptions==null){chosenOptions=function(){};}
+defaultOptions={minTermLength:3,afterTypeDelay:500,jsonTermKey:"term"};select=this;chosenXhr=null;options=$.extend({},defaultOptions,settings);this.chosen(chosenOptions?chosenOptions:{});return this.each(function(){return $(this).next('.chzn-container').find(".search-field > input, .chzn-search > input").bind('keyup',function(){var field,msg,success,untrimmed_val,val;untrimmed_val=$(this).attr('value');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===$(this).data('prevVal')){return false;}
+$(this).data('prevVal',val);if(this.timer){clearTimeout(this.timer);}
+if(val.length<options.minTermLength){return false;}
+field=$(this);if(!(options.data!=null)){options.data={};}
+options.data[options.jsonTermKey]=val;if(options.dataCallback!=null){options.data=options.dataCallback(options.data);}
+success=options.success;options.success=function(data){var items,selected_values;if(!(data!=null)){return;}
+selected_values=[];select.find('optgroup').each(function(){return $(this).remove();});select.find('option').each(function(){if(!$(this).is(":selected")){return $(this).remove();}else{return selected_values.push($(this).val()+"-"+$(this).text());}});items=callback(data);$.each(items,function(value,element){var group;if(element.group){group=$("<optgroup />").attr('label',element.text).appendTo(select);return $.each(element.items,function(value,text){if($.inArray(value+"-"+text,selected_values)===-1){return $("<option />").attr('value',value).html(text).appendTo(group);}});}else if($.inArray(value+"-"+element,selected_values)===-1){return $("<option />").attr('value',value).html(element).appendTo(select);}});select.trigger("liszt:updated");if(success!=null){success(data);}
+return field.attr('value',untrimmed_val);};return this.timer=setTimeout(function(){if(chosenXhr){chosenXhr.abort();}
+return chosenXhr=$.ajax(options);},options.afterTypeDelay);});});};})(jQuery);
View
14 package.json
@@ -0,0 +1,14 @@
+{
+ "name": "ajax-chosen",
+ "description": "A complement to the jQuery library Chosen that adds ajax autocomplete",
+ "version": "0.2.0",
+ "author": {
+ "name": "Ryan LeFevre",
+ "email": "meltingice8917@gmail.com",
+ "url": "http://meltingice.net"
+ },
+ "devDependencies": {
+ "coffee-script": ">= 1.3.1",
+ "jsmin": "*"
+ }
+}

0 comments on commit f037ddc

Please sign in to comment.
Something went wrong with that request. Please try again.