diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 92eefea..a0291b1 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -29,6 +29,11 @@ Drupal.behaviors.AJAX = { } $(element_settings.selector).each(function () { element_settings.element = this; + + // Check whether to bind behaviors using .one() instead of .bind(). + if ($(this).hasClass('ajax-once')) { + element_settings.bindMethod = 'one'; + } Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); }); @@ -48,6 +53,10 @@ Drupal.behaviors.AJAX = { element_settings.url = $(this).attr('href'); element_settings.event = 'click'; } + // Check whether to bind behaviors using .one() instead of .bind(). + if ($(this).hasClass('ajax-once')) { + element_settings.bindMethod = 'one'; + } var base = $(this).attr('id'); Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); }); @@ -173,11 +182,25 @@ Drupal.ajax = function (base, element, element_settings) { type: 'POST' }; - // Bind the ajaxSubmit function to the element event. - $(ajax.element).bind(element_settings.event, function (event) { + // By default, behaviors are bound using .bind(). + if (!element_settings.bindMethod) { + element_settings.bindMethod = 'bind'; + } + + // Bind the handler to the element event using whichever bind method was set. + $(ajax.element)[element_settings.bindMethod](element_settings.event, function (event) { return ajax.eventResponse(this, event); }); + // If the behavior was only bound once, the browser's default behavior needs + // to be prevented on subsequent events, so as to not follow links. + if (element_settings.bindMethod == 'one') { + $(ajax.element).bind(element_settings.event, function () { + return false; + }); + } + + // If necessary, enable keyboard submission so that Ajax behaviors // can be triggered through keyboard input as well as e.g. a mousedown // action.