forked from tuupola/jquery_chained
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.chained.remote.min.js
2 lines (2 loc) · 1.5 KB
/
jquery.chained.remote.min.js
1
2
/*! Chained 0.9.10 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function(a){"use strict";a.fn.remoteChained=function(b,c,d){var e;return"object"==typeof b&&"undefined"!=typeof b.url?e=a.extend({},a.fn.remoteChained.defaults,b):(e=a.extend({},a.fn.remoteChained.defaults,d),e.parents=b,e.url=c),this.each(function(){function b(b){var d=a(":selected",c).val();a("option",c).remove();var e=[];if(a.isArray(b))e=b;else for(var f in b)b.hasOwnProperty(f)&&e.push([f,b[f]]);for(var g=0;g!==e.length;g++){var h=e[g][0],i=e[g][1];if("selected"!==h){var j=a("<option />").val(h).append(i);a(c).append(j)}else d=i}a(c).children().each(function(){a(this).val()===d&&a(this).attr("selected","selected")}),1===a("option",c).size()&&""===a(c).val()?a(c).prop("disabled",!0):a(c).prop("disabled",!1)}var c=this,d=!1;a(e.parents).each(function(){a(this).bind("change",function(){var f={};a(e.parents).each(function(){var b=a(this).attr(e.attribute),d=a(":selected",this).val();f[b]=d,e.depends&&a(e.depends).each(function(){if(c!==this){var b=a(this).attr(e.attribute),d=a(this).val();f[b]=d}})}),d&&a.isFunction(d.abort)&&(d.abort(),d=!1),e.clear&&(e.loading?b.call(c,{"":e.loading}):a("option",c).remove(),a(c).trigger("change")),d=a.getJSON(e.url,f,function(d){b.call(c,d),a(c).trigger("change")})}),e.bootstrap&&(b.call(c,e.bootstrap),e.bootstrap=null)})})},a.fn.remoteChainedTo=a.fn.remoteChained,a.fn.remoteChained.defaults={attribute:"name",depends:null,bootstrap:null,loading:null,clear:!1}}(window.jQuery||window.Zepto,window,document);