summaryrefslogtreecommitdiff
path: root/lib/rdoc/generator/template/darkfish/js/darkfish.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/generator/template/darkfish/js/darkfish.js')
-rw-r--r--lib/rdoc/generator/template/darkfish/js/darkfish.js161
1 files changed, 99 insertions, 62 deletions
diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js
index 84565c1e2d..4be722fac3 100644
--- a/lib/rdoc/generator/template/darkfish/js/darkfish.js
+++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js
@@ -9,12 +9,12 @@
/* Provide console simulation for firebug-less environments */
if (!("console" in window) || !("firebug" in console)) {
- var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
+ var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
- window.console = {};
- for (var i = 0; i < names.length; ++i)
- window.console[names[i]] = function() {};
+ window.console = {};
+ for (var i = 0; i < names.length; ++i)
+ window.console[names[i]] = function() {};
};
@@ -23,94 +23,131 @@ if (!("console" in window) || !("firebug" in console)) {
*/
$.fn.unwrap = function( expr ) {
return this.each( function() {
- $(this).parents( expr ).eq( 0 ).after( this ).remove();
+ $(this).parents( expr ).eq( 0 ).after( this ).remove();
});
};
function showSource( e ) {
- var target = e.target;
- var codeSections = $(target).
- parents('.method-detail').
- find('.method-source-code');
-
- $(target).
- parents('.method-detail').
- find('.method-source-code').
- slideToggle();
+ var target = e.target;
+ var codeSections = $(target).
+ parents('.method-detail').
+ find('.method-source-code');
+
+ $(target).
+ parents('.method-detail').
+ find('.method-source-code').
+ slideToggle();
};
function hookSourceViews() {
- $('.method-description,.method-heading').click( showSource );
+ $('.method-heading').click( showSource );
};
function toggleDebuggingSection() {
- $('.debugging-section').slideToggle();
+ $('.debugging-section').slideToggle();
};
function hookDebuggingToggle() {
- $('#debugging-toggle img').click( toggleDebuggingSection );
+ $('#debugging-toggle img').click( toggleDebuggingSection );
};
-function hookQuickSearch() {
- $('.quicksearch-field').each( function() {
- var searchElems = $(this).parents('.section').find( 'li' );
- var toggle = $(this).parents('.section').find('h3 .search-toggle');
- // console.debug( "Toggle is: %o", toggle );
- var qsbox = $(this).parents('form').get( 0 );
-
- $(this).quicksearch( this, searchElems, {
- noSearchResultsIndicator: 'no-class-search-results',
- focusOnLoad: false
- });
- $(toggle).click( function() {
- // console.debug( "Toggling qsbox: %o", qsbox );
- $(qsbox).toggle();
- });
- });
+function hookTableOfContentsToggle() {
+ $('.indexpage li .toc-toggle').each( function() {
+ $(this).click( function() {
+ $(this).toggleClass('open');
+ });
+
+ var section = $(this).next();
+
+ $(this).click( function() {
+ section.slideToggle();
+ });
+ });
+}
+
+function hookSearch() {
+ var input = $('#search-field').eq(0);
+ var result = $('#search-results').eq(0);
+ $(result).show();
+
+ var search_section = $('#search-section').get(0);
+ $(search_section).show();
+
+ var search = new Search(search_data, input, result);
+
+ search.renderItem = function(result) {
+ var li = document.createElement('li');
+ var html = '';
+
+ // TODO add relative path to <script> per-page
+ html += '<p class="search-match"><a href="' + rdoc_rel_prefix + result.path + '">' + this.hlt(result.title);
+ if (result.params)
+ html += '<span class="params">' + result.params + '</span>';
+ html += '</a>';
+
+
+ if (result.namespace)
+ html += '<p class="search-namespace">' + this.hlt(result.namespace);
+
+ if (result.snippet)
+ html += '<div class="search-snippet">' + result.snippet + '</div>';
+
+ li.innerHTML = html;
+
+ return li;
+ }
+
+ search.select = function(result) {
+ var result_element = result.get(0);
+ window.location.href = result_element.firstChild.firstChild.href;
+ }
+
+ search.scrollIntoView = search.scrollInWindow;
};
function highlightTarget( anchor ) {
- console.debug( "Highlighting target '%s'.", anchor );
-
- $("a[name=" + anchor + "]").each( function() {
- if ( !$(this).parent().parent().hasClass('target-section') ) {
- console.debug( "Wrapping the target-section" );
- $('div.method-detail').unwrap( 'div.target-section' );
- $(this).parent().wrap( '<div class="target-section"></div>' );
- } else {
- console.debug( "Already wrapped." );
- }
- });
+ console.debug( "Highlighting target '%s'.", anchor );
+
+ $("a[name=" + anchor + "]").each( function() {
+ if ( !$(this).parent().parent().hasClass('target-section') ) {
+ console.debug( "Wrapping the target-section" );
+ $('div.method-detail').unwrap( 'div.target-section' );
+ $(this).parent().wrap( '<div class="target-section"></div>' );
+ } else {
+ console.debug( "Already wrapped." );
+ }
+ });
};
function highlightLocationTarget() {
- console.debug( "Location hash: %s", window.location.hash );
- if ( ! window.location.hash || window.location.hash.length == 0 ) return;
+ console.debug( "Location hash: %s", window.location.hash );
+ if ( ! window.location.hash || window.location.hash.length == 0 ) return;
- var anchor = window.location.hash.substring(1);
- console.debug( "Found anchor: %s; matching %s", anchor, "a[name=" + anchor + "]" );
+ var anchor = window.location.hash.substring(1);
+ console.debug( "Found anchor: %s; matching %s", anchor, "a[name=" + anchor + "]" );
- highlightTarget( anchor );
+ highlightTarget( anchor );
};
function highlightClickTarget( event ) {
- console.debug( "Highlighting click target for event %o", event.target );
- try {
- var anchor = $(event.target).attr( 'href' ).substring(1);
- console.debug( "Found target anchor: %s", anchor );
- highlightTarget( anchor );
- } catch ( err ) {
- console.error( "Exception while highlighting: %o", err );
- };
+ console.debug( "Highlighting click target for event %o", event.target );
+ try {
+ var anchor = $(event.target).attr( 'href' ).substring(1);
+ console.debug( "Found target anchor: %s", anchor );
+ highlightTarget( anchor );
+ } catch ( err ) {
+ console.error( "Exception while highlighting: %o", err );
+ };
};
$(document).ready( function() {
- hookSourceViews();
- hookDebuggingToggle();
- hookQuickSearch();
- highlightLocationTarget();
+ hookSourceViews();
+ hookDebuggingToggle();
+ hookSearch();
+ highlightLocationTarget();
+ hookTableOfContentsToggle();
- $('ul.link-list a').bind( "click", highlightClickTarget );
+ $('ul.link-list a').bind( "click", highlightClickTarget );
});