--- /dev/null
+// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt\r
+\r
+/**\r
+* Chained Selects for jQuery \r
+* Copyright (C) 2008 Ziadin Givan www.CodeAssembly.com \r
+*\r
+* This program is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program. If not, see http://www.gnu.org/licenses/\r
+*\r
+* \r
+* settings = { usePost : true, before:function() {}, after: function() {}, default: null, parameters : { parameter1 : 'value1', parameter2 : 'value2'} } \r
+* if usePost is true, then the form will use POST to pass the parameters to the target, otherwise will use GET\r
+* "before" function is called before the ajax request and "after" function is called after the ajax request.\r
+* If defaultValue is not null then the specified option will be selected.\r
+* You can specify additional parameters to be sent to the the server in settings.parameters.\r
+*\r
+*/\r
+;(function($) {\r
+ \r
+jQuery.fn.chainSelect = function( target, url, settings ) \r
+{\r
+ return this.each( function()\r
+ {\r
+ $(this).change( function( ) \r
+ {\r
+ settings = $.extend(\r
+ {\r
+ after : null,\r
+ before : null,\r
+ usePost : false,\r
+ defaultValue : null,\r
+ parameters : {'_id' : $(this).attr('id'), '_name' : $(this).attr('name')}\r
+ } , settings);\r
+\r
+ settings.parameters._value = $(this).val();\r
+\r
+ if (settings.before != null) \r
+ {\r
+ settings.before( target );\r
+ }\r
+\r
+ ajaxCallback = function(data, textStatus) \r
+ {\r
+ $(target).html("");//clear old options\r
+ data = eval(data);//get json array\r
+ if ( data != null ) {\r
+ for (i = 0; i < data.length; i++) {\r
+ $(target).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);\r
+ }\r
+ } else {\r
+ $(target).get(0).add(new Option('- select a country -', ''), document.all ? i : null);\r
+ }\r
+\r
+ if (settings.defaultValue != null)\r
+ {\r
+ $(target).val(settings.defaultValue);//select default value\r
+ } else\r
+ {\r
+ $("option:first", target).attr( "selected", "selected" );//select first option\r
+ }\r
+\r
+ if (settings.after != null) \r
+ {\r
+ settings.after(target);\r
+ }\r
+\r
+ $(target).change();//call next chain\r
+ };\r
+\r
+ if (settings.usePost == true)\r
+ {\r
+ $.post( url, settings.parameters, ajaxCallback );\r
+ } else\r
+ {\r
+ $.get( url, settings.parameters, ajaxCallback );\r
+ }\r
+ });\r
+ });\r
+};\r
+\r
+})(jQuery);\r
+\r
+\r
+// @license-end
\ No newline at end of file