/*
	select-filters.js v0.9 **http://select-filters.projet.cc
	jQuery plugin that allow you to link a text input with a select tag, and use the input to filter options

	Copyright (c) 2014 Ezzayer Amine **http://www.ezzayer.me
	MIT license **https://raw.github.com/ezz-amine/select-filters/master/LICENSE
	
 */
$.fn.selectFilters = function(opt,p,v){
	if($(this).length > 1){
		$(this).each(function(){
			$(this).selectFilters(opt,p,v);
		});
		return false;
	} 
	var fi = $(this[0]);
	var target = null;
	var defaultParam = {
		min:3,
		on:"keyup", //keyup, keydown, change
		multipleWord:{
			active: false,
			method  : "and" // "and" or "or"
		},
		accentFolding: true
	};
	functionCheck(opt,p,v);
	check(opt,init);
	function check(opt,callback){
		if(!fi.is("input:text")){
			console.log("$.selectFilters work only with text input.");
			return false;
		}
		target = fi.data("target");
		if(typeof target === "undefined"){
			console.log("$.selectFilters need a data-target attribut pointing to a select tag.");
			return false;
		}
		target = $(target);
		if(!target.is("select")){
			console.log("$.selectFilters need a select tag, a none select tag giving.");
			return false;
		}
		optCheck(opt);
		callback();
	}
	function init(){
		param= fi.data("param");
		target.find("option").each(function(){
			opt = $(this);
			val = opt.text().trim();
			opt.attr("data-value",val);
		});
		fi.data("options",target.find("option"));
		fi.data("filtered",false);
		fi.on(param.on,event_triggered);
	}
	function functionCheck(opt,p,v){
		if(typeof opt === "string"){
			if(opt == "option") return option(p,v);
		}
	}
	function optCheck(opt){
		opt = typeof opt === "undefined" ? {}  : opt;
		fi.data("param",defaultParam);
		$.extend(fi.data("param"),opt);
	}
	function option(p,v){
		if(typeof p !== "undefined"){
			param= fi.data("param");
			if(typeof v === "undefined"){
				return param['p'];
			}else{
				param['p'] = v;
			}
		}
		return fi;
	}
	function rd(str){
		param = fi.data("param");
		return param.accentFolding ? removeDiacritics(str) : str;
	}
	function event_triggered(e){
		param= fi.data("param");
		if(param.min <= $(this).val().length){
			target.empty();
			fi.data("filtered",true);
			fi.data("options").filter(function(){
				opt = $(this);
				if(param.multipleWord.active){
					words = fi.val().split(" ");
					var rep = (param.multipleWord.method == 'and');
					$.each(words,function(id,val){
						if(param.multipleWord.method == 'and'){
							rep = rep && (rd(opt.data("value")).toLowerCase().indexOf(rd(val).toLowerCase()) != -1);
						}else{
							rep = rep || (rd(opt.data("value")).toLowerCase().indexOf(rd(val).toLowerCase()) != -1);
						}
					});
					return rep;
				}else{
					return (rd(opt.data("value")).toLowerCase().indexOf(rd(fi.val()).toLowerCase()) != -1);
				}
			}).appendTo(target);
		}else{
			if(fi.data("filtered")){
				fi.data("options").appendTo(target);
				fi.data("filtered",false);
			}
		}
	}
	return fi;
}
@@ -458,10 +458,9 @@
 ;%0A%09%7D
- 
 %0A
+
 %09var
@@ -1184,16 +1184,34 @@
 ;%0A%09%09%7D%0A%09%09
+if(opt !== false) 
 optCheck
@@ -1622,16 +1622,56 @@
 n(p,v);%0A
+%09%09%09if(opt == %22reload%22) return reload();%0A
 %09%09%7D%0A%09%7D%0A%09
@@ -2002,24 +2002,271 @@
 turn fi;%0A%09%7D%0A
+%09function reload()%7B%0A%09%09check(false,function()%7B%0A%09%09%09target.find(%22option:not(%5Bdata-value%5D)%22).each(function()%7B%0A%09%09%09%09opt = $(this);%0A%09%09%09%09val = opt.text().trim();%0A%09%09%09%09opt.attr(%22data-value%22,val);%0A%09%09%09%7D);%0A%09%09%09fi.data(%22options%22,target.find(%22option%22));%0A%09%09%7D);%0A%09%7D%0A
 %09function rd
@@ -3279,9 +3279,10 @@
 urn fi;%0A
-
 %7D
+%0A

Update select-filters.js