From 3ce31dbb6d09bfcd473da492b4fab5e9f945e83e Tue, 15 Nov 2011 13:03:57 +0100 From: Bram Goffings Date: Tue, 15 Nov 2011 13:03:40 +0100 Subject: [PATCH] Remove .bind, .unbind in favour of .on and .off diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 92eefea..27dc683 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -174,7 +174,7 @@ }; // 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); }); @@ -191,7 +191,7 @@ // For example, prevent the browser default action of a click, even if the // AJAX behavior binds to mousedown. if (element_settings.prevent) { - $(ajax.element).bind(element_settings.prevent, false); + $(ajax.element).on(element_settings.prevent, false); } }; diff --git a/core/misc/form.js b/core/misc/form.js index 259b84e..2a7b32e 100644 --- a/core/misc/form.js +++ b/core/misc/form.js @@ -29,8 +29,8 @@ .data('summaryCallback', callback) // To prevent duplicate events, the handlers are first removed and then // (re-)added. - .unbind('formUpdated.summary') - .bind('formUpdated.summary', function () { + .off('formUpdated.summary') + .on('formUpdated.summary', function () { self.trigger('summaryUpdated'); }) // The actual summaryUpdated handler doesn't fire when the callback is @@ -51,7 +51,7 @@ .find(':input').andSelf().filter(':input') // To prevent duplicate events, the handlers are first removed and then // (re-)added. - .unbind(events).bind(events, function () { + .off(events).on(events, function () { $(this).trigger('formUpdated'); }); } diff --git a/core/misc/machine-name.js b/core/misc/machine-name.js index 2691c3b..2ad6f68 100644 --- a/core/misc/machine-name.js +++ b/core/misc/machine-name.js @@ -65,7 +65,7 @@ $wrapper.show(); $target.focus(); $suffix.hide(); - $source.unbind('.machineName'); + $source.off('.machineName'); return false; }); $suffix.append(' ').append($link); @@ -74,7 +74,7 @@ // 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 () { + $source.on('keyup.machineName change.machineName', function () { machine = self.transliterate($(this).val(), options); // Set the machine name to the transliterated value. if (machine != options.replace && machine != '') { diff --git a/core/misc/states.js b/core/misc/states.js index 1eb7df3..079de3d 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -96,7 +96,7 @@ self.values[selector][state.pristine] = undefined; // Monitor state changes of the specified state for this dependee. - $(selector).bind('state:' + state, function (e) { + $(selector).on('state:' + state, function (e) { var complies = self.compare(value, e.value); self.update(selector, state, complies); }); @@ -214,7 +214,7 @@ var oldValue = valueFn.call(this.element); // Attach the event callback. - this.element.bind(event, function (e) { + this.element.on(event, function (e) { var value = valueFn.call(self.element, e); // Only trigger the event if the value has actually changed. if (oldValue !== value) { @@ -355,7 +355,7 @@ * 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 // element monitoring itself. if (e.trigger) { @@ -369,7 +369,7 @@ } }); - $(document).bind('state:required', function(e) { + $(document).on('state:required', function(e) { if (e.trigger) { if (e.value) { $(e.target).closest('.form-item, .form-wrapper').find('label').append('*'); @@ -380,19 +380,19 @@ } }); - $(document).bind('state:visible', function(e) { + $(document).on('state:visible', function(e) { if (e.trigger) { $(e.target).closest('.form-item, .form-submit, .form-wrapper')[e.value ? 'show' : 'hide'](); } }); - $(document).bind('state:checked', function(e) { + $(document).on('state:checked', function(e) { if (e.trigger) { $(e.target).attr('checked', e.value); } }); - $(document).bind('state:collapsed', function(e) { + $(document).on('state:collapsed', function(e) { if (e.trigger) { if ($(e.target).is('.collapsed') !== e.value) { $('> legend a', e.target).click(); diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js index b9b5822..1ef59b8 100644 --- a/core/misc/tabledrag.js +++ b/core/misc/tabledrag.js @@ -106,8 +106,8 @@ // Add mouse bindings to the document. The self variable is passed along // as event handlers do not have direct access to the tableDrag object. - $(document).bind('mousemove', function (event) { return self.dragRow(event, self); }); - $(document).bind('mouseup', function (event) { return self.dropRow(event, self); }); + $(document).on('mousemove', function (event) { return self.dragRow(event, self); }); + $(document).on('mouseup', function (event) { return self.dropRow(event, self); }); }; /** diff --git a/core/misc/tableheader.js b/core/misc/tableheader.js index 949ef52..80b4357 100644 --- a/core/misc/tableheader.js +++ b/core/misc/tableheader.js @@ -40,16 +40,16 @@ this.originalTable.addClass('sticky-table'); $(window) - .bind('scroll.drupal-tableheader', $.proxy(this, 'eventhandlerRecalculateStickyHeader')) - .bind('resize.drupal-tableheader', { calculateWidth: true }, $.proxy(this, 'eventhandlerRecalculateStickyHeader')) + .on('scroll.drupal-tableheader', $.proxy(this, 'eventhandlerRecalculateStickyHeader')) + .on('resize.drupal-tableheader', { calculateWidth: true }, $.proxy(this, 'eventhandlerRecalculateStickyHeader')) // Make sure the anchor being scrolled into view is not hidden beneath the // sticky table header. Adjust the scrollTop if it does. - .bind('drupalDisplaceAnchor.drupal-tableheader', function () { + .on('drupalDisplaceAnchor.drupal-tableheader', function () { window.scrollBy(0, -self.stickyTable.outerHeight()); }) // Make sure the element being focused is not hidden beneath the sticky // table header. Adjust the scrollTop if it does. - .bind('drupalDisplaceFocus.drupal-tableheader', function (event) { + .on('drupalDisplaceFocus.drupal-tableheader', function (event) { if (self.stickyVisible && event.clientY < (self.stickyOffsetTop + self.stickyTable.outerHeight()) && event.$target.closest('sticky-header').length === 0) { window.scrollBy(0, -self.stickyTable.outerHeight()); } diff --git a/core/misc/textarea.js b/core/misc/textarea.js index 0ab5e71..b38708f 100644 --- a/core/misc/textarea.js +++ b/core/misc/textarea.js @@ -22,7 +22,7 @@ } function endDrag(e) { - $(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag); + $(document).off('mousemove', performDrag).off('mouseup', endDrag); textarea.css('opacity', 1); } }); diff --git a/core/misc/vertical-tabs.js b/core/misc/vertical-tabs.js index 82dcd2c..32aea12 100644 --- a/core/misc/vertical-tabs.js +++ b/core/misc/vertical-tabs.js @@ -103,7 +103,7 @@ }); this.fieldset - .bind('summaryUpdated', function () { + .on('summaryUpdated', function () { self.updateSummary(); }) .trigger('summaryUpdated'); diff --git a/core/modules/color/color.js b/core/modules/color/color.js index 3e53ce1..af3a48a 100644 --- a/core/modules/color/color.js +++ b/core/modules/color/color.js @@ -163,8 +163,8 @@ function focus() { var input = this; // Remove old bindings. - focused && $(focused).unbind('keyup', farb.updateValue) - .unbind('keyup', preview).unbind('keyup', resetScheme) + focused && $(focused).off('keyup', farb.updateValue) + .off('keyup', preview).off('keyup', resetScheme) .parent().removeClass('item-selected'); // Add new bindings. diff --git a/core/modules/contextual/contextual.js b/core/modules/contextual/contextual.js index ee5b7a0..a98969f 100644 --- a/core/modules/contextual/contextual.js +++ b/core/modules/contextual/contextual.js @@ -24,7 +24,7 @@ function () { $region.removeClass('contextual-links-region-active'); } ); // Hide the contextual links when user clicks a link or rolls out of the .contextual-links-region. - $region.bind('mouseleave click', Drupal.contextualLinks.mouseleave); + $region.on('mouseleave click', Drupal.contextualLinks.mouseleave); // Prepend the trigger. $wrapper.prepend($trigger); }); diff --git a/core/modules/field_ui/field_ui.js b/core/modules/field_ui/field_ui.js index c35571b..5859675 100644 --- a/core/modules/field_ui/field_ui.js +++ b/core/modules/field_ui/field_ui.js @@ -26,7 +26,7 @@ $('.field-type-select', table).each(function () { this.targetSelect = $('.widget-type-select', $(this).parents('tr').eq(0)); - $(this).bind('change keyup', function () { + $(this).on('change keyup', function () { var selectedFieldType = this.options[this.selectedIndex].value; var options = (selectedFieldType in widgetTypes ? widgetTypes[selectedFieldType] : []); this.targetSelect.fieldUIPopulateOptions(options); @@ -42,7 +42,7 @@ this.targetSelect = $('.widget-type-select', $(this).parents('tr').eq(0)); this.targetTextfield = $('.label-textfield', $(this).parents('tr').eq(0)); - $(this).bind('change keyup', function (e, updateText) { + $(this).on('change keyup', function (e, updateText) { var updateText = (typeof updateText == 'undefined' ? true : updateText); var selectedField = this.options[this.selectedIndex].value; var selectedFieldType = (selectedField in fields ? fields[selectedField].type : null); diff --git a/core/modules/file/file.js b/core/modules/file/file.js index 1071384..d0fcf9b 100644 --- a/core/modules/file/file.js +++ b/core/modules/file/file.js @@ -18,14 +18,14 @@ if (settings.file && settings.file.elements) { $.each(settings.file.elements, function(selector) { var extensions = settings.file.elements[selector]; - $(selector, context).bind('change', {extensions: extensions}, Drupal.file.validateExtension); + $(selector, context).on('change', {extensions: extensions}, Drupal.file.validateExtension); }); } }, detach: function (context, settings) { if (settings.file && settings.file.elements) { $.each(settings.file.elements, function(selector) { - $(selector, context).unbind('change', Drupal.file.validateExtension); + $(selector, context).off('change', Drupal.file.validateExtension); }); } } @@ -36,12 +36,12 @@ */ Drupal.behaviors.fileButtons = { attach: function (context) { - $('input.form-submit', context).bind('mousedown', Drupal.file.disableFields); - $('div.form-managed-file input.form-submit', context).bind('mousedown', Drupal.file.progressBar); + $('input.form-submit', context).on('mousedown', Drupal.file.disableFields); + $('div.form-managed-file input.form-submit', context).on('mousedown', Drupal.file.progressBar); }, detach: function (context) { - $('input.form-submit', context).unbind('mousedown', Drupal.file.disableFields); - $('div.form-managed-file input.form-submit', context).unbind('mousedown', Drupal.file.progressBar); + $('input.form-submit', context).off('mousedown', Drupal.file.disableFields); + $('div.form-managed-file input.form-submit', context).off('mousedown', Drupal.file.progressBar); } }; @@ -50,10 +50,10 @@ */ Drupal.behaviors.filePreviewLinks = { attach: function (context) { - $('div.form-managed-file .file a, .file-widget .file a', context).bind('click',Drupal.file.openInNewWindow); + $('div.form-managed-file .file a, .file-widget .file a', context).on('click',Drupal.file.openInNewWindow); }, detach: function (context){ - $('div.form-managed-file .file a, .file-widget .file a', context).unbind('click', Drupal.file.openInNewWindow); + $('div.form-managed-file .file a, .file-widget .file a', context).off('click', Drupal.file.openInNewWindow); } }; diff --git a/core/modules/filter/filter.admin.js b/core/modules/filter/filter.admin.js index 3bc6233..1e12edf 100644 --- a/core/modules/filter/filter.admin.js +++ b/core/modules/filter/filter.admin.js @@ -11,7 +11,7 @@ // 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 () { + $checkbox.on('click.filterUpdate', function () { if ($checkbox.is(':checked')) { $row.show(); if (tab) { diff --git a/core/modules/filter/filter.js b/core/modules/filter/filter.js index 94e01c1..ffeeb6b 100644 --- a/core/modules/filter/filter.js +++ b/core/modules/filter/filter.js @@ -8,7 +8,7 @@ $('.filter-guidelines', context).once('filter-guidelines') .find(':header').hide() .parents('.filter-wrapper').find('select.filter-list') - .bind('change', function () { + .on('change', function () { $(this).parents('.filter-wrapper') .find('.filter-guidelines-item').hide() .siblings('.filter-guidelines-' + this.value).show(); diff --git a/core/modules/overlay/overlay-child.js b/core/modules/overlay/overlay-child.js index e78e383..6d251be 100644 --- a/core/modules/overlay/overlay-child.js +++ b/core/modules/overlay/overlay-child.js @@ -98,7 +98,7 @@ * to bind their own handlers to links and also to prevent overlay's handling. */ Drupal.overlayChild.behaviors.addClickHandler = function (context, settings) { - $(document).bind('click.drupal-overlay mouseup.drupal-overlay', $.proxy(parent.Drupal.overlay, 'eventhandlerOverrideLink')); + $(document).on('click.drupal-overlay mouseup.drupal-overlay', $.proxy(parent.Drupal.overlay, 'eventhandlerOverrideLink')); }; /** @@ -131,7 +131,7 @@ var text = Drupal.t('Loading'); var dots = ''; - $(document).bind('drupalOverlayBeforeLoad.drupal-overlay.drupal-overlay-child-loading', function () { + $(document).on'drupalOverlayBeforeLoad.drupal-overlay.drupal-overlay-child-loading', function () { $title = $('#overlay-title').text(text); var id = setInterval(function () { dots = (dots.length > 10) ? '' : dots + '.'; @@ -146,7 +146,7 @@ Drupal.overlayChild.behaviors.tabs = function (context, settings) { var $tabsLinks = $('#overlay-tabs > li > a'); - $('#overlay-tabs > li > a').bind('click.drupal-overlay', function () { + $('#overlay-tabs > li > a').on('click.drupal-overlay', function () { var active_tab = Drupal.t('(active tab)'); $tabsLinks.parent().siblings().removeClass('active').find('element-invisible:contains(' + active_tab + ')').appendTo(this); $(this).parent().addClass('active'); @@ -165,7 +165,7 @@ $addToShortcuts.insertAfter('#overlay-title'); } - $(document).bind('drupalOverlayBeforeLoad.drupal-overlay.drupal-overlay-child-loading', function () { + $(document).on('drupalOverlayBeforeLoad.drupal-overlay.drupal-overlay-child-loading', function () { $('#overlay-titlebar').find('.add-or-remove-shortcuts').remove(); }); }; diff --git a/core/modules/overlay/overlay-parent.js b/core/modules/overlay/overlay-parent.js index 135320f..85b0c5c 100644 --- a/core/modules/overlay/overlay-parent.js +++ b/core/modules/overlay/overlay-parent.js @@ -17,7 +17,7 @@ $(window) // When the hash (URL fragment) changes, open the overlay if needed. - .bind('hashchange.drupal-overlay', $.proxy(Drupal.overlay, 'eventhandlerOperateByURLFragment')) + .on('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'); @@ -27,7 +27,7 @@ // 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')); + .on('click.drupal-overlay mouseup.drupal-overlay', $.proxy(Drupal.overlay, 'eventhandlerOverrideLink')); } }; @@ -110,27 +110,27 @@ this.inactiveFrame = this.$iframeB = $(Drupal.theme('overlayElement')) .appendTo(this.$container); - this.$iframeA.bind('load.drupal-overlay', { self: this.$iframeA[0], sibling: this.$iframeB }, $.proxy(this, 'loadChild')); - this.$iframeB.bind('load.drupal-overlay', { self: this.$iframeB[0], sibling: this.$iframeA }, $.proxy(this, 'loadChild')); + this.$iframeA.on('load.drupal-overlay', { self: this.$iframeA[0], sibling: this.$iframeB }, $.proxy(this, 'loadChild')); + this.$iframeB.on('load.drupal-overlay', { self: this.$iframeB[0], sibling: this.$iframeA }, $.proxy(this, 'loadChild')); // Add a second class "drupal-overlay-open" to indicate these event handlers // should only be bound when the overlay is open. var eventClass = '.drupal-overlay.drupal-overlay-open'; $(window) - .bind('resize' + eventClass, $.proxy(this, 'eventhandlerOuterResize')); + .on('resize' + eventClass, $.proxy(this, 'eventhandlerOuterResize')); $(document) - .bind('drupalOverlayLoad' + eventClass, $.proxy(this, 'eventhandlerOuterResize')) - .bind('drupalOverlayReady' + eventClass + + .on('drupalOverlayLoad' + eventClass, $.proxy(this, 'eventhandlerOuterResize')) + .on('drupalOverlayReady' + eventClass + ' drupalOverlayClose' + eventClass, $.proxy(this, 'eventhandlerSyncURLFragment')) - .bind('drupalOverlayClose' + eventClass, $.proxy(this, 'eventhandlerRefreshPage')) - .bind('drupalOverlayBeforeClose' + eventClass + + .on('drupalOverlayClose' + eventClass, $.proxy(this, 'eventhandlerRefreshPage')) + .on('drupalOverlayBeforeClose' + eventClass + ' drupalOverlayBeforeLoad' + eventClass + ' drupalOverlayResize' + eventClass, $.proxy(this, 'eventhandlerDispatchEvent')); if ($('.overlay-displace-top, .overlay-displace-bottom').length) { $(document) - .bind('drupalOverlayResize' + eventClass, $.proxy(this, 'eventhandlerAlterDisplacedElements')) - .bind('drupalOverlayClose' + eventClass, $.proxy(this, 'eventhandlerRestoreDisplacedElements')); + .on('drupalOverlayResize' + eventClass, $.proxy(this, 'eventhandlerAlterDisplacedElements')) + .on('drupalOverlayClose' + eventClass, $.proxy(this, 'eventhandlerRestoreDisplacedElements')); } }; @@ -207,7 +207,7 @@ * Destroy the overlay. */ Drupal.overlay.destroy = function () { - $([document, window]).unbind('.drupal-overlay-open'); + $([document, window]).off('.drupal-overlay-open'); this.$container.remove(); this.$container = null; diff --git a/core/modules/system/system.js b/core/modules/system/system.js index 5446d28..1bb2410 100644 --- a/core/modules/system/system.js +++ b/core/modules/system/system.js @@ -76,7 +76,7 @@ Drupal.behaviors.copyFieldValue = { attach: function (context, settings) { for (var sourceId in settings.copyFieldValue) { - $('#' + sourceId, context).once('copy-field-values').bind('blur', function () { + $('#' + sourceId, context).once('copy-field-values').on('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. diff --git a/core/modules/user/user.js b/core/modules/user/user.js index 44c00f3..aff9e96 100644 --- a/core/modules/user/user.js +++ b/core/modules/user/user.js @@ -182,7 +182,7 @@ if ($checkbox.size()) { $('input#edit-instance-required', context).once('user-register-form-checkbox', function () { - $(this).bind('change', function (e) { + $(this).on('change', function (e) { if ($(this).attr('checked')) { $checkbox.attr('checked', true); } diff --git a/core/modules/user/user.permissions.js b/core/modules/user/user.permissions.js index 988820e..69b0575 100644 --- a/core/modules/user/user.permissions.js +++ b/core/modules/user/user.permissions.js @@ -36,7 +36,7 @@ // Initialize the authenticated user checkbox. $('input[type=checkbox].rid-2', this) - .bind('click.permissions', self.toggle) + .on('click.permissions', self.toggle) // .triggerHandler() cannot be used here, as it only affects the first // element. .each(self.toggle);