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