summaryrefslogtreecommitdiff
path: root/modules/system/system.js
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-31 05:51:08 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-31 05:51:08 +0000
commite6e29ac1b0d6780241ced3d5ebcb0558e219e468 (patch)
treea6bdbf6b69ab26e54295d8063e7d1c839cd42f3a /modules/system/system.js
parent41dca3c4e0ec3d355977735f74af2e49ea0eedd7 (diff)
downloadbrdo-e6e29ac1b0d6780241ced3d5ebcb0558e219e468.tar.gz
brdo-e6e29ac1b0d6780241ced3d5ebcb0558e219e468.tar.bz2
- Patch #444344 by kkaefer, sun, Rob Loach: this change introduces a jQuery .once() method which streamlines the way behavior functions work. Previously, we had to manually ensure that an element is only initialized once. Usually, this happens by adding classes and selecting only those elements which do not have that class. However, this process can be separated out into a jQuery ‘filtering’ function which does all the grunt work.
Diffstat (limited to 'modules/system/system.js')
-rw-r--r--modules/system/system.js32
1 files changed, 13 insertions, 19 deletions
diff --git a/modules/system/system.js b/modules/system/system.js
index 11aa8b4b8..4da80811d 100644
--- a/modules/system/system.js
+++ b/modules/system/system.js
@@ -32,7 +32,7 @@ Drupal.behaviors.cleanURLsSettingsCheck = {
// This behavior attaches by ID, so is only valid once on a page.
// Also skip if we are on an install page, as Drupal.cleanURLsInstallCheck will handle
// the processing.
- if (!($('#edit-clean-url').size()) || $('.clean-url-processed, #edit-clean-url.install').size()) {
+ if (!($('#edit-clean-url').length) || $('#edit-clean-url.install').once('clean-url').length) {
return;
}
var url = settings.basePath + 'admin/config/search/clean-urls/check';
@@ -44,7 +44,6 @@ Drupal.behaviors.cleanURLsSettingsCheck = {
location = settings.basePath +"admin/config/search/clean-urls";
}
});
- $('#clean-url').addClass('clean-url-processed');
}
};
@@ -68,7 +67,6 @@ Drupal.cleanURLsInstallCheck = function () {
$('#edit-clean-url').attr('value', 1);
}
});
- $('#edit-clean-url').addClass('clean-url-processed');
};
/**
@@ -79,21 +77,17 @@ Drupal.cleanURLsInstallCheck = function () {
Drupal.behaviors.copyFieldValue = {
attach: function (context, settings) {
for (var sourceId in settings.copyFieldValue) {
- // Get the list of target fields.
- targetIds = settings.copyFieldValue[sourceId];
- if (!$('#'+ sourceId + '.copy-field-values-processed', context).size()) {
+ $('#' + sourceId, context).once('copy-field-values').bind('blur', function () {
+ // Get the list of target fields.
+ var targetIds = settings.copyFieldValue[sourceId];
// Add the behavior to update target fields on blur of the primary field.
- sourceField = $('#' + sourceId);
- sourceField.bind('blur', function () {
- for (var delta in targetIds) {
- var targetField = $('#'+ targetIds[delta]);
- if (targetField.val() == '') {
- targetField.val(this.value);
- }
+ for (var delta in targetIds) {
+ var targetField = $('#' + targetIds[delta]);
+ if (targetField.val() == '') {
+ targetField.val(this.value);
}
- });
- sourceField.addClass('copy-field-values-processed');
- }
+ }
+ });
}
}
};
@@ -104,12 +98,12 @@ Drupal.behaviors.copyFieldValue = {
Drupal.behaviors.dateTime = {
attach: function (context, settings) {
// Show/hide custom format depending on the select's value.
- $('select.date-format:not(.date-time-processed)', context).change(function () {
- $(this).addClass('date-time-processed').parents('div.date-container').children('div.custom-container')[$(this).val() == 'custom' ? 'show' : 'hide']();
+ $('select.date-format', context).once('date-time').change(function () {
+ $(this).parents('div.date-container').children('div.custom-container')[$(this).val() == 'custom' ? 'show' : 'hide']();
});
// Attach keyup handler to custom format inputs.
- $('input.custom-format:not(.date-time-processed)', context).addClass('date-time-processed').keyup(function () {
+ $('input.custom-format', context).once('date-time').keyup(function () {
var input = $(this);
var url = settings.dateTime.lookup + (settings.dateTime.lookup.match(/\?q=/) ? '&format=' : '?format=') + encodeURIComponent(input.val());
$.getJSON(url, function (data) {