{:uriI"file:///Users/sean/dev/subdivision_select/app/assets/javascripts/subdivision_select.js?type=application/javascript&pipeline=self&id=3577cfe01dac74471f3cb5a92279b4d9084f4e6e08e7cb51ff420ba5fdf1c2c9:ET:load_pathI">/Users/sean/dev/subdivision_select/app/assets/javascripts;F: filenameI"T/Users/sean/dev/subdivision_select/app/assets/javascripts/subdivision_select.js;T: nameI"subdivision_select;T:logical_pathI"subdivision_select.self.js;T:content_typeI"application/javascript;T: sourceI"var SubdivisionSelect = (function() { SubdivisionSelect.subdivisionSelector = "select.subdivision-selector"; SubdivisionSelect.countrySelector = "select[id$=country]"; function SubdivisionSelect(element) { this._countrySelect = element; this._subdivisionSelect = $(element). closest("form"). find(SubdivisionSelect.subdivisionSelector); }; SubdivisionSelect.init = function () { var klass = this; return $(klass.countrySelector).each(function() { return new klass(this).init(); }); }; SubdivisionSelect.prototype.init = function() { var self = this; $(this._countrySelect).change(function() { $.ajax( { url: "/subdivisions", data: { country_code: $(this).val() } }).success(function(newSubdivisions) { self._clearSubdivisionSelect(); self._updateSubdivisionSelect(newSubdivisions); }); }); }; SubdivisionSelect.prototype._updateSubdivisionSelect = function(newSubdivisions) { var self = this; var isEmpty = $.isEmptyObject(newSubdivisions); $.each(newSubdivisions, function(alpha2, name) { self._subdivisionSelect.append($("").attr("value", alpha2).text(name)); }); // Disable the select if there are no newSubdivisions (and un-do that once there are some) self._subdivisionSelect.prop("disabled", isEmpty); // If there are none, make it say "none" if (isEmpty) { self._subdivisionSelect.append($("").text("none")); } }; // Not only empty the select, but: // if the first element is blank, add a blank element before all others SubdivisionSelect.prototype._clearSubdivisionSelect = function() { var includeBlank = this._subdivisionSelect.children().first().text() === ""; this._subdivisionSelect.empty(); if (includeBlank) { this._subdivisionSelect.append($("")); } }; return SubdivisionSelect; })(); $(function() { SubdivisionSelect.init(); }); ;T: metadata{ :dependencieso:Set: @hash{ I"environment-version;TTI"environment-paths;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"bfile-digest:///Users/sean/dev/subdivision_select/app/assets/javascripts/subdivision_select.js;TT: requiredo;;{: stubbedo;;{: linkso;;{: charsetI" utf-8;F: digest"%p30/ȠXOA\KhtK\: lengthi:integrityI"Xni:///sha-256;vsIZp3AzMC8TyKD_WJ1_o09Bja-xDlzQS_1odLaUS1w?ct=application/javascript;T:dependencies_digest"%p òݓq ?uD)劻n'Ɗhx:idI"E3577cfe01dac74471f3cb5a92279b4d9084f4e6e08e7cb51ff420ba5fdf1c2c9;F: mtimel+?LU