1

I load some libraries in my module by using this hook :

function food_truck_form_views_pre_render(&$view) {
  if ($view->name == 'marqueurs_admin') {
    drupal_add_css(libraries_get_path('animate') . '/animate.min.css');
    drupal_add_js(libraries_get_path('bootstrap_notify') . '/bootstrap-notify.min.js');
    drupal_add_js(drupal_get_path('module', 'food_truck_form') . '/js/food_truck_form_admin.js');
  }
}

But when I write a notify in my food_truck_form_admin.js (this code) :

(function($) {
    $.notify({
    icon : 'fa fa-exclamation',
    message : 'TEST'
    }, {
    animate : {
        enter : 'animated flipInY',
        exit : 'animated zoomOutUp'
    },
    type : 'danger'
    });
})(jQuery);

I get this error :

2bootstrap-notify.min.js?o68oa5:1 Uncaught TypeError: this.$ele.find(...).on is not a function

have you got an idea ?

PS : is it the best method to load libraries ? I see on libraries API there was libraries_load... method but i don't understand how to use them :/

0

I suppose you should be loading the libraries through the libraries API:

It is in the Libraries API documentation

libraries_load($name);

// Usually, you'll want to do something after the library has been loaded.
// Because you cannot always depend on the library being installed you have 
// to check first if the loading was actually successful:
// Try to load the library and check if that worked.
if (($library = libraries_load($name)) && !empty($library['loaded'])) {
  // Do something with the library here.
}

Since you say you don't understand this. The above check makes sure the library is loaded correct. So you will not run into weird errors or exceptions. Just put all the code that depends on the libraries inside that if-statement. (As a matter of fact is it much important for PHP than it if for JS, but nevertheless it prevents errors.)

UPDATE:

Oh wait. The problem is that jQuery.on() the function that throws the error was added in jQuery 1.7. Stock Drupal runs on 1.4, so in order to get this to work, have a look at jQuery update and make sure Drupal runs at leat 1.7.

| improve this answer | |
  • Thanks, i doesn't understand before than i need to declare my library into my module to use it ^^ And yes i upgraded Jquery and this works ! Thanks :) – Kpone Apr 27 '16 at 7:40

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.