0

I spent the entire day trying to figure out why my custom JavaScript was not working.

Eventually I stumbled into the JQuery Update configuration and set it so that the JQuery that I use for my site was the "default (provided by Drupal)" setting and then it worked. Before it was set to 1.7 jQuery version. Looks like someone set it to 1.7 perhaps for magnific.js because that is now spitting out errors in my console "TypeError: a.off is not a function." Not sure what we use that js file for, but I find it strange that I never found anything on line about this being a potential issue when I was trying to troubleshoot my custom javascript.

Does anyone know anything about this? or am I just in left field? I know it wasn't the same issue the gentleman had in this post.

My custom code was not complex and it never worked. So I reduced it all down to just console out a simple message. But that proved to not work either. My simple console out code for my pulsing.js is: (function ($) { Drupal.behaviors.notWorking = { attach: function () { console.log("finally is working"); } }; }(jQuery));

Ill just show the screen shots. The first one is the image where my custom code doesnt work because of jQuery update settings as I said above. enter image description here

The second one is what makes my custom code actually work - but like I said magnify.js then breaks - which maybe i'll hack at it or look for a newer version or something. enter image description here

  • This is not technically a Drupal question. Your custom code is not compatible with the jQuery version on the site. – cilefen Jan 28 '16 at 21:55
  • If what your saying is true, then none of my custom javascript code, which was wrapped up with the Drupal.behaviors... boilerplate code, works for any jQuery version but that which comes straight out of Drupal's box. jQuery 1.5, 1.7, none of them worked. So it sounds like the answer is do not use any other jQuery version when coding for Drupal than the one that comes straight out of the box? – Daedalus Jan 28 '16 at 22:09
  • My code was a simple: (function ($) { Drupal.behaviors.exampleModule = { attach: function (context, settings) { // Code to be run on page load, and console.log("hello"); } }; }(jQuery)); – Daedalus Jan 28 '16 at 22:22
  • I sure didn't say that. You must code in the context of the libraries you have. – cilefen Jan 28 '16 at 22:22
  • 1
    FYI Drupal.behaviors doesn't provide any special jQuery integration. It just helps load your code. Your code still must be compatible with jQuery and any other libraries on the page. – cilefen Jan 28 '16 at 22:30
0

magnific.js clearly needs the .off() function which was added in jQuery 1.7. If you need magnific.js, you will need jQuery 1.7 and it is your job to upgraded your custom JavaScript accordingly.

You may find the changes you need are minimal.

  • That literally was all I was trying to do. All day. And the only thing that changed it was my solution in my question. – Daedalus Jan 28 '16 at 22:24
  • Maybe if you start from the standpoint of what errors are thrown by your custom code in 1.7? – cilefen Jan 28 '16 at 22:27
  • There were no errors. For that file – Daedalus Jan 28 '16 at 23:00

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.