Issue #1342198 by nod_, droplet, cosmicdreams, RobLoach, aspilicious: Use .on and .off instead of .bind, .unbind and .delegate.

8.0.x
Nathaniel Catchpole 2013-12-04 14:28:18 +00:00
parent 182099941f
commit d4dcb5c357
26 changed files with 97 additions and 96 deletions

View File

@ -258,7 +258,7 @@ Drupal.ajax = function (base, element, element_settings) {
} }
// Bind the ajaxSubmit function to the element event. // Bind the ajaxSubmit function to the element event.
$(ajax.element).bind(element_settings.event, function (event) { $(ajax.element).on(element_settings.event, function (event) {
return ajax.eventResponse(this, event); return ajax.eventResponse(this, event);
}); });
@ -266,7 +266,7 @@ Drupal.ajax = function (base, element, element_settings) {
// can be triggered through keyboard input as well as e.g. a mousedown // can be triggered through keyboard input as well as e.g. a mousedown
// action. // action.
if (element_settings.keypress) { if (element_settings.keypress) {
$(ajax.element).keypress(function (event) { $(ajax.element).on('keypress', function (event) {
return ajax.keypressResponse(this, event); return ajax.keypressResponse(this, event);
}); });
} }
@ -275,7 +275,7 @@ Drupal.ajax = function (base, element, element_settings) {
// For example, prevent the browser default action of a click, even if the // For example, prevent the browser default action of a click, even if the
// AJAX behavior binds to mousedown. // AJAX behavior binds to mousedown.
if (element_settings.prevent) { if (element_settings.prevent) {
$(ajax.element).bind(element_settings.prevent, false); $(ajax.element).on(element_settings.prevent, false);
} }
}; };

View File

@ -40,7 +40,7 @@ $.extend(CollapsibleDetails.prototype, {
setupSummary: function () { setupSummary: function () {
this.$summary = $('<span class="summary"></span>'); this.$summary = $('<span class="summary"></span>');
this.$node this.$node
.bind('summaryUpdated', $.proxy(this.onSummaryUpdated, this)) .on('summaryUpdated', $.proxy(this.onSummaryUpdated, this))
.trigger('summaryUpdated'); .trigger('summaryUpdated');
}, },
/** /**
@ -60,7 +60,7 @@ $.extend(CollapsibleDetails.prototype, {
.attr('href', '#' + this.$node.attr('id')) .attr('href', '#' + this.$node.attr('id'))
.prepend($legend.contents()) .prepend($legend.contents())
.appendTo($legend) .appendTo($legend)
.click($.proxy(this.onLegendClick, this)); .on('click', $.proxy(this.onLegendClick, this));
$legend.append(this.$summary); $legend.append(this.$summary);
}, },
/** /**

View File

@ -31,8 +31,8 @@ $.fn.drupalSetSummary = function (callback) {
.data('summaryCallback', callback) .data('summaryCallback', callback)
// To prevent duplicate events, the handlers are first removed and then // To prevent duplicate events, the handlers are first removed and then
// (re-)added. // (re-)added.
.unbind('formUpdated.summary') .off('formUpdated.summary')
.bind('formUpdated.summary', function () { .on('formUpdated.summary', function () {
self.trigger('summaryUpdated'); self.trigger('summaryUpdated');
}) })
// The actual summaryUpdated handler doesn't fire when the callback is // The actual summaryUpdated handler doesn't fire when the callback is
@ -53,7 +53,7 @@ Drupal.behaviors.formUpdated = {
.find(':input').addBack().filter(':input') .find(':input').addBack().filter(':input')
// To prevent duplicate events, the handlers are first removed and then // To prevent duplicate events, the handlers are first removed and then
// (re-)added. // (re-)added.
.unbind(events).bind(events, function () { .off(events).on(events, function () {
$(this).trigger('formUpdated'); $(this).trigger('formUpdated');
}); });
} }

View File

@ -35,9 +35,9 @@ Drupal.behaviors.machineName = {
var data = e.data; var data = e.data;
e.preventDefault(); e.preventDefault();
data.$wrapper.show(); data.$wrapper.show();
data.$target.focus(); data.$target.trigger('focus');
data.$suffix.hide(); data.$suffix.hide();
data.$source.unbind('.machineName'); data.$source.off('.machineName');
} }
function machineNameHandler(e) { function machineNameHandler(e) {
@ -109,16 +109,16 @@ Drupal.behaviors.machineName = {
options: options options: options
}; };
// If it is editable, append an edit link. // If it is editable, append an edit link.
var $link = $('<span class="admin-link"><button type="button" class="link">' + Drupal.t('Edit') + '</button></span>').bind('click', eventData, clickEditHandler); var $link = $('<span class="admin-link"><button type="button" class="link">' + Drupal.t('Edit') + '</button></span>').on('click', eventData, clickEditHandler);
$suffix.append(' ').append($link); $suffix.append(' ').append($link);
// Preview the machine name in realtime when the human-readable name // 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 // changes, but only if there is no machine name yet; i.e., only upon
// initial creation, not when editing. // initial creation, not when editing.
if ($target.val() === '') { if ($target.val() === '') {
$source.bind('keyup.machineName change.machineName input.machineName', eventData, machineNameHandler) $source.on('keyup.machineName change.machineName input.machineName', eventData, machineNameHandler)
// Initialize machine name preview. // Initialize machine name preview.
.keyup(); .trigger('keyup');
} }
} }
} }

View File

@ -118,7 +118,7 @@ states.Dependent.prototype = {
this.values[selector][state.name] = null; this.values[selector][state.name] = null;
// Monitor state changes of the specified state for this dependee. // Monitor state changes of the specified state for this dependee.
$(selector).bind('state:' + state, {selector: selector, state: state}, stateEventHandler); $(selector).on('state:' + state, {selector: selector, state: state}, stateEventHandler);
// Make sure the event we just bound ourselves to is actually fired. // Make sure the event we just bound ourselves to is actually fired.
new states.Trigger({ selector: selector, state: state }); new states.Trigger({ selector: selector, state: state });
@ -348,7 +348,7 @@ states.Trigger.prototype = {
var oldValue = valueFn.call(this.element); var oldValue = valueFn.call(this.element);
// Attach the event callback. // Attach the event callback.
this.element.bind(event, $.proxy(function (e) { this.element.on(event, $.proxy(function (e) {
var value = valueFn.call(this.element, e); var value = valueFn.call(this.element, e);
// Only trigger the event if the value has actually changed. // Only trigger the event if the value has actually changed.
if (oldValue !== value) { if (oldValue !== value) {
@ -500,7 +500,7 @@ states.State.prototype = {
* can override these state change handlers for particular parts of a page. * can override these state change handlers for particular parts of a page.
*/ */
$(document).bind('state:disabled', function(e) { $(document).on('state:disabled', function (e) {
// Only act when this change was triggered by a dependency and not by the // Only act when this change was triggered by a dependency and not by the
// element monitoring itself. // element monitoring itself.
if (e.trigger) { if (e.trigger) {
@ -514,7 +514,7 @@ $(document).bind('state:disabled', function(e) {
} }
}); });
$(document).bind('state:required', function(e) { $(document).on('state:required', function (e) {
if (e.trigger) { if (e.trigger) {
if (e.value) { if (e.value) {
var $label = $(e.target).attr({ 'required': 'required', 'aria-required': 'aria-required' }).closest('.form-item, .form-wrapper').find('label'); var $label = $(e.target).attr({ 'required': 'required', 'aria-required': 'aria-required' }).closest('.form-item, .form-wrapper').find('label');
@ -529,22 +529,22 @@ $(document).bind('state:required', function(e) {
} }
}); });
$(document).bind('state:visible', function(e) { $(document).on('state:visible', function (e) {
if (e.trigger) { if (e.trigger) {
$(e.target).closest('.form-item, .form-submit, .form-wrapper').toggle(e.value); $(e.target).closest('.form-item, .form-submit, .form-wrapper').toggle(e.value);
} }
}); });
$(document).bind('state:checked', function(e) { $(document).on('state:checked', function (e) {
if (e.trigger) { if (e.trigger) {
$(e.target).prop('checked', e.value); $(e.target).prop('checked', e.value);
} }
}); });
$(document).bind('state:collapsed', function(e) { $(document).on('state:collapsed', function (e) {
if (e.trigger) { if (e.trigger) {
if ($(e.target).is('[open]') === e.value) { if ($(e.target).is('[open]') === e.value) {
$(e.target).find('> summary a').click(); $(e.target).find('> summary a').trigger('click');
} }
} }
}); });

View File

@ -127,7 +127,7 @@ $.extend(TabbingManager.prototype, {
if ($hasFocus.length === 0) { if ($hasFocus.length === 0) {
$hasFocus = $set.eq(0); $hasFocus = $set.eq(0);
} }
$hasFocus.focus(); $hasFocus.trigger('focus');
}, },
/** /**

View File

@ -106,7 +106,7 @@ Drupal.tableDrag = function (table, tableSettings) {
// Add a link before the table for users to show or hide weight columns. // Add a link before the table for users to show or hide weight columns.
$table.before($('<button type="button" class="link tabledrag-toggle-weight"></button>') $table.before($('<button type="button" class="link tabledrag-toggle-weight"></button>')
.attr('title', Drupal.t('Re-order rows by numerical weight instead of dragging.')) .attr('title', Drupal.t('Re-order rows by numerical weight instead of dragging.'))
.click($.proxy(function (e) { .on('click', $.proxy(function (e) {
e.preventDefault(); e.preventDefault();
this.toggleColumns(); this.toggleColumns();
}, this)) }, this))
@ -123,16 +123,16 @@ Drupal.tableDrag = function (table, tableSettings) {
// Add event bindings to the document. The self variable is passed along // Add event bindings to the document. The self variable is passed along
// as event handlers do not have direct access to the tableDrag object. // as event handlers do not have direct access to the tableDrag object.
if (Modernizr.touch) { if (Modernizr.touch) {
$(document).bind('touchmove', function (event) { return self.dragRow(event.originalEvent.touches[0], self); }); $(document).on('touchmove', function (event) { return self.dragRow(event.originalEvent.touches[0], self); });
$(document).bind('touchend', function (event) { return self.dropRow(event.originalEvent.touches[0], self); }); $(document).on('touchend', function (event) { return self.dropRow(event.originalEvent.touches[0], self); });
} }
else { else {
$(document).bind('mousemove', function (event) { return self.dragRow(event, self); }); $(document).on('mousemove', function (event) { return self.dragRow(event, self); });
$(document).bind('mouseup', function (event) { return self.dropRow(event, self); }); $(document).on('mouseup', function (event) { return self.dropRow(event, self); });
} }
// React to localStorage event showing or hiding weight columns. // React to localStorage event showing or hiding weight columns.
$(window).bind('storage', $.proxy(function (e) { $(window).on('storage', $.proxy(function (e) {
// Only react to 'Drupal.tableDrag.showWeight' value change. // Only react to 'Drupal.tableDrag.showWeight' value change.
if (e.originalEvent.key === 'Drupal.tableDrag.showWeight') { if (e.originalEvent.key === 'Drupal.tableDrag.showWeight') {
// This was changed in another window, get the new value for this window. // This was changed in another window, get the new value for this window.
@ -332,32 +332,32 @@ Drupal.tableDrag.prototype.makeDraggable = function (item) {
}); });
} }
else { else {
handle.mousedown(function (event) { handle.on('mousedown', function (event) {
event.preventDefault(); event.preventDefault();
self.dragStart(event, self, item); self.dragStart(event, self, item);
}); });
} }
// Prevent the anchor tag from jumping us to the top of the page. // Prevent the anchor tag from jumping us to the top of the page.
handle.click(function (e) { handle.on('click', function (e) {
e.preventDefault(); e.preventDefault();
}); });
// Set blur cleanup when a handle is focused. // Set blur cleanup when a handle is focused.
handle.focus(function () { handle.on('focus', function () {
self.safeBlur = true; self.safeBlur = true;
}); });
// On blur, fire the same function as a touchend/mouseup. This is used to // On blur, fire the same function as a touchend/mouseup. This is used to
// update values after a row has been moved through the keyboard support. // update values after a row has been moved through the keyboard support.
handle.blur(function (event) { handle.on('blur', function (event) {
if (self.rowObject && self.safeBlur) { if (self.rowObject && self.safeBlur) {
self.dropRow(event, self); self.dropRow(event, self);
} }
}); });
// Add arrow-key support to the handle. // Add arrow-key support to the handle.
handle.keydown(function (event) { handle.on('keydown', function (event) {
// If a rowObject doesn't yet exist and this isn't the tab key. // If a rowObject doesn't yet exist and this isn't the tab key.
if (event.keyCode !== 9 && !self.rowObject) { if (event.keyCode !== 9 && !self.rowObject) {
self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true); self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true);
@ -406,7 +406,7 @@ Drupal.tableDrag.prototype.makeDraggable = function (item) {
self.rowObject.indent(0); self.rowObject.indent(0);
window.scrollBy(0, -parseInt(item.offsetHeight, 10)); window.scrollBy(0, -parseInt(item.offsetHeight, 10));
} }
handle.get(0).focus(); // Regain focus after the DOM manipulation. handle.trigger('focus'); // Regain focus after the DOM manipulation.
} }
break; break;
case 39: // Right arrow. case 39: // Right arrow.
@ -448,7 +448,7 @@ Drupal.tableDrag.prototype.makeDraggable = function (item) {
self.rowObject.indent(0); self.rowObject.indent(0);
window.scrollBy(0, parseInt(item.offsetHeight, 10)); window.scrollBy(0, parseInt(item.offsetHeight, 10));
} }
handle.get(0).focus(); // Regain focus after the DOM manipulation. handle.trigger('focus'); // Regain focus after the DOM manipulation.
} }
break; break;
} }
@ -472,7 +472,7 @@ Drupal.tableDrag.prototype.makeDraggable = function (item) {
// Compatibility addition, return false on keypress to prevent unwanted scrolling. // Compatibility addition, return false on keypress to prevent unwanted scrolling.
// IE and Safari will suppress scrolling on keydown, but all other browsers // IE and Safari will suppress scrolling on keydown, but all other browsers
// need to return false on keypress. http://www.quirksmode.org/js/keys.html // need to return false on keypress. http://www.quirksmode.org/js/keys.html
handle.keypress(function (event) { handle.on('keypress', function (event) {
switch (event.keyCode) { switch (event.keyCode) {
case 37: // Left arrow. case 37: // Left arrow.
case 38: // Up arrow. case 38: // Up arrow.
@ -504,7 +504,7 @@ Drupal.tableDrag.prototype.dragStart = function (event, self, item) {
// If there's a lingering row object from the keyboard, remove its focus. // If there's a lingering row object from the keyboard, remove its focus.
if (self.rowObject) { if (self.rowObject) {
$(self.rowObject.element).find('a.tabledrag-handle').blur(); $(self.rowObject.element).find('a.tabledrag-handle').trigger('blur');
} }
// Create a new rowObject for manipulation of this row. // Create a new rowObject for manipulation of this row.

View File

@ -93,7 +93,7 @@ function TableHeader(table) {
this.tableOffset = this.$originalTable.offset(); this.tableOffset = this.$originalTable.offset();
// React to columns change to avoid making checks in the scroll callback. // React to columns change to avoid making checks in the scroll callback.
this.$originalTable.bind('columnschange', {tableHeader: this}, function (e, display) { this.$originalTable.on('columnschange', {tableHeader: this}, function (e, display) {
var tableHeader = e.data.tableHeader; var tableHeader = e.data.tableHeader;
if (tableHeader.displayWeight === null || tableHeader.displayWeight !== display) { if (tableHeader.displayWeight === null || tableHeader.displayWeight !== display) {
tableHeader.recalculateSticky(); tableHeader.recalculateSticky();

View File

@ -28,7 +28,7 @@ Drupal.tableSelect = function () {
}; };
// Find all <th> with class select-all, and insert the check all checkbox. // Find all <th> with class select-all, and insert the check all checkbox.
$table.find('th.select-all').prepend($('<input type="checkbox" class="form-checkbox" />').attr('title', strings.selectAll)).click(function (event) { $table.find('th.select-all').prepend($('<input type="checkbox" class="form-checkbox" />').attr('title', strings.selectAll)).on('click', function (event) {
if ($(event.target).is('input[type="checkbox"]')) { if ($(event.target).is('input[type="checkbox"]')) {
// Loop through all checkboxes and set their state to the select all checkbox' state. // Loop through all checkboxes and set their state to the select all checkbox' state.
checkboxes.each(function () { checkboxes.each(function () {
@ -42,7 +42,7 @@ Drupal.tableSelect = function () {
}); });
// For each of the checkboxes within the table that are not disabled. // For each of the checkboxes within the table that are not disabled.
checkboxes = $table.find('td input[type="checkbox"]:enabled').click(function (e) { checkboxes = $table.find('td input[type="checkbox"]:enabled').on('click', function (e) {
// Either add or remove the selected class based on the state of the check all checkbox. // Either add or remove the selected class based on the state of the check all checkbox.
$(this).closest('tr').toggleClass('selected', this.checked); $(this).closest('tr').toggleClass('selected', this.checked);

View File

@ -90,24 +90,24 @@ Drupal.verticalTab = function (settings) {
this.link.attr('href', '#' + settings.details.attr('id')); this.link.attr('href', '#' + settings.details.attr('id'));
this.link.click(function (e) { this.link.on('click', function (e) {
e.preventDefault(); e.preventDefault();
self.focus(); self.focus();
}); });
// Keyboard events added: // Keyboard events added:
// Pressing the Enter key will open the tab pane. // Pressing the Enter key will open the tab pane.
this.link.keydown(function(event) { this.link.on('keydown', function (event) {
event.preventDefault(); event.preventDefault();
if (event.keyCode === 13) { if (event.keyCode === 13) {
self.focus(); self.focus();
// Set focus on the first input field of the visible details/tab pane. // Set focus on the first input field of the visible details/tab pane.
$(".vertical-tabs-pane :input:visible:enabled:first").focus(); $(".vertical-tabs-pane :input:visible:enabled:first").trigger('focus');
} }
}); });
this.details this.details
.bind('summaryUpdated', function () { .on('summaryUpdated', function () {
self.updateSummary(); self.updateSummary();
}) })
.trigger('summaryUpdated'); .trigger('summaryUpdated');

View File

@ -78,7 +78,7 @@ Drupal.behaviors.blockDrag = {
window.alert(Drupal.t('The block cannot be placed in this region.')); window.alert(Drupal.t('The block cannot be placed in this region.'));
// Simulate that there was a selected element change, so the row is put // Simulate that there was a selected element change, so the row is put
// back to from where the user tried to drag it. // back to from where the user tried to drag it.
regionField.change(); regionField.trigger('change');
} }
else if ($rowElement.prev('tr').is('.region-message')) { else if ($rowElement.prev('tr').is('.region-message')) {
var weightField = $rowElement.find('select.block-weight'); var weightField = $rowElement.find('select.block-weight');
@ -94,7 +94,7 @@ Drupal.behaviors.blockDrag = {
// Add the behavior to each region select list. // Add the behavior to each region select list.
$(context).find('select.block-region-select').once('block-region-select', function () { $(context).find('select.block-region-select').once('block-region-select', function () {
$(this).change(function (event) { $(this).on('change', function (event) {
// Make our new row and select field. // Make our new row and select field.
var row = $(this).closest('tr'); var row = $(this).closest('tr');
var select = $(this); var select = $(this);
@ -106,7 +106,7 @@ Drupal.behaviors.blockDrag = {
// Modify empty regions with added or removed fields. // Modify empty regions with added or removed fields.
checkEmptyRegions(table, row); checkEmptyRegions(table, row);
// Remove focus from selectbox. // Remove focus from selectbox.
select.get(0).blur(); select.trigger('blur');
}); });
}); });

View File

@ -536,7 +536,7 @@ Drupal.ckeditor = {
if (success) { if (success) {
$group.appendTo($(event.currentTarget).closest('.ckeditor-row').children('.ckeditor-toolbar-groups')); $group.appendTo($(event.currentTarget).closest('.ckeditor-row').children('.ckeditor-toolbar-groups'));
// Focus on the new group. // Focus on the new group.
$group.focus(); $group.trigger('focus');
} }
} }
@ -574,7 +574,7 @@ Drupal.ckeditor = {
* elements involved in the sort action. * elements involved in the sort action.
*/ */
startButtonDrag: function (event, ui) { startButtonDrag: function (event, ui) {
this.$el.find('a:focus').blur(); this.$el.find('a:focus').trigger('blur');
// Show the button group names as soon as the user starts dragging. // Show the button group names as soon as the user starts dragging.
this.model.set('groupNamesVisible', true); this.model.set('groupNamesVisible', true);
@ -597,7 +597,7 @@ Drupal.ckeditor = {
} }
// Refocus the target button so that the user can continue from a known // Refocus the target button so that the user can continue from a known
// place. // place.
ui.item.find('a').focus(); ui.item.find('a').trigger('focus');
}); });
}, },
@ -809,7 +809,7 @@ Drupal.ckeditor = {
.off() .off()
.remove(); .remove();
// Focus on the first button in the active toolbar. // Focus on the first button in the active toolbar.
$activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).children().eq(0).children().focus(); $activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).children().eq(0).children().trigger('focus');
} }
// Otherwise, move it. // Otherwise, move it.
else { else {
@ -852,7 +852,7 @@ Drupal.ckeditor = {
} }
// Refocus the target button so that the user can continue from a known // Refocus the target button so that the user can continue from a known
// place. // place.
$target.focus(); $target.trigger('focus');
}); });
event.preventDefault(); event.preventDefault();
@ -933,7 +933,7 @@ Drupal.ckeditor = {
} }
registerGroupMove(this, $group); registerGroupMove(this, $group);
$group.focus(); $group.trigger('focus');
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
} }
@ -1410,7 +1410,7 @@ function openGroupNameDialog (view, $group, callback) {
// When editing, set the "group name" input in the form to the current value. // When editing, set the "group name" input in the form to the current value.
.attr('value', $group.attr('data-drupal-ckeditor-toolbar-group-name')) .attr('value', $group.attr('data-drupal-ckeditor-toolbar-group-name'))
// Focus on the "group name" input in the form. // Focus on the "group name" input in the form.
.focus(); .trigger('focus');
} }
/** /**

View File

@ -55,7 +55,7 @@ Drupal.behaviors.color = {
} }
// Set up colorScheme selector. // Set up colorScheme selector.
form.find('#edit-scheme').change(function () { form.find('#edit-scheme').on('change', function () {
var schemes = settings.color.schemes, colorScheme = this.options[this.selectedIndex].value; var schemes = settings.color.schemes, colorScheme = this.options[this.selectedIndex].value;
if (colorScheme !== '' && schemes[colorScheme]) { if (colorScheme !== '' && schemes[colorScheme]) {
// Get colors of active scheme. // Get colors of active scheme.
@ -184,8 +184,8 @@ Drupal.behaviors.color = {
var input = e.target; var input = e.target;
// Remove old bindings. // Remove old bindings.
if (focused) { if (focused) {
$(focused).unbind('keyup', farb.updateValue) $(focused).off('keyup', farb.updateValue)
.unbind('keyup', preview).unbind('keyup', resetScheme) .off('keyup', preview).off('keyup', resetScheme)
.parent().removeClass('item-selected'); .parent().removeClass('item-selected');
} }
@ -193,7 +193,7 @@ Drupal.behaviors.color = {
focused = input; focused = input;
farb.linkTo(function (color) { callback(input, color, true, false); }); farb.linkTo(function (color) { callback(input, color, true, false); });
farb.setColor(input.value); farb.setColor(input.value);
$(focused).keyup(farb.updateValue).keyup(preview).keyup(resetScheme) $(focused).on('keyup', farb.updateValue).on('keyup', preview).on('keyup', resetScheme)
.parent().addClass('item-selected'); .parent().addClass('item-selected');
} }
@ -240,11 +240,11 @@ Drupal.behaviors.color = {
$(this).after(hook); $(this).after(hook);
hooks.push(hook); hooks.push(hook);
$(this).parent().find('.lock').click(); $(this).parent().find('.lock').trigger('click');
this.i = i; this.i = i;
inputs.push(this); inputs.push(this);
}) })
.focus(focus); .on('focus', focus);
form.find('#palette label'); form.find('#palette label');

View File

@ -55,7 +55,7 @@ Drupal.behaviors.editor = {
}); });
} }
// Detach any editor when the containing form is submitted. // Detach any editor when the containing form is submitted.
$this.parents('form').submit(function (event) { $this.parents('form').on('submit', function (event) {
// Do not detach if the event was canceled. // Do not detach if the event was canceled.
if (event.isDefaultPrevented()) { if (event.isDefaultPrevented()) {
return; return;

View File

@ -157,7 +157,7 @@ Drupal.fieldUIOverview = {
// Fire the Ajax update. // Fire the Ajax update.
$('input[name=refresh_rows]').val(rowNames.join(' ')); $('input[name=refresh_rows]').val(rowNames.join(' '));
$('input#edit-refresh').mousedown(); $('input#edit-refresh').trigger('mousedown');
// Disabled elements do not appear in POST ajax data, so we mark the // Disabled elements do not appear in POST ajax data, so we mark the
// elements disabled only after firing the request. // elements disabled only after firing the request.
@ -190,7 +190,7 @@ Drupal.fieldUIDisplayOverview.field = function (row, data) {
// Attach change listener to the 'plugin type' select. // Attach change listener to the 'plugin type' select.
this.$pluginSelect = $(row).find('select.field-plugin-type'); this.$pluginSelect = $(row).find('select.field-plugin-type');
this.$pluginSelect.change(Drupal.fieldUIOverview.onChange); this.$pluginSelect.on('change', Drupal.fieldUIOverview.onChange);
return this; return this;
}; };

View File

@ -23,7 +23,7 @@ Drupal.behaviors.fileValidateAutoAttach = {
elements = settings.file.elements; elements = settings.file.elements;
for (selector in elements) { for (selector in elements) {
if (elements.hasOwnProperty(selector)) { if (elements.hasOwnProperty(selector)) {
$context.find(selector).bind('change', {extensions: elements[selector]}, validateExtension); $context.find(selector).on('change', {extensions: elements[selector]}, validateExtension);
} }
} }
} }
@ -36,7 +36,7 @@ Drupal.behaviors.fileValidateAutoAttach = {
elements = settings.file.elements; elements = settings.file.elements;
for (selector in elements) { for (selector in elements) {
if (elements.hasOwnProperty(selector)) { if (elements.hasOwnProperty(selector)) {
$context.find(selector).unbind('change', validateExtension); $context.find(selector).off('change', validateExtension);
} }
} }
} }
@ -63,13 +63,13 @@ Drupal.behaviors.fileAutoUpload = {
Drupal.behaviors.fileButtons = { Drupal.behaviors.fileButtons = {
attach: function (context) { attach: function (context) {
var $context = $(context); var $context = $(context);
$context.find('input.form-submit').bind('mousedown', Drupal.file.disableFields); $context.find('input.form-submit').on('mousedown', Drupal.file.disableFields);
$context.find('div.form-managed-file input.form-submit').bind('mousedown', Drupal.file.progressBar); $context.find('div.form-managed-file input.form-submit').on('mousedown', Drupal.file.progressBar);
}, },
detach: function (context) { detach: function (context) {
var $context = $(context); var $context = $(context);
$context.find('input.form-submit').unbind('mousedown', Drupal.file.disableFields); $context.find('input.form-submit').off('mousedown', Drupal.file.disableFields);
$context.find('div.form-managed-file input.form-submit').unbind('mousedown', Drupal.file.progressBar); $context.find('div.form-managed-file input.form-submit').off('mousedown', Drupal.file.progressBar);
} }
}; };
@ -78,10 +78,10 @@ Drupal.behaviors.fileButtons = {
*/ */
Drupal.behaviors.filePreviewLinks = { Drupal.behaviors.filePreviewLinks = {
attach: function (context) { attach: function (context) {
$(context).find('div.form-managed-file .file a, .file-widget .file a').bind('click',Drupal.file.openInNewWindow); $(context).find('div.form-managed-file .file a, .file-widget .file a').on('click',Drupal.file.openInNewWindow);
}, },
detach: function (context){ detach: function (context){
$(context).find('div.form-managed-file .file a, .file-widget .file a').unbind('click', Drupal.file.openInNewWindow); $(context).find('div.form-managed-file .file a, .file-widget .file a').off('click', Drupal.file.openInNewWindow);
} }
}; };

View File

@ -20,7 +20,7 @@ Drupal.behaviors.filterStatus = {
// Bind click handler to this checkbox to conditionally show and hide the // Bind click handler to this checkbox to conditionally show and hide the
// filter's tableDrag row and vertical tab pane. // filter's tableDrag row and vertical tab pane.
$checkbox.bind('click.filterUpdate', function () { $checkbox.on('click.filterUpdate', function () {
if ($checkbox.is(':checked')) { if ($checkbox.is(':checked')) {
$row.show(); $row.show();
if (filterSettingsTab) { if (filterSettingsTab) {

View File

@ -15,12 +15,12 @@ Drupal.behaviors.filterGuidelines = {
$(context).find('.filter-guidelines').once('filter-guidelines') $(context).find('.filter-guidelines').once('filter-guidelines')
.find(':header').hide() .find(':header').hide()
.closest('.filter-wrapper').find('select.filter-list') .closest('.filter-wrapper').find('select.filter-list')
.bind('change', function () { .on('change', function () {
$(this).closest('.filter-wrapper') $(this).closest('.filter-wrapper')
.find('.filter-guidelines-item').hide() .find('.filter-guidelines-item').hide()
.filter('.filter-guidelines-' + this.value).show(); .filter('.filter-guidelines-' + this.value).show();
}) })
.change(); .trigger('change');
} }
}; };

View File

@ -39,7 +39,7 @@ Drupal.behaviors.menuLinkAutomaticTitle = {
$link_title.data('menuLinkAutomaticTitleOveridden', true); $link_title.data('menuLinkAutomaticTitleOveridden', true);
} }
// Whenever the value is changed manually, disable this behavior. // Whenever the value is changed manually, disable this behavior.
$link_title.keyup(function () { $link_title.on('keyup', function () {
$link_title.data('menuLinkAutomaticTitleOveridden', true); $link_title.data('menuLinkAutomaticTitleOveridden', true);
}); });
// Global trigger on checkbox (do not fill-in a value when disabled). // Global trigger on checkbox (do not fill-in a value when disabled).
@ -57,7 +57,7 @@ Drupal.behaviors.menuLinkAutomaticTitle = {
$checkbox.trigger('formUpdated'); $checkbox.trigger('formUpdated');
}); });
// Take over any title change. // Take over any title change.
$title.keyup(function () { $title.on('keyup', function () {
if (!$link_title.data('menuLinkAutomaticTitleOveridden') && $checkbox.is(':checked')) { if (!$link_title.data('menuLinkAutomaticTitleOveridden') && $checkbox.is(':checked')) {
$link_title.val($title.val()); $link_title.val($title.val());
$link_title.val($title.val()).trigger('formUpdated'); $link_title.val($title.val()).trigger('formUpdated');

View File

@ -11,7 +11,7 @@ Drupal.behaviors.newSet = {
var selectDefault = function() { var selectDefault = function() {
$(this).closest('form').find('.form-item-set .form-type-radio:last input').prop('checked', true); $(this).closest('form').find('.form-item-set .form-type-radio:last input').prop('checked', true);
}; };
$('div.form-item-new input').focus(selectDefault).keyup(selectDefault); $('div.form-item-new input').on('focus', selectDefault).on('keyup', selectDefault);
} }
}; };

View File

@ -15,7 +15,7 @@ Drupal.behaviors.simpleTestMenuCollapse = {
$this.html(drupalSettings.simpleTest.images[direction]); $this.html(drupalSettings.simpleTest.images[direction]);
// Adds group toggling functionality to arrow images. // Adds group toggling functionality to arrow images.
$this.click(function () { $this.on('click', function () {
var trs = $this.closest('tbody').children('.' + drupalSettings.simpleTest[this.id].testClass); var trs = $this.closest('tbody').children('.' + drupalSettings.simpleTest[this.id].testClass);
var direction = drupalSettings.simpleTest[this.id].imageDirection; var direction = drupalSettings.simpleTest[this.id].imageDirection;
var row = direction ? trs.length - 1 : 0; var row = direction ? trs.length - 1 : 0;
@ -80,7 +80,7 @@ Drupal.behaviors.simpleTestSelectAll = {
} }
// Have the single-test checkboxes follow the group checkbox. // Have the single-test checkboxes follow the group checkbox.
groupCheckbox.change(function () { groupCheckbox.on('change', function () {
var checked = $(this).prop('checked'); var checked = $(this).prop('checked');
for (var i = 0; i < testCheckboxes.length; i++) { for (var i = 0; i < testCheckboxes.length; i++) {
$('#' + testCheckboxes[i]).prop('checked', checked); $('#' + testCheckboxes[i]).prop('checked', checked);
@ -89,7 +89,7 @@ Drupal.behaviors.simpleTestSelectAll = {
// Have the group checkbox follow the single-test checkboxes. // Have the group checkbox follow the single-test checkboxes.
for (var i = 0; i < testCheckboxes.length; i++) { for (var i = 0; i < testCheckboxes.length; i++) {
$('#' + testCheckboxes[i]).change(updateGroupCheckbox); $('#' + testCheckboxes[i]).on('change', updateGroupCheckbox);
} }
// Initialize status for the group checkbox correctly. // Initialize status for the group checkbox correctly.

View File

@ -42,7 +42,7 @@ Drupal.behaviors.textSummary = {
// If no summary is set, hide the summary field. // If no summary is set, hide the summary field.
if ($widget.find('.text-summary').val() === '') { if ($widget.find('.text-summary').val() === '') {
$link.click(); $link.trigger('click');
} }
}); });
} }

View File

@ -180,7 +180,7 @@ Drupal.behaviors.fieldUserRegistration = {
if ($checkbox.length) { if ($checkbox.length) {
$(context).find('input#edit-instance-required').once('user-register-form-checkbox', function () { $(context).find('input#edit-instance-required').once('user-register-form-checkbox', function () {
$(this).bind('change', function (e) { $(this).on('change', function (e) {
if ($(this).prop('checked')) { if ($(this).prop('checked')) {
$checkbox.prop('checked', true); $checkbox.prop('checked', true);
} }

View File

@ -41,7 +41,7 @@ Drupal.behaviors.permissions = {
// Initialize the authenticated user checkbox. // Initialize the authenticated user checkbox.
$table.find('input[type=checkbox].rid-authenticated') $table.find('input[type=checkbox].rid-authenticated')
.bind('click.permissions', self.toggle) .on('click.permissions', self.toggle)
// .triggerHandler() cannot be used here, as it only affects the first // .triggerHandler() cannot be used here, as it only affects the first
// element. // element.
.each(self.toggle); .each(self.toggle);

View File

@ -49,9 +49,9 @@
*/ */
Drupal.behaviors.livePreview = { Drupal.behaviors.livePreview = {
attach: function (context) { attach: function (context) {
$('input#edit-displays-live-preview', context).once('views-ajax-processed').click(function() { $('input#edit-displays-live-preview', context).once('views-ajax').on('click', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('#preview-submit').click(); $('#preview-submit').trigger('click');
} }
}); });
} }
@ -62,13 +62,13 @@
*/ */
Drupal.behaviors.syncPreviewDisplay = { Drupal.behaviors.syncPreviewDisplay = {
attach: function (context) { attach: function (context) {
$("#views-tabset a").once('views-ajax-processed').click(function() { $("#views-tabset a").once('views-ajax').on('click', function () {
var href = $(this).attr('href'); var href = $(this).attr('href');
// Cut of #views-tabset. // Cut of #views-tabset.
var display_id = href.substr(11); var display_id = href.substr(11);
// Set the form element. // Set the form element.
$("#views-live-preview #preview-display-id").val(display_id); $("#views-live-preview #preview-display-id").val(display_id);
}).addClass('views-ajax-processed'); });
} }
}; };
@ -80,7 +80,7 @@
'progress': { 'type': 'throbber' } 'progress': { 'type': 'throbber' }
}; };
// Bind AJAX behaviors to all items showing the class. // Bind AJAX behaviors to all items showing the class.
$('a.views-ajax-link', context).once('views-ajax-processed').each(function () { $('a.views-ajax-link', context).once('views-ajax').each(function () {
var element_settings = base_element_settings; var element_settings = base_element_settings;
// Set the URL to go to the anchor. // Set the URL to go to the anchor.
if ($(this).attr('href')) { if ($(this).attr('href')) {
@ -91,7 +91,7 @@
}); });
$('div#views-live-preview a') $('div#views-live-preview a')
.once('views-ajax-processed').each(function () { .once('views-ajax').each(function () {
// We don't bind to links without a URL. // We don't bind to links without a URL.
if (!$(this).attr('href')) { if (!$(this).attr('href')) {
return true; return true;
@ -115,8 +115,8 @@
// @todo Revisit this after fixing Views UI to display a Preview outside // @todo Revisit this after fixing Views UI to display a Preview outside
// of the main Edit form. // of the main Edit form.
$('div#views-live-preview input[type=submit]') $('div#views-live-preview input[type=submit]')
.once('views-ajax-processed').each(function(event) { .once('views-ajax').each(function(event) {
$(this).click(function () { $(this).on('click', function () {
this.form.clk = this; this.form.clk = this;
return true; return true;
}); });

View File

@ -307,7 +307,7 @@ Drupal.viewsUi.OptionsSearch = function ($form) {
this.$form = $form; this.$form = $form;
// Add a keyup handler to the search box. // Add a keyup handler to the search box.
this.$searchBox = this.$form.find('#edit-override-controls-options-search'); this.$searchBox = this.$form.find('#edit-override-controls-options-search');
this.$searchBox.keyup($.proxy(this.handleKeyup, this)); this.$searchBox.on('keyup', $.proxy(this.handleKeyup, this));
// Get a list of option labels and their corresponding divs and maintain it // Get a list of option labels and their corresponding divs and maintain it
// in memory, so we have as little overhead as possible at keyup time. // in memory, so we have as little overhead as possible at keyup time.
this.options = this.getOptions(this.$form.find('.filterable-option')); this.options = this.getOptions(this.$form.find('.filterable-option'));
@ -527,7 +527,7 @@ $.extend(Drupal.viewsUi.RearrangeFilterHandler.prototype, {
clickAddGroupButton: function () { clickAddGroupButton: function () {
// Due to conflicts between Drupal core's AJAX system and the Views AJAX // Due to conflicts between Drupal core's AJAX system and the Views AJAX
// system, the only way to get this to work seems to be to trigger both the // system, the only way to get this to work seems to be to trigger both the
// .mousedown() and .submit() events. // mousedown and submit events.
this.addGroupButton this.addGroupButton
.trigger('mousedown') .trigger('mousedown')
.trigger('submit'); .trigger('submit');
@ -856,7 +856,7 @@ Drupal.viewsUi.Checkboxifier = function (button) {
this.$button.hide(); this.$button.hide();
this.$parent.find('.exposed-description, .grouped-description').hide(); this.$parent.find('.exposed-description, .grouped-description').hide();
this.$input.click($.proxy(this, 'clickHandler')); this.$input.on('click', $.proxy(this, 'clickHandler'));
}; };
@ -864,8 +864,9 @@ Drupal.viewsUi.Checkboxifier = function (button) {
* When the checkbox is checked or unchecked, simulate a button press. * When the checkbox is checked or unchecked, simulate a button press.
*/ */
Drupal.viewsUi.Checkboxifier.prototype.clickHandler = function (e) { Drupal.viewsUi.Checkboxifier.prototype.clickHandler = function (e) {
this.$button.mousedown(); this.$button
this.$button.submit(); .trigger('mousedown')
.trigger('submit');
}; };
/** /**