| 1 |
// $Id: location_autocomplete.js,v 1.2 2008/08/06 15:29:51 bdragon Exp $
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Twiddle the province autocomplete whenever the user changes the country.
|
| 5 |
*/
|
| 6 |
Drupal.behaviors.location = function(context) {
|
| 7 |
$('select.location_auto_country:not(.location-processed)', context).change(function(e) {
|
| 8 |
var obj = this;
|
| 9 |
var input = null;
|
| 10 |
var result = this.className.match(/(location_auto_join_[^ ]*)/);
|
| 11 |
if (result) {
|
| 12 |
input = $('.location_auto_province.' + result)
|
| 13 |
}
|
| 14 |
else {
|
| 15 |
// No joining class found, fallback to searching the immediate area.
|
| 16 |
input = $('.location_auto_province', $(this).parents('fieldset:first, .views-exposed-form:first'))
|
| 17 |
}
|
| 18 |
|
| 19 |
if (input && input.length) {
|
| 20 |
//Unbind events on province field and empty its value
|
| 21 |
input.unbind().val('');
|
| 22 |
input.each(function(i) {
|
| 23 |
//Get the (hidden) *-autocomplete input element
|
| 24 |
var input_autocomplete = $('#' + this.id + '-autocomplete');
|
| 25 |
// Update autocomplete url
|
| 26 |
input_autocomplete.val(input_autocomplete.val().substr(0, input_autocomplete.val().lastIndexOf('/') + 1) + $(obj).val());
|
| 27 |
// Mark as not processed.
|
| 28 |
input_autocomplete.removeClass('autocomplete-processed');
|
| 29 |
});
|
| 30 |
// Reprocess.
|
| 31 |
Drupal.behaviors.autocomplete(document);
|
| 32 |
}
|
| 33 |
}).addClass('location-processed');
|
| 34 |
};
|