1

I defined a simple block on my module, using the following code.

function visita_virtual_block_view($delta = '') {
  switch ($delta) {
    case 'mapa':
      $path = drupal_get_path('module','visita_virtual');
      drupal_add_js('https://maps.google.com/maps/api/js?sensor=false','external');
      drupal_add_js($path.'/visitavirtual.js');
      $block['subject'] = t('google maps');
      $block['content'] = visita_virtual_mapa_content();
      return $block;
  }
}

That returns a simple div with an specific id, wich will allow me to alter it later through the usage of the google maps api. For that I defined my 'visitavirtual.js' file, and inside of it I declared the Drupal behavior. That function is supposed to get executed when the whole page is loaded, since it'as a wrapper of the JQuery ready function.

(function($){
  Drupal.behaviours.visita_virtual = {
    attach: function(context,settings) {
      alert('Entered the init function');
      var latlng = new google.maps.LatLng(-34.397, 150.644);
      var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };

      var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
    }
  };
})(JQuery);

However, that code is not executed; I can't even see the alert window. What am I doing wrong?

1 Answer 1

4

Lol, it was a silly typo, Sorry. First it's behaviors not behaviours and then the namespace is jQuery not JQuery. Hard to find them on the IDE since it's valid javascript after all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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