Tutorial :Problem to have access to jquery plugin inside $(document).ready() with django-debug-toolbar



Question:

I wrote my own jquery plugin and was amazing that I haven't access to it inside $(document).ready function.

I write this testpage and was amazing more:

    /**       * jQuery anchor plugin       */      (function($) {          $.anchor = {              hashTrim: /^.*#/,          }      })(jQuery);        console.log($.ajax);      console.log($.anchor);        $(function() {          console.log($.ajax);          console.log($.anchor);      });  

I'v got 4 complettely different values in firebug console. Do somebody know and can describe me wy it is? And main question - how I can have access to my $.anchor variable inside $(function() {} ???

Thу testcase is here http://movister.ru:5190/html/test.html

Thanks!

UPDATE:

I just catch the problem - django-debug-toolbar. When I disabled it, everythings becomes ok!

Does anyone know how to make friendship between jquery and django-debug-toolbar?


Solution:1

try

$.fn.anchor  

Just tested your code sample, and both times the result is identical. But in general and for the future extend $.fn due to the fact it extends the jQuery object prototype. When you do just $.anchor you are just extending that instance of the object.


Solution:2

I think that should be:

(function($) {      $.fn.anchor = {          hashTrim: /^.*#/,      }  })(jQuery);  

Edit:

I get the same result both times too, same as the other guys.


Solution:3

I partially solve this problem by switching to the another fork - alex's django_debug_toolbar.

But I think it's more ugly, then david cramer's django_debug_toolbar, that I use before and which contains this problem with jQuery. I hope to move functionality for avoiding this problem from alex's to dcramer's fork in future.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »