| 1 |
// $Id: system.js,v 1.36 2009/10/13 21:34:15 dries Exp $
|
| 2 |
(function ($) {
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Show/hide the 'Email site administrator when updates are available' checkbox
|
| 6 |
* on the install page.
|
| 7 |
*/
|
| 8 |
Drupal.hideEmailAdministratorCheckbox = function () {
|
| 9 |
// Make sure the secondary box is shown / hidden as necessary on page load.
|
| 10 |
if ($('#edit-update-status-module-1').is(':checked')) {
|
| 11 |
$('.form-item-update-status-module-2').show();
|
| 12 |
}
|
| 13 |
else {
|
| 14 |
$('.form-item-update-status-module-2').hide();
|
| 15 |
}
|
| 16 |
|
| 17 |
// Toggle the display as necessary when the checkbox is clicked.
|
| 18 |
$('#edit-update-status-module-1').change( function () {
|
| 19 |
$('.form-item-update-status-module-2').toggle();
|
| 20 |
})
|
| 21 |
};
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Internal function to check using Ajax if clean URLs can be enabled on the
|
| 25 |
* settings page.
|
| 26 |
*
|
| 27 |
* This function is not used to verify whether or not clean URLs
|
| 28 |
* are currently enabled.
|
| 29 |
*/
|
| 30 |
Drupal.behaviors.cleanURLsSettingsCheck = {
|
| 31 |
attach: function (context, settings) {
|
| 32 |
// This behavior attaches by ID, so is only valid once on a page.
|
| 33 |
// Also skip if we are on an install page, as Drupal.cleanURLsInstallCheck will handle
|
| 34 |
// the processing.
|
| 35 |
if (!($('#edit-clean-url').length) || $('#edit-clean-url.install').once('clean-url').length) {
|
| 36 |
return;
|
| 37 |
}
|
| 38 |
var url = settings.basePath + 'admin/config/search/clean-urls/check';
|
| 39 |
$.ajax({
|
| 40 |
url: location.protocol + '//' + location.host + url,
|
| 41 |
dataType: 'json',
|
| 42 |
success: function () {
|
| 43 |
// Check was successful. Redirect using a "clean URL". This will force the form that allows enabling clean URLs.
|
| 44 |
location = settings.basePath +"admin/config/search/clean-urls";
|
| 45 |
}
|
| 46 |
});
|
| 47 |
}
|
| 48 |
};
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Internal function to check using Ajax if clean URLs can be enabled on the
|
| 52 |
* install page.
|
| 53 |
*
|
| 54 |
* This function is not used to verify whether or not clean URLs
|
| 55 |
* are currently enabled.
|
| 56 |
*/
|
| 57 |
Drupal.cleanURLsInstallCheck = function () {
|
| 58 |
var url = location.protocol + '//' + location.host + Drupal.settings.basePath + 'admin/config/search/clean-urls/check';
|
| 59 |
// Submit a synchronous request to avoid database errors associated with
|
| 60 |
// concurrent requests during install.
|
| 61 |
$.ajax({
|
| 62 |
async: false,
|
| 63 |
url: url,
|
| 64 |
dataType: 'json',
|
| 65 |
success: function () {
|
| 66 |
// Check was successful.
|
| 67 |
$('#edit-clean-url').attr('value', 1);
|
| 68 |
}
|
| 69 |
});
|
| 70 |
};
|
| 71 |
|
| 72 |
/**
|
| 73 |
* When a field is filled out, apply its value to other fields that will likely
|
| 74 |
* use the same value. In the installer this is used to populate the
|
| 75 |
* administrator e-mail address with the same value as the site e-mail address.
|
| 76 |
*/
|
| 77 |
Drupal.behaviors.copyFieldValue = {
|
| 78 |
attach: function (context, settings) {
|
| 79 |
for (var sourceId in settings.copyFieldValue) {
|
| 80 |
$('#' + sourceId, context).once('copy-field-values').bind('blur', function () {
|
| 81 |
// Get the list of target fields.
|
| 82 |
var targetIds = settings.copyFieldValue[sourceId];
|
| 83 |
// Add the behavior to update target fields on blur of the primary field.
|
| 84 |
for (var delta in targetIds) {
|
| 85 |
var targetField = $('#' + targetIds[delta]);
|
| 86 |
if (targetField.val() == '') {
|
| 87 |
targetField.val(this.value);
|
| 88 |
}
|
| 89 |
}
|
| 90 |
});
|
| 91 |
}
|
| 92 |
}
|
| 93 |
};
|
| 94 |
|
| 95 |
/**
|
| 96 |
* Show/hide custom format sections on the regional settings page.
|
| 97 |
*/
|
| 98 |
Drupal.behaviors.dateTime = {
|
| 99 |
attach: function (context, settings) {
|
| 100 |
for (var value in settings.dateTime) {
|
| 101 |
var settings = settings.dateTime[value];
|
| 102 |
var source = '#edit-' + value;
|
| 103 |
var suffix = source + '-suffix';
|
| 104 |
|
| 105 |
// Attach keyup handler to custom format inputs.
|
| 106 |
$('input' + source, context).once('date-time').keyup(function () {
|
| 107 |
var input = $(this);
|
| 108 |
var url = settings.lookup + (settings.lookup.match(/\?q=/) ? '&format=' : '?format=') + encodeURIComponent(input.val());
|
| 109 |
$.getJSON(url, function (data) {
|
| 110 |
$(suffix).empty().append(' ' + settings.text + ': <em>' + data + '</em>');
|
| 111 |
});
|
| 112 |
});
|
| 113 |
}
|
| 114 |
}
|
| 115 |
};
|
| 116 |
|
| 117 |
/**
|
| 118 |
* Show the powered by Drupal image preview
|
| 119 |
*/
|
| 120 |
Drupal.behaviors.poweredByPreview = {
|
| 121 |
attach: function (context, settings) {
|
| 122 |
$('#edit-color, #edit-size').change(function () {
|
| 123 |
var path = settings.basePath + 'misc/' + $('#edit-color').val() + '-' + $('#edit-size').val() + '.png';
|
| 124 |
$('img.powered-by-preview').attr('src', path);
|
| 125 |
});
|
| 126 |
}
|
| 127 |
};
|
| 128 |
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Show/hide settings for page caching depending on whether page caching is
|
| 132 |
* enabled or not.
|
| 133 |
*/
|
| 134 |
Drupal.behaviors.pageCache = {
|
| 135 |
attach: function (context, settings) {
|
| 136 |
$('#edit-cache-0', context).change(function () {
|
| 137 |
$('#page-compression-wrapper').hide();
|
| 138 |
$('#cache-error').hide();
|
| 139 |
});
|
| 140 |
$('#edit-cache-1', context).change(function () {
|
| 141 |
$('#page-compression-wrapper').show();
|
| 142 |
$('#cache-error').hide();
|
| 143 |
});
|
| 144 |
$('#edit-cache-2', context).change(function () {
|
| 145 |
$('#page-compression-wrapper').show();
|
| 146 |
$('#cache-error').show();
|
| 147 |
});
|
| 148 |
}
|
| 149 |
};
|
| 150 |
|
| 151 |
/**
|
| 152 |
* Attach the auto machine readable name behavior.
|
| 153 |
*
|
| 154 |
* Settings are expected to be an object of elements to process, where the key
|
| 155 |
* defines the source element in the form and the value is an object defining
|
| 156 |
* the following properties:
|
| 157 |
* - text: The label to display before the auto-generated value.
|
| 158 |
* - target: The target form element name.
|
| 159 |
* - searchPattern: A regular expression (without modifiers) matching disallowed
|
| 160 |
* characters in the machine readable name, f.e. '[^a-z0-9]+'.
|
| 161 |
* - replaceToken: A replacement string to replace disallowed characters, f.e.
|
| 162 |
* '-' or '_'.
|
| 163 |
*
|
| 164 |
* @see menu_edit_menu()
|
| 165 |
*/
|
| 166 |
Drupal.behaviors.machineReadableValue = {
|
| 167 |
attach: function () {
|
| 168 |
for (var value in Drupal.settings.machineReadableValue) {
|
| 169 |
var settings = Drupal.settings.machineReadableValue[value];
|
| 170 |
|
| 171 |
var searchPattern = new RegExp(settings.searchPattern, 'g');
|
| 172 |
// Build selector for the source name entered by a user.
|
| 173 |
var source = '#edit-' + value;
|
| 174 |
var suffix = source + '-suffix';
|
| 175 |
// Build selector for the machine readable name.
|
| 176 |
var target = '#edit-' + settings.target;
|
| 177 |
// Build selector for the wrapper element around the target field.
|
| 178 |
var wrapper = '.form-item-' + settings.target;
|
| 179 |
|
| 180 |
// Do not process the element if we got an error or the given name and the
|
| 181 |
// machine readable name are identical or the machine readable name is
|
| 182 |
// empty.
|
| 183 |
if (!$(target).hasClass('error') && ($(target).val() == $(source).val().toLowerCase().replace(searchPattern, settings.replaceToken) || $(target).val() == '')) {
|
| 184 |
// Hide wrapper element.
|
| 185 |
$(wrapper).hide();
|
| 186 |
// Bind keyup event to source element.
|
| 187 |
$(source).keyup(function () {
|
| 188 |
var machine = $(this).val().toLowerCase().replace(searchPattern, settings.replaceToken);
|
| 189 |
if (machine != '_' && machine != '') {
|
| 190 |
// Set machine readable name to the user entered value.
|
| 191 |
$(target).val(machine);
|
| 192 |
// Append the machine readable name and a link to edit it to the source field.
|
| 193 |
$(suffix).empty().append(' ' + settings.text + ': ' + machine + ' [').append($('<a href="#">' + Drupal.t('Edit') + '</a>').click(function () {
|
| 194 |
$(wrapper).show();
|
| 195 |
$(target).focus();
|
| 196 |
$(suffix).hide();
|
| 197 |
$(source).unbind('keyup');
|
| 198 |
return false;
|
| 199 |
})).append(']');
|
| 200 |
}
|
| 201 |
else {
|
| 202 |
$(target).val(machine);
|
| 203 |
$(suffix).text('');
|
| 204 |
}
|
| 205 |
});
|
| 206 |
// Call keyup event on source element.
|
| 207 |
$(source).keyup();
|
| 208 |
}
|
| 209 |
}
|
| 210 |
}
|
| 211 |
};
|
| 212 |
|
| 213 |
})(jQuery);
|
| 214 |
|