views:

51

answers:

2
$(window).load(function(){

alert(typeof $.fn.init_deps);

});

$(document).ready(function(){

    /* Departments switcher */
    $.fn.init_deps = function(s){

        var o = {
            deps:false,
            cats:false              
        }
        $.extend(o,s);

        if(!s.deps || !s.cats) {return;}
        return this.each(function(){

            var select = $('<select id="department" name="department"></select>')
                .appendTo(this)
                .departments(s)
                .change(function(){
                    var select = $('select#category');
                    select.categories({cats:s.cats,current_dep:$(this).val()});

                    var p_width = select.parent().outerWidth();
                    var ch_width = select.outerWidth();
                    select.parent().css('width',p_width+'px')
                        .find('select').css('width',(ch_width + 8)+'px')
                        .parent().find('span').css('width',(p_width - 20)+'px');    
                    $.uniform.update(select);
                });

            var p_width = select.parent().outerWidth();
            var ch_width = select.outerWidth();
            select.uniform({selectClass:'selector uni1'})
                .parent().css('width',p_width+'px')
                .find('select').css('width',(ch_width + 8)+'px')
                .parent().find('span').css('width',(p_width - 20)+'px');            

        });

    }
});

Alert returns undefined in IE7, but in all other browsers it returns function.

Help, can't figure out where is problem.

+1  A: 

window onload probably fires before the function is bound in IE. You should define the $.fn before document ready.

$(window).load(function(){

alert(typeof $.fn.init_deps);

});
(function($){

    $.fn.init_deps = function(s){

        var o = {
            deps:false,
            cats:false              
        }
        $.extend(o,s);

        if(!s.deps || !s.cats) {return;}
        return this.each(function(){

            var select = $('<select id="department" name="department"></select>')
                .appendTo(this)
                .departments(s)
                .change(function(){
                    var select = $('select#category');
                    select.categories({cats:s.cats,current_dep:$(this).val()});

                    var p_width = select.parent().outerWidth();
                    var ch_width = select.outerWidth();
                    select.parent().css('width',p_width+'px')
                        .find('select').css('width',(ch_width + 8)+'px')
                        .parent().find('span').css('width',(p_width - 20)+'px');    
                    $.uniform.update(select);
                });

            var p_width = select.parent().outerWidth();
            var ch_width = select.outerWidth();
            select.uniform({selectClass:'selector uni1'})
                .parent().css('width',p_width+'px')
                .find('select').css('width',(ch_width + 8)+'px')
                .parent().find('span').css('width',(p_width - 20)+'px');            

        });

    }
})(jQuery);
meder
IE doesn't throw alert at all and throws no errors. I'm totally confused. But i does throw alert if I remove functions completely.
Beck
that means there's a script error. try commenting out portions of the code, like the parts where you are mathematically assigning width/height and see if its in the right format. also make sure you aren't using IE reserved words, try giving certain variables a different name.
meder
Make sure `$.fn.departments` and `$.fn.categories` is also assigned BEFORE DOM READY by putting it in the `(function($){` function.
meder
Damn i have found where it stops. var o = {deps:false,} further in the code. But WHY IE haven't thrown an error? Sorry everyone.
Beck
+1  A: 

$document.ready works differently in different browsers. In IE it will bind to windows onload

window.attachEvent( "onload", jQuery.ready );

Therefore you can't count on code in a document.ready block to run before an onload block.

Matthew Manela