The solution is to not add more focus events if they've already been added:

date_popup.js

/**
 * Attaches the calendar behavior to all required fields
 */
(function ($) {
Drupal.behaviors.date_popup = {
  attach: function (context) {
  for (var id in Drupal.settings.datePopup) {
    - $('#'+ id).bind('focus', Drupal.settings.datePopup[id], function(e) {
    + $('#:not(.date-popup-processed)'+ id).addClass('date-popup-processed').bind('focus', Drupal.settings.datePopup[id], function(e) {
      <SNIP>
    });
  }
  }
};
})(jQuery);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vijaycs85’s picture

Issue summary: View changes
FileSize
633 bytes

Let's see if it breaks any...

Status: Needs review » Needs work

The last submitted patch, 1: 1840370-date-popup_js-1.patch, failed testing.

Jorrit’s picture

I think it is more appropriate with respect to Drupal standards to make this change:

- $('#'+ id)
+ $('#'+ id, context)

For AJAX requests context is set to the container where new contents are placed. Elements outside this container are automatically not affected.

Jorrit’s picture

Status: Needs work » Needs review
FileSize
498 bytes

Please see the attached patch.

steinmb’s picture

Issue tags: -Performance, -JavaScript

Thank you for the patch.
JS is not area of expertise so I just have to ask to be sure. Will this change break anything for existing sites changing this?

Jorrit’s picture

It works for me ™

steinmb’s picture

Have to leave it some one else to RTBC it then.