Initial commit
[porter2stemmer.git] / doc / js / darkfish.js
1 /**
2 *
3 * Darkfish Page Functions
4 * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
5 *
6 * Author: Michael Granger <mgranger@laika.com>
7 *
8 */
9
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"];
14
15 window.console = {};
16 for (var i = 0; i < names.length; ++i)
17 window.console[names[i]] = function() {};
18 };
19
20
21 /**
22 * Unwrap the first element that matches the given @expr@ from the targets and return them.
23 */
24 $.fn.unwrap = function( expr ) {
25 return this.each( function() {
26 $(this).parents( expr ).eq( 0 ).after( this ).remove();
27 });
28 };
29
30
31 function showSource( e ) {
32 var target = e.target;
33 var codeSections = $(target).
34 parents('.method-detail').
35 find('.method-source-code');
36
37 $(target).
38 parents('.method-detail').
39 find('.method-source-code').
40 slideToggle();
41 };
42
43 function hookSourceViews() {
44 $('.method-description,.method-heading').click( showSource );
45 };
46
47 function toggleDebuggingSection() {
48 $('.debugging-section').slideToggle();
49 };
50
51 function hookDebuggingToggle() {
52 $('#debugging-toggle img').click( toggleDebuggingSection );
53 };
54
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 );
61
62 $(this).quicksearch( this, searchElems, {
63 noSearchResultsIndicator: 'no-class-search-results',
64 focusOnLoad: false
65 });
66 $(toggle).click( function() {
67 // console.debug( "Toggling qsbox: %o", qsbox );
68 $(qsbox).toggle();
69 });
70 });
71 };
72
73 function highlightTarget( anchor ) {
74 console.debug( "Highlighting target '%s'.", anchor );
75
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>' );
81 } else {
82 console.debug( "Already wrapped." );
83 }
84 });
85 };
86
87 function highlightLocationTarget() {
88 console.debug( "Location hash: %s", window.location.hash );
89 if ( ! window.location.hash || window.location.hash.length == 0 ) return;
90
91 var anchor = window.location.hash.substring(1);
92 console.debug( "Found anchor: %s; matching %s", anchor, "a[name=" + anchor + "]" );
93
94 highlightTarget( anchor );
95 };
96
97 function highlightClickTarget( event ) {
98 console.debug( "Highlighting click target for event %o", event.target );
99 try {
100 var anchor = $(event.target).attr( 'href' ).substring(1);
101 console.debug( "Found target anchor: %s", anchor );
102 highlightTarget( anchor );
103 } catch ( err ) {
104 console.error( "Exception while highlighting: %o", err );
105 };
106 };
107
108
109 $(document).ready( function() {
110 hookSourceViews();
111 hookDebuggingToggle();
112 hookQuickSearch();
113 highlightLocationTarget();
114
115 $('ul.link-list a').bind( "click", highlightClickTarget );
116 });