1

I have a use case where I need to listen to the insertIntoActiveEditor event in the insertIntoActiveEditor event in the Insert module, but with this code:

(function ($) {

/**
 * Custom behavior to generate image style derivatives on S3 when an image is
 * inserted into the WYSWIYG editor.
 */
Drupal.behaviors.generateDerivative = {
  attach: function(context, settings) {
    $(document).on('insertIntoActiveEditor', function(event, data) {
      var test = 'a';

    })
  }
}
})(jQuery);

I'm getting an error that says

Uncaught TypeError: $(...).on is not a function

on this line

$(document).on('insertIntoActiveEditor', function(event, data) {

I thought I had that syntax correct, but apparently I don't. Do I need to change my selector to be the Insert button (the same as is used in the module JS)? I"ve tried changing it to

$('input[value="Insert"]').on('insertIntoActiveEditor', function(event, data) {

but I still get the same error.

Thanks.

1

The cause was pretty basic - this is in the admin theme, which in Drupal 7 is set to use jQuery 1.4.4, and .on() wasn't added until 1.7. I switched to using .bind(), and it works fine now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.