views:

528

answers:

3

Hi, 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?

+2  A: 

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.

Dmitri Farkov
no, the same problem
ramusus
It gives me the same 2 values both times. I don't get the problem.
Dmitri Farkov
sorry, i catch error - django-debug-toolbar! thanks a lot! spasibo! :-)
ramusus
+2  A: 

I think that should be:

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

Edit:

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

xenon
no the same problem
ramusus
sorry, i catch my problem - django-debug-toolbar! thanks a lot! spasibo! :-)
ramusus
A: 

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.

ramusus