NRuby
84 строки · 2.3 Кб
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/*
12if (!("console" in window) || !("firebug" in console)) {
13var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
14"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
15
16window.console = {};
17for (var i = 0; i < names.length; ++i)
18window.console[names[i]] = function() {};
19};
20*/
21
22
23function showSource( e ) {24var target = e.target;25while (!target.classList.contains('method-detail')) {26target = target.parentNode;27}28if (typeof target !== "undefined" && target !== null) {29target = target.querySelector('.method-source-code');30}31if (typeof target !== "undefined" && target !== null) {32target.classList.toggle('active-menu')33}34};35
36function hookSourceViews() {37document.querySelectorAll('.method-heading').forEach(function (codeObject) {38codeObject.addEventListener('click', showSource);39});40};41
42function hookSearch() {43var input = document.querySelector('#search-field');44var result = document.querySelector('#search-results');45result.classList.remove("initially-hidden");46
47var search_section = document.querySelector('#search-section');48search_section.classList.remove("initially-hidden");49
50var search = new Search(search_data, input, result);51
52search.renderItem = function(result) {53var li = document.createElement('li');54var html = '';55
56// TODO add relative path to <script> per-page57html += '<p class="search-match"><a href="' + index_rel_prefix + result.path + '">' + this.hlt(result.title);58if (result.params)59html += '<span class="params">' + result.params + '</span>';60html += '</a>';61
62
63if (result.namespace)64html += '<p class="search-namespace">' + this.hlt(result.namespace);65
66if (result.snippet)67html += '<div class="search-snippet">' + result.snippet + '</div>';68
69li.innerHTML = html;70
71return li;72}73
74search.select = function(result) {75window.location.href = result.firstChild.firstChild.href;76}77
78search.scrollIntoView = search.scrollInWindow;79};80
81document.addEventListener('DOMContentLoaded', function() {82hookSourceViews();83hookSearch();84});85