0

I am using latest Drupal 7.

I just noticed my admin overlay is not working.

First I thought its due to Jquery Update contrib module installation however that not it. Its apparently due to my custom module, overlay works if I uninstall my module.

My module consists of few basic hooks like hook_menu, hook_form, etc and a simple js file with delete confirm popup code in it.

Also in Home » Administration » Structure » Content types » Basic page, in manage fields tab, 'select a widget' select list (dropdown) shows all options. It is suppose to show options according to field type selected.

$(function() { 
 $(document).ready(function () {

  $(".del-link").click(function () {
   var answer = confirm("This action will delete this record?")
    if (answer){ // if yes is clicked on the confirm box.
     var del_record_id = this.id; // get record id that needs to be deleted.
      window.location = "/delete_url/" + del_record_id; // go to url which trigs the delete function and the record is deleted.
    }   
  });

  $("#edit-my-form-field").click(function () {
    $("#edit-my-form-field").is(":checked") ? $("#show-hide-div").hide() : $("#show-hide-div").show(); 
  }); // end of click function.

 }); // end of  $(document).ready(function ().
}); // end of $(function().

Has anyone come across similar issue?

6
  • 6
    Sounds very much like you've introduced javascript errors in your simple js file that are stopping the rest of the JS on the page from loading. Are there errors in the browser console?
    – Clive
    Jan 17, 2013 at 11:22
  • Yes, you are right, apparently there seems to be an error in js. Browser Console shows >>> Error: ReferenceError: jQuery is not defined Source File: egl_dcs/misc/drupal.js?mgz5hk Line: 5. Line 5 is >> // Allow other JavaScript libraries to use $. jQuery.noConflict(); Pls help! :-/
    – NewBie
    Jan 22, 2013 at 9:23
  • Can we see your JS code? How do you load it in Drupal?
    – ermannob
    Jan 23, 2013 at 11:01
  • I hav added js code in my question. :)
    – NewBie
    Jan 23, 2013 at 12:24
  • It seems like jquery is not loaded or something like that. As @ermannob asked, how do you call this JS file in your module?
    – Mika A.
    Jan 23, 2013 at 12:45

2 Answers 2

1

I figured (googled) it out. :)

I added my custom js in my custom module's info file instead of using drupal_add_js in my module directly.

scripts[] = my_module.js

and added drupal behaviors in my js file as well, so now my custom js looks like below

(function ($) {
Drupal.behaviors.my_module = {
attach: function (context) {

// my js code

 }
};
})(jQuery);

I spent many hours figuring this out but it was as simple as could be be.

Hope this helps someone! :)

0

did you wrap your code in a closure? if it is Drupal 7 you should wrap everything like nya:

(function($) {
  // Your custom code here.
})(jQuery);

Just throwing the $ around like that in the global scope is cray.

0

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