3 * Darkfish Page Functions
4 * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
6 * Author: Michael Granger <mgranger@laika.com>
10 /* Provide console simulation for firebug-less environments */
11 if (!("console" in window) || !("firebug" in console)) {
12 var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
13 "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
16 for (var i = 0; i < names.length; ++i)
17 window.console[names[i]] = function() {};
22 * Unwrap the first element that matches the given @expr@ from the targets and return them.
24 $.fn.unwrap = function( expr ) {
25 return this.each( function() {
26 $(this).parents( expr ).eq( 0 ).after( this ).remove();
31 function showSource( e ) {
32 var target = e.target;
33 var codeSections = $(target).
34 parents('.method-detail').
35 find('.method-source-code');
38 parents('.method-detail').
39 find('.method-source-code').
43 function hookSourceViews() {
44 $('.method-description,.method-heading').click( showSource );
47 function toggleDebuggingSection() {
48 $('.debugging-section').slideToggle();
51 function hookDebuggingToggle() {
52 $('#debugging-toggle img').click( toggleDebuggingSection );
55 function hookQuickSearch() {
56 $('.quicksearch-field').each( function() {
57 var searchElems = $(this).parents('.section').find( 'li' );
58 var toggle = $(this).parents('.section').find('h3 .search-toggle');
59 // console.debug( "Toggle is: %o", toggle );
60 var qsbox = $(this).parents('form').get( 0 );
62 $(this).quicksearch( this, searchElems, {
63 noSearchResultsIndicator: 'no-class-search-results',
66 $(toggle).click( function() {
67 // console.debug( "Toggling qsbox: %o", qsbox );
73 function highlightTarget( anchor ) {
74 console.debug( "Highlighting target '%s'.", anchor );
76 $("a[name=" + anchor + "]").each( function() {
77 if ( !$(this).parent().parent().hasClass('target-section') ) {
78 console.debug( "Wrapping the target-section" );
79 $('div.method-detail').unwrap( 'div.target-section' );
80 $(this).parent().wrap( '<div class="target-section"></div>' );
82 console.debug( "Already wrapped." );
87 function highlightLocationTarget() {
88 console.debug( "Location hash: %s", window.location.hash );
89 if ( ! window.location.hash || window.location.hash.length == 0 ) return;
91 var anchor = window.location.hash.substring(1);
92 console.debug( "Found anchor: %s; matching %s", anchor, "a[name=" + anchor + "]" );
94 highlightTarget( anchor );
97 function highlightClickTarget( event ) {
98 console.debug( "Highlighting click target for event %o", event.target );
100 var anchor = $(event.target).attr( 'href' ).substring(1);
101 console.debug( "Found target anchor: %s", anchor );
102 highlightTarget( anchor );
104 console.error( "Exception while highlighting: %o", err );
109 $(document).ready( function() {
111 hookDebuggingToggle();
113 highlightLocationTarget();
115 $('ul.link-list a').bind( "click", highlightClickTarget );