diff --git a/core/misc/ajax.js b/core/misc/ajax.js
index c35241c..0f197d0 100644
--- a/core/misc/ajax.js
+++ b/core/misc/ajax.js
@@ -17,56 +17,56 @@ Drupal.ajax = Drupal.ajax || {};
/**
* Attaches the Ajax behavior to each Ajax form element.
*/
-Drupal.behaviors.AJAX = {
- attach: function (context, settings) {
- // Load all Ajax behaviors specified in the settings.
- for (var base in settings.ajax) {
- var element_settings = settings.ajax[base];
- if (typeof element_settings.selector == 'undefined') {
- element_settings.selector = '#' + base;
- }
- $(element_settings.selector).once('drupal-ajax', function() {
- element_settings.element = this;
- Drupal.ajax[element_settings.selector] = new Drupal.ajax(base, this, element_settings);
- });
+$(document).on('ready attach', function (e, settings) {
+ var context = e.target;
+ settings = settings || Drupal.settings;
+ // Load all Ajax behaviors specified in the settings.
+ for (var base in settings.ajax) {
+ var element_settings = settings.ajax[base];
+ if (typeof element_settings.selector == 'undefined') {
+ element_settings.selector = '#' + base;
}
-
- // Bind Ajax behaviors to all items showing the class.
- $('.use-ajax').once('ajax', function () {
- var element_settings = {};
- // Clicked links look better with the throbber than the progress bar.
- element_settings.progress = { 'type': 'throbber' };
-
- // For anchor tags, these will go to the target of the anchor rather
- // than the usual location.
- if ($(this).attr('href')) {
- element_settings.url = $(this).attr('href');
- element_settings.event = 'click';
- }
- var base = $(this).attr('id');
- Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
+ $(element_settings.selector).once('drupal-ajax', function() {
+ element_settings.element = this;
+ Drupal.ajax[element_settings.selector] = new Drupal.ajax(base, this, element_settings);
});
+ }
+
+ // Bind Ajax behaviors to all items showing the class.
+ $('.use-ajax').once('ajax', function () {
+ var element_settings = {};
+ // Clicked links look better with the throbber than the progress bar.
+ element_settings.progress = { 'type': 'throbber' };
- // This class means to submit the form to the action using Ajax.
- $('.use-ajax-submit').once('ajax', function () {
- var element_settings = {};
-
- // Ajax submits specified in this manner automatically submit to the
- // normal form action.
- element_settings.url = $(this.form).attr('action');
- // Form submit button clicks need to tell the form what was clicked so
- // it gets passed in the POST request.
- element_settings.setClick = true;
- // Form buttons use the 'click' event rather than mousedown.
+ // For anchor tags, these will go to the target of the anchor rather
+ // than the usual location.
+ if ($(this).attr('href')) {
+ element_settings.url = $(this).attr('href');
element_settings.event = 'click';
- // Clicked form buttons look better with the throbber than the progress bar.
- element_settings.progress = { 'type': 'throbber' };
+ }
+ var base = $(this).attr('id');
+ Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
+ });
- var base = $(this).attr('id');
- Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
- });
- }
-};
+ // This class means to submit the form to the action using Ajax.
+ $('.use-ajax-submit').once('ajax', function () {
+ var element_settings = {};
+
+ // Ajax submits specified in this manner automatically submit to the
+ // normal form action.
+ element_settings.url = $(this.form).attr('action');
+ // Form submit button clicks need to tell the form what was clicked so
+ // it gets passed in the POST request.
+ element_settings.setClick = true;
+ // Form buttons use the 'click' event rather than mousedown.
+ element_settings.event = 'click';
+ // Clicked form buttons look better with the throbber than the progress bar.
+ element_settings.progress = { 'type': 'throbber' };
+
+ var base = $(this).attr('id');
+ Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
+ });
+});
/**
* Ajax object.
@@ -282,7 +282,7 @@ Drupal.ajax.prototype.beforeSerialize = function (element, options) {
// isn't called, but don't rely on that: explicitly check this.form.
if (this.form) {
var settings = this.settings || Drupal.settings;
- Drupal.detachBehaviors(this.form, settings, 'serialize');
+ $(this.form).trigger('detach', settings, 'serialize');
}
// Prevent duplicate HTML ids in the returned markup.
@@ -402,7 +402,7 @@ Drupal.ajax.prototype.success = function (response, status) {
// to be reattached.
if (this.form) {
var settings = this.settings || Drupal.settings;
- Drupal.attachBehaviors(this.form, settings);
+ $(this.form).trigger('attach', settings);
}
Drupal.unfreezeHeight();
@@ -458,7 +458,7 @@ Drupal.ajax.prototype.error = function (response, uri) {
// Reattach behaviors, if they were detached in beforeSerialize().
if (this.form) {
var settings = response.settings || this.settings || Drupal.settings;
- Drupal.attachBehaviors(this.form, settings);
+ $(this.form).trigger('attach', settings);
}
};
@@ -506,7 +506,7 @@ Drupal.ajax.prototype.commands = {
case 'empty':
case 'remove':
var settings = response.settings || ajax.settings || Drupal.settings;
- Drupal.detachBehaviors(wrapper, settings);
+ $(wrapper).trigger('detach', settings);
}
// Add the new content to the page.
@@ -534,7 +534,7 @@ Drupal.ajax.prototype.commands = {
if (new_content.parents('html').length > 0) {
// Apply any settings from the returned JSON if available.
var settings = response.settings || ajax.settings || Drupal.settings;
- Drupal.attachBehaviors(new_content, settings);
+ $(new_content).trigger('attach', settings);
}
},
@@ -543,7 +543,7 @@ Drupal.ajax.prototype.commands = {
*/
remove: function (ajax, response, status) {
var settings = response.settings || ajax.settings || Drupal.settings;
- Drupal.detachBehaviors($(response.selector), settings);
+ $(response.selector).trigger('detach', settings);
$(response.selector).remove();
},
diff --git a/core/misc/authorize.js b/core/misc/authorize.js
index d522a5b..1ac6792 100644
--- a/core/misc/authorize.js
+++ b/core/misc/authorize.js
@@ -7,21 +7,19 @@
(function ($) {
-Drupal.behaviors.authorizeFileTransferForm = {
- attach: function(context) {
- $('#edit-connection-settings-authorize-filetransfer-default').change(function() {
- $('.filetransfer').hide().filter('.filetransfer-' + $(this).val()).show();
- });
- $('.filetransfer').hide().filter('.filetransfer-' + $('#edit-connection-settings-authorize-filetransfer-default').val()).show();
+$(document).on('ready attach', function (e) {
+ $('#edit-connection-settings-authorize-filetransfer-default').change(function() {
+ $('.filetransfer').hide().filter('.filetransfer-' + $(this).val()).show();
+ });
+ $('.filetransfer').hide().filter('.filetransfer-' + $('#edit-connection-settings-authorize-filetransfer-default').val()).show();
- // Removes the float on the select box (used for non-JS interface).
- if ($('.connection-settings-update-filetransfer-default-wrapper').length > 0) {
- $('.connection-settings-update-filetransfer-default-wrapper').css('float', 'none');
- }
- // Hides the submit button for non-js users.
- $('#edit-submit-connection').hide();
- $('#edit-submit-process').show();
+ // Removes the float on the select box (used for non-JS interface).
+ if ($('.connection-settings-update-filetransfer-default-wrapper').length > 0) {
+ $('.connection-settings-update-filetransfer-default-wrapper').css('float', 'none');
}
-};
+ // Hides the submit button for non-js users.
+ $('#edit-submit-connection').hide();
+ $('#edit-submit-process').show();
+});
})(jQuery);
diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js
index a4f6335..83e200b 100644
--- a/core/misc/autocomplete.js
+++ b/core/misc/autocomplete.js
@@ -3,27 +3,26 @@
/**
* Attaches the autocomplete behavior to all required fields.
*/
-Drupal.behaviors.autocomplete = {
- attach: function (context, settings) {
- var acdb = [];
- $(context).find('input.autocomplete').once('autocomplete', function () {
- var uri = this.value;
- if (!acdb[uri]) {
- acdb[uri] = new Drupal.ACDB(uri);
- }
- var $input = $('#' + this.id.substr(0, this.id.length - 13))
- .attr('autocomplete', 'OFF')
- .attr('aria-autocomplete', 'list');
- $($input[0].form).submit(Drupal.autocompleteSubmit);
- $input.parent()
- .attr('role', 'application')
- .append($('')
- .attr('id', $input[0].id + '-autocomplete-aria-live')
- );
- new Drupal.jsAC($input, acdb[uri]);
- });
- }
-};
+$(document).on('ready attach', function (e) {
+ var context = e.target;
+ var acdb = [];
+ $(context).find('input.autocomplete').once('autocomplete', function () {
+ var uri = this.value;
+ if (!acdb[uri]) {
+ acdb[uri] = new Drupal.ACDB(uri);
+ }
+ var $input = $('#' + this.id.substr(0, this.id.length - 13))
+ .attr('autocomplete', 'OFF')
+ .attr('aria-autocomplete', 'list');
+ $($input[0].form).submit(Drupal.autocompleteSubmit);
+ $input.parent()
+ .attr('role', 'application')
+ .append($('')
+ .attr('id', $input[0].id + '-autocomplete-aria-live')
+ );
+ new Drupal.jsAC($input, acdb[uri]);
+ });
+});
/**
* Prevents the form from submitting if the suggestions popup is open
diff --git a/core/misc/batch.js b/core/misc/batch.js
index 6d28b69..5c78059 100644
--- a/core/misc/batch.js
+++ b/core/misc/batch.js
@@ -3,30 +3,28 @@
/**
* Attaches the batch behavior to progress bars.
*/
-Drupal.behaviors.batch = {
- attach: function (context, settings) {
- $(context).find('#progress').once('batch', function () {
- var holder = $(this);
+$(document).on('ready attach', function (context, settings) {
+ $(context).find('#progress').once('batch', function () {
+ var holder = $(this);
- // Success: redirect to the summary.
- var updateCallback = function (progress, status, pb) {
- if (progress == 100) {
- pb.stopMonitoring();
- window.location = settings.batch.uri + '&op=finished';
- }
- };
+ // Success: redirect to the summary.
+ var updateCallback = function (progress, status, pb) {
+ if (progress == 100) {
+ pb.stopMonitoring();
+ window.location = settings.batch.uri + '&op=finished';
+ }
+ };
- var errorCallback = function (pb) {
- holder.prepend($('
').html(settings.batch.errorMessage));
- $('#wait').hide();
- };
+ var errorCallback = function (pb) {
+ holder.prepend($('').html(settings.batch.errorMessage));
+ $('#wait').hide();
+ };
- var progress = new Drupal.progressBar('updateprogress', updateCallback, 'POST', errorCallback);
- progress.setProgress(-1, settings.batch.initMessage);
- holder.append(progress.element);
- progress.startMonitoring(settings.batch.uri + '&op=do', 10);
- });
- }
-};
+ var progress = new Drupal.progressBar('updateprogress', updateCallback, 'POST', errorCallback);
+ progress.setProgress(-1, settings.batch.initMessage);
+ holder.append(progress.element);
+ progress.startMonitoring(settings.batch.uri + '&op=do', 10);
+ });
+});
})(jQuery);
diff --git a/core/misc/collapse.js b/core/misc/collapse.js
index 28281a1..6f7f5cc 100644
--- a/core/misc/collapse.js
+++ b/core/misc/collapse.js
@@ -53,51 +53,49 @@ Drupal.collapseScrollIntoView = function (node) {
}
};
-Drupal.behaviors.collapse = {
- attach: function (context, settings) {
- $(context).find('fieldset.collapsible').once('collapse', function () {
- var $fieldset = $(this);
- // Expand fieldset if there are errors inside, or if it contains an
- // element that is targeted by the uri fragment identifier.
- var anchor = location.hash && location.hash != '#' ? ', ' + location.hash : '';
- if ($fieldset.find('.error' + anchor).length) {
- $fieldset.removeClass('collapsed');
- }
+$(document).on('ready attach', function (e, settings) {
+ $(e.target).find('fieldset.collapsible').once('collapse', function () {
+ var $fieldset = $(this);
+ // Expand fieldset if there are errors inside, or if it contains an
+ // element that is targeted by the uri fragment identifier.
+ var anchor = location.hash && location.hash != '#' ? ', ' + location.hash : '';
+ if ($fieldset.find('.error' + anchor).length) {
+ $fieldset.removeClass('collapsed');
+ }
- var summary = $('');
- $fieldset.
- bind('summaryUpdated', function () {
- var text = $.trim($fieldset.drupalGetSummary());
- summary.html(text ? ' (' + text + ')' : '');
- })
- .trigger('summaryUpdated');
+ var summary = $('');
+ $fieldset.
+ bind('summaryUpdated', function () {
+ var text = $.trim($fieldset.drupalGetSummary());
+ summary.html(text ? ' (' + text + ')' : '');
+ })
+ .trigger('summaryUpdated');
- // Turn the legend into a clickable link, but retain span.fieldset-legend
- // for CSS positioning.
- var $legend = $fieldset.find('> legend .fieldset-legend');
+ // Turn the legend into a clickable link, but retain span.fieldset-legend
+ // for CSS positioning.
+ var $legend = $fieldset.find('> legend .fieldset-legend');
- $('')
- .append($fieldset.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide'))
- .prependTo($legend)
- .after(' ');
+ $('')
+ .append($fieldset.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide'))
+ .prependTo($legend)
+ .after(' ');
- // .wrapInner() does not retain bound events.
- var $link = $('')
- .prepend($legend.contents())
- .appendTo($legend)
- .click(function () {
- var fieldset = $fieldset.get(0);
- // Don't animate multiple times.
- if (!fieldset.animating) {
- fieldset.animating = true;
- Drupal.toggleFieldset(fieldset);
- }
- return false;
- });
+ // .wrapInner() does not retain bound events.
+ var $link = $('')
+ .prepend($legend.contents())
+ .appendTo($legend)
+ .click(function () {
+ var fieldset = $fieldset.get(0);
+ // Don't animate multiple times.
+ if (!fieldset.animating) {
+ fieldset.animating = true;
+ Drupal.toggleFieldset(fieldset);
+ }
+ return false;
+ });
- $legend.append(summary);
- });
- }
-};
+ $legend.append(summary);
+ });
+});
})(jQuery);
diff --git a/core/misc/drupal.js b/core/misc/drupal.js
index 1c771bc..7c67c71 100644
--- a/core/misc/drupal.js
+++ b/core/misc/drupal.js
@@ -6,115 +6,13 @@ jQuery.noConflict();
(function ($) {
/**
- * Attach all registered behaviors to a page element.
+ * To initialize your scripts, bind the 'ready' and 'attach' event on the document.
*
- * Behaviors are event-triggered actions that attach to page elements, enhancing
- * default non-JavaScript UIs. Behaviors are registered in the Drupal.behaviors
- * object using the method 'attach' and optionally also 'detach' as follows:
- * @code
- * Drupal.behaviors.behaviorName = {
- * attach: function (context, settings) {
- * ...
- * },
- * detach: function (context, settings, trigger) {
- * ...
- * }
- * };
- * @endcode
- *
- * Drupal.attachBehaviors is added below to the jQuery ready event and so
- * runs on initial page load. Developers implementing AHAH/Ajax in their
- * solutions should also call this function after new page content has been
- * loaded, feeding in an element to be processed, in order to attach all
- * behaviors to the new content.
- *
- * Behaviors should use
- * @code
- * $(selector).once('behavior-name', function () {
- * ...
- * });
- * @endcode
- * to ensure the behavior is attached only once to a given element. (Doing so
- * enables the reprocessing of given elements, which may be needed on occasion
- * despite the ability to limit behavior attachment to a particular element.)
- *
- * @param context
- * An element to attach behaviors to. If none is given, the document element
- * is used.
- * @param settings
- * An object containing settings for the current context. If none given, the
- * global Drupal.settings object is used.
*/
-Drupal.attachBehaviors = function (context, settings) {
- context = context || document;
- settings = settings || Drupal.settings;
- var i, behaviors = Drupal.behaviors,
- $document = $(document);
- // Execute all of them.
- for (i in behaviors) {
- if (behaviors.hasOwnProperty(i) && typeof behaviors[i].attach === 'function') {
- $document.bind('attach.drupal', $.proxy(function (e) {
- this.attach(e.target, settings);
- }, behaviors[i]));
- }
- }
-};
/**
- * Detach registered behaviors from a page element.
- *
- * Developers implementing AHAH/Ajax in their solutions should call this
- * function before page content is about to be removed, feeding in an element
- * to be processed, in order to allow special behaviors to detach from the
- * content.
- *
- * Such implementations should look for the class name that was added in their
- * corresponding Drupal.behaviors.behaviorName.attach implementation, i.e.
- * behaviorName-processed, to ensure the behavior is detached only from
- * previously processed elements.
- *
- * @param context
- * An element to detach behaviors from. If none is given, the document element
- * is used.
- * @param settings
- * An object containing settings for the current context. If none given, the
- * global Drupal.settings object is used.
- * @param trigger
- * A string containing what's causing the behaviors to be detached. The
- * possible triggers are:
- * - unload: (default) The context element is being removed from the DOM.
- * - move: The element is about to be moved within the DOM (for example,
- * during a tabledrag row swap). After the move is completed,
- * Drupal.attachBehaviors() is called, so that the behavior can undo
- * whatever it did in response to the move. Many behaviors won't need to
- * do anything simply in response to the element being moved, but because
- * IFRAME elements reload their "src" when being moved within the DOM,
- * behaviors bound to IFRAME elements (like WYSIWYG editors) may need to
- * take some action.
- * - serialize: When an Ajax form is submitted, this is called with the
- * form as the context. This provides every behavior within the form an
- * opportunity to ensure that the field elements have correct content
- * in them before the form is serialized. The canonical use-case is so
- * that WYSIWYG editors can update the hidden textarea to which they are
- * bound.
- *
- * @see Drupal.attachBehaviors
+ * To clean up your scripts, bind the 'detach' event on the document.
*/
-Drupal.detachBehaviors = function (context, settings, trigger) {
- context = context || document;
- settings = settings || Drupal.settings;
- trigger = trigger || 'unload';
- var i, behaviors = Drupal.behaviors,
- $document = $(document);
- // Execute all of them.
- for (i in behaviors) {
- if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function' ) {
- $document.bind('detach.durpal', $.proxy(function () {
- this.detach(context, settings, trigger);
- }, behaviors[i]));
- }
- }
-};
/**
* Encode special characters in a plain-text string for display as HTML.
@@ -374,22 +272,15 @@ Drupal.ajaxError = function (xmlhttp, uri) {
};
// Class indicating that JS is enabled; used for styling purpose.
-$('html').addClass('js');
+document.documentElement.className += " js";
// 'js enabled' cookie.
document.cookie = 'has_js=1; path=/';
-//Attach all behaviors.
-$(function () {
- Drupal.attachBehaviors(document, Drupal.settings);
- $(document).trigger('attach.drupal');
-});
-
/**
* The default themes.
*/
Drupal.theme.prototype = {
-
/**
* Formats text for emphasized display in a placeholder inside a sentence.
*
diff --git a/core/misc/form.js b/core/misc/form.js
index 4dc5b8c..787df0e 100644
--- a/core/misc/form.js
+++ b/core/misc/form.js
@@ -41,41 +41,37 @@ $.fn.drupalSetSummary = function (callback) {
/**
* Sends a 'formUpdated' event each time a form element is modified.
*/
-Drupal.behaviors.formUpdated = {
- attach: function (context) {
- // These events are namespaced so that we can remove them later.
- var events = 'change.formUpdated click.formUpdated blur.formUpdated keyup.formUpdated';
- $(context)
- // Since context could be an input element itself, it's added back to
- // the jQuery object and filtered again.
- .find(':input').andSelf().filter(':input')
- // To prevent duplicate events, the handlers are first removed and then
- // (re-)added.
- .unbind(events).bind(events, function () {
- $(this).trigger('formUpdated');
- });
- }
-};
+$(document).on('ready attach', function (e) {
+ // These events are namespaced so that we can remove them later.
+ var events = 'change.formUpdated click.formUpdated blur.formUpdated keyup.formUpdated';
+ $(e.target)
+ // Since context could be an input element itself, it's added back to
+ // the jQuery object and filtered again.
+ .find(':input').andSelf().filter(':input')
+ // To prevent duplicate events, the handlers are first removed and then
+ // (re-)added.
+ .unbind(events).bind(events, function () {
+ $(this).trigger('formUpdated');
+ });
+});
/**
* Prepopulate form fields with information from the visitor cookie.
*/
-Drupal.behaviors.fillUserInfoFromCookie = {
- attach: function (context, settings) {
- var userInfo = ['name', 'mail', 'homepage'];
- $('form.user-info-from-cookie').once('user-info-from-cookie', function () {
- var formContext = this;
- var $formContext = $(this);
- var i, il, $element, cookie;
- for (i = 0, il = userInfo.length; i < il; i += 1) {
- $element = $formContext.find('[name=' + userInfo[i] + ']');
- cookie = $.cookie('Drupal.visitor.' + userInfo[i]);
- if ($element.length && cookie) {
- $element.val(cookie);
- }
+$(document).on('ready attach', function (e) {
+ var userInfo = ['name', 'mail', 'homepage'];
+ $('form.user-info-from-cookie').once('user-info-from-cookie', function () {
+ var formContext = this;
+ var $formContext = $(this);
+ var i, il, $element, cookie;
+ for (i = 0, il = userInfo.length; i < il; i += 1) {
+ $element = $formContext.find('[name=' + userInfo[i] + ']');
+ cookie = $.cookie('Drupal.visitor.' + userInfo[i]);
+ if ($element.length && cookie) {
+ $element.val(cookie);
}
- });
- }
-};
+ }
+ });
+});
})(jQuery);
diff --git a/core/misc/machine-name.js b/core/misc/machine-name.js
index ffe774f..89eb104 100644
--- a/core/misc/machine-name.js
+++ b/core/misc/machine-name.js
@@ -1,112 +1,108 @@
(function ($) {
/**
- * Attach the machine-readable name form element behavior.
+ * Attaches the behavior.
+ *
+ * @param settings.machineName
+ * A list of elements to process, keyed by the HTML ID of the form element
+ * containing the human-readable value. Each element is an object defining
+ * the following properties:
+ * - target: The HTML ID of the machine name form element.
+ * - suffix: The HTML ID of a container to show the machine name preview in
+ * (usually a field suffix after the human-readable name form element).
+ * - label: The label to show for the machine name preview.
+ * - replace_pattern: A regular expression (without modifiers) matching
+ * disallowed characters in the machine name; e.g., '[^a-z0-9]+'.
+ * - replace: A character to replace disallowed characters with; e.g., '_'
+ * or '-'.
+ * - standalone: Whether the preview should stay in its own element rather
+ * than the suffix of the source element.
+ * - field_prefix: The #field_prefix of the form element.
+ * - field_suffix: The #field_suffix of the form element.
*/
-Drupal.behaviors.machineName = {
- /**
- * Attaches the behavior.
- *
- * @param settings.machineName
- * A list of elements to process, keyed by the HTML ID of the form element
- * containing the human-readable value. Each element is an object defining
- * the following properties:
- * - target: The HTML ID of the machine name form element.
- * - suffix: The HTML ID of a container to show the machine name preview in
- * (usually a field suffix after the human-readable name form element).
- * - label: The label to show for the machine name preview.
- * - replace_pattern: A regular expression (without modifiers) matching
- * disallowed characters in the machine name; e.g., '[^a-z0-9]+'.
- * - replace: A character to replace disallowed characters with; e.g., '_'
- * or '-'.
- * - standalone: Whether the preview should stay in its own element rather
- * than the suffix of the source element.
- * - field_prefix: The #field_prefix of the form element.
- * - field_suffix: The #field_suffix of the form element.
- */
- attach: function (context, settings) {
- var self = this;
- var $context = $(context);
- for (var i in settings.machineName) {
- if (settings.machineName.hasOwnProperty(i)) {
- (function (source_id, options) {
- var $source = $context.find(source_id).addClass('machine-name-source');
- var $target = $context.find(options.target).addClass('machine-name-target');
- var $suffix = $context.find(options.suffix);
- var $wrapper = $target.closest('.form-item');
- // All elements have to exist.
- if (!$source.length || !$target.length || !$suffix.length || !$wrapper.length) {
- return;
- }
- // Skip processing upon a form validation error on the machine name.
- if ($target.hasClass('error')) {
- return;
- }
- // Figure out the maximum length for the machine name.
- options.maxlength = $target.attr('maxlength');
- // Hide the form item container of the machine name form element.
- $wrapper.hide();
- // Determine the initial machine name value. Unless the machine name form
- // element is disabled or not empty, the initial default value is based on
- // the human-readable form element value.
- if ($target.is(':disabled') || $target.val() != '') {
- var machine = $target.val();
- }
- else {
- var machine = self.transliterate($source.val(), options);
- }
- // Append the machine name preview to the source field.
- var $preview = $('' + options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix + '');
- $suffix.empty();
- if (options.label) {
- $suffix.append(' ').append('' + options.label + ':');
- }
- $suffix.append(' ').append($preview);
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var self = this;
+ var $context = $(e.target);
+ for (var i in settings.machineName) {
+ if (settings.machineName.hasOwnProperty(i)) {
+ (function (source_id, options) {
+ var $source = $context.find(source_id).addClass('machine-name-source');
+ var $target = $context.find(options.target).addClass('machine-name-target');
+ var $suffix = $context.find(options.suffix);
+ var $wrapper = $target.closest('.form-item');
+ // All elements have to exist.
+ if (!$source.length || !$target.length || !$suffix.length || !$wrapper.length) {
+ return;
+ }
+ // Skip processing upon a form validation error on the machine name.
+ if ($target.hasClass('error')) {
+ return;
+ }
+ // Figure out the maximum length for the machine name.
+ options.maxlength = $target.attr('maxlength');
+ // Hide the form item container of the machine name form element.
+ $wrapper.hide();
+ // Determine the initial machine name value. Unless the machine name form
+ // element is disabled or not empty, the initial default value is based on
+ // the human-readable form element value.
+ if ($target.is(':disabled') || $target.val() != '') {
+ var machine = $target.val();
+ }
+ else {
+ var machine = transliterate($source.val(), options);
+ }
+ // Append the machine name preview to the source field.
+ var $preview = $('' + options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix + '');
+ $suffix.empty();
+ if (options.label) {
+ $suffix.append(' ').append('' + options.label + ':');
+ }
+ $suffix.append(' ').append($preview);
- // If the machine name cannot be edited, stop further processing.
- if ($target.is(':disabled')) {
- return;
- }
+ // If the machine name cannot be edited, stop further processing.
+ if ($target.is(':disabled')) {
+ return;
+ }
- // If it is editable, append an edit link.
- var $link = $('' + Drupal.t('Edit') + '')
- .click(function () {
- $wrapper.show();
- $target.focus();
- $suffix.hide();
- $source.unbind('.machineName');
- return false;
- });
- $suffix.append(' ').append($link);
+ // If it is editable, append an edit link.
+ var $link = $('' + Drupal.t('Edit') + '')
+ .click(function () {
+ $wrapper.show();
+ $target.focus();
+ $suffix.hide();
+ $source.unbind('.machineName');
+ return false;
+ });
+ $suffix.append(' ').append($link);
- // Preview the machine name in realtime when the human-readable name
- // changes, but only if there is no machine name yet; i.e., only upon
- // initial creation, not when editing.
- if ($target.val() == '') {
- $source.bind('keyup.machineName change.machineName', function () {
- machine = self.transliterate($(this).val(), options);
- // Set the machine name to the transliterated value.
- if (machine != '') {
- if (machine != options.replace) {
- $target.val(machine);
- $preview.html(options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix);
- }
- $suffix.show();
- }
- else {
- $suffix.hide();
+ // Preview the machine name in realtime when the human-readable name
+ // changes, but only if there is no machine name yet; i.e., only upon
+ // initial creation, not when editing.
+ if ($target.val() == '') {
+ $source.bind('keyup.machineName change.machineName', function () {
+ machine = transliterate($(this).val(), options);
+ // Set the machine name to the transliterated value.
+ if (machine != '') {
+ if (machine != options.replace) {
$target.val(machine);
- $preview.empty();
+ $preview.html(options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix);
}
- });
- // Initialize machine name preview.
- $source.keyup();
- }
- }(i, settings.machineName[i]));
- }
+ $suffix.show();
+ }
+ else {
+ $suffix.hide();
+ $target.val(machine);
+ $preview.empty();
+ }
+ });
+ // Initialize machine name preview.
+ $source.keyup();
+ }
+ }(i, settings.machineName[i]));
}
- },
-
+ }
+});
/**
* Transliterate a human-readable name to a machine name.
*
@@ -123,10 +119,9 @@ Drupal.behaviors.machineName = {
* @return
* The transliterated source string.
*/
- transliterate: function (source, settings) {
- var rx = new RegExp(settings.replace_pattern, 'g');
- return source.toLowerCase().replace(rx, settings.replace).substr(0, settings.maxlength);
- }
-};
+function transliterate (source, settings) {
+ var rx = new RegExp(settings.replace_pattern, 'g');
+ return source.toLowerCase().replace(rx, settings.replace).substr(0, settings.maxlength);
+}
})(jQuery);
diff --git a/core/misc/states.js b/core/misc/states.js
index 30b63ba..3b41afb 100644
--- a/core/misc/states.js
+++ b/core/misc/states.js
@@ -14,24 +14,23 @@ var states = Drupal.states = {
/**
* Attaches the states.
*/
-Drupal.behaviors.states = {
- attach: function (context, settings) {
- for (var selector in settings.states) {
- for (var state in settings.states[selector]) {
- new states.Dependent({
- element: $(selector),
- state: states.State.sanitize(state),
- constraints: settings.states[selector][state]
- });
- }
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ for (var selector in settings.states) {
+ for (var state in settings.states[selector]) {
+ new states.Dependent({
+ element: $(selector),
+ state: states.State.sanitize(state),
+ constraints: settings.states[selector][state]
+ });
}
+ }
- // Execute all postponed functions now.
- while (states.postponed.length) {
- (states.postponed.shift())();
- }
+ // Execute all postponed functions now.
+ while (states.postponed.length) {
+ (states.postponed.shift())();
}
-};
+});
/**
* Object representing an element that depends on other elements.
diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js
index 16800e0..2f1c741 100644
--- a/core/misc/tabledrag.js
+++ b/core/misc/tabledrag.js
@@ -11,17 +11,17 @@
* overriding the .onDrag, .onDrop, .row.onSwap, and .row.onIndent methods.
* See blocks.js for an example of adding additional functionality to tableDrag.
*/
-Drupal.behaviors.tableDrag = {
- attach: function (context, settings) {
- for (var base in settings.tableDrag) {
- $(context).find('#' + base).once('tabledrag', function () {
- // Create the new tableDrag instance. Save in the Drupal variable
- // to allow other scripts access to the object.
- Drupal.tableDrag[base] = new Drupal.tableDrag(this, settings.tableDrag[base]);
- });
- }
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var context = e.target;
+ for (var base in settings.tableDrag) {
+ $(context).find('#' + base).once('tabledrag', function () {
+ // Create the new tableDrag instance. Save in the Drupal variable
+ // to allow other scripts access to the object.
+ Drupal.tableDrag[base] = new Drupal.tableDrag(this, settings.tableDrag[base]);
+ });
}
-};
+});
/**
* Constructor for the tableDrag object. Provides table and field manipulation.
@@ -1003,9 +1003,10 @@ Drupal.tableDrag.prototype.row.prototype.isValidSwap = function (row) {
* DOM element what will be swapped with the row group.
*/
Drupal.tableDrag.prototype.row.prototype.swap = function (position, row) {
- Drupal.detachBehaviors(this.group, Drupal.settings, 'move');
+ var $group = $(this.group);
+ $group.trigger('detach', Drupal.settings, 'move');
$(row)[position](this.group);
- Drupal.attachBehaviors(this.group, Drupal.settings);
+ $group.trigger('attach', Drupal.settings);
this.changed = true;
this.onSwap(row);
};
diff --git a/core/misc/tableheader.js b/core/misc/tableheader.js
index aa1c8bb..5249fb5 100644
--- a/core/misc/tableheader.js
+++ b/core/misc/tableheader.js
@@ -3,17 +3,15 @@
/**
* Attaches sticky table headers.
*/
-Drupal.behaviors.tableHeader = {
- attach: function (context, settings) {
- if (!$.support.fixedPosition) {
- return;
- }
-
- $(context).find('table.sticky-enabled').once('tableheader', function () {
- $(this).data("drupal-tableheader", new Drupal.tableHeader(this));
- });
+$(document).on('ready attach', function (e) {
+ if (!$.support.fixedPosition) {
+ return;
}
-};
+
+ $(e.target).find('table.sticky-enabled').once('tableheader', function () {
+ $(this).data("drupal-tableheader", new Drupal.tableHeader(this));
+ });
+});
/**
* Constructor for the tableHeader object. Provides sticky table headers.
diff --git a/core/misc/tableselect.js b/core/misc/tableselect.js
index b7011e0..d6df099 100644
--- a/core/misc/tableselect.js
+++ b/core/misc/tableselect.js
@@ -1,11 +1,9 @@
(function ($) {
-Drupal.behaviors.tableSelect = {
- attach: function (context, settings) {
- // Select the inner-most table in case of nested tables.
- $(context).find('th.select-all').closest('table').once('table-select', Drupal.tableSelect);
- }
-};
+$(document).on('ready attach', function (e) {
+ // Select the inner-most table in case of nested tables.
+ $(e.target).find('th.select-all').closest('table').once('table-select', Drupal.tableSelect);
+});
Drupal.tableSelect = function () {
// Do not add a "Select all" checkbox if there are no rows with checkboxes in the table
diff --git a/core/misc/timezone.js b/core/misc/timezone.js
index 62b7d4b..bd249d1 100644
--- a/core/misc/timezone.js
+++ b/core/misc/timezone.js
@@ -3,64 +3,62 @@
/**
* Set the client's system time zone as default values of form fields.
*/
-Drupal.behaviors.setTimezone = {
- attach: function (context, settings) {
- $(context).find('select.timezone-detect').once('timezone', function () {
- var dateString = Date();
- // In some client environments, date strings include a time zone
- // abbreviation, between 3 and 5 letters enclosed in parentheses,
- // which can be interpreted by PHP.
- var matches = dateString.match(/\(([A-Z]{3,5})\)/);
- var abbreviation = matches ? matches[1] : 0;
+$(document).on('ready attach', function (e) {
+ $(e.target).find('select.timezone-detect').once('timezone', function () {
+ var dateString = Date();
+ // In some client environments, date strings include a time zone
+ // abbreviation, between 3 and 5 letters enclosed in parentheses,
+ // which can be interpreted by PHP.
+ var matches = dateString.match(/\(([A-Z]{3,5})\)/);
+ var abbreviation = matches ? matches[1] : 0;
- // For all other client environments, the abbreviation is set to "0"
- // and the current offset from UTC and daylight saving time status are
- // used to guess the time zone.
- var dateNow = new Date();
- var offsetNow = dateNow.getTimezoneOffset() * -60;
+ // For all other client environments, the abbreviation is set to "0"
+ // and the current offset from UTC and daylight saving time status are
+ // used to guess the time zone.
+ var dateNow = new Date();
+ var offsetNow = dateNow.getTimezoneOffset() * -60;
- // Use January 1 and July 1 as test dates for determining daylight
- // saving time status by comparing their offsets.
- var dateJan = new Date(dateNow.getFullYear(), 0, 1, 12, 0, 0, 0);
- var dateJul = new Date(dateNow.getFullYear(), 6, 1, 12, 0, 0, 0);
- var offsetJan = dateJan.getTimezoneOffset() * -60;
- var offsetJul = dateJul.getTimezoneOffset() * -60;
+ // Use January 1 and July 1 as test dates for determining daylight
+ // saving time status by comparing their offsets.
+ var dateJan = new Date(dateNow.getFullYear(), 0, 1, 12, 0, 0, 0);
+ var dateJul = new Date(dateNow.getFullYear(), 6, 1, 12, 0, 0, 0);
+ var offsetJan = dateJan.getTimezoneOffset() * -60;
+ var offsetJul = dateJul.getTimezoneOffset() * -60;
- var isDaylightSavingTime;
- // If the offset from UTC is identical on January 1 and July 1,
- // assume daylight saving time is not used in this time zone.
- if (offsetJan == offsetJul) {
- isDaylightSavingTime = '';
- }
- // If the maximum annual offset is equivalent to the current offset,
- // assume daylight saving time is in effect.
- else if (Math.max(offsetJan, offsetJul) == offsetNow) {
- isDaylightSavingTime = 1;
- }
- // Otherwise, assume daylight saving time is not in effect.
- else {
- isDaylightSavingTime = 0;
- }
+ var isDaylightSavingTime;
+ // If the offset from UTC is identical on January 1 and July 1,
+ // assume daylight saving time is not used in this time zone.
+ if (offsetJan == offsetJul) {
+ isDaylightSavingTime = '';
+ }
+ // If the maximum annual offset is equivalent to the current offset,
+ // assume daylight saving time is in effect.
+ else if (Math.max(offsetJan, offsetJul) == offsetNow) {
+ isDaylightSavingTime = 1;
+ }
+ // Otherwise, assume daylight saving time is not in effect.
+ else {
+ isDaylightSavingTime = 0;
+ }
- // Submit request to the system/timezone callback and set the form field
- // to the response time zone. The client date is passed to the callback
- // for debugging purposes. Submit a synchronous request to avoid database
- // errors associated with concurrent requests during install.
- var path = 'system/timezone/' + abbreviation + '/' + offsetNow + '/' + isDaylightSavingTime;
- var element = this;
- $.ajax({
- async: false,
- url: settings.basePath,
- data: { q: path, date: dateString },
- dataType: 'json',
- success: function (data) {
- if (data) {
- $(element).val(data);
- }
+ // Submit request to the system/timezone callback and set the form field
+ // to the response time zone. The client date is passed to the callback
+ // for debugging purposes. Submit a synchronous request to avoid database
+ // errors associated with concurrent requests during install.
+ var path = 'system/timezone/' + abbreviation + '/' + offsetNow + '/' + isDaylightSavingTime;
+ var element = this;
+ $.ajax({
+ async: false,
+ url: settings.basePath,
+ data: { q: path, date: dateString },
+ dataType: 'json',
+ success: function (data) {
+ if (data) {
+ $(element).val(data);
}
- });
+ }
});
- }
-};
+ });
+});
})(jQuery);
diff --git a/core/misc/vertical-tabs.js b/core/misc/vertical-tabs.js
index 65e5683..d465e29 100644
--- a/core/misc/vertical-tabs.js
+++ b/core/misc/vertical-tabs.js
@@ -11,60 +11,58 @@
* which is called every time the user performs an update to a form
* element inside the tab pane.
*/
-Drupal.behaviors.verticalTabs = {
- attach: function (context) {
- $(context).find('.vertical-tabs-panes').once('vertical-tabs', function () {
- var $this = $(this);
- var focusID = $this.find(':hidden.vertical-tabs-active-tab').val();
- var tab_focus;
+$(document).on('ready attach', function (e) {
+ $(e.target).find('.vertical-tabs-panes').once('vertical-tabs', function () {
+ var $this = $(this);
+ var focusID = $this.find(':hidden.vertical-tabs-active-tab').val();
+ var tab_focus;
+
+ // Check if there are some fieldsets that can be converted to vertical-tabs
+ var $fieldsets = $this.find('> fieldset');
+ if ($fieldsets.length == 0) {
+ return;
+ }
- // Check if there are some fieldsets that can be converted to vertical-tabs
- var $fieldsets = $this.find('> fieldset');
- if ($fieldsets.length == 0) {
- return;
- }
+ // Create the tab column.
+ var tab_list = $('
');
+ $this.wrap('').before(tab_list);
- // Create the tab column.
- var tab_list = $('
');
- $this.wrap('').before(tab_list);
-
- // Transform each fieldset into a tab.
- $fieldsets.each(function () {
- var $this = $(this);
- var vertical_tab = new Drupal.verticalTab({
- title: $this.find('> legend').text(),
- fieldset: $this
- });
- tab_list.append(vertical_tab.item);
- $this
- .removeClass('collapsible collapsed')
- .addClass('vertical-tabs-pane')
- .data('verticalTab', vertical_tab);
- if (this.id == focusID) {
- tab_focus = $this;
- }
+ // Transform each fieldset into a tab.
+ $fieldsets.each(function () {
+ var $this = $(this);
+ var vertical_tab = new Drupal.verticalTab({
+ title: $this.find('> legend').text(),
+ fieldset: $this
});
+ tab_list.append(vertical_tab.item);
+ $this
+ .removeClass('collapsible collapsed')
+ .addClass('vertical-tabs-pane')
+ .data('verticalTab', vertical_tab);
+ if (this.id == focusID) {
+ tab_focus = $this;
+ }
+ });
+
+ $(tab_list).find('> li:first').addClass('first');
+ $(tab_list).find('> li:last').addClass('last');
- $(tab_list).find('> li:first').addClass('first');
- $(tab_list).find('> li:last').addClass('last');
-
- if (!tab_focus) {
- // If the current URL has a fragment and one of the tabs contains an
- // element that matches the URL fragment, activate that tab.
- var $locationHash = $this.find(window.location.hash);
- if (window.location.hash && $locationHash.length) {
- tab_focus = $locationHash.closest('.vertical-tabs-pane');
- }
- else {
- tab_focus = $this.find('> .vertical-tabs-pane:first');
- }
+ if (!tab_focus) {
+ // If the current URL has a fragment and one of the tabs contains an
+ // element that matches the URL fragment, activate that tab.
+ var $locationHash = $this.find(window.location.hash);
+ if (window.location.hash && $locationHash.length) {
+ tab_focus = $locationHash.closest('.vertical-tabs-pane');
}
- if (tab_focus.length) {
- tab_focus.data('verticalTab').focus();
+ else {
+ tab_focus = $this.find('> .vertical-tabs-pane:first');
}
- });
- }
-};
+ }
+ if (tab_focus.length) {
+ tab_focus.data('verticalTab').focus();
+ }
+ });
+});
/**
* The vertical tab object represents a single tab within a tab group.
diff --git a/core/modules/block/block.js b/core/modules/block/block.js
index dabb570..9a4fe78 100644
--- a/core/modules/block/block.js
+++ b/core/modules/block/block.js
@@ -3,70 +3,68 @@
/**
* Provide the summary information for the block settings vertical tabs.
*/
-Drupal.behaviors.blockSettingsSummary = {
- attach: function (context) {
- // The drupalSetSummary method required for this behavior is not available
- // on the Blocks administration page, so we need to make sure this
- // behavior is processed only if drupalSetSummary is defined.
- if (typeof jQuery.fn.drupalSetSummary == 'undefined') {
- return;
- }
+$(document).on('ready attach', function (e) {
+ // The drupalSetSummary method required for this behavior is not available
+ // on the Blocks administration page, so we need to make sure this
+ // behavior is processed only if drupalSetSummary is defined.
+ if (typeof jQuery.fn.drupalSetSummary == 'undefined') {
+ return;
+ }
- var $context = $(context);
- $context.find('fieldset#edit-path').drupalSetSummary(function (context) {
- if (!$(context).find('textarea[name="pages"]').val()) {
- return Drupal.t('Not restricted');
- }
- else {
- return Drupal.t('Restricted to certain pages');
- }
- });
+ var $context = $(e.target);
+ $context.find('fieldset#edit-path').drupalSetSummary(function (context) {
+ if (!$(context).find('textarea[name="pages"]').val()) {
+ return Drupal.t('Not restricted');
+ }
+ else {
+ return Drupal.t('Restricted to certain pages');
+ }
+ });
- $context.find('fieldset#edit-node-type').drupalSetSummary(function (context) {
- var vals = [];
- $(context).find('input[type="checkbox"]:checked').each(function () {
- vals.push($.trim($(this).next('label').text()));
- });
- if (!vals.length) {
- vals.push(Drupal.t('Not restricted'));
- }
- return vals.join(', ');
+ $context.find('fieldset#edit-node-type').drupalSetSummary(function (context) {
+ var vals = [];
+ $(context).find('input[type="checkbox"]:checked').each(function () {
+ vals.push($.trim($(this).next('label').text()));
});
+ if (!vals.length) {
+ vals.push(Drupal.t('Not restricted'));
+ }
+ return vals.join(', ');
+ });
- $context.find('fieldset#edit-language').drupalSetSummary(function (context) {
- var vals = [];
- $(context).find('input[type="checkbox"]:checked').each(function () {
- vals.push($.trim($(this).next('label').text()));
- });
- if (!vals.length) {
- vals.push(Drupal.t('Not restricted'));
- }
- return vals.join(', ');
+ $context.find('fieldset#edit-language').drupalSetSummary(function (context) {
+ var vals = [];
+ $(context).find('input[type="checkbox"]:checked').each(function () {
+ vals.push($.trim($(this).next('label').text()));
});
+ if (!vals.length) {
+ vals.push(Drupal.t('Not restricted'));
+ }
+ return vals.join(', ');
+ });
- $context.find('fieldset#edit-role').drupalSetSummary(function (context) {
- var vals = [];
- $(context).find('input[type="checkbox"]:checked').each(function () {
- vals.push($.trim($(this).next('label').text()));
- });
- if (!vals.length) {
- vals.push(Drupal.t('Not restricted'));
- }
- return vals.join(', ');
+ $context.find('fieldset#edit-role').drupalSetSummary(function (context) {
+ var vals = [];
+ $(context).find('input[type="checkbox"]:checked').each(function () {
+ vals.push($.trim($(this).next('label').text()));
});
+ if (!vals.length) {
+ vals.push(Drupal.t('Not restricted'));
+ }
+ return vals.join(', ');
+ });
- $context.find('fieldset#edit-user').drupalSetSummary(function (context) {
- var $radio = $(context).find('input[name="custom"]:checked');
- if ($radio.val() == 0) {
- return Drupal.t('Not customizable');
- }
- else {
- return $radio.next('label').text();
- }
- });
- }
-};
+ $context.find('fieldset#edit-user').drupalSetSummary(function (context) {
+ var $radio = $(context).find('input[name="custom"]:checked');
+ if ($radio.val() == 0) {
+ return Drupal.t('Not customizable');
+ }
+ else {
+ return $radio.next('label').text();
+ }
+ });
+});
/**
* Move a block in the blocks table from one region to another via select list.
@@ -74,94 +72,92 @@ Drupal.behaviors.blockSettingsSummary = {
* This behavior is dependent on the tableDrag behavior, since it uses the
* objects initialized in that behavior to update the row.
*/
-Drupal.behaviors.blockDrag = {
- attach: function (context, settings) {
- // tableDrag is required and we should be on the blocks admin page.
- if (typeof Drupal.tableDrag == 'undefined' || typeof Drupal.tableDrag.blocks == 'undefined') {
- return;
+$(document).on('ready attach', function (e) {
+ // tableDrag is required and we should be on the blocks admin page.
+ if (typeof Drupal.tableDrag == 'undefined' || typeof Drupal.tableDrag.blocks == 'undefined') {
+ return;
+ }
+ var context = e.target;
+ var table = $('table#blocks');
+ var tableDrag = Drupal.tableDrag.blocks; // Get the blocks tableDrag object.
+
+ // Add a handler for when a row is swapped, update empty regions.
+ tableDrag.row.prototype.onSwap = function (swappedRow) {
+ checkEmptyRegions(table, this);
+ };
+
+ // A custom message for the blocks page specifically.
+ Drupal.theme.tableDragChangedWarning = function () {
+ return '
' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('The changes to these blocks will not be saved until the Save blocks button is clicked.') + '
';
+ };
+
+ // Add a handler so when a row is dropped, update fields dropped into new regions.
+ tableDrag.onDrop = function () {
+ var dragObject = this;
+ var $rowElement = $(dragObject.rowObject.element);
+ // Use "region-message" row instead of "region" row because
+ // "region-{region_name}-message" is less prone to regexp match errors.
+ var regionRow = $rowElement.prevAll('tr.region-message').get(0);
+ var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
+ var regionField = $rowElement.find('select.block-region-select');
+ // Check whether the newly picked region is available for this block.
+ if (regionField.find('option[value=' + regionName + ']').length == 0) {
+ // If not, alert the user and keep the block in its old region setting.
+ alert(Drupal.t('The block cannot be placed in this region.'));
+ // Simulate that there was a selected element change, so the row is put
+ // back to from where the user tried to drag it.
+ regionField.change();
}
-
- var table = $('table#blocks');
- var tableDrag = Drupal.tableDrag.blocks; // Get the blocks tableDrag object.
-
- // Add a handler for when a row is swapped, update empty regions.
- tableDrag.row.prototype.onSwap = function (swappedRow) {
- checkEmptyRegions(table, this);
- };
-
- // A custom message for the blocks page specifically.
- Drupal.theme.tableDragChangedWarning = function () {
- return '
' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('The changes to these blocks will not be saved until the Save blocks button is clicked.') + '
';
- };
-
- // Add a handler so when a row is dropped, update fields dropped into new regions.
- tableDrag.onDrop = function () {
- var dragObject = this;
- var $rowElement = $(dragObject.rowObject.element);
- // Use "region-message" row instead of "region" row because
- // "region-{region_name}-message" is less prone to regexp match errors.
- var regionRow = $rowElement.prevAll('tr.region-message').get(0);
- var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
- var regionField = $rowElement.find('select.block-region-select');
- // Check whether the newly picked region is available for this block.
- if (regionField.find('option[value=' + regionName + ']').length == 0) {
- // If not, alert the user and keep the block in its old region setting.
- alert(Drupal.t('The block cannot be placed in this region.'));
- // Simulate that there was a selected element change, so the row is put
- // back to from where the user tried to drag it.
- regionField.change();
+ else if ($rowElement.prev('tr').is('.region-message')) {
+ var weightField = $rowElement.find('select.block-weight');
+ var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
+
+ if (!regionField.is('.block-region-' + regionName)) {
+ regionField.removeClass('block-region-' + oldRegionName).addClass('block-region-' + regionName);
+ weightField.removeClass('block-weight-' + oldRegionName).addClass('block-weight-' + regionName);
+ regionField.val(regionName);
}
- else if ($rowElement.prev('tr').is('.region-message')) {
- var weightField = $rowElement.find('select.block-weight');
- var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
-
- if (!regionField.is('.block-region-' + regionName)) {
- regionField.removeClass('block-region-' + oldRegionName).addClass('block-region-' + regionName);
- weightField.removeClass('block-weight-' + oldRegionName).addClass('block-weight-' + regionName);
- regionField.val(regionName);
+ }
+ };
+
+ // Add the behavior to each region select list.
+ $(context).find('select.block-region-select').once('block-region-select', function () {
+ $(this).change(function (event) {
+ // Make our new row and select field.
+ var row = $(this).closest('tr');
+ var select = $(this);
+ tableDrag.rowObject = new tableDrag.row(row);
+
+ // Find the correct region and insert the row as the last in the region.
+ table.find('.region-' + select[0].value + '-message').nextUntil('.region-message').last().before(row);
+
+ // Modify empty regions with added or removed fields.
+ checkEmptyRegions(table, row);
+ // Remove focus from selectbox.
+ select.get(0).blur();
+ });
+ });
+
+ var checkEmptyRegions = function (table, rowObject) {
+ table.find('tr.region-message').each(function () {
+ var $this = $(this);
+ // If the dragged row is in this region, but above the message row, swap it down one space.
+ if ($this.prev('tr').get(0) == rowObject.element) {
+ // Prevent a recursion problem when using the keyboard to move rows up.
+ if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
+ rowObject.swap('after', this);
}
}
- };
-
- // Add the behavior to each region select list.
- $(context).find('select.block-region-select').once('block-region-select', function () {
- $(this).change(function (event) {
- // Make our new row and select field.
- var row = $(this).closest('tr');
- var select = $(this);
- tableDrag.rowObject = new tableDrag.row(row);
-
- // Find the correct region and insert the row as the last in the region.
- table.find('.region-' + select[0].value + '-message').nextUntil('.region-message').last().before(row);
-
- // Modify empty regions with added or removed fields.
- checkEmptyRegions(table, row);
- // Remove focus from selectbox.
- select.get(0).blur();
- });
+ // This region has become empty.
+ if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length == 0) {
+ $this.removeClass('region-populated').addClass('region-empty');
+ }
+ // This region has become populated.
+ else if ($this.is('.region-empty')) {
+ $this.removeClass('region-empty').addClass('region-populated');
+ }
});
-
- var checkEmptyRegions = function (table, rowObject) {
- table.find('tr.region-message').each(function () {
- var $this = $(this);
- // If the dragged row is in this region, but above the message row, swap it down one space.
- if ($this.prev('tr').get(0) == rowObject.element) {
- // Prevent a recursion problem when using the keyboard to move rows up.
- if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
- rowObject.swap('after', this);
- }
- }
- // This region has become empty.
- if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length == 0) {
- $this.removeClass('region-populated').addClass('region-empty');
- }
- // This region has become populated.
- else if ($this.is('.region-empty')) {
- $this.removeClass('region-empty').addClass('region-populated');
- }
- });
- };
- }
-};
+ };
+});
})(jQuery);
diff --git a/core/modules/book/book.js b/core/modules/book/book.js
index e6ab4fa..df113f7 100644
--- a/core/modules/book/book.js
+++ b/core/modules/book/book.js
@@ -1,22 +1,20 @@
(function ($) {
-Drupal.behaviors.bookFieldsetSummaries = {
- attach: function (context) {
- $(context).find('fieldset.book-outline-form').drupalSetSummary(function (context) {
- var $select = $('.form-item-book-bid select');
- var val = $select.val();
+$(document).on('ready attach', function (e) {
+ $(e.target).find('fieldset.book-outline-form').drupalSetSummary(function (context) {
+ var $select = $('.form-item-book-bid select');
+ var val = $select.val();
- if (val === '0') {
- return Drupal.t('Not in book');
- }
- else if (val === 'new') {
- return Drupal.t('New book');
- }
- else {
- return Drupal.checkPlain($select.find(':selected').text());
- }
- });
- }
-};
+ if (val === '0') {
+ return Drupal.t('Not in book');
+ }
+ else if (val === 'new') {
+ return Drupal.t('New book');
+ }
+ else {
+ return Drupal.checkPlain($select.find(':selected').text());
+ }
+ });
+});
})(jQuery);
diff --git a/core/modules/color/color.js b/core/modules/color/color.js
index d833a4b..0813e00 100644
--- a/core/modules/color/color.js
+++ b/core/modules/color/color.js
@@ -5,238 +5,238 @@
(function ($) {
-Drupal.behaviors.color = {
- attach: function (context, settings) {
- var i, j, colors, field_name;
- // This behavior attaches by ID, so is only valid once on a page.
- var form = $(context).find('#system-theme-settings .color-form').once('color');
- if (form.length == 0) {
- return;
- }
- var inputs = [];
- var hooks = [];
- var locks = [];
- var focused = null;
-
- // Add Farbtastic.
- $('').once('color').prependTo(form);
- var farb = $.farbtastic('#placeholder');
-
- // Decode reference colors to HSL.
- var reference = settings.color.reference;
- for (i in reference) {
- reference[i] = farb.RGBToHSL(farb.unpack(reference[i]));
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var i, j, colors, field_name;
+ var context = e.target;
+ // This behavior attaches by ID, so is only valid once on a page.
+ var form = $(context).find('#system-theme-settings .color-form').once('color');
+ if (form.length == 0) {
+ return;
+ }
+ var inputs = [];
+ var hooks = [];
+ var locks = [];
+ var focused = null;
+
+ // Add Farbtastic.
+ $('').once('color').prependTo(form);
+ var farb = $.farbtastic('#placeholder');
+
+ // Decode reference colors to HSL.
+ var reference = settings.color.reference;
+ for (i in reference) {
+ reference[i] = farb.RGBToHSL(farb.unpack(reference[i]));
+ }
+
+ // Build a preview.
+ var height = [];
+ var width = [];
+ // Loop through all defined gradients.
+ for (i in settings.gradients) {
+ // Add element to display the gradient.
+ $('#preview').once('color').append('');
+ var gradient = $('#preview #gradient-' + i);
+ // Add height of current gradient to the list (divided by 10).
+ height.push(parseInt(gradient.css('height'), 10) / 10);
+ // Add width of current gradient to the list (divided by 10).
+ width.push(parseInt(gradient.css('width'), 10) / 10);
+ // Add rows (or columns for horizontal gradients).
+ // Each gradient line should have a height (or width for horizontal
+ // gradients) of 10px (because we divided the height/width by 10 above).
+ for (j = 0; j < (settings.gradients[i]['direction'] == 'vertical' ? height[i] : width[i]); ++j) {
+ gradient.append('');
}
+ }
- // Build a preview.
- var height = [];
- var width = [];
- // Loop through all defined gradients.
- for (i in settings.gradients) {
- // Add element to display the gradient.
- $('#preview').once('color').append('');
- var gradient = $('#preview #gradient-' + i);
- // Add height of current gradient to the list (divided by 10).
- height.push(parseInt(gradient.css('height'), 10) / 10);
- // Add width of current gradient to the list (divided by 10).
- width.push(parseInt(gradient.css('width'), 10) / 10);
- // Add rows (or columns for horizontal gradients).
- // Each gradient line should have a height (or width for horizontal
- // gradients) of 10px (because we divided the height/width by 10 above).
- for (j = 0; j < (settings.gradients[i]['direction'] == 'vertical' ? height[i] : width[i]); ++j) {
- gradient.append('');
+ // Set up colorScheme selector.
+ form.find('#edit-scheme').change(function () {
+ var schemes = settings.color.schemes, colorScheme = this.options[this.selectedIndex].value;
+ if (colorScheme != '' && schemes[colorScheme]) {
+ // Get colors of active scheme.
+ colors = schemes[colorScheme];
+ for (field_name in colors) {
+ callback($('#edit-palette-' + field_name), colors[field_name], false, true);
}
+ preview();
}
+ });
- // Set up colorScheme selector.
- form.find('#edit-scheme').change(function () {
- var schemes = settings.color.schemes, colorScheme = this.options[this.selectedIndex].value;
- if (colorScheme != '' && schemes[colorScheme]) {
- // Get colors of active scheme.
- colors = schemes[colorScheme];
- for (field_name in colors) {
- callback($('#edit-palette-' + field_name), colors[field_name], false, true);
- }
- preview();
- }
- });
+ /**
+ * Renders the preview.
+ */
+ function preview() {
+ Drupal.color.callback(context, settings, form, farb, height, width);
+ }
- /**
- * Renders the preview.
- */
- function preview() {
- Drupal.color.callback(context, settings, form, farb, height, width);
+ /**
+ * Shifts a given color, using a reference pair (ref in HSL).
+ *
+ * This algorithm ensures relative ordering on the saturation and luminance
+ * axes is preserved, and performs a simple hue shift.
+ *
+ * It is also symmetrical. If: shift_color(c, a, b) == d, then
+ * shift_color(d, b, a) == c.
+ */
+ function shift_color(given, ref1, ref2) {
+ // Convert to HSL.
+ given = farb.RGBToHSL(farb.unpack(given));
+
+ // Hue: apply delta.
+ given[0] += ref2[0] - ref1[0];
+
+ // Saturation: interpolate.
+ if (ref1[1] == 0 || ref2[1] == 0) {
+ given[1] = ref2[1];
}
-
- /**
- * Shifts a given color, using a reference pair (ref in HSL).
- *
- * This algorithm ensures relative ordering on the saturation and luminance
- * axes is preserved, and performs a simple hue shift.
- *
- * It is also symmetrical. If: shift_color(c, a, b) == d, then
- * shift_color(d, b, a) == c.
- */
- function shift_color(given, ref1, ref2) {
- // Convert to HSL.
- given = farb.RGBToHSL(farb.unpack(given));
-
- // Hue: apply delta.
- given[0] += ref2[0] - ref1[0];
-
- // Saturation: interpolate.
- if (ref1[1] == 0 || ref2[1] == 0) {
- given[1] = ref2[1];
+ else {
+ var d = ref1[1] / ref2[1];
+ if (d > 1) {
+ given[1] /= d;
}
else {
- var d = ref1[1] / ref2[1];
- if (d > 1) {
- given[1] /= d;
- }
- else {
- given[1] = 1 - (1 - given[1]) * d;
- }
+ given[1] = 1 - (1 - given[1]) * d;
}
+ }
- // Luminance: interpolate.
- if (ref1[2] == 0 || ref2[2] == 0) {
- given[2] = ref2[2];
+ // Luminance: interpolate.
+ if (ref1[2] == 0 || ref2[2] == 0) {
+ given[2] = ref2[2];
+ }
+ else {
+ var d = ref1[2] / ref2[2];
+ if (d > 1) {
+ given[2] /= d;
}
else {
- var d = ref1[2] / ref2[2];
- if (d > 1) {
- given[2] /= d;
- }
- else {
- given[2] = 1 - (1 - given[2]) * d;
- }
+ given[2] = 1 - (1 - given[2]) * d;
}
-
- return farb.pack(farb.HSLToRGB(given));
}
- /**
- * Callback for Farbtastic when a new color is chosen.
- */
- function callback(input, color, propagate, colorScheme) {
- var matched;
- // Set background/foreground colors.
- $(input).css({
- backgroundColor: color,
- 'color': farb.RGBToHSL(farb.unpack(color))[2] > 0.5 ? '#000' : '#fff'
- });
-
- // Change input value.
- if ($(input).val() && $(input).val() != color) {
- $(input).val(color);
-
- // Update locked values.
- if (propagate) {
- i = input.i;
- for (j = i + 1; ; ++j) {
- if (!locks[j - 1] || $(locks[j - 1]).is('.unlocked')) break;
- matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
- callback(inputs[j], matched, false);
- }
- for (j = i - 1; ; --j) {
- if (!locks[j] || $(locks[j]).is('.unlocked')) break;
- matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
- callback(inputs[j], matched, false);
- }
-
- // Update preview.
- preview();
- }
+ return farb.pack(farb.HSLToRGB(given));
+ }
+
+ /**
+ * Callback for Farbtastic when a new color is chosen.
+ */
+ function callback(input, color, propagate, colorScheme) {
+ var matched;
+ // Set background/foreground colors.
+ $(input).css({
+ backgroundColor: color,
+ 'color': farb.RGBToHSL(farb.unpack(color))[2] > 0.5 ? '#000' : '#fff'
+ });
- // Reset colorScheme selector.
- if (!colorScheme) {
- resetScheme();
+ // Change input value.
+ if ($(input).val() && $(input).val() != color) {
+ $(input).val(color);
+
+ // Update locked values.
+ if (propagate) {
+ i = input.i;
+ for (j = i + 1; ; ++j) {
+ if (!locks[j - 1] || $(locks[j - 1]).is('.unlocked')) break;
+ matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
+ callback(inputs[j], matched, false);
+ }
+ for (j = i - 1; ; --j) {
+ if (!locks[j] || $(locks[j]).is('.unlocked')) break;
+ matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
+ callback(inputs[j], matched, false);
}
+
+ // Update preview.
+ preview();
}
- }
- /**
- * Resets the color scheme selector.
- */
- function resetScheme() {
- form.find('#edit-scheme').each(function () {
- this.selectedIndex = this.options.length - 1;
- });
+ // Reset colorScheme selector.
+ if (!colorScheme) {
+ resetScheme();
+ }
}
+ }
- /**
- * Focuses Farbtastic on a particular field.
- */
- function focus() {
- var input = this;
- // Remove old bindings.
- focused && $(focused).unbind('keyup', farb.updateValue)
- .unbind('keyup', preview).unbind('keyup', resetScheme)
- .parent().removeClass('item-selected');
-
- // Add new bindings.
- focused = this;
- farb.linkTo(function (color) { callback(input, color, true, false); });
- farb.setColor(this.value);
- $(focused).keyup(farb.updateValue).keyup(preview).keyup(resetScheme)
- .parent().addClass('item-selected');
- }
+ /**
+ * Resets the color scheme selector.
+ */
+ function resetScheme() {
+ form.find('#edit-scheme').each(function () {
+ this.selectedIndex = this.options.length - 1;
+ });
+ }
- // Initialize color fields.
- form.find('#palette input.form-text')
- .each(function () {
- // Extract palette field name
- this.key = this.id.substring(13);
-
- // Link to color picker temporarily to initialize.
- farb.linkTo(function () {}).setColor('#000').linkTo(this);
-
- // Add lock.
- var i = inputs.length;
- if (inputs.length) {
- var lock = $('').toggle(
- function () {
- $(this).addClass('unlocked');
- $(hooks[i - 1]).attr('class',
- locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook up' : 'hook'
- );
- $(hooks[i]).attr('class',
- locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook down' : 'hook'
- );
- },
- function () {
- $(this).removeClass('unlocked');
- $(hooks[i - 1]).attr('class',
- locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook both' : 'hook down'
- );
- $(hooks[i]).attr('class',
- locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook both' : 'hook up'
- );
- }
- );
- $(this).after(lock);
- locks.push(lock);
- };
-
- // Add hook.
- var hook = $('');
- $(this).after(hook);
- hooks.push(hook);
-
- $(this).parent().find('.lock').click();
- this.i = i;
- inputs.push(this);
- })
- .focus(focus);
-
- form.find('#palette label');
-
- // Focus first color.
- focus.call(inputs[0]);
-
- // Render preview.
- preview();
+ /**
+ * Focuses Farbtastic on a particular field.
+ */
+ function focus() {
+ var input = this;
+ // Remove old bindings.
+ focused && $(focused).unbind('keyup', farb.updateValue)
+ .unbind('keyup', preview).unbind('keyup', resetScheme)
+ .parent().removeClass('item-selected');
+
+ // Add new bindings.
+ focused = this;
+ farb.linkTo(function (color) { callback(input, color, true, false); });
+ farb.setColor(this.value);
+ $(focused).keyup(farb.updateValue).keyup(preview).keyup(resetScheme)
+ .parent().addClass('item-selected');
}
-};
+
+ // Initialize color fields.
+ form.find('#palette input.form-text')
+ .each(function () {
+ // Extract palette field name
+ this.key = this.id.substring(13);
+
+ // Link to color picker temporarily to initialize.
+ farb.linkTo(function () {}).setColor('#000').linkTo(this);
+
+ // Add lock.
+ var i = inputs.length;
+ if (inputs.length) {
+ var lock = $('').toggle(
+ function () {
+ $(this).addClass('unlocked');
+ $(hooks[i - 1]).attr('class',
+ locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook up' : 'hook'
+ );
+ $(hooks[i]).attr('class',
+ locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook down' : 'hook'
+ );
+ },
+ function () {
+ $(this).removeClass('unlocked');
+ $(hooks[i - 1]).attr('class',
+ locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook both' : 'hook down'
+ );
+ $(hooks[i]).attr('class',
+ locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook both' : 'hook up'
+ );
+ }
+ );
+ $(this).after(lock);
+ locks.push(lock);
+ };
+
+ // Add hook.
+ var hook = $('');
+ $(this).after(hook);
+ hooks.push(hook);
+
+ $(this).parent().find('.lock').click();
+ this.i = i;
+ inputs.push(this);
+ })
+ .focus(focus);
+
+ form.find('#palette label');
+
+ // Focus first color.
+ focus.call(inputs[0]);
+
+ // Render preview.
+ preview();
+});
})(jQuery);
diff --git a/core/modules/comment/comment-node-form.js b/core/modules/comment/comment-node-form.js
index 51ea492..d50b886 100644
--- a/core/modules/comment/comment-node-form.js
+++ b/core/modules/comment/comment-node-form.js
@@ -5,34 +5,32 @@
(function ($) {
-Drupal.behaviors.commentFieldsetSummaries = {
- attach: function (context) {
+$(document).on('ready attach', function (e) {
+ var $context = $(e.target);
+ $context.find('fieldset.comment-node-settings-form').drupalSetSummary(function (context) {
+ return Drupal.checkPlain($(context).find('.form-item-comment input:checked').next('label').text());
+ });
+
+ // Provide the summary for the node type form.
+ $context.find('fieldset.comment-node-type-settings-form').drupalSetSummary(function(context) {
var $context = $(context);
- $context.find('fieldset.comment-node-settings-form').drupalSetSummary(function (context) {
- return Drupal.checkPlain($(context).find('.form-item-comment input:checked').next('label').text());
- });
-
- // Provide the summary for the node type form.
- $context.find('fieldset.comment-node-type-settings-form').drupalSetSummary(function(context) {
- var $context = $(context);
- var vals = [];
-
- // Default comment setting.
- vals.push($context.find(".form-item-comment select option:selected").text());
-
- // Threading.
- var threading = $(context).find(".form-item-comment-default-mode input:checked").next('label').text();
- if (threading) {
- vals.push(threading);
- }
-
- // Comments per page.
- var number = $context.find(".form-item-comment-default-per-page select option:selected").val();
- vals.push(Drupal.t('@number comments per page', {'@number': number}));
-
- return Drupal.checkPlain(vals.join(', '));
- });
- }
-};
+ var vals = [];
+
+ // Default comment setting.
+ vals.push($context.find(".form-item-comment select option:selected").text());
+
+ // Threading.
+ var threading = $(context).find(".form-item-comment-default-mode input:checked").next('label').text();
+ if (threading) {
+ vals.push(threading);
+ }
+
+ // Comments per page.
+ var number = $context.find(".form-item-comment-default-per-page select option:selected").val();
+ vals.push(Drupal.t('@number comments per page', {'@number': number}));
+
+ return Drupal.checkPlain(vals.join(', '));
+ });
+});
})(jQuery);
diff --git a/core/modules/contextual/contextual.js b/core/modules/contextual/contextual.js
index 1c3305f..40e0399 100644
--- a/core/modules/contextual/contextual.js
+++ b/core/modules/contextual/contextual.js
@@ -10,35 +10,33 @@ Drupal.contextualLinks = Drupal.contextualLinks || {};
/**
* Attaches outline behavior for regions associated with contextual links.
*/
-Drupal.behaviors.contextualLinks = {
- attach: function (context) {
- $(context).find('div.contextual-links-wrapper').once('contextual-links', function () {
- var $wrapper = $(this);
- var $region = $wrapper.closest('.contextual-region');
- var $links = $wrapper.find('ul');
- var $trigger = $('').text(Drupal.t('Configure')).click(
- function () {
- $links.stop(true, true).slideToggle(100);
- $wrapper.toggleClass('contextual-active');
- return false;
- }
- );
- // Attach hover behavior to trigger and ul.contextual-links.
- $trigger.add($links).hover(
- function () { $region.addClass('contextual-region-active'); },
- function () { $region.removeClass('contextual-region-active'); }
- );
- // Hide the contextual links when user clicks a link or rolls out of the .contextual-region.
- $region.bind('mouseleave click', Drupal.contextualLinks.mouseleave);
- $region.hover(
- function() { $trigger.addClass('contextual-links-trigger-active'); },
- function() { $trigger.removeClass('contextual-links-trigger-active'); }
- );
- // Prepend the trigger.
- $wrapper.prepend($trigger);
- });
- }
-};
+$(document).on('ready attach', function (e) {
+ $(e.target).find('div.contextual-links-wrapper').once('contextual-links', function () {
+ var $wrapper = $(this);
+ var $region = $wrapper.closest('.contextual-region');
+ var $links = $wrapper.find('ul');
+ var $trigger = $('').text(Drupal.t('Configure')).click(
+ function () {
+ $links.stop(true, true).slideToggle(100);
+ $wrapper.toggleClass('contextual-active');
+ return false;
+ }
+ );
+ // Attach hover behavior to trigger and ul.contextual-links.
+ $trigger.add($links).hover(
+ function () { $region.addClass('contextual-region-active'); },
+ function () { $region.removeClass('contextual-region-active'); }
+ );
+ // Hide the contextual links when user clicks a link or rolls out of the .contextual-region.
+ $region.bind('mouseleave click', Drupal.contextualLinks.mouseleave);
+ $region.hover(
+ function() { $trigger.addClass('contextual-links-trigger-active'); },
+ function() { $trigger.removeClass('contextual-links-trigger-active'); }
+ );
+ // Prepend the trigger.
+ $wrapper.prepend($trigger);
+ });
+});
/**
* Disables outline for the region contextual links are associated with.
diff --git a/core/modules/dashboard/dashboard.js b/core/modules/dashboard/dashboard.js
index 39d87c2..0cf42ed 100644
--- a/core/modules/dashboard/dashboard.js
+++ b/core/modules/dashboard/dashboard.js
@@ -182,7 +182,7 @@ Drupal.behaviors.dashboard = {
item.find('div.content').html(Drupal.settings.dashboard.emptyBlockText);
}
- Drupal.attachBehaviors(item);
+ $(item).trigger('attach');
},
'html'
);
diff --git a/core/modules/field/modules/text/text.js b/core/modules/field/modules/text/text.js
index 8527355..c24f014 100644
--- a/core/modules/field/modules/text/text.js
+++ b/core/modules/field/modules/text/text.js
@@ -3,46 +3,44 @@
/**
* Auto-hide summary textarea if empty and show hide and unhide links.
*/
-Drupal.behaviors.textSummary = {
- attach: function (context, settings) {
- $(context).find('.text-summary').once('text-summary', function () {
- var $widget = $(this).closest('div.field-type-text-with-summary');
- var $summaries = $widget.find('div.text-summary-wrapper');
+$(document).on('ready attach', function (e) {
+ $(e.target).find('.text-summary').once('text-summary', function () {
+ var $widget = $(this).closest('div.field-type-text-with-summary');
+ var $summaries = $widget.find('div.text-summary-wrapper');
- $summaries.once('text-summary-wrapper').each(function(index) {
- var $summary = $(this);
- var $summaryLabel = $summary.find('label');
- var $full = $widget.find('.text-full').eq(index).closest('.form-item');
- var $fullLabel = $full.find('label');
+ $summaries.once('text-summary-wrapper').each(function(index) {
+ var $summary = $(this);
+ var $summaryLabel = $summary.find('label');
+ var $full = $widget.find('.text-full').eq(index).closest('.form-item');
+ var $fullLabel = $full.find('label');
- // Create a placeholder label when the field cardinality is
- // unlimited or greater than 1.
- if ($fullLabel.length == 0) {
- $fullLabel = $('').prependTo($full);
- }
-
- // Setup the edit/hide summary link.
- var $link = $('(' + Drupal.t('Hide summary') + ')').toggle(
- function () {
- $summary.hide();
- $(this).find('a').html(Drupal.t('Edit summary')).end().appendTo($fullLabel);
- return false;
- },
- function () {
- $summary.show();
- $(this).find('a').html(Drupal.t('Hide summary')).end().appendTo($summaryLabel);
- return false;
- }
- ).appendTo($summaryLabel);
+ // Create a placeholder label when the field cardinality is
+ // unlimited or greater than 1.
+ if ($fullLabel.length == 0) {
+ $fullLabel = $('').prependTo($full);
+ }
- // If no summary is set, hide the summary field.
- if ($(this).find('.text-summary').val() == '') {
- $link.click();
+ // Setup the edit/hide summary link.
+ var $link = $('(' + Drupal.t('Hide summary') + ')').toggle(
+ function () {
+ $summary.hide();
+ $(this).find('a').html(Drupal.t('Edit summary')).end().appendTo($fullLabel);
+ return false;
+ },
+ function () {
+ $summary.show();
+ $(this).find('a').html(Drupal.t('Hide summary')).end().appendTo($summaryLabel);
+ return false;
}
- return;
- });
+ ).appendTo($summaryLabel);
+
+ // If no summary is set, hide the summary field.
+ if ($(this).find('.text-summary').val() == '') {
+ $link.click();
+ }
+ return;
});
- }
-};
+ });
+});
})(jQuery);
diff --git a/core/modules/field_ui/field_ui.js b/core/modules/field_ui/field_ui.js
index 6de5c15..fdb5cf4 100644
--- a/core/modules/field_ui/field_ui.js
+++ b/core/modules/field_ui/field_ui.js
@@ -2,16 +2,14 @@
* @file
* Attaches the behaviors for the Field UI module.
*/
-
+
(function($) {
-Drupal.behaviors.fieldUIFieldOverview = {
- attach: function (context, settings) {
- $(context).find('table#field-overview').once('field-overview', function () {
- Drupal.fieldUIFieldOverview.attachUpdateSelects(this, settings);
- });
- }
-};
+$(document).on('ready attach', function (e) {
+ $(e.target).find('table#field-overview').once('field-overview', function () {
+ Drupal.fieldUIFieldOverview.attachUpdateSelects(this, Drupal.settings);
+ });
+});
Drupal.fieldUIFieldOverview = {
/**
@@ -105,13 +103,11 @@ jQuery.fn.fieldUIPopulateOptions = function (options, selected) {
});
};
-Drupal.behaviors.fieldUIDisplayOverview = {
- attach: function (context, settings) {
- $(context).find('table#field-display-overview').once('field-display-overview', function() {
- Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview);
- });
- }
-};
+$(document).on('ready attach', function (e) {
+ $(e.target).find('table#field-display-overview').once('field-display-overview', function() {
+ Drupal.fieldUIOverview.attach(this, Drupal.settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview);
+ });
+});
Drupal.fieldUIOverview = {
/**
diff --git a/core/modules/file/file.js b/core/modules/file/file.js
index a934afe..03ea255 100644
--- a/core/modules/file/file.js
+++ b/core/modules/file/file.js
@@ -12,62 +12,58 @@
/**
* Attach behaviors to managed file element upload fields.
*/
-Drupal.behaviors.fileValidateAutoAttach = {
- attach: function (context, settings) {
- var $context = $(context);
- var validateExtension = Drupal.file.validateExtension;
- var selector, elements;
- if (settings.file && settings.file.elements) {
- elements = settings.file.elements;
- for (selector in elements) {
- if (elements.hasOwnProperty(selector)) {
- $context.find(selector).bind('change', {extensions: elements[selector]}, validateExtension);
- }
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var $context = $(e.target);
+ var validateExtension = Drupal.file.validateExtension;
+ var selector, elements;
+ if (settings.file && settings.file.elements) {
+ elements = settings.file.elements;
+ for (selector in elements) {
+ if (elements.hasOwnProperty(selector)) {
+ $context.find(selector).bind('change', {extensions: elements[selector]}, validateExtension);
}
}
- },
- detach: function (context, settings) {
- var $context = $(context);
- var validateExtension = Drupal.file.validateExtension;
- var selector, elements;
- if (settings.file && settings.file.elements) {
- elements = settings.file.elements;
- for (selector in elements) {
- if (elements.hasOwnProperty(selector)) {
- $context.find(selector).unbind('change', validateExtension);
- }
+ }
+});
+
+$(document).on('detach', function (e, settings, trigger) {
+ var $context = $(e.target);
+ var validateExtension = Drupal.file.validateExtension;
+ var selector, elements;
+ if (settings.file && settings.file.elements) {
+ elements = settings.file.elements;
+ for (selector in elements) {
+ if (elements.hasOwnProperty(selector)) {
+ $context.find(selector).unbind('change', validateExtension);
}
}
}
-};
+});
/**
* Attach behaviors to the file upload and remove buttons.
*/
-Drupal.behaviors.fileButtons = {
- attach: function (context) {
- var $context = $(context);
- $context.find('input.form-submit').bind('mousedown', Drupal.file.disableFields);
- $context.find('div.form-managed-file input.form-submit').bind('mousedown', Drupal.file.progressBar);
- },
- detach: function (context) {
- var $context = $(context);
- $context.find('input.form-submit').unbind('mousedown', Drupal.file.disableFields);
- $context.find('div.form-managed-file input.form-submit').unbind('mousedown', Drupal.file.progressBar);
- }
-};
+$(document).on('ready attach', function (e) {
+ var $context = $(e.target);
+ $context.find('input.form-submit').bind('mousedown', Drupal.file.disableFields);
+ $context.find('div.form-managed-file input.form-submit').bind('mousedown', Drupal.file.progressBar);
+});
+$(document).on('detach', function (e) {
+ var $context = $(e.target);
+ $context.find('input.form-submit').unbind('mousedown', Drupal.file.disableFields);
+ $context.find('div.form-managed-file input.form-submit').unbind('mousedown', Drupal.file.progressBar);
+});
/**
* Attach behaviors to links within managed file elements.
*/
-Drupal.behaviors.filePreviewLinks = {
- attach: function (context) {
- $(context).find('div.form-managed-file .file a, .file-widget .file a').bind('click',Drupal.file.openInNewWindow);
- },
- detach: function (context){
- $(context).find('div.form-managed-file .file a, .file-widget .file a').unbind('click', Drupal.file.openInNewWindow);
- }
-};
+$(document).on('ready attach', function (e) {
+ $(e.target).find('div.form-managed-file .file a, .file-widget .file a').bind('click',Drupal.file.openInNewWindow);
+});
+$(document).on('detach', function (e){
+ $(e.target).find('div.form-managed-file .file a, .file-widget .file a').unbind('click', Drupal.file.openInNewWindow);
+});
/**
* File upload utility functions.
diff --git a/core/modules/filter/filter.admin.js b/core/modules/filter/filter.admin.js
index 43cda26..e0caab6 100644
--- a/core/modules/filter/filter.admin.js
+++ b/core/modules/filter/filter.admin.js
@@ -1,45 +1,44 @@
(function ($) {
-Drupal.behaviors.filterStatus = {
- attach: function (context, settings) {
- var $context = $(context);
- $context.find('#filters-status-wrapper input.form-checkbox').once('filter-status', function () {
- var $checkbox = $(this);
- // Retrieve the tabledrag row belonging to this filter.
- var $row = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-weight')).closest('tr');
- // Retrieve the vertical tab belonging to this filter.
- var tab = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-settings')).data('verticalTab');
+$(document).on('ready attach', function (context, settings) {
+ settings = settings || Drupal.settings;
+ var $context = $(e.target);
+ $context.find('#filters-status-wrapper input.form-checkbox').once('filter-status', function () {
+ var $checkbox = $(this);
+ // Retrieve the tabledrag row belonging to this filter.
+ var $row = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-weight')).closest('tr');
+ // Retrieve the vertical tab belonging to this filter.
+ var tab = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-settings')).data('verticalTab');
- // Bind click handler to this checkbox to conditionally show and hide the
- // filter's tableDrag row and vertical tab pane.
- $checkbox.bind('click.filterUpdate', function () {
- if ($checkbox.is(':checked')) {
- $row.show();
- if (tab) {
- tab.tabShow().updateSummary();
- }
+ // Bind click handler to this checkbox to conditionally show and hide the
+ // filter's tableDrag row and vertical tab pane.
+ $checkbox.bind('click.filterUpdate', function () {
+ if ($checkbox.is(':checked')) {
+ $row.show();
+ if (tab) {
+ tab.tabShow().updateSummary();
}
- else {
- $row.hide();
- if (tab) {
- tab.tabHide().updateSummary();
- }
+ }
+ else {
+ $row.hide();
+ if (tab) {
+ tab.tabHide().updateSummary();
}
- // Restripe table after toggling visibility of table row.
- Drupal.tableDrag['filter-order'].restripeTable();
- });
-
- // Attach summary for configurable filters (only for screen-readers).
- if (tab) {
- tab.fieldset.drupalSetSummary(function (tabContext) {
- return $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled');
- });
}
-
- // Trigger our bound click handler to update elements to initial state.
- $checkbox.triggerHandler('click.filterUpdate');
+ // Restripe table after toggling visibility of table row.
+ Drupal.tableDrag['filter-order'].restripeTable();
});
- }
-};
+
+ // Attach summary for configurable filters (only for screen-readers).
+ if (tab) {
+ tab.fieldset.drupalSetSummary(function (tabContext) {
+ return $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled');
+ });
+ }
+
+ // Trigger our bound click handler to update elements to initial state.
+ $checkbox.triggerHandler('click.filterUpdate');
+ });
+});
})(jQuery);
diff --git a/core/modules/filter/filter.js b/core/modules/filter/filter.js
index db5f42a..58ab580 100644
--- a/core/modules/filter/filter.js
+++ b/core/modules/filter/filter.js
@@ -3,18 +3,16 @@
/**
* Automatically display the guidelines of the selected text format.
*/
-Drupal.behaviors.filterGuidelines = {
- attach: function (context) {
- $(context).find('.filter-guidelines').once('filter-guidelines')
- .find(':header').hide()
- .closest('.filter-wrapper').find('select.filter-list')
- .bind('change', function () {
- $(this).closest('.filter-wrapper')
- .find('.filter-guidelines-item').hide()
- .siblings('.filter-guidelines-' + this.value).show();
- })
- .change();
- }
-};
+$(document).on('ready attach', function (e) {
+ $(e.target).find('.filter-guidelines').once('filter-guidelines')
+ .find(':header').hide()
+ .closest('.filter-wrapper').find('select.filter-list')
+ .bind('change', function () {
+ $(this).closest('.filter-wrapper')
+ .find('.filter-guidelines-item').hide()
+ .siblings('.filter-guidelines-' + this.value).show();
+ })
+ .change();
+});
})(jQuery);
diff --git a/core/modules/menu/menu.admin.js b/core/modules/menu/menu.admin.js
index 4e5bf07..48eb88e 100644
--- a/core/modules/menu/menu.admin.js
+++ b/core/modules/menu/menu.admin.js
@@ -1,15 +1,13 @@
(function ($) {
-Drupal.behaviors.menuChangeParentItems = {
- attach: function (context, settings) {
- $('fieldset#edit-menu input').each(function () {
- $(this).change(function () {
- // Update list of available parent menu items.
- Drupal.menu_update_parent_list();
- });
+$(document).on('ready attach', function (e) {
+ $('fieldset#edit-menu input').each(function () {
+ $(this).change(function () {
+ // Update list of available parent menu items.
+ Drupal.menu_update_parent_list();
});
- }
-};
+ });
+});
/**
* Function to set the options of the menu parent item dropdown.
diff --git a/core/modules/menu/menu.js b/core/modules/menu/menu.js
index f315e7a..de521cb 100644
--- a/core/modules/menu/menu.js
+++ b/core/modules/menu/menu.js
@@ -1,68 +1,64 @@
(function ($) {
-Drupal.behaviors.menuFieldsetSummaries = {
- attach: function (context) {
- $(context).find('fieldset.menu-link-form').drupalSetSummary(function (context) {
- var $context = $(context);
- if ($context.find('.form-item-menu-enabled input').is(':checked')) {
- return Drupal.checkPlain($context.find('.form-item-menu-link-title input').val());
- }
- else {
- return Drupal.t('Not in menu');
- }
- });
- }
-};
+$(document).on('ready attach', function (e) {
+ $(e.target).find('fieldset.menu-link-form').drupalSetSummary(function (context) {
+ var $context = $(context);
+ if ($context.find('.form-item-menu-enabled input').is(':checked')) {
+ return Drupal.checkPlain($context.find('.form-item-menu-link-title input').val());
+ }
+ else {
+ return Drupal.t('Not in menu');
+ }
+ });
+});
/**
* Automatically fill in a menu link title, if possible.
*/
-Drupal.behaviors.menuLinkAutomaticTitle = {
- attach: function (context) {
- var $context = $(context);
- $context.find('fieldset.menu-link-form').each(function () {
- var $this = $(this);
- // Try to find menu settings widget elements as well as a 'title' field in
- // the form, but play nicely with user permissions and form alterations.
- var $checkbox = $this.find('.form-item-menu-enabled input');
- var $link_title = $context.find('.form-item-menu-link-title input');
- var $title = $this.closest('form').find('.form-item-title input');
- // Bail out if we do not have all required fields.
- if (!($checkbox.length && $link_title.length && $title.length)) {
- return;
- }
- // If there is a link title already, mark it as overridden. The user expects
- // that toggling the checkbox twice will take over the node's title.
- if ($checkbox.is(':checked') && $link_title.val().length) {
- $link_title.data('menuLinkAutomaticTitleOveridden', true);
- }
- // Whenever the value is changed manually, disable this behavior.
- $link_title.keyup(function () {
- $link_title.data('menuLinkAutomaticTitleOveridden', true);
- });
- // Global trigger on checkbox (do not fill-in a value when disabled).
- $checkbox.change(function () {
- if ($checkbox.is(':checked')) {
- if (!$link_title.data('menuLinkAutomaticTitleOveridden')) {
- $link_title.val($title.val());
- }
- }
- else {
- $link_title.val('');
- $link_title.removeData('menuLinkAutomaticTitleOveridden');
- }
- $checkbox.closest('fieldset.vertical-tabs-pane').trigger('summaryUpdated');
- $checkbox.trigger('formUpdated');
- });
- // Take over any title change.
- $title.keyup(function () {
- if (!$link_title.data('menuLinkAutomaticTitleOveridden') && $checkbox.is(':checked')) {
+$(document).on('ready attach', function (e) {
+ var $context = $(e.target);
+ $context.find('fieldset.menu-link-form').each(function () {
+ var $this = $(this);
+ // Try to find menu settings widget elements as well as a 'title' field in
+ // the form, but play nicely with user permissions and form alterations.
+ var $checkbox = $this.find('.form-item-menu-enabled input');
+ var $link_title = $context.find('.form-item-menu-link-title input');
+ var $title = $this.closest('form').find('.form-item-title input');
+ // Bail out if we do not have all required fields.
+ if (!($checkbox.length && $link_title.length && $title.length)) {
+ return;
+ }
+ // If there is a link title already, mark it as overridden. The user expects
+ // that toggling the checkbox twice will take over the node's title.
+ if ($checkbox.is(':checked') && $link_title.val().length) {
+ $link_title.data('menuLinkAutomaticTitleOveridden', true);
+ }
+ // Whenever the value is changed manually, disable this behavior.
+ $link_title.keyup(function () {
+ $link_title.data('menuLinkAutomaticTitleOveridden', true);
+ });
+ // Global trigger on checkbox (do not fill-in a value when disabled).
+ $checkbox.change(function () {
+ if ($checkbox.is(':checked')) {
+ if (!$link_title.data('menuLinkAutomaticTitleOveridden')) {
$link_title.val($title.val());
- $link_title.val($title.val()).trigger('formUpdated');
}
- });
+ }
+ else {
+ $link_title.val('');
+ $link_title.removeData('menuLinkAutomaticTitleOveridden');
+ }
+ $checkbox.closest('fieldset.vertical-tabs-pane').trigger('summaryUpdated');
+ $checkbox.trigger('formUpdated');
+ });
+ // Take over any title change.
+ $title.keyup(function () {
+ if (!$link_title.data('menuLinkAutomaticTitleOveridden') && $checkbox.is(':checked')) {
+ $link_title.val($title.val());
+ $link_title.val($title.val()).trigger('formUpdated');
+ }
});
- }
-};
+ });
+});
})(jQuery);
diff --git a/core/modules/node/content_types.js b/core/modules/node/content_types.js
index 43cfa37..fc5be18 100644
--- a/core/modules/node/content_types.js
+++ b/core/modules/node/content_types.js
@@ -1,36 +1,34 @@
(function ($) {
-Drupal.behaviors.contentTypes = {
- attach: function (context) {
- var $context = $(context);
- // Provide the vertical tab summaries.
- $context.find('fieldset#edit-submission').drupalSetSummary(function(context) {
- var vals = [];
- vals.push(Drupal.checkPlain($(context).find('#edit-title-label').val()) || Drupal.t('Requires a title'));
- return vals.join(', ');
- });
- $context.find('fieldset#edit-workflow').drupalSetSummary(function(context) {
- var vals = [];
- $(context).find("input[name^='node_options']:checked").parent().each(function() {
- vals.push(Drupal.checkPlain($(this).text()));
- });
- if (!$(context).find('#edit-node-options-status').is(':checked')) {
- vals.unshift(Drupal.t('Not published'));
- }
- return vals.join(', ');
+$(document).on('ready attach', function (e) {
+ var $context = $(e.target);
+ // Provide the vertical tab summaries.
+ $context.find('fieldset#edit-submission').drupalSetSummary(function(context) {
+ var vals = [];
+ vals.push(Drupal.checkPlain($(context).find('#edit-title-label').val()) || Drupal.t('Requires a title'));
+ return vals.join(', ');
+ });
+ $context.find('fieldset#edit-workflow').drupalSetSummary(function(context) {
+ var vals = [];
+ $(context).find("input[name^='node_options']:checked").parent().each(function() {
+ vals.push(Drupal.checkPlain($(this).text()));
});
- $context.find('fieldset#edit-display').drupalSetSummary(function(context) {
- var vals = [];
- var $context = $(context);
- $context.find('input:checked').next('label').each(function() {
- vals.push(Drupal.checkPlain($(this).text()));
- });
- if (!$context.find('#edit-node-submitted').is(':checked')) {
- vals.unshift(Drupal.t("Don't display post information"));
- }
- return vals.join(', ');
+ if (!$(context).find('#edit-node-options-status').is(':checked')) {
+ vals.unshift(Drupal.t('Not published'));
+ }
+ return vals.join(', ');
+ });
+ $context.find('fieldset#edit-display').drupalSetSummary(function(context) {
+ var vals = [];
+ var $context = $(context);
+ $context.find('input:checked').next('label').each(function() {
+ vals.push(Drupal.checkPlain($(this).text()));
});
- }
-};
+ if (!$context.find('#edit-node-submitted').is(':checked')) {
+ vals.unshift(Drupal.t("Don't display post information"));
+ }
+ return vals.join(', ');
+ });
+});
})(jQuery);
diff --git a/core/modules/node/node.js b/core/modules/node/node.js
index 8990164..77e7f3e 100644
--- a/core/modules/node/node.js
+++ b/core/modules/node/node.js
@@ -1,46 +1,44 @@
(function ($) {
-Drupal.behaviors.nodeFieldsetSummaries = {
- attach: function (context) {
+$(document).on('ready attach', function (e) {
+ var $context = $(e.target);
+ $context.find('fieldset.node-form-revision-information').drupalSetSummary(function (context) {
var $context = $(context);
- $context.find('fieldset.node-form-revision-information').drupalSetSummary(function (context) {
- var $context = $(context);
- var revisionCheckbox = $context.find('.form-item-revision input');
-
- // Return 'New revision' if the 'Create new revision' checkbox is checked,
- // or if the checkbox doesn't exist, but the revision log does. For users
- // without the "Administer content" permission the checkbox won't appear,
- // but the revision log will if the content type is set to auto-revision.
- if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $context.find('.form-item-log textarea').length)) {
- return Drupal.t('New revision');
- }
-
- return Drupal.t('No revision');
- });
+ var revisionCheckbox = $context.find('.form-item-revision input');
- $context.find('fieldset.node-form-author').drupalSetSummary(function (context) {
- var $context = $(context);
- var name = $context.find('.form-item-name input').val() || Drupal.settings.anonymous,
- date = $context.find('.form-item-date input').val();
- return date ?
- Drupal.t('By @name on @date', { '@name': name, '@date': date }) :
- Drupal.t('By @name', { '@name': name });
- });
+ // Return 'New revision' if the 'Create new revision' checkbox is checked,
+ // or if the checkbox doesn't exist, but the revision log does. For users
+ // without the "Administer content" permission the checkbox won't appear,
+ // but the revision log will if the content type is set to auto-revision.
+ if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $context.find('.form-item-log textarea').length)) {
+ return Drupal.t('New revision');
+ }
- $context.find('fieldset.node-form-options').drupalSetSummary(function (context) {
- var $context = $(context);
- var vals = [];
+ return Drupal.t('No revision');
+ });
- $context.find('input:checked').parent().each(function () {
- vals.push(Drupal.checkPlain($.trim($(this).text())));
- });
+ $context.find('fieldset.node-form-author').drupalSetSummary(function (context) {
+ var $context = $(context);
+ var name = $context.find('.form-item-name input').val() || Drupal.settings.anonymous,
+ date = $context.find('.form-item-date input').val();
+ return date ?
+ Drupal.t('By @name on @date', { '@name': name, '@date': date }) :
+ Drupal.t('By @name', { '@name': name });
+ });
+
+ $context.find('fieldset.node-form-options').drupalSetSummary(function (context) {
+ var $context = $(context);
+ var vals = [];
- if (!$context.find('.form-item-status input').is(':checked')) {
- vals.unshift(Drupal.t('Not published'));
- }
- return vals.join(', ');
+ $context.find('input:checked').parent().each(function () {
+ vals.push(Drupal.checkPlain($.trim($(this).text())));
});
- }
-};
+
+ if (!$context.find('.form-item-status input').is(':checked')) {
+ vals.unshift(Drupal.t('Not published'));
+ }
+ return vals.join(', ');
+ });
+});
})(jQuery);
diff --git a/core/modules/openid/openid.js b/core/modules/openid/openid.js
index 754efb1..0e7d598 100644
--- a/core/modules/openid/openid.js
+++ b/core/modules/openid/openid.js
@@ -1,51 +1,49 @@
(function ($) {
-Drupal.behaviors.openid = {
- attach: function (context) {
- var $context = $(context);
- var loginElements = $('.form-item-name, .form-item-pass, li.openid-link');
- var openidElements = $('.form-item-openid-identifier, li.user-link');
- var cookie = $.cookie('Drupal.visitor.openid_identifier');
+$(document).on('ready attach', function (e) {
+ var $context = $(e.target);
+ var loginElements = $('.form-item-name, .form-item-pass, li.openid-link');
+ var openidElements = $('.form-item-openid-identifier, li.user-link');
+ var cookie = $.cookie('Drupal.visitor.openid_identifier');
- // This behavior attaches by ID, so is only valid once on a page.
- if (cookie || location.hash == '#openid-login') {
- $edit_openid_identifier = $('#edit-openid-identifier');
- if (cookie) {
- $edit_openid_identifier.val(cookie);
- }
- $edit_openid_identifier.once('openid', function() {
- loginElements.hide();
- // Use .css('display', 'block') instead of .show() to be Konqueror friendly.
- openidElements.css('display', 'block');
- });
+ // This behavior attaches by ID, so is only valid once on a page.
+ if (cookie || location.hash == '#openid-login') {
+ $edit_openid_identifier = $('#edit-openid-identifier');
+ if (cookie) {
+ $edit_openid_identifier.val(cookie);
}
+ $edit_openid_identifier.once('openid', function() {
+ loginElements.hide();
+ // Use .css('display', 'block') instead of .show() to be Konqueror friendly.
+ openidElements.css('display', 'block');
+ });
+ }
- $context.find('li.openid-link')
- .once('openid')
- .click(function () {
- loginElements.hide();
- openidElements.css('display', 'block');
- // Remove possible error message.
- $('#edit-name, #edit-pass').removeClass('error');
- $('div.messages.error').hide();
- // Set focus on OpenID Identifier field.
- $('#edit-openid-identifier')[0].focus();
- return false;
- });
- $context.find('li.user-link')
- .once('openid')
- .click(function () {
- openidElements.hide();
- loginElements.css('display', 'block');
- // Clear OpenID Identifier field and remove possible error message.
- $('#edit-openid-identifier').val('').removeClass('error');
- $('div.messages.error').css('display', 'block');
- // Set focus on username field.
- $('#edit-name')[0].focus();
- return false;
- });
- }
-};
+ $context.find('li.openid-link')
+ .once('openid')
+ .click(function () {
+ loginElements.hide();
+ openidElements.css('display', 'block');
+ // Remove possible error message.
+ $('#edit-name, #edit-pass').removeClass('error');
+ $('div.messages.error').hide();
+ // Set focus on OpenID Identifier field.
+ $('#edit-openid-identifier')[0].focus();
+ return false;
+ });
+ $context.find('li.user-link')
+ .once('openid')
+ .click(function () {
+ openidElements.hide();
+ loginElements.css('display', 'block');
+ // Clear OpenID Identifier field and remove possible error message.
+ $('#edit-openid-identifier').val('').removeClass('error');
+ $('div.messages.error').css('display', 'block');
+ // Set focus on username field.
+ $('#edit-name')[0].focus();
+ return false;
+ });
+});
})(jQuery);
diff --git a/core/modules/overlay/overlay-child.js b/core/modules/overlay/overlay-child.js
index ff111d8..8065882 100644
--- a/core/modules/overlay/overlay-child.js
+++ b/core/modules/overlay/overlay-child.js
@@ -3,73 +3,73 @@
/**
* Attach the child dialog behavior to new content.
*/
-Drupal.behaviors.overlayChild = {
- attach: function (context, settings) {
- // Make sure this behavior is not processed more than once.
- if (this.processed) {
- return;
- }
- this.processed = true;
-
- // If we cannot reach the parent window, break out of the overlay.
- if (!parent.Drupal || !parent.Drupal.overlay) {
- window.location = window.location.href.replace(/([?&]?)render=overlay&?/g, '$1').replace(/\?$/, '');
- }
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var context = e.target;
+ // Make sure this behavior is not processed more than once.
+ if (this.processed) {
+ return;
+ }
+ this.processed = true;
- var settings = settings.overlayChild || {};
+ // If we cannot reach the parent window, break out of the overlay.
+ if (!parent.Drupal || !parent.Drupal.overlay) {
+ window.location = window.location.href.replace(/([?&]?)render=overlay&?/g, '$1').replace(/\?$/, '');
+ }
- // If the entire parent window should be refreshed when the overlay is
- // closed, pass that information to the parent window.
- if (settings.refreshPage) {
- parent.Drupal.overlay.refreshPage = true;
- }
+ var settings = settings.overlayChild || {};
- // If a form has been submitted successfully, then the server side script
- // may have decided to tell the parent window to close the popup dialog.
- if (settings.closeOverlay) {
- parent.Drupal.overlay.bindChild(window, true);
- // Use setTimeout to close the child window from a separate thread,
- // because the current one is busy processing Drupal behaviors.
- setTimeout(function () {
- if (typeof settings.redirect == 'string') {
- parent.Drupal.overlay.redirect(settings.redirect);
- }
- else {
- parent.Drupal.overlay.close();
- }
- }, 1);
- return;
- }
+ // If the entire parent window should be refreshed when the overlay is
+ // closed, pass that information to the parent window.
+ if (settings.refreshPage) {
+ parent.Drupal.overlay.refreshPage = true;
+ }
- // If one of the regions displaying outside the overlay needs to be
- // reloaded immediately, let the parent window know.
- if (settings.refreshRegions) {
- parent.Drupal.overlay.refreshRegions(settings.refreshRegions);
- }
+ // If a form has been submitted successfully, then the server side script
+ // may have decided to tell the parent window to close the popup dialog.
+ if (settings.closeOverlay) {
+ parent.Drupal.overlay.bindChild(window, true);
+ // Use setTimeout to close the child window from a separate thread,
+ // because the current one is busy processing Drupal behaviors.
+ setTimeout(function () {
+ if (typeof settings.redirect == 'string') {
+ parent.Drupal.overlay.redirect(settings.redirect);
+ }
+ else {
+ parent.Drupal.overlay.close();
+ }
+ }, 1);
+ return;
+ }
- // Ok, now we can tell the parent window we're ready.
- parent.Drupal.overlay.bindChild(window);
-
- // IE8 crashes on certain pages if this isn't called; reason unknown.
- window.scrollTo(window.scrollX, window.scrollY);
-
- // Attach child related behaviors to the iframe document.
- Drupal.overlayChild.attachBehaviors(context, settings);
-
- // There are two links within the message that informs people about the
- // overlay and how to disable it. Make sure both links are visible when
- // either one has focus and add a class to the wrapper for styling purposes.
- $(context).find('#overlay-disable-message')
- .focusin(function () {
- $(this).addClass('overlay-disable-message-focused')
- .find('a.element-focusable').removeClass('element-invisible');
- })
- .focusout(function () {
- $(this).removeClass('overlay-disable-message-focused')
- .find('a.element-focusable').addClass('element-invisible');
- });
+ // If one of the regions displaying outside the overlay needs to be
+ // reloaded immediately, let the parent window know.
+ if (settings.refreshRegions) {
+ parent.Drupal.overlay.refreshRegions(settings.refreshRegions);
}
-};
+
+ // Ok, now we can tell the parent window we're ready.
+ parent.Drupal.overlay.bindChild(window);
+
+ // IE8 crashes on certain pages if this isn't called; reason unknown.
+ window.scrollTo(window.scrollX, window.scrollY);
+
+ // Attach child related behaviors to the iframe document.
+ Drupal.overlayChild.attachBehaviors(context, settings);
+
+ // There are two links within the message that informs people about the
+ // overlay and how to disable it. Make sure both links are visible when
+ // either one has focus and add a class to the wrapper for styling purposes.
+ $(context).find('#overlay-disable-message')
+ .focusin(function () {
+ $(this).addClass('overlay-disable-message-focused')
+ .find('a.element-focusable').removeClass('element-invisible');
+ })
+ .focusout(function () {
+ $(this).removeClass('overlay-disable-message-focused')
+ .find('a.element-focusable').addClass('element-invisible');
+ });
+});
/**
* Overlay object for child windows.
diff --git a/core/modules/overlay/overlay-parent.js b/core/modules/overlay/overlay-parent.js
index 19d2d64..acc02d8 100644
--- a/core/modules/overlay/overlay-parent.js
+++ b/core/modules/overlay/overlay-parent.js
@@ -3,32 +3,30 @@
/**
* Open the overlay, or load content into it, when an admin link is clicked.
*/
-Drupal.behaviors.overlayParent = {
- attach: function (context, settings) {
- if (Drupal.overlay.isOpen) {
- Drupal.overlay.makeDocumentUntabbable(context);
- }
+$(document).on('ready attach', function (e) {
+ if (Drupal.overlay.isOpen) {
+ Drupal.overlay.makeDocumentUntabbable(e.target);
+ }
- if (this.processed) {
- return;
- }
- this.processed = true;
+ if (this.processed) {
+ return;
+ }
+ this.processed = true;
- $(window)
- // When the hash (URL fragment) changes, open the overlay if needed.
- .bind('hashchange.drupal-overlay', $.proxy(Drupal.overlay, 'eventhandlerOperateByURLFragment'))
- // Trigger the hashchange handler once, after the page is loaded, so that
- // permalinks open the overlay.
- .triggerHandler('hashchange.drupal-overlay');
+ $(window)
+ // When the hash (URL fragment) changes, open the overlay if needed.
+ .bind('hashchange.drupal-overlay', $.proxy(Drupal.overlay, 'eventhandlerOperateByURLFragment'))
+ // Trigger the hashchange handler once, after the page is loaded, so that
+ // permalinks open the overlay.
+ .triggerHandler('hashchange.drupal-overlay');
- $(document)
- // Instead of binding a click event handler to every link we bind one to
- // the document and only handle events that bubble up. This allows other
- // scripts to bind their own handlers to links and also to prevent
- // overlay's handling.
- .bind('click.drupal-overlay mouseup.drupal-overlay', $.proxy(Drupal.overlay, 'eventhandlerOverrideLink'));
- }
-};
+ $(document)
+ // Instead of binding a click event handler to every link we bind one to
+ // the document and only handle events that bubble up. This allows other
+ // scripts to bind their own handlers to links and also to prevent
+ // overlay's handling.
+ .bind('click.drupal-overlay mouseup.drupal-overlay', $.proxy(Drupal.overlay, 'eventhandlerOverrideLink'));
+});
/**
* Overlay object for parent windows.
@@ -782,10 +780,10 @@ Drupal.overlay.refreshRegions = function (data) {
if (region_info.hasOwnProperty(regionClass)) {
(function (regionName, regionSelector) {
var $region = $(regionSelector);
- Drupal.detachBehaviors($region);
+ $region.trigger('detach');
$.get(Drupal.settings.basePath + Drupal.settings.overlay.ajaxCallback + '/' + regionName, function (newElement) {
$region.replaceWith($(newElement));
- Drupal.attachBehaviors($region, Drupal.settings);
+ $region.trigger('attach', Drupal.settings);
});
}(region_info[regionClass], '.' + regionClass));
}
diff --git a/core/modules/path/path.js b/core/modules/path/path.js
index b20378e..65336ca 100644
--- a/core/modules/path/path.js
+++ b/core/modules/path/path.js
@@ -4,16 +4,14 @@
*/
(function ($) {
-Drupal.behaviors.pathFieldsetSummaries = {
- attach: function (context) {
- $(context).find('fieldset.path-form').drupalSetSummary(function (context) {
- var path = $('.form-item-path-alias input').val();
+$(document).on('ready attach', function (e) {
+ $(e.target).find('fieldset.path-form').drupalSetSummary(function (context) {
+ var path = $('.form-item-path-alias input').val();
- return path ?
- Drupal.t('Alias: @alias', { '@alias': path }) :
- Drupal.t('No alias');
- });
- }
-};
+ return path ?
+ Drupal.t('Alias: @alias', { '@alias': path }) :
+ Drupal.t('No alias');
+ });
+});
})(jQuery);
diff --git a/core/modules/shortcut/shortcut.admin.js b/core/modules/shortcut/shortcut.admin.js
index 2647f34..0ffa4b8 100644
--- a/core/modules/shortcut/shortcut.admin.js
+++ b/core/modules/shortcut/shortcut.admin.js
@@ -6,111 +6,107 @@
* This behavior is dependent on the tableDrag behavior, since it uses the
* objects initialized in that behavior to update the row.
*/
-Drupal.behaviors.shortcutDrag = {
- attach: function (context, settings) {
- if (Drupal.tableDrag) {
- var table = $('table#shortcuts'),
- visibleLength = 0,
- slots = 0,
- tableDrag = Drupal.tableDrag.shortcuts;
- table.find('> tbody > tr, > tr')
- .filter(':visible')
- .filter(':odd').filter('.odd')
- .removeClass('odd').addClass('even')
- .end().end()
- .filter(':even').filter('.even')
- .removeClass('even').addClass('odd')
- .end().end()
- .end()
- .filter('.shortcut-slot-empty').each(function(index) {
- if ($(this).is(':visible')) {
- visibleLength++;
- }
- slots++;
- });
+$(document).on('ready attach', function (e) {
+ if (Drupal.tableDrag) {
+ var table = $('table#shortcuts'),
+ visibleLength = 0,
+ slots = 0,
+ tableDrag = Drupal.tableDrag.shortcuts;
+ table.find('> tbody > tr, > tr')
+ .filter(':visible')
+ .filter(':odd').filter('.odd')
+ .removeClass('odd').addClass('even')
+ .end().end()
+ .filter(':even').filter('.even')
+ .removeClass('even').addClass('odd')
+ .end().end()
+ .end()
+ .filter('.shortcut-slot-empty').each(function(index) {
+ if ($(this).is(':visible')) {
+ visibleLength++;
+ }
+ slots++;
+ });
- // Add a handler for when a row is swapped.
- tableDrag.row.prototype.onSwap = function (swappedRow) {
- var disabledIndex = table.find('tr').index(table.find('tr.shortcut-status-disabled')) - slots - 2,
- count = 0;
- table.find('tr.shortcut-status-enabled').nextAll(':not(.shortcut-slot-empty)').each(function(index) {
- if (index < disabledIndex) {
- count++;
- }
- });
- var total = slots - count;
- if (total == -1) {
- var disabled = $(table).find('tr.shortcut-status-disabled');
- // To maintain the shortcut links limit, we need to move the last
- // element from the enabled section to the disabled section.
- var changedRow = disabled.prevAll(':not(.shortcut-slot-empty)').not($(this.element)).get(0);
- disabled.after(changedRow);
- if ($(changedRow).hasClass('draggable')) {
- // The dropped element will automatically be marked as changed by
- // the tableDrag system. However, the row that swapped with it
- // has moved to the "disabled" section, so we need to force its
- // status to be disabled and mark it also as changed.
- var changedRowObject = new tableDrag.row(changedRow, 'mouse', self.indentEnabled, self.maxDepth, true);
- changedRowObject.markChanged();
- tableDrag.rowStatusChange(changedRowObject);
- }
+ // Add a handler for when a row is swapped.
+ tableDrag.row.prototype.onSwap = function (swappedRow) {
+ var disabledIndex = table.find('tr').index(table.find('tr.shortcut-status-disabled')) - slots - 2,
+ count = 0;
+ table.find('tr.shortcut-status-enabled').nextAll(':not(.shortcut-slot-empty)').each(function(index) {
+ if (index < disabledIndex) {
+ count++;
+ }
+ });
+ var total = slots - count;
+ if (total == -1) {
+ var disabled = $(table).find('tr.shortcut-status-disabled');
+ // To maintain the shortcut links limit, we need to move the last
+ // element from the enabled section to the disabled section.
+ var changedRow = disabled.prevAll(':not(.shortcut-slot-empty)').not($(this.element)).get(0);
+ disabled.after(changedRow);
+ if ($(changedRow).hasClass('draggable')) {
+ // The dropped element will automatically be marked as changed by
+ // the tableDrag system. However, the row that swapped with it
+ // has moved to the "disabled" section, so we need to force its
+ // status to be disabled and mark it also as changed.
+ var changedRowObject = new tableDrag.row(changedRow, 'mouse', self.indentEnabled, self.maxDepth, true);
+ changedRowObject.markChanged();
+ tableDrag.rowStatusChange(changedRowObject);
+ }
+ }
+ else if (total != visibleLength) {
+ if (total > visibleLength) {
+ // Less slots on screen than needed.
+ $('.shortcut-slot-empty:hidden:last').show();
+ visibleLength++;
}
- else if (total != visibleLength) {
- if (total > visibleLength) {
- // Less slots on screen than needed.
- $('.shortcut-slot-empty:hidden:last').show();
- visibleLength++;
- }
- else {
- // More slots on screen than needed.
- $('.shortcut-slot-empty:visible:last').hide();
- visibleLength--;
- }
+ else {
+ // More slots on screen than needed.
+ $('.shortcut-slot-empty:visible:last').hide();
+ visibleLength--;
}
- };
+ }
+ };
- // Add a handler so when a row is dropped, update fields dropped into new regions.
- tableDrag.onDrop = function () {
- tableDrag.rowStatusChange(this.rowObject);
- return true;
- };
+ // Add a handler so when a row is dropped, update fields dropped into new regions.
+ tableDrag.onDrop = function () {
+ tableDrag.rowStatusChange(this.rowObject);
+ return true;
+ };
- tableDrag.rowStatusChange = function (rowObject) {
- // Use "status-message" row instead of "status" row because
- // "status-{status_name}-message" is less prone to regexp match errors.
- var $rowElement = $(rowObject.element);
- var statusRow = $rowElement.prevAll('tr.shortcut-status').get(0);
- var statusName = statusRow.className.replace(/([^ ]+[ ]+)*shortcut-status-([^ ]+)([ ]+[^ ]+)*/, '$2');
- var statusField = $rowElement.find('select.shortcut-status-select');
- statusField.val(statusName);
- };
+ tableDrag.rowStatusChange = function (rowObject) {
+ // Use "status-message" row instead of "status" row because
+ // "status-{status_name}-message" is less prone to regexp match errors.
+ var $rowElement = $(rowObject.element);
+ var statusRow = $rowElement.prevAll('tr.shortcut-status').get(0);
+ var statusName = statusRow.className.replace(/([^ ]+[ ]+)*shortcut-status-([^ ]+)([ ]+[^ ]+)*/, '$2');
+ var statusField = $rowElement.find('select.shortcut-status-select');
+ statusField.val(statusName);
+ };
- tableDrag.restripeTable = function () {
- // :even and :odd are reversed because jQuery counts from 0 and
- // we count from 1, so we're out of sync.
- // Match immediate children of the parent element to allow nesting.
- $(this.table).find('> tbody > tr:visible, > tr:visible')
- .filter(':odd').filter('.odd')
- .removeClass('odd').addClass('even')
- .end().end()
- .filter(':even').filter('.even')
- .removeClass('even').addClass('odd');
- };
- }
+ tableDrag.restripeTable = function () {
+ // :even and :odd are reversed because jQuery counts from 0 and
+ // we count from 1, so we're out of sync.
+ // Match immediate children of the parent element to allow nesting.
+ $(this.table).find('> tbody > tr:visible, > tr:visible')
+ .filter(':odd').filter('.odd')
+ .removeClass('odd').addClass('even')
+ .end().end()
+ .filter(':even').filter('.even')
+ .removeClass('even').addClass('odd');
+ };
}
-};
+});
/**
* Make it so when you enter text into the "New set" textfield, the
* corresponding radio button gets selected.
*/
-Drupal.behaviors.newSet = {
- attach: function (context, settings) {
- var selectDefault = function() {
- $(this).closest('form').find('.form-item-set .form-type-radio:last input').attr('checked', 'checked');
- };
- $('div.form-item-new input').focus(selectDefault).keyup(selectDefault);
- }
-};
+$(document).on('ready attach', function (e) {
+ var selectDefault = function() {
+ $(this).closest('form').find('.form-item-set .form-type-radio:last input').attr('checked', 'checked');
+ };
+ $('div.form-item-new input').focus(selectDefault).keyup(selectDefault);
+});
})(jQuery);
diff --git a/core/modules/simpletest/simpletest.js b/core/modules/simpletest/simpletest.js
index 2199fed..07250d2 100644
--- a/core/modules/simpletest/simpletest.js
+++ b/core/modules/simpletest/simpletest.js
@@ -3,102 +3,100 @@
/**
* Add the cool table collapsing on the testing overview page.
*/
-Drupal.behaviors.simpleTestMenuCollapse = {
- attach: function (context, settings) {
- var timeout = null;
- // Adds expand-collapse functionality.
- $('div.simpletest-image').once('simpletest-image', function () {
- var $this = $(this);
- var direction = settings.simpleTest[this.id].imageDirection;
- $this.html(settings.simpleTest.images[direction]);
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var timeout = null;
+ // Adds expand-collapse functionality.
+ $('div.simpletest-image').once('simpletest-image', function () {
+ var $this = $(this);
+ var direction = settings.simpleTest[this.id].imageDirection;
+ $this.html(settings.simpleTest.images[direction]);
- // Adds group toggling functionality to arrow images.
- $this.click(function () {
- var trs = $this.closest('tbody').children('.' + settings.simpleTest[this.id].testClass);
- var direction = settings.simpleTest[this.id].imageDirection;
- var row = direction ? trs.length - 1 : 0;
+ // Adds group toggling functionality to arrow images.
+ $this.click(function () {
+ var trs = $this.closest('tbody').children('.' + settings.simpleTest[this.id].testClass);
+ var direction = settings.simpleTest[this.id].imageDirection;
+ var row = direction ? trs.length - 1 : 0;
- // If clicked in the middle of expanding a group, stop so we can switch directions.
- if (timeout) {
- clearTimeout(timeout);
- }
+ // If clicked in the middle of expanding a group, stop so we can switch directions.
+ if (timeout) {
+ clearTimeout(timeout);
+ }
- // Function to toggle an individual row according to the current direction.
- // We set a timeout of 20 ms until the next row will be shown/hidden to
- // create a sliding effect.
- function rowToggle() {
- if (direction) {
- if (row >= 0) {
- $(trs[row]).hide();
- row--;
- timeout = setTimeout(rowToggle, 20);
- }
+ // Function to toggle an individual row according to the current direction.
+ // We set a timeout of 20 ms until the next row will be shown/hidden to
+ // create a sliding effect.
+ function rowToggle() {
+ if (direction) {
+ if (row >= 0) {
+ $(trs[row]).hide();
+ row--;
+ timeout = setTimeout(rowToggle, 20);
}
- else {
- if (row < trs.length) {
- $(trs[row]).removeClass('js-hide').show();
- row++;
- timeout = setTimeout(rowToggle, 20);
- }
+ }
+ else {
+ if (row < trs.length) {
+ $(trs[row]).removeClass('js-hide').show();
+ row++;
+ timeout = setTimeout(rowToggle, 20);
}
}
+ }
- // Kick-off the toggling upon a new click.
- rowToggle();
+ // Kick-off the toggling upon a new click.
+ rowToggle();
- // Toggle the arrow image next to the test group title.
- $this.html(settings.simpleTest.images[(direction ? 0 : 1)]);
- settings.simpleTest[this.id].imageDirection = !direction;
+ // Toggle the arrow image next to the test group title.
+ $this.html(settings.simpleTest.images[(direction ? 0 : 1)]);
+ settings.simpleTest[this.id].imageDirection = !direction;
- });
});
- }
-};
+ });
+});
/**
* Select/deselect all the inner checkboxes when the outer checkboxes are
* selected/deselected.
*/
-Drupal.behaviors.simpleTestSelectAll = {
- attach: function (context, settings) {
- $('td.simpletest-select-all').once('simpletest-select-all', function () {
- var testCheckboxes = settings.simpleTest['simpletest-test-group-' + $(this).attr('id')].testNames;
- var groupCheckbox = $('');
-
- // Each time a single-test checkbox is checked or unchecked, make sure
- // that the associated group checkbox gets the right state too.
- var updateGroupCheckbox = function () {
- var checkedTests = 0;
- for (var i = 0; i < testCheckboxes.length; i++) {
- $('#' + testCheckboxes[i]).each(function () {
- if (($(this).attr('checked'))) {
- checkedTests++;
- }
- });
- }
- $(groupCheckbox).attr('checked', (checkedTests == testCheckboxes.length));
- };
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ $('td.simpletest-select-all').once('simpletest-select-all', function () {
+ var testCheckboxes = settings.simpleTest['simpletest-test-group-' + $(this).attr('id')].testNames;
+ var groupCheckbox = $('');
- // Have the single-test checkboxes follow the group checkbox.
- groupCheckbox.change(function () {
- var checked = !!($(this).attr('checked'));
- for (var i = 0; i < testCheckboxes.length; i++) {
- $('#' + testCheckboxes[i]).attr('checked', checked);
- }
- });
-
- // Have the group checkbox follow the single-test checkboxes.
+ // Each time a single-test checkbox is checked or unchecked, make sure
+ // that the associated group checkbox gets the right state too.
+ var updateGroupCheckbox = function () {
+ var checkedTests = 0;
for (var i = 0; i < testCheckboxes.length; i++) {
- $('#' + testCheckboxes[i]).change(function () {
- updateGroupCheckbox();
+ $('#' + testCheckboxes[i]).each(function () {
+ if (($(this).attr('checked'))) {
+ checkedTests++;
+ }
});
}
+ $(groupCheckbox).attr('checked', (checkedTests == testCheckboxes.length));
+ };
- // Initialize status for the group checkbox correctly.
- updateGroupCheckbox();
- $(this).append(groupCheckbox);
+ // Have the single-test checkboxes follow the group checkbox.
+ groupCheckbox.change(function () {
+ var checked = !!($(this).attr('checked'));
+ for (var i = 0; i < testCheckboxes.length; i++) {
+ $('#' + testCheckboxes[i]).attr('checked', checked);
+ }
});
- }
-};
+
+ // Have the group checkbox follow the single-test checkboxes.
+ for (var i = 0; i < testCheckboxes.length; i++) {
+ $('#' + testCheckboxes[i]).change(function () {
+ updateGroupCheckbox();
+ });
+ }
+
+ // Initialize status for the group checkbox correctly.
+ updateGroupCheckbox();
+ $(this).append(groupCheckbox);
+ });
+});
})(jQuery);
diff --git a/core/modules/system/system.cron.js b/core/modules/system/system.cron.js
index af17dab..cc5178c 100644
--- a/core/modules/system/system.cron.js
+++ b/core/modules/system/system.cron.js
@@ -3,17 +3,16 @@
/**
* Checks to see if the cron should be automatically run.
*/
-Drupal.behaviors.cronCheck = {
- attach: function(context, settings) {
- if (settings.cronCheck || false) {
- $('body').once('cron-check', function() {
- // Only execute the cron check if its the right time.
- if (Math.round(new Date().getTime() / 1000.0) > settings.cronCheck) {
- $.get(settings.basePath + 'system/run-cron-check');
- }
- });
- }
+$(document).on('ready attach', function(e, settings) {
+ settings = settings || Drupal.settings;
+ if (settings.cronCheck || false) {
+ $('body').once('cron-check', function() {
+ // Only execute the cron check if its the right time.
+ if (Math.round(new Date().getTime() / 1000.0) > settings.cronCheck) {
+ $.get(settings.basePath + 'system/run-cron-check');
+ }
+ });
}
-};
+});
})(jQuery);
diff --git a/core/modules/system/system.js b/core/modules/system/system.js
index 98da1a6..595491c 100644
--- a/core/modules/system/system.js
+++ b/core/modules/system/system.js
@@ -26,25 +26,24 @@ Drupal.hideEmailAdministratorCheckbox = function () {
* This function is not used to verify whether or not clean URLs
* are currently enabled.
*/
-Drupal.behaviors.cleanURLsSettingsCheck = {
- attach: function (context, settings) {
- // 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').length) || $('#edit-clean-url.install').once('clean-url').length) {
- return;
- }
- var url = settings.basePath + 'admin/config/search/clean-urls/check';
- $.ajax({
- url: location.protocol + '//' + location.host + url,
- dataType: 'json',
- success: function () {
- // Check was successful. Redirect using a "clean URL". This will force the form that allows enabling clean URLs.
- location = settings.basePath +"admin/config/search/clean-urls";
- }
- });
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ // 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').length) || $('#edit-clean-url.install').once('clean-url').length) {
+ return;
}
-};
+ var url = settings.basePath + 'admin/config/search/clean-urls/check';
+ $.ajax({
+ url: location.protocol + '//' + location.host + url,
+ dataType: 'json',
+ success: function () {
+ // Check was successful. Redirect using a "clean URL". This will force the form that allows enabling clean URLs.
+ location = settings.basePath +"admin/config/search/clean-urls";
+ }
+ });
+});
/**
* Internal function to check using Ajax if clean URLs can be enabled on the
@@ -73,69 +72,67 @@ Drupal.cleanURLsInstallCheck = function () {
* use the same value. In the installer this is used to populate the
* administrator e-mail address with the same value as the site e-mail address.
*/
-Drupal.behaviors.copyFieldValue = {
- attach: function (context, settings) {
- for (var sourceId in settings.copyFieldValue) {
- $('#' + 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.
- for (var delta in targetIds) {
- var targetField = $('#' + targetIds[delta]);
- if (targetField.val() == '') {
- targetField.val(this.value);
- }
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var context = e.target;
+ for (var sourceId in settings.copyFieldValue) {
+ $('#' + 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.
+ for (var delta in targetIds) {
+ var targetField = $('#' + targetIds[delta]);
+ if (targetField.val() == '') {
+ targetField.val(this.value);
}
- });
- }
+ }
+ });
}
-};
+});
/**
* Show/hide custom format sections on the regional settings page.
*/
-Drupal.behaviors.dateTime = {
- attach: function (context, settings) {
- for (var fieldName in settings.dateTime) {
- if (settings.dateTime.hasOwnProperty(fieldName)) {
- (function (fieldSettings, fieldName) {
- var source = '#edit-' + fieldName;
- var suffix = source + '-suffix';
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var context = e.target;
+ for (var fieldName in settings.dateTime) {
+ if (settings.dateTime.hasOwnProperty(fieldName)) {
+ (function (fieldSettings, fieldName) {
+ var source = '#edit-' + fieldName;
+ var suffix = source + '-suffix';
- // Attach keyup handler to custom format inputs.
- $(context).find('input' + source).once('date-time').keyup(function () {
- var input = $(this);
- var url = fieldSettings.lookup + (/\?q=/.test(fieldSettings.lookup) ? '&format=' : '?format=') + encodeURIComponent(input.val());
- $.getJSON(url, function (data) {
- $(suffix).empty().append(' ' + fieldSettings.text + ': ' + data + '');
- });
+ // Attach keyup handler to custom format inputs.
+ $(context).find('input' + source).once('date-time').keyup(function () {
+ var input = $(this);
+ var url = fieldSettings.lookup + (/\?q=/.test(fieldSettings.lookup) ? '&format=' : '?format=') + encodeURIComponent(input.val());
+ $.getJSON(url, function (data) {
+ $(suffix).empty().append(' ' + fieldSettings.text + ': ' + data + '');
});
- })(settings.dateTime[fieldName], fieldName);
- }
+ });
+ })(settings.dateTime[fieldName], fieldName);
}
}
-};
+});
/**
* Show/hide settings for page caching depending on whether page caching is
* enabled or not.
*/
-Drupal.behaviors.pageCache = {
- attach: function (context, settings) {
- var $context = $(context);
- $context.find('#edit-cache-0').change(function () {
- $('#page-compression-wrapper').hide();
- $('#cache-error').hide();
- });
- $context.find('#edit-cache-1').change(function () {
- $('#page-compression-wrapper').show();
- $('#cache-error').hide();
- });
- $context.find('#edit-cache-2').change(function () {
- $('#page-compression-wrapper').show();
- $('#cache-error').show();
- });
- }
-};
+ $(document).on('ready attach', function (e) {
+ var $context = $(e.target);
+ $context.find('#edit-cache-0').change(function () {
+ $('#page-compression-wrapper').hide();
+ $('#cache-error').hide();
+ });
+ $context.find('#edit-cache-1').change(function () {
+ $('#page-compression-wrapper').show();
+ $('#cache-error').hide();
+ });
+ $context.find('#edit-cache-2').change(function () {
+ $('#page-compression-wrapper').show();
+ $('#cache-error').show();
+ });
+});
})(jQuery);
diff --git a/core/modules/taxonomy/taxonomy.js b/core/modules/taxonomy/taxonomy.js
index 035dc29..04dbebd 100644
--- a/core/modules/taxonomy/taxonomy.js
+++ b/core/modules/taxonomy/taxonomy.js
@@ -6,35 +6,34 @@
* This behavior is dependent on the tableDrag behavior, since it uses the
* objects initialized in that behavior to update the row.
*/
-Drupal.behaviors.termDrag = {
- attach: function (context, settings) {
- var table = $(context).find('#taxonomy');
- var tableDrag = Drupal.tableDrag.taxonomy; // Get the blocks tableDrag object.
- var rows = table.find('tr').length;
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var table = $(e.target).find('#taxonomy');
+ var tableDrag = Drupal.tableDrag.taxonomy; // Get the blocks tableDrag object.
+ var rows = table.find('tr').length;
- // When a row is swapped, keep previous and next page classes set.
- tableDrag.row.prototype.onSwap = function (swappedRow) {
- table.find('tr.taxonomy-term-preview').removeClass('taxonomy-term-preview');
- table.find('tr.taxonomy-term-divider-top').removeClass('taxonomy-term-divider-top');
- table.find('tr.taxonomy-term-divider-bottom').removeClass('taxonomy-term-divider-bottom');
+ // When a row is swapped, keep previous and next page classes set.
+ tableDrag.row.prototype.onSwap = function (swappedRow) {
+ table.find('tr.taxonomy-term-preview').removeClass('taxonomy-term-preview');
+ table.find('tr.taxonomy-term-divider-top').removeClass('taxonomy-term-divider-top');
+ table.find('tr.taxonomy-term-divider-bottom').removeClass('taxonomy-term-divider-bottom');
- if (settings.taxonomy.backStep) {
- for (var n = 0; n < settings.taxonomy.backStep; n++) {
- $(table[0].tBodies[0].rows[n]).addClass('taxonomy-term-preview');
- }
- $(table[0].tBodies[0].rows[settings.taxonomy.backStep - 1]).addClass('taxonomy-term-divider-top');
- $(table[0].tBodies[0].rows[settings.taxonomy.backStep]).addClass('taxonomy-term-divider-bottom');
+ if (settings.taxonomy.backStep) {
+ for (var n = 0; n < settings.taxonomy.backStep; n++) {
+ $(table[0].tBodies[0].rows[n]).addClass('taxonomy-term-preview');
}
+ $(table[0].tBodies[0].rows[settings.taxonomy.backStep - 1]).addClass('taxonomy-term-divider-top');
+ $(table[0].tBodies[0].rows[settings.taxonomy.backStep]).addClass('taxonomy-term-divider-bottom');
+ }
- if (settings.taxonomy.forwardStep) {
- for (var n = rows - settings.taxonomy.forwardStep - 1; n < rows - 1; n++) {
- $(table[0].tBodies[0].rows[n]).addClass('taxonomy-term-preview');
- }
- $(table[0].tBodies[0].rows[rows - settings.taxonomy.forwardStep - 2]).addClass('taxonomy-term-divider-top');
- $(table[0].tBodies[0].rows[rows - settings.taxonomy.forwardStep - 1]).addClass('taxonomy-term-divider-bottom');
+ if (settings.taxonomy.forwardStep) {
+ for (var n = rows - settings.taxonomy.forwardStep - 1; n < rows - 1; n++) {
+ $(table[0].tBodies[0].rows[n]).addClass('taxonomy-term-preview');
}
- };
- }
-};
+ $(table[0].tBodies[0].rows[rows - settings.taxonomy.forwardStep - 2]).addClass('taxonomy-term-divider-top');
+ $(table[0].tBodies[0].rows[rows - settings.taxonomy.forwardStep - 1]).addClass('taxonomy-term-divider-bottom');
+ }
+ };
+});
})(jQuery);
diff --git a/core/modules/toolbar/toolbar.js b/core/modules/toolbar/toolbar.js
index d345284..0f2b2ba 100644
--- a/core/modules/toolbar/toolbar.js
+++ b/core/modules/toolbar/toolbar.js
@@ -5,21 +5,19 @@ Drupal.toolbar = Drupal.toolbar || {};
/**
* Attach toggling behavior and notify the overlay of the toolbar.
*/
-Drupal.behaviors.toolbar = {
- attach: function(context) {
- var $context = $(context);
- // Set the initial state of the toolbar.
- $context.find('#toolbar').once('toolbar', Drupal.toolbar.init);
+$(document).on('ready attach', function(e, settings) {
+ var $context = $(e.target);
+ // Set the initial state of the toolbar.
+ $context.find('#toolbar').once('toolbar', Drupal.toolbar.init);
- // Toggling toolbar drawer.
- $context.find('#toolbar a.toggle').once('toolbar-toggle').click(function(e) {
- Drupal.toolbar.toggle();
- // Allow resize event handlers to recalculate sizes/positions.
- $(window).triggerHandler('resize');
- return false;
- });
- }
-};
+ // Toggling toolbar drawer.
+ $context.find('#toolbar a.toggle').once('toolbar-toggle').click(function(e) {
+ Drupal.toolbar.toggle();
+ // Allow resize event handlers to recalculate sizes/positions.
+ $(window).triggerHandler('resize');
+ return false;
+ });
+});
/**
* Retrieve last saved cookie settings and set up the initial toolbar state.
diff --git a/core/modules/user/user.js b/core/modules/user/user.js
index 59a178e..39e2409 100644
--- a/core/modules/user/user.js
+++ b/core/modules/user/user.js
@@ -4,90 +4,89 @@
* Attach handlers to evaluate the strength of any password fields and to check
* that its confirmation is correct.
*/
-Drupal.behaviors.password = {
- attach: function (context, settings) {
- var translate = settings.password;
- $(context).find('input.password-field').once('password', function () {
- var passwordInput = $(this);
- var innerWrapper = $(this).parent();
- var outerWrapper = $(this).parent().parent();
-
- // Add identifying class to password element parent.
- innerWrapper.addClass('password-parent');
-
- // Add the password confirmation layer.
- outerWrapper.find('input.password-confirm').parent().prepend('
' + translate['confirmTitle'] + '
').addClass('confirm-parent');
- var confirmInput = outerWrapper.find('input.password-confirm');
- var confirmResult = outerWrapper.find('div.password-confirm');
- var confirmChild = confirmResult.find('span');
-
- // Add the description box.
- var passwordMeter = '
' + translate['strengthTitle'] + '
';
- confirmInput.parent().after('');
- innerWrapper.prepend(passwordMeter);
- var passwordDescription = outerWrapper.find('div.password-suggestions').hide();
-
- // Check the password strength.
- var passwordCheck = function () {
-
- // Evaluate the password strength.
- var result = Drupal.evaluatePasswordStrength(passwordInput.val(), settings.password);
-
- // Update the suggestions for how to improve the password.
- if (passwordDescription.html() != result.message) {
- passwordDescription.html(result.message);
+$(document).on('ready attach', function (e, settings) {
+ settings = settings || Drupal.settings;
+ var translate = settings.password;
+ $(e.target).find('input.password-field').once('password', function () {
+ var passwordInput = $(this);
+ var innerWrapper = $(this).parent();
+ var outerWrapper = $(this).parent().parent();
+
+ // Add identifying class to password element parent.
+ innerWrapper.addClass('password-parent');
+
+ // Add the password confirmation layer.
+ outerWrapper.find('input.password-confirm').parent().prepend('
' + translate['confirmTitle'] + '
').addClass('confirm-parent');
+ var confirmInput = outerWrapper.find('input.password-confirm');
+ var confirmResult = outerWrapper.find('div.password-confirm');
+ var confirmChild = confirmResult.find('span');
+
+ // Add the description box.
+ var passwordMeter = '
' + translate['strengthTitle'] + '
';
+ confirmInput.parent().after('');
+ innerWrapper.prepend(passwordMeter);
+ var passwordDescription = outerWrapper.find('div.password-suggestions').hide();
+
+ // Check the password strength.
+ var passwordCheck = function () {
+
+ // Evaluate the password strength.
+ var result = Drupal.evaluatePasswordStrength(passwordInput.val(), settings.password);
+
+ // Update the suggestions for how to improve the password.
+ if (passwordDescription.html() != result.message) {
+ passwordDescription.html(result.message);
+ }
+
+ // Only show the description box if there is a weakness in the password.
+ if (result.strength == 100) {
+ passwordDescription.hide();
+ }
+ else {
+ passwordDescription.show();
+ }
+
+ // Adjust the length of the strength indicator.
+ innerWrapper.find('.indicator')
+ .css('width', result.strength + '%')
+ .css('background-color', result.indicatorColor);
+
+ // Update the strength indication text.
+ innerWrapper.find('.password-strength-text').html(result.indicatorText);
+
+ passwordCheckMatch();
+ };
+
+ // Check that password and confirmation inputs match.
+ var passwordCheckMatch = function () {
+
+ if (confirmInput.val()) {
+ var success = passwordInput.val() === confirmInput.val();
+
+ // Show the confirm result.
+ confirmResult.css({ visibility: 'visible' });
+
+ // Remove the previous styling if any exists.
+ if (this.confirmClass) {
+ confirmChild.removeClass(this.confirmClass);
}
- // Only show the description box if there is a weakness in the password.
- if (result.strength == 100) {
- passwordDescription.hide();
- }
- else {
- passwordDescription.show();
- }
-
- // Adjust the length of the strength indicator.
- innerWrapper.find('.indicator')
- .css('width', result.strength + '%')
- .css('background-color', result.indicatorColor);
-
- // Update the strength indication text.
- innerWrapper.find('.password-strength-text').html(result.indicatorText);
-
- passwordCheckMatch();
- };
-
- // Check that password and confirmation inputs match.
- var passwordCheckMatch = function () {
-
- if (confirmInput.val()) {
- var success = passwordInput.val() === confirmInput.val();
-
- // Show the confirm result.
- confirmResult.css({ visibility: 'visible' });
-
- // Remove the previous styling if any exists.
- if (this.confirmClass) {
- confirmChild.removeClass(this.confirmClass);
- }
-
- // Fill in the success message and set the class accordingly.
- var confirmClass = success ? 'ok' : 'error';
- confirmChild.html(translate['confirm' + (success ? 'Success' : 'Failure')]).addClass(confirmClass);
- this.confirmClass = confirmClass;
- }
- else {
- confirmResult.css({ visibility: 'hidden' });
- }
- };
-
- // Monitor keyup and blur events.
- // Blur must be used because a mouse paste does not trigger keyup.
- passwordInput.keyup(passwordCheck).focus(passwordCheck).blur(passwordCheck);
- confirmInput.keyup(passwordCheckMatch).blur(passwordCheckMatch);
- });
- }
-};
+ // Fill in the success message and set the class accordingly.
+ var confirmClass = success ? 'ok' : 'error';
+ confirmChild.html(translate['confirm' + (success ? 'Success' : 'Failure')]).addClass(confirmClass);
+ this.confirmClass = confirmClass;
+ }
+ else {
+ confirmResult.css({ visibility: 'hidden' });
+ }
+ };
+
+ // Monitor keyup and blur events.
+ // Blur must be used because a mouse paste does not trigger keyup.
+ passwordInput.keyup(passwordCheck).focus(passwordCheck).blur(passwordCheck);
+ confirmInput.keyup(passwordCheckMatch).blur(passwordCheckMatch);
+ });
+});
/**
* Evaluate the strength of a user's password.
@@ -182,21 +181,19 @@ Drupal.evaluatePasswordStrength = function (password, translate) {
* Field instance settings screen: force the 'Display on registration form'
* checkbox checked whenever 'Required' is checked.
*/
-Drupal.behaviors.fieldUserRegistration = {
- attach: function (context, settings) {
- var $checkbox = $('form#field-ui-field-edit-form input#edit-instance-settings-user-register-form');
-
- if ($checkbox.length) {
- $(context).find('input#edit-instance-required').once('user-register-form-checkbox', function () {
- $(this).bind('change', function (e) {
- if ($(this).attr('checked')) {
- $checkbox.attr('checked', true);
- }
- });
+$(document).on('ready attach', function (e) {
+ var $checkbox = $('form#field-ui-field-edit-form input#edit-instance-settings-user-register-form');
+
+ if ($checkbox.length) {
+ $(e.target).find('input#edit-instance-required').once('user-register-form-checkbox', function () {
+ $(this).bind('change', function (e) {
+ if ($(this).attr('checked')) {
+ $checkbox.attr('checked', true);
+ }
});
+ });
- }
}
-};
+});
})(jQuery);
diff --git a/core/modules/user/user.permissions.js b/core/modules/user/user.permissions.js
index 896c936..2ac0f2a 100644
--- a/core/modules/user/user.permissions.js
+++ b/core/modules/user/user.permissions.js
@@ -4,7 +4,7 @@
* Shows checked and disabled checkboxes for inherited permissions.
*/
Drupal.behaviors.permissions = {
- attach: function (context) {
+ attach: function (e) {
var self = this;
$('table#permissions').once('permissions', function () {
// On a site with many roles and permissions, this behavior initially has
@@ -65,5 +65,6 @@ Drupal.behaviors.permissions = {
});
}
};
+$(document).on('ready attach', Drupal.behaviors.permissions.attach);
})(jQuery);