forked from tuupola/jquery_chained
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.chained.remote.min.js
2 lines (2 loc) · 1.35 KB
/
jquery.chained.remote.min.js
1
2
/*! Chained 0.9.9 - MIT license - Copyright 2010-2013 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).attr("disabled","disabled"):a(c).removeAttr("disabled")}var c=this;a(e.parents).each(function(){a(this).bind("change",function(){var d={};a(e.parents).each(function(){var b=a(this).attr(e.attribute),f=a(":selected",this).val();d[b]=f,e.depends&&a(e.depends).each(function(){if(c!==this){var b=a(this).attr(e.attribute),f=a(this).val();d[b]=f}})}),a.getJSON(e.url,d,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}}(window.jQuery||window.Zepto,window,document);