tags:

views:

20

answers:

1

Middle way down on jQuery UI's demo web page here what is the source code for the "View Source" link that opens and close a window of the source code?

+2  A: 

This is just a function in their script that hides and shows the source div:

if ($('#demo-source').length == 0) {
    $('<div id="demo-source"><a href="#" class="source-closed">View Source</a><div><pre><code></code></pre></div></div>').insertAfter('#demo-notes');
    $('#demo-source').find("> a").click(function() {
        $(this).toggleClass("source-closed").toggleClass("source-open").next().toggle();
        return false;
    }).end().find("> div").hide();
}
$('#demo-source code').empty().text(source);

You can view the full script here, it grabs the code via ajax ($.get() of the current page, or when you click a demo link on the right, grabs that one), formats it for display, then passes it into that function to insert a "view source" div/link at the right place in the page.

Nick Craver