annotate modules/system/system.js @ 1:c1f4ac30525a 6.0

Drupal 6.0
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:28:28 +0100
parents
children
rev   line source
webmaster@1 1 // $Id: system.js,v 1.14.2.1 2008/02/07 18:23:30 goba Exp $
webmaster@1 2
webmaster@1 3 /**
webmaster@1 4 * Internal function to check using Ajax if clean URLs can be enabled on the
webmaster@1 5 * settings page.
webmaster@1 6 *
webmaster@1 7 * This function is not used to verify whether or not clean URLs
webmaster@1 8 * are currently enabled.
webmaster@1 9 */
webmaster@1 10 Drupal.behaviors.cleanURLsSettingsCheck = function(context) {
webmaster@1 11 // This behavior attaches by ID, so is only valid once on a page.
webmaster@1 12 // Also skip if we are on an install page, as Drupal.cleanURLsInstallCheck will handle
webmaster@1 13 // the processing.
webmaster@1 14 if ($("#clean-url.clean-url-processed, #clean-url.install").size()) {
webmaster@1 15 return;
webmaster@1 16 }
webmaster@1 17 var url = Drupal.settings.basePath +"admin/settings/clean-urls/check";
webmaster@1 18 $("#clean-url .description span").html('<div id="testing">'+ Drupal.t('Testing clean URLs...') +"</div>");
webmaster@1 19 $("#clean-url p").hide();
webmaster@1 20 $.ajax({
webmaster@1 21 url: location.protocol +"//"+ location.host + url,
webmaster@1 22 dataType: 'json',
webmaster@1 23 success: function () {
webmaster@1 24 // Check was successful.
webmaster@1 25 $("#clean-url input.form-radio").attr("disabled", false);
webmaster@1 26 $("#clean-url .description span").append('<div class="ok">'+ Drupal.t('Your server has been successfully tested to support this feature.') +"</div>");
webmaster@1 27 $("#testing").hide();
webmaster@1 28 },
webmaster@1 29 error: function() {
webmaster@1 30 // Check failed.
webmaster@1 31 $("#clean-url .description span").append('<div class="warning">'+ Drupal.t('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.') +"</div>");
webmaster@1 32 $("#testing").hide();
webmaster@1 33 }
webmaster@1 34 });
webmaster@1 35 $("#clean-url").addClass('clean-url-processed');
webmaster@1 36 };
webmaster@1 37
webmaster@1 38 /**
webmaster@1 39 * Internal function to check using Ajax if clean URLs can be enabled on the
webmaster@1 40 * install page.
webmaster@1 41 *
webmaster@1 42 * This function is not used to verify whether or not clean URLs
webmaster@1 43 * are currently enabled.
webmaster@1 44 */
webmaster@1 45 Drupal.cleanURLsInstallCheck = function() {
webmaster@1 46 var url = location.protocol +"//"+ location.host + Drupal.settings.basePath +"admin/settings/clean-urls/check";
webmaster@1 47 $("#clean-url .description").append('<span><div id="testing">'+ Drupal.settings.cleanURL.testing +"</div></span>");
webmaster@1 48 $("#clean-url.install").css("display", "block");
webmaster@1 49 $.ajax({
webmaster@1 50 url: url,
webmaster@1 51 dataType: 'json',
webmaster@1 52 success: function () {
webmaster@1 53 // Check was successful.
webmaster@1 54 $("#clean-url input.form-radio").attr("disabled", false);
webmaster@1 55 $("#clean-url input.form-radio").attr("checked", 1);
webmaster@1 56 $("#clean-url .description span").append('<div class="ok">'+ Drupal.settings.cleanURL.success +"</div>");
webmaster@1 57 $("#testing").hide();
webmaster@1 58 },
webmaster@1 59 error: function() {
webmaster@1 60 // Check failed.
webmaster@1 61 $("#clean-url .description span").append('<div class="warning">'+ Drupal.settings.cleanURL.failure +"</div>");
webmaster@1 62 $("#testing").hide();
webmaster@1 63 }
webmaster@1 64 });
webmaster@1 65 $("#clean-url").addClass('clean-url-processed');
webmaster@1 66 };
webmaster@1 67
webmaster@1 68 /**
webmaster@1 69 * When a field is filled out, apply its value to other fields that will likely
webmaster@1 70 * use the same value. In the installer this is used to populate the
webmaster@1 71 * administrator e-mail address with the same value as the site e-mail address.
webmaster@1 72 */
webmaster@1 73 Drupal.behaviors.copyFieldValue = function (context) {
webmaster@1 74 for (var sourceId in Drupal.settings.copyFieldValue) {
webmaster@1 75 // Get the list of target fields.
webmaster@1 76 targetIds = Drupal.settings.copyFieldValue[sourceId];
webmaster@1 77 if (!$('#'+ sourceId + '.copy-field-values-processed').size(), context) {
webmaster@1 78 // Add the behavior to update target fields on blur of the primary field.
webmaster@1 79 sourceField = $('#' + sourceId);
webmaster@1 80 sourceField.bind('blur', function() {
webmaster@1 81 for (var delta in targetIds) {
webmaster@1 82 var targetField = $('#'+ targetIds[delta]);
webmaster@1 83 if (targetField.val() == '') {
webmaster@1 84 targetField.val(this.value);
webmaster@1 85 }
webmaster@1 86 }
webmaster@1 87 });
webmaster@1 88 sourceField.addClass('copy-field-values-processed');
webmaster@1 89 }
webmaster@1 90 }
webmaster@1 91 };
webmaster@1 92
webmaster@1 93 /**
webmaster@1 94 * Show/hide custom format sections on the date-time settings page.
webmaster@1 95 */
webmaster@1 96 Drupal.behaviors.dateTime = function(context) {
webmaster@1 97 // Show/hide custom format depending on the select's value.
webmaster@1 98 $('select.date-format:not(.date-time-processed)', context).change(function() {
webmaster@1 99 $(this).addClass('date-time-processed').parents("div.date-container").children("div.custom-container")[$(this).val() == "custom" ? "show" : "hide"]();
webmaster@1 100 });
webmaster@1 101
webmaster@1 102 // Attach keyup handler to custom format inputs.
webmaster@1 103 $('input.custom-format:not(.date-time-processed)', context).addClass('date-time-processed').keyup(function() {
webmaster@1 104 var input = $(this);
webmaster@1 105 var url = Drupal.settings.dateTime.lookup +(Drupal.settings.dateTime.lookup.match(/\?q=/) ? "&format=" : "?format=") + Drupal.encodeURIComponent(input.val());
webmaster@1 106 $.getJSON(url, function(data) {
webmaster@1 107 $("div.description span", input.parent()).html(data);
webmaster@1 108 });
webmaster@1 109 });
webmaster@1 110
webmaster@1 111 // Trigger the event handler to show the form input if necessary.
webmaster@1 112 $('select.date-format', context).trigger('change');
webmaster@1 113 };