geocoder.admin.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. jQuery(document).ready(function(){
  2. geocoder_admin_field_selected();
  3. geocoder_admin_handler_selected();
  4. });
  5. function geocoder_admin_field_selected() {
  6. var field = jQuery('#edit-instance-widget-settings-geocoder-field').val();
  7. var field_type = Drupal.settings.geocoder_widget_settings.types[field];
  8. var valid_handlers = Drupal.settings.geocoder_widget_settings.handlers[field_type];
  9. // Filter the options list to ones that are valid for this field
  10. jQuery('#edit-instance-widget-settings-geocoder-handler option').each(function() {
  11. handler_type = jQuery(this).val();
  12. if (geocoder_admin_handler_in_array(handler_type,valid_handlers)) {
  13. jQuery(this).attr('disabled',false);
  14. jQuery(this).show();
  15. }
  16. else {
  17. jQuery(this).attr('disabled','disabled');
  18. jQuery(this).hide();
  19. }
  20. });
  21. // If the currently selected handler is not valid, set it to the first valid handler
  22. if (!geocoder_admin_handler_in_array(jQuery('#edit-instance-widget-settings-geocoder-handler').val(),valid_handlers)) {
  23. jQuery('#edit-instance-widget-settings-geocoder-handler').val(valid_handlers[0]);
  24. }
  25. geocoder_admin_handler_selected();
  26. }
  27. function geocoder_admin_handler_in_array(needle, haystack) {
  28. var length = haystack.length;
  29. for(var i = 0; i < length; i++) {
  30. if(haystack[i] == needle) return true;
  31. }
  32. return false;
  33. }
  34. function geocoder_admin_handler_selected() {
  35. var handler = jQuery('#edit-instance-widget-settings-geocoder-handler').val();
  36. jQuery('.geocoder-handler-setting').hide();
  37. jQuery('.geocoder-handler-setting-' + handler).show();
  38. }