webmaster@1: // $Id: system.js,v 1.14.2.1 2008/02/07 18:23:30 goba Exp $ webmaster@1: webmaster@1: /** webmaster@1: * Internal function to check using Ajax if clean URLs can be enabled on the webmaster@1: * settings page. webmaster@1: * webmaster@1: * This function is not used to verify whether or not clean URLs webmaster@1: * are currently enabled. webmaster@1: */ webmaster@1: Drupal.behaviors.cleanURLsSettingsCheck = function(context) { webmaster@1: // This behavior attaches by ID, so is only valid once on a page. webmaster@1: // Also skip if we are on an install page, as Drupal.cleanURLsInstallCheck will handle webmaster@1: // the processing. webmaster@1: if ($("#clean-url.clean-url-processed, #clean-url.install").size()) { webmaster@1: return; webmaster@1: } webmaster@1: var url = Drupal.settings.basePath +"admin/settings/clean-urls/check"; webmaster@1: $("#clean-url .description span").html('
'+ Drupal.t('Testing clean URLs...') +"
"); webmaster@1: $("#clean-url p").hide(); webmaster@1: $.ajax({ webmaster@1: url: location.protocol +"//"+ location.host + url, webmaster@1: dataType: 'json', webmaster@1: success: function () { webmaster@1: // Check was successful. webmaster@1: $("#clean-url input.form-radio").attr("disabled", false); webmaster@1: $("#clean-url .description span").append('
'+ Drupal.t('Your server has been successfully tested to support this feature.') +"
"); webmaster@1: $("#testing").hide(); webmaster@1: }, webmaster@1: error: function() { webmaster@1: // Check failed. webmaster@1: $("#clean-url .description span").append('
'+ Drupal.t('Your system configuration does not currently support this feature. The handbook page on Clean URLs has additional troubleshooting information.') +"
"); webmaster@1: $("#testing").hide(); webmaster@1: } webmaster@1: }); webmaster@1: $("#clean-url").addClass('clean-url-processed'); webmaster@1: }; webmaster@1: webmaster@1: /** webmaster@1: * Internal function to check using Ajax if clean URLs can be enabled on the webmaster@1: * install page. webmaster@1: * webmaster@1: * This function is not used to verify whether or not clean URLs webmaster@1: * are currently enabled. webmaster@1: */ webmaster@1: Drupal.cleanURLsInstallCheck = function() { webmaster@1: var url = location.protocol +"//"+ location.host + Drupal.settings.basePath +"admin/settings/clean-urls/check"; webmaster@1: $("#clean-url .description").append('
'+ Drupal.settings.cleanURL.testing +"
"); webmaster@1: $("#clean-url.install").css("display", "block"); webmaster@1: $.ajax({ webmaster@1: url: url, webmaster@1: dataType: 'json', webmaster@1: success: function () { webmaster@1: // Check was successful. webmaster@1: $("#clean-url input.form-radio").attr("disabled", false); webmaster@1: $("#clean-url input.form-radio").attr("checked", 1); webmaster@1: $("#clean-url .description span").append('
'+ Drupal.settings.cleanURL.success +"
"); webmaster@1: $("#testing").hide(); webmaster@1: }, webmaster@1: error: function() { webmaster@1: // Check failed. webmaster@1: $("#clean-url .description span").append('
'+ Drupal.settings.cleanURL.failure +"
"); webmaster@1: $("#testing").hide(); webmaster@1: } webmaster@1: }); webmaster@1: $("#clean-url").addClass('clean-url-processed'); webmaster@1: }; webmaster@1: webmaster@1: /** webmaster@1: * When a field is filled out, apply its value to other fields that will likely webmaster@1: * use the same value. In the installer this is used to populate the webmaster@1: * administrator e-mail address with the same value as the site e-mail address. webmaster@1: */ webmaster@1: Drupal.behaviors.copyFieldValue = function (context) { webmaster@1: for (var sourceId in Drupal.settings.copyFieldValue) { webmaster@1: // Get the list of target fields. webmaster@1: targetIds = Drupal.settings.copyFieldValue[sourceId]; webmaster@1: if (!$('#'+ sourceId + '.copy-field-values-processed').size(), context) { webmaster@1: // Add the behavior to update target fields on blur of the primary field. webmaster@1: sourceField = $('#' + sourceId); webmaster@1: sourceField.bind('blur', function() { webmaster@1: for (var delta in targetIds) { webmaster@1: var targetField = $('#'+ targetIds[delta]); webmaster@1: if (targetField.val() == '') { webmaster@1: targetField.val(this.value); webmaster@1: } webmaster@1: } webmaster@1: }); webmaster@1: sourceField.addClass('copy-field-values-processed'); webmaster@1: } webmaster@1: } webmaster@1: }; webmaster@1: webmaster@1: /** webmaster@1: * Show/hide custom format sections on the date-time settings page. webmaster@1: */ webmaster@1: Drupal.behaviors.dateTime = function(context) { webmaster@1: // Show/hide custom format depending on the select's value. webmaster@1: $('select.date-format:not(.date-time-processed)', context).change(function() { webmaster@1: $(this).addClass('date-time-processed').parents("div.date-container").children("div.custom-container")[$(this).val() == "custom" ? "show" : "hide"](); webmaster@1: }); webmaster@1: webmaster@1: // Attach keyup handler to custom format inputs. webmaster@1: $('input.custom-format:not(.date-time-processed)', context).addClass('date-time-processed').keyup(function() { webmaster@1: var input = $(this); webmaster@1: var url = Drupal.settings.dateTime.lookup +(Drupal.settings.dateTime.lookup.match(/\?q=/) ? "&format=" : "?format=") + Drupal.encodeURIComponent(input.val()); webmaster@1: $.getJSON(url, function(data) { webmaster@1: $("div.description span", input.parent()).html(data); webmaster@1: }); webmaster@1: }); webmaster@1: webmaster@1: // Trigger the event handler to show the form input if necessary. webmaster@1: $('select.date-format', context).trigger('change'); webmaster@1: };