views:

32

answers:

4

How can I move my initialization code i.e.

  <script type="text/javascript">
        $(document).ready(function() {
            var t; // This will be a timeout
            $('.navHover').mouseover(function() {
                if (t)
                {
                    clearTimeout(t);
                }

                $('.navigation').slideDown(400);
            }).mouseout(function() {
                t = setTimeout(function() {
                    $('.navigation').slideUp(400);
                }, 800); // .8 second delay before hiding
            });

            $('.navigation').mouseover(function() {
                if (t)
                {
                    clearTimeout(t);
                }
            }).mouseout(function() {
                t = setTimeout(function() {
                    $('.navigation').slideUp(400);
                }, 800); // .8 second delay before hiding
            });
        });
    </script>

Into a separate file? main.js?

Thanks

+1  A: 

What do you mean properly? Because it's in a document ready handler, you can safely just paste that code into a separate file and include it in the head of your page.

Tesserex
+1  A: 

This may seem too easy of a solution but can't you just copy from $(document) through to the closing tags '});' and paste that into a separate js file? Then load that file the way you would normally by using

<script type="text/javascript" src="main.js"></script>
Slevin
You might want to double check that `language` property =)
HurnsMobile
Haha Good catch. I'll have to pay more attention before giving my two cents.
Slevin
No worries, just have to be fast on the `edit` button!
HurnsMobile
A: 

Put it in a JS file and include that JS file the same way you include your jQuery file. Main will work fine.

knowncitizen
Only thing to look out for is to keep the link tags ordered by dependency. jQuery first, then libraries, then the body of your application code to be run at load.
sparkey0
+3  A: 

Simply create a text file, paste that code into it (minus the script tags) and add :

<script type="text/javascript" src="path-to\main.js"></script>

Into the <head> of your page.

HurnsMobile
Or, ideally, after the `</html>`.
mitjak