1

I am having to use document ready twice it was the only way after ripping apart code to get the menu working is there a better way of implementing it or what is going wrong for future reference? it was the ol accordion the top one that was causing the menu not to work. didnt work in the html as a and cant load it below or above the toggle menu - click div....

am i writing it wrong?

$(document).ready(function () {
            $('ol').accordion();
        });



$(document).ready(function() {
// TOGGLE MENU ~ CLICK DIV
    $('div.logo_menu').click(function() {
    $('#logo_menu ul').show('medium');
    return false;
  });

    $('#logo_menu a').click(function() {
    $(this).parents('ul').not('#logo_menu').hide('slow');
    return false;
  });

    $('#logo_menu ul').mouseleave(function() {
    $(this).hide('slow');
  });

// TOGGLE MENU ~ CLICK aHREF
/*
$('a.drop').hover(function(e) {
    $(this).next("div").slideDown('slow');
    console.log('div clicked');
    e.preventDefault();
    return false;
});
    $('li.mainmenudrop').mouseleave(function() {
    $(this).children("div").slideUp('medium');
  });
});*/  

// EXPAND PAGE
    $('.accordionButton').click(function() {
        //NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
        $('.accordionContent').slideToggle(500,'easeInOutQuad');
        //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
        if($(this).next().is(':hidden') == true) {
            //OPEN THE SLIDE
            $(this).next().slideToggle(500,'easeInOutQuad');
         } 
     });
    $('.accordionContent').hide();

$.extend($.easing,
 {
     easeInOutQuad: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t + b;
        return -c/2 * ((--t)*(t-2) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
        return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
    }

    });
//EXPAND PAGE DIV CONTENT SLIDE
$(".tab_item").mouseover(function() {
            var $this = $(this);
            $this.parent().find(".moving_bg").stop().animate({
                left: $this.position()['left']
            }, { duration: 500 });
    });
var TabbedContent = {
    current: {i:null, obj:null},
    init: function() {
        $(".tab_item").click(function() {
            var $this = $(this);
            TabbedContent.slideContent($this);
        });
        TabbedContent.current.i = 0;
        TabbedContent.current.obj = $(".tabslider li").eq(0);
    },
    slideContent: function($obj) {
        var $container = $obj.closest(".tabbed_content");
        var $tabslider = $container.find(".tabslider");
        var i = $obj.index() - 1;
        var $lis = $tabslider.find("li");
        $new = $lis.eq(i);
        if(i === TabbedContent.current.i) {
            return;
        }
        $lis.hide().filter($new.add(TabbedContent.current.obj)).show();
        var margin_1 = (i > TabbedContent.current.i) ? 0 : -$new.width();
        var margin_2 = (i < TabbedContent.current.i) ? 0 : -$new.width();
        $tabslider.stop().css({
            marginLeft: margin_1 + "px"
        }).animate({
            marginLeft: margin_2 + "px"
        }, 800);
        TabbedContent.current.i = i;
        TabbedContent.current.obj = $new;
    }
}
TabbedContent.init();

// BIG BOX SEARCH LEAVE
$(".searchbox").blur(function() {
    var searchbox = this,
        searchbox_val = $.trim( this.value );
    if (searchbox_val.length > 0) {
        $(searchbox).addClass("blur");
        return true;
    } else {
        $(searchbox).removeClass("blur");
        return false;
    }
});

// SELECT BOX LEAVE 
$(".selectlist").blur(function() {
    var selectlist = this,
        selectlist_val = $.trim( this.value );
    if (selectlist_val.length > 0) {
        $(selectlist).addClass("blur");
        return true;
    } else {
        $(selectlist).removeClass("blur");
        return false;
    }
});
/* TEXT AREA EXPAND */
$('#textareae').elastic();
/* END */

});
/* ALERT BOXES AND DIALOGS (Can Use: Name, ClassName = elements + Val.[0]/ Id = element, NO [0].
--------------------------------*/
function check_searchdomain_input() { // ALERT - Domain Search       
    var searchdomain_val = document.getElementById("searchdomain");
    if (searchdomain_val.value.length > 0) {
    return true;
    } else {
    $( "#dialog_domainsearch" ).dialog();
    return false;
    }
}

function check_menudomain_input() { // ALERT -  Menu domain search   
    var menudomain_val = document.getElementById("menudomain");
    if (menudomain_val.value.length > 0) {
    return true;
    } else{
    $( "#dialog_domainsearch" ).dialog();
    return false;
    }
}

function check_login_input() { // ALERT Login - Enter username       
    var login_val = document.getElementsByName("username");
    if (login_val[0].value.length > 0) {
    return true;
    } else {
    $( "#dialog_login" ).dialog();
    return false;
    }
}
mgibsonbr
  • 21,755
  • 7
  • 70
  • 112
alwayslearning
  • 411
  • 5
  • 18
  • 1
    using `ready()` method just add the functions to the list of function that will be called when the DOM is ready. So it is not a problem to call twice or more. If your menu does not work, its another problem. – MatRt Feb 12 '13 at 00:35
  • The menu works 100% now as long as i have the command as above will try the using ready and add it below with the rest. thank you – alwayslearning Feb 12 '13 at 00:38
  • ok mr hunting for duplicate posts check the users first! be helpful! – alwayslearning Feb 12 '13 at 00:39
  • like this (ready)(function () { $('ol').accordion(); }); – alwayslearning Feb 12 '13 at 00:41
  • didnt work menu is collapsed open again. – alwayslearning Feb 12 '13 at 00:42
  • @Dwhizz I saw m59's answer, but as he doesn't have enough rep to mark as duplicate, I did it myself (the comment above was put by the system, not me). And BTW closing a question is not a "punishment", just a way to organize site contents better. If your question is different from the one marked as possible duplicate, you can always improve it to highlight the difference, make it unique, this way it won't be closed (or, if already closed, can be reopened). – mgibsonbr Feb 12 '13 at 00:47
  • @Dwhizz and there's no need to put such statement in the top, close votes [expire after some time](http://meta.stackexchange.com/q/120896/177950), so the notice will go away if other users don't agree with it. Reverting... – mgibsonbr Feb 12 '13 at 00:52
  • Thats good keep up the good work, problem solved as to why still unsure. Lucky the post stayed open long enough. thanks you sir – alwayslearning Feb 12 '13 at 01:01
  • This looks to be a duplicate of http://stackoverflow.com/questions/1327756/can-you-have-multiple-document-readyfunction-sections. You can use as many as you want, but it is messy. – m59 Feb 12 '13 at 00:35

1 Answers1

1

so this doesn't work?

$(document).ready(function() {
$('ol').accordion();
// TOGGLE MENU ~ CLICK DIV
$('div.logo_menu').click(function() {
$('#logo_menu ul').show('medium');
return false;
//all the rest
kelly johnson
  • 1,596
  • 3
  • 16
  • 26
  • Yes indeed it does but it is the only place where it will work? doesnt work further down, is there a reason for future reference? – alwayslearning Feb 12 '13 at 00:49