Click here to Skip to main content
15,909,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How would I delay Jquery Address script by about 1 second before script fires? Many Thanks.
JavaScript
<script type="text/javascript">

    var tabs,
        tabulation = false,
        initialTab = 'Overview',
        navSelector = '#tabs .ui-tabs-nav',
        navFilter = function(el) {
            return $(el).attr('href').replace(/^#/, '');
        },
        panelSelector = '#tabs .ui-tabs-panel',
        panelFilter = function() {
            $(panelSelector + ' a').filter(function() {
                return $(navSelector + ' a[title=' + $(this).attr('title') + ']').size() != 0;
            }).each(function(event) {
                $(this).attr('href', '#' + $(this).attr('title').replace(/ /g, '_'));
            });
        };

    if ($.address.value() == '') {
        $.address.value(initialTab);
    }

    // Address handler
    $.address.history(false).strict(false).wrap(true).init(function(event) {

        // Adds the ID in a lazy manner to prevent scrolling
        $(panelSelector).attr('id', initialTab);

        // Enables the plugin for all the content links
        $(panelSelector + ' a').address(function() {
            return navFilter(this);
        });

        panelFilter();

        // Tabs setup
        tabs = $('#tabs')
            .tabs({
                load: function(event, ui) {
                    // Filters the content and applies the plugin if needed
                    $(ui.panel).html($(panelSelector, ui.panel).html());
                    panelFilter();
                },
                fx: {
                    opacity: 'toggle',
                    duration: 'slow'
                }
            })
            .css('display', 'block');

        // Enables the plugin for all the tabs
        $(navSelector + ' a').click(function(event) {
            tabulation = true;
            $.address.value(navFilter(event.target));
            tabulation = false;
            return false;
        });

    }).change(function(event) {

        var current = $('a[href=#' + event.value + ']:first');

        // Sets the page title
        $.address.title($.address.title().split(' | ')[0] + ' | ' + current.text());

        // Selects the proper tab
        if (!tabulation) {
            tabs.tabs('select', current.attr('href'));
        }

    }).history(true);

    // Hides the tabs during initialization
    document.write('<style type="text/css"> #tabs { display: none; } </style>');

</script>
Posted
Updated 9-Sep-11 14:01pm
v2
Comments
DaveAuld 10-Sep-11 6:43am    
wrap the script in a function and call it using a setTimeout(xxx,functionName);

Insert .delay(1000) before the bit you want to wait for a second - see the docs[^] for details.
 
Share this answer
 
Thanks for the help dudes. I chose Daves method as it helped me isolate the code and call it when needed. see you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900