diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/darkfish.js | 84 | ||||
-rw-r--r-- | js/navigation.js | 105 | ||||
-rw-r--r-- | js/navigation.js.gz | bin | 0 -> 833 bytes | |||
-rw-r--r-- | js/search.js | 110 | ||||
-rw-r--r-- | js/search_index.js | 1 | ||||
-rw-r--r-- | js/search_index.js.gz | bin | 0 -> 3942 bytes | |||
-rw-r--r-- | js/searcher.js | 229 | ||||
-rw-r--r-- | js/searcher.js.gz | bin | 0 -> 1688 bytes |
8 files changed, 529 insertions, 0 deletions
diff --git a/js/darkfish.js b/js/darkfish.js new file mode 100644 index 0000000..111bbf8 --- /dev/null +++ b/js/darkfish.js @@ -0,0 +1,84 @@ +/** + * + * Darkfish Page Functions + * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $ + * + * Author: Michael Granger <mgranger@laika.com> + * + */ + +/* Provide console simulation for firebug-less environments */ +/* +if (!("console" in window) || !("firebug" in console)) { + 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() {}; +}; +*/ + + +function showSource( e ) { + var target = e.target; + while (!target.classList.contains('method-detail')) { + target = target.parentNode; + } + if (typeof target !== "undefined" && target !== null) { + target = target.querySelector('.method-source-code'); + } + if (typeof target !== "undefined" && target !== null) { + target.classList.toggle('active-menu') + } +}; + +function hookSourceViews() { + document.querySelectorAll('.method-heading').forEach(function (codeObject) { + codeObject.addEventListener('click', showSource); + }); +}; + +function hookSearch() { + var input = document.querySelector('#search-field'); + var result = document.querySelector('#search-results'); + result.classList.remove("initially-hidden"); + + var search_section = document.querySelector('#search-section'); + search_section.classList.remove("initially-hidden"); + + 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="' + index_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) { + window.location.href = result.firstChild.firstChild.href; + } + + search.scrollIntoView = search.scrollInWindow; +}; + +document.addEventListener('DOMContentLoaded', function() { + hookSourceViews(); + hookSearch(); +}); diff --git a/js/navigation.js b/js/navigation.js new file mode 100644 index 0000000..dfad74b --- /dev/null +++ b/js/navigation.js @@ -0,0 +1,105 @@ +/* + * Navigation allows movement using the arrow keys through the search results. + * + * When using this library you will need to set scrollIntoView to the + * appropriate function for your layout. Use scrollInWindow if the container + * is not scrollable and scrollInElement if the container is a separate + * scrolling region. + */ +Navigation = new function() { + this.initNavigation = function() { + var _this = this; + + document.addEventListener('keydown', function(e) { + _this.onkeydown(e); + }); + + this.navigationActive = true; + } + + this.setNavigationActive = function(state) { + this.navigationActive = state; + } + + this.onkeydown = function(e) { + if (!this.navigationActive) return; + switch(e.keyCode) { + case 37: //Event.KEY_LEFT: + if (this.moveLeft()) e.preventDefault(); + break; + case 38: //Event.KEY_UP: + if (e.keyCode == 38 || e.ctrlKey) { + if (this.moveUp()) e.preventDefault(); + } + break; + case 39: //Event.KEY_RIGHT: + if (this.moveRight()) e.preventDefault(); + break; + case 40: //Event.KEY_DOWN: + if (e.keyCode == 40 || e.ctrlKey) { + if (this.moveDown()) e.preventDefault(); + } + break; + case 13: //Event.KEY_RETURN: + if (this.current) e.preventDefault(); + this.select(this.current); + break; + } + if (e.ctrlKey && e.shiftKey) this.select(this.current); + } + + this.moveRight = function() { + } + + this.moveLeft = function() { + } + + this.move = function(isDown) { + } + + this.moveUp = function() { + return this.move(false); + } + + this.moveDown = function() { + return this.move(true); + } + + /* + * Scrolls to the given element in the scrollable element view. + */ + this.scrollInElement = function(element, view) { + var offset, viewHeight, viewScroll, height; + offset = element.offsetTop; + height = element.offsetHeight; + viewHeight = view.offsetHeight; + viewScroll = view.scrollTop; + + if (offset - viewScroll + height > viewHeight) { + view.scrollTop = offset - viewHeight + height; + } + if (offset < viewScroll) { + view.scrollTop = offset; + } + } + + /* + * Scrolls to the given element in the window. The second argument is + * ignored + */ + this.scrollInWindow = function(element, ignored) { + var offset, viewHeight, viewScroll, height; + offset = element.offsetTop; + height = element.offsetHeight; + viewHeight = window.innerHeight; + viewScroll = window.scrollY; + + if (offset - viewScroll + height > viewHeight) { + window.scrollTo(window.scrollX, offset - viewHeight + height); + } + if (offset < viewScroll) { + window.scrollTo(window.scrollX, offset); + } + } +} + diff --git a/js/navigation.js.gz b/js/navigation.js.gz Binary files differnew file mode 100644 index 0000000..dbb8b1a --- /dev/null +++ b/js/navigation.js.gz diff --git a/js/search.js b/js/search.js new file mode 100644 index 0000000..b558ca5 --- /dev/null +++ b/js/search.js @@ -0,0 +1,110 @@ +Search = function(data, input, result) { + this.data = data; + this.input = input; + this.result = result; + + this.current = null; + this.view = this.result.parentNode; + this.searcher = new Searcher(data.index); + this.init(); +} + +Search.prototype = Object.assign({}, Navigation, new function() { + var suid = 1; + + this.init = function() { + var _this = this; + var observer = function(e) { + switch(e.keyCode) { + case 38: // Event.KEY_UP + case 40: // Event.KEY_DOWN + return; + } + _this.search(_this.input.value); + }; + this.input.addEventListener('keyup', observer); + this.input.addEventListener('click', observer); // mac's clear field + + this.searcher.ready(function(results, isLast) { + _this.addResults(results, isLast); + }) + + this.initNavigation(); + this.setNavigationActive(false); + } + + this.search = function(value, selectFirstMatch) { + value = value.trim().toLowerCase(); + if (value) { + this.setNavigationActive(true); + } else { + this.setNavigationActive(false); + } + + if (value == '') { + this.lastQuery = value; + this.result.innerHTML = ''; + this.result.setAttribute('aria-expanded', 'false'); + this.setNavigationActive(false); + } else if (value != this.lastQuery) { + this.lastQuery = value; + this.result.setAttribute('aria-busy', 'true'); + this.result.setAttribute('aria-expanded', 'true'); + this.firstRun = true; + this.searcher.find(value); + } + } + + this.addResults = function(results, isLast) { + var target = this.result; + if (this.firstRun && (results.length > 0 || isLast)) { + this.current = null; + this.result.innerHTML = ''; + } + + for (var i=0, l = results.length; i < l; i++) { + var item = this.renderItem.call(this, results[i]); + item.setAttribute('id', 'search-result-' + target.childElementCount); + target.appendChild(item); + }; + + if (this.firstRun && results.length > 0) { + this.firstRun = false; + this.current = target.firstChild; + this.current.classList.add('search-selected'); + } + //TODO: ECMAScript + //if (jQuery.browser.msie) this.$element[0].className += ''; + + if (isLast) this.result.setAttribute('aria-busy', 'false'); + } + + this.move = function(isDown) { + if (!this.current) return; + var next = isDown ? this.current.nextElementSibling : this.current.previousElementSibling; + if (next) { + this.current.classList.remove('search-selected'); + next.classList.add('search-selected'); + this.input.setAttribute('aria-activedescendant', next.getAttribute('id')); + this.scrollIntoView(next, this.view); + this.current = next; + this.input.value = next.firstChild.firstChild.text; + this.input.select(); + } + return true; + } + + this.hlt = function(html) { + return this.escapeHTML(html). + replace(/\u0001/g, '<em>'). + replace(/\u0002/g, '</em>'); + } + + this.escapeHTML = function(html) { + return html.replace(/[&<>]/g, function(c) { + return '&#' + c.charCodeAt(0) + ';'; + }); + } + +}); + diff --git a/js/search_index.js b/js/search_index.js new file mode 100644 index 0000000..97c314a --- /dev/null +++ b/js/search_index.js @@ -0,0 +1 @@ +var search_data = {"index":{"searchIndex":["array","diff","diff::lcs::internals","diff::lcs::ldiff","fixnum","lcs","balancedcallbacks","block","change","contextchange","contextdiffcallbacks","defaultcallbacks","diffcallbacks","htmldiff","hunk","sdiffcallbacks","sequencecallbacks","string","<=>()","<=>()","==()","==()","lcs()","adding?()","analyze_patchset()","callbacks_for()","change()","change()","change()","change()","change()","changed?()","deleting?()","diff()","diff()","diff()","diff_size()","discard_a()","discard_a()","discard_a()","discard_a()","discard_a()","discard_a()","discard_b()","discard_b()","discard_b()","discard_b()","discard_b()","discard_b()","finish()","finished_a?()","finished_b?()","from_a()","from_a()","inspect()","intuit_diff_direction()","lcs()","lcs()","lcs()","match()","match()","match()","match()","match()","merge()","missing_last_newline?()","new()","new()","new()","new()","new()","new()","new()","op()","overlaps?()","patch()","patch()","patch!()","patch!()","patch_me()","positive?()","run()","sdiff()","sdiff()","simplify()","to_a()","to_a()","to_ary()","to_ary()","traverse_balanced()","traverse_balanced()","traverse_sequences()","traverse_sequences()","unchanged?()","unpatch()","unpatch!()","unpatch!()","unpatch_me()","unshift()","valid_action?()","code-of-conduct","contributing","history","license","manifest","readme","copying","artistic"],"longSearchIndex":["array","diff","diff::lcs::internals","diff::lcs::ldiff","fixnum","lcs","lcs::balancedcallbacks","lcs::block","lcs::change","lcs::contextchange","lcs::contextdiffcallbacks","lcs::defaultcallbacks","lcs::diffcallbacks","lcs::htmldiff","lcs::hunk","lcs::sdiffcallbacks","lcs::sequencecallbacks","string","lcs::change#<=>()","lcs::contextchange#<=>()","lcs::change#==()","lcs::contextchange#==()","lcs::lcs()","lcs::change#adding?()","diff::lcs::internals::analyze_patchset()","lcs::callbacks_for()","lcs::contextdiffcallbacks#change()","lcs::defaultcallbacks::change()","lcs::defaultcallbacks::change()","lcs::defaultcallbacks::change()","lcs::sdiffcallbacks#change()","lcs::change#changed?()","lcs::change#deleting?()","lcs::diff()","lcs#diff()","lcs::hunk#diff()","lcs::block#diff_size()","lcs::contextdiffcallbacks#discard_a()","lcs::defaultcallbacks::discard_a()","lcs::defaultcallbacks::discard_a()","lcs::defaultcallbacks::discard_a()","lcs::diffcallbacks#discard_a()","lcs::sdiffcallbacks#discard_a()","lcs::contextdiffcallbacks#discard_b()","lcs::defaultcallbacks::discard_b()","lcs::defaultcallbacks::discard_b()","lcs::defaultcallbacks::discard_b()","lcs::diffcallbacks#discard_b()","lcs::sdiffcallbacks#discard_b()","lcs::diffcallbacks#finish()","lcs::change#finished_a?()","lcs::change#finished_b?()","lcs::change::from_a()","lcs::contextchange::from_a()","lcs::change#inspect()","diff::lcs::internals::intuit_diff_direction()","diff::lcs::internals::lcs()","lcs::lcs()","lcs#lcs()","lcs::defaultcallbacks::match()","lcs::defaultcallbacks::match()","lcs::defaultcallbacks::match()","lcs::diffcallbacks#match()","lcs::sdiffcallbacks#match()","lcs::hunk#merge()","lcs::hunk#missing_last_newline?()","lcs::block::new()","lcs::change::new()","lcs::contextchange::new()","lcs::diffcallbacks::new()","lcs::htmldiff::new()","lcs::hunk::new()","lcs::sdiffcallbacks::new()","lcs::block#op()","lcs::hunk#overlaps?()","lcs#patch()","lcs::patch()","lcs::patch!()","lcs#patch!()","lcs#patch_me()","fixnum#positive?()","lcs::htmldiff#run()","lcs#sdiff()","lcs::sdiff()","lcs::contextchange::simplify()","lcs::change#to_a()","lcs::contextchange#to_a()","lcs::change#to_ary()","lcs::contextchange#to_ary()","lcs::traverse_balanced()","lcs#traverse_balanced()","lcs::traverse_sequences()","lcs#traverse_sequences()","lcs::change#unchanged?()","lcs#unpatch()","lcs#unpatch!()","lcs::unpatch!()","lcs#unpatch_me()","lcs::hunk#unshift()","lcs::change::valid_action?()","","","","","","","",""],"info":[["Array","","Array.html","",""],["Diff","","Diff.html","",""],["Diff::LCS::Internals","","Diff/LCS/Internals.html","",""],["Diff::LCS::Ldiff","","Diff/LCS/Ldiff.html","",""],["Fixnum","","Fixnum.html","",""],["LCS","","LCS.html","","<p>How Diff Works (by Mark-Jason Dominus)\n<p>I once read an article written by the authors of <code>diff</code>; they said …\n"],["LCS::BalancedCallbacks","","LCS/DefaultCallbacks.html","","<p>This callback object implements the default set of callback events, which only returns the event itself. …\n"],["LCS::Block","","LCS/Block.html","","<p>A block is an operation removing, adding, or changing a group of items. Basically, this is just a list …\n"],["LCS::Change","","LCS/Change.html","","<p>Represents a simplistic (non-contextual) change. Represents the removal or addition of an element from …\n"],["LCS::ContextChange","","LCS/ContextChange.html","","<p>Represents a contextual change. Contains the position and values of the elements in the old and the new …\n"],["LCS::ContextDiffCallbacks","","LCS/ContextDiffCallbacks.html","","<p>This will produce a compound array of contextual diff change objects. Each element in the #diffs array …\n"],["LCS::DefaultCallbacks","","LCS/DefaultCallbacks.html","","<p>This callback object implements the default set of callback events, which only returns the event itself. …\n"],["LCS::DiffCallbacks","","LCS/DiffCallbacks.html","","<p>This will produce a compound array of simple diff change objects. Each element in the #diffs array is …\n"],["LCS::HTMLDiff","","LCS/HTMLDiff.html","","<p>Produce a simple HTML diff view.\n"],["LCS::Hunk","","LCS/Hunk.html","","<p>A Hunk is a group of Blocks which overlap because of the context surrounding each block. (So if we're …\n"],["LCS::SDiffCallbacks","","LCS/SDiffCallbacks.html","","<p>This will produce a simple array of diff change objects. Each element in the #diffs array is a single …\n"],["LCS::SequenceCallbacks","","LCS/DefaultCallbacks.html","","<p>This callback object implements the default set of callback events, which only returns the event itself. …\n"],["String","","String.html","",""],["<=>","LCS::Change","LCS/Change.html#method-i-3C-3D-3E","(other)",""],["<=>","LCS::ContextChange","LCS/ContextChange.html#method-i-3C-3D-3E","(other)",""],["==","LCS::Change","LCS/Change.html#method-i-3D-3D","(other)",""],["==","LCS::ContextChange","LCS/ContextChange.html#method-i-3D-3D","(other)",""],["LCS","LCS","LCS.html#method-c-LCS","(seq1, seq2, &block)",""],["adding?","LCS::Change","LCS/Change.html#method-i-adding-3F","()",""],["analyze_patchset","Diff::LCS::Internals","Diff/LCS/Internals.html#method-c-analyze_patchset","(patchset, depth = 0)","<p>This method will analyze the provided patchset to provide a single-pass normalization (conversion of …\n"],["callbacks_for","LCS","LCS.html#method-c-callbacks_for","(callbacks)",""],["change","LCS::ContextDiffCallbacks","LCS/ContextDiffCallbacks.html#method-i-change","(event)",""],["change","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-change","(event)","<p>Called when both the old and new values have changed.\n"],["change","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-change","(event)","<p>Called when both the old and new values have changed.\n"],["change","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-change","(event)","<p>Called when both the old and new values have changed.\n"],["change","LCS::SDiffCallbacks","LCS/SDiffCallbacks.html#method-i-change","(event)",""],["changed?","LCS::Change","LCS/Change.html#method-i-changed-3F","()",""],["deleting?","LCS::Change","LCS/Change.html#method-i-deleting-3F","()",""],["diff","LCS","LCS.html#method-c-diff","(seq1, seq2, callbacks = nil, &block)","<p>#diff computes the smallest set of additions and deletions necessary to turn the first sequence into …\n"],["diff","LCS","LCS.html#method-i-diff","(other, callbacks = nil, &block)","<p>Returns the difference set between <code>self</code> and <code>other</code>. See Diff::LCS#diff.\n"],["diff","LCS::Hunk","LCS/Hunk.html#method-i-diff","(format, last = false)","<p>Returns a diff string based on a format.\n"],["diff_size","LCS::Block","LCS/Block.html#method-i-diff_size","()",""],["discard_a","LCS::ContextDiffCallbacks","LCS/ContextDiffCallbacks.html#method-i-discard_a","(event)",""],["discard_a","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-discard_a","(event)","<p>Called when the old value is discarded in favour of the new value.\n"],["discard_a","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-discard_a","(event)","<p>Called when the old value is discarded in favour of the new value.\n"],["discard_a","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-discard_a","(event)","<p>Called when the old value is discarded in favour of the new value.\n"],["discard_a","LCS::DiffCallbacks","LCS/DiffCallbacks.html#method-i-discard_a","(event)",""],["discard_a","LCS::SDiffCallbacks","LCS/SDiffCallbacks.html#method-i-discard_a","(event)",""],["discard_b","LCS::ContextDiffCallbacks","LCS/ContextDiffCallbacks.html#method-i-discard_b","(event)",""],["discard_b","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-discard_b","(event)","<p>Called when the new value is discarded in favour of the old value.\n"],["discard_b","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-discard_b","(event)","<p>Called when the new value is discarded in favour of the old value.\n"],["discard_b","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-discard_b","(event)","<p>Called when the new value is discarded in favour of the old value.\n"],["discard_b","LCS::DiffCallbacks","LCS/DiffCallbacks.html#method-i-discard_b","(event)",""],["discard_b","LCS::SDiffCallbacks","LCS/SDiffCallbacks.html#method-i-discard_b","(event)",""],["finish","LCS::DiffCallbacks","LCS/DiffCallbacks.html#method-i-finish","()","<p>Finalizes the diff process. If an unprocessed hunk still exists, then it is appended to the diff list. …\n"],["finished_a?","LCS::Change","LCS/Change.html#method-i-finished_a-3F","()",""],["finished_b?","LCS::Change","LCS/Change.html#method-i-finished_b-3F","()",""],["from_a","LCS::Change","LCS/Change.html#method-c-from_a","(arr)",""],["from_a","LCS::ContextChange","LCS/ContextChange.html#method-c-from_a","(arr)",""],["inspect","LCS::Change","LCS/Change.html#method-i-inspect","(*_args)",""],["intuit_diff_direction","Diff::LCS::Internals","Diff/LCS/Internals.html#method-c-intuit_diff_direction","(src, patchset, limit = nil)","<p>Examine the patchset and the source to see in which direction the patch should be applied.\n<p>WARNING: By …\n"],["lcs","Diff::LCS::Internals","Diff/LCS/Internals.html#method-c-lcs","(a, b)","<p>Compute the longest common subsequence between the sequenced Enumerables <code>a</code> and <code>b</code>. The result is an array …\n"],["lcs","LCS","LCS.html#method-c-lcs","(seq1, seq2, &block)",""],["lcs","LCS","LCS.html#method-i-lcs","(other, &block)","<p>Returns an Array containing the longest common subsequence(s) between <code>self</code> and <code>other</code>. See Diff::LCS#lcs …\n"],["match","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-match","(event)","<p>Called when two items match.\n"],["match","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-match","(event)","<p>Called when two items match.\n"],["match","LCS::DefaultCallbacks","LCS/DefaultCallbacks.html#method-c-match","(event)","<p>Called when two items match.\n"],["match","LCS::DiffCallbacks","LCS/DiffCallbacks.html#method-i-match","(_event)",""],["match","LCS::SDiffCallbacks","LCS/SDiffCallbacks.html#method-i-match","(event)",""],["merge","LCS::Hunk","LCS/Hunk.html#method-i-merge","(hunk)","<p>Merges this hunk and the provided hunk together if they overlap. Returns a truthy value so that if there …\n"],["missing_last_newline?","LCS::Hunk","LCS/Hunk.html#method-i-missing_last_newline-3F","(data)",""],["new","LCS::Block","LCS/Block.html#method-c-new","(chunk)",""],["new","LCS::Change","LCS/Change.html#method-c-new","(*args)",""],["new","LCS::ContextChange","LCS/ContextChange.html#method-c-new","(*args)",""],["new","LCS::DiffCallbacks","LCS/DiffCallbacks.html#method-c-new","()",""],["new","LCS::HTMLDiff","LCS/HTMLDiff.html#method-c-new","(left, right, options = nil)",""],["new","LCS::Hunk","LCS/Hunk.html#method-c-new","(data_old, data_new, piece, flag_context, file_length_difference)","<p>Create a hunk using references to both the old and new data, as well as the piece of data.\n"],["new","LCS::SDiffCallbacks","LCS/SDiffCallbacks.html#method-c-new","()",""],["op","LCS::Block","LCS/Block.html#method-i-op","()",""],["overlaps?","LCS::Hunk","LCS/Hunk.html#method-i-overlaps-3F","(hunk)","<p>Determines whether there is an overlap between this hunk and the provided hunk. This will be true if …\n"],["patch","LCS","LCS.html#method-i-patch","(patchset)","<p>Attempts to patch <code>self</code> with the provided <code>patchset</code>. A new sequence based on <code>self</code> and the <code>patchset</code> will …\n"],["patch","LCS","LCS.html#method-c-patch","(src, patchset, direction = nil)","<p>Applies a <code>patchset</code> to the sequence <code>src</code> according to the <code>direction</code> (<code>:patch</code> or <code>:unpatch</code>), producing a new …\n"],["patch!","LCS","LCS.html#method-c-patch-21","(src, patchset)","<p>Given a set of patchset, convert the current version to the next version. Does no auto-discovery.\n"],["patch!","LCS","LCS.html#method-i-patch-21","(patchset)","<p>Attempts to patch <code>self</code> with the provided <code>patchset</code>. A new sequence based on <code>self</code> and the <code>patchset</code> will …\n"],["patch_me","LCS","LCS.html#method-i-patch_me","(patchset)","<p>Attempts to patch <code>self</code> with the provided <code>patchset</code>, using #patch!. If the sequence this is used on supports …\n"],["positive?","Fixnum","Fixnum.html#method-i-positive-3F","()",""],["run","LCS::HTMLDiff","LCS/HTMLDiff.html#method-i-run","()",""],["sdiff","LCS","LCS.html#method-i-sdiff","(other, callbacks = nil, &block)","<p>Returns the balanced (“side-by-side”) difference set between <code>self</code> and <code>other</code>. See Diff::LCS#sdiff …\n"],["sdiff","LCS","LCS.html#method-c-sdiff","(seq1, seq2, callbacks = nil, &block)","<p>#sdiff computes all necessary components to show two sequences and their minimized differences side by …\n"],["simplify","LCS::ContextChange","LCS/ContextChange.html#method-c-simplify","(event)","<p>Simplifies a context change for use in some diff callbacks. '<' actions are converted to '-' …\n"],["to_a","LCS::Change","LCS/Change.html#method-i-to_a","()",""],["to_a","LCS::ContextChange","LCS/ContextChange.html#method-i-to_a","()",""],["to_ary","LCS::Change","LCS/Change.html#method-i-to_ary","()",""],["to_ary","LCS::ContextChange","LCS/ContextChange.html#method-i-to_ary","()",""],["traverse_balanced","LCS","LCS.html#method-c-traverse_balanced","(seq1, seq2, callbacks = Diff::LCS::BalancedCallbacks)","<p>#traverse_balanced is an alternative to #traverse_sequences. It uses a different algorithm to iterate …\n"],["traverse_balanced","LCS","LCS.html#method-i-traverse_balanced","(other, callbacks = nil, &block)","<p>Traverses the discovered longest common subsequences between <code>self</code> and <code>other</code> using the alternate, balanced …\n"],["traverse_sequences","LCS","LCS.html#method-c-traverse_sequences","(seq1, seq2, callbacks = Diff::LCS::SequenceCallbacks)","<p>#traverse_sequences is the most general facility provided by this module; #diff and #lcs are implemented …\n"],["traverse_sequences","LCS","LCS.html#method-i-traverse_sequences","(other, callbacks = nil, &block)","<p>Traverses the discovered longest common subsequences between <code>self</code> and <code>other</code>. See Diff::LCS#traverse_sequences …\n"],["unchanged?","LCS::Change","LCS/Change.html#method-i-unchanged-3F","()",""],["unpatch","LCS","LCS.html#method-i-unpatch","(patchset)",""],["unpatch!","LCS","LCS.html#method-i-unpatch-21","(patchset)","<p>Attempts to unpatch <code>self</code> with the provided <code>patchset</code>. A new sequence based on <code>self</code> and the <code>patchset</code> will …\n"],["unpatch!","LCS","LCS.html#method-c-unpatch-21","(src, patchset)","<p>Given a set of patchset, convert the current version to the prior version. Does no auto-discovery.\n"],["unpatch_me","LCS","LCS.html#method-i-unpatch_me","(patchset)","<p>Attempts to unpatch <code>self</code> with the provided <code>patchset</code>, using #unpatch!. If the sequence this is used on …\n"],["unshift","LCS::Hunk","LCS/Hunk.html#method-i-unshift","(hunk)",""],["valid_action?","LCS::Change","LCS/Change.html#method-c-valid_action-3F","(action)",""],["Code-of-Conduct","","Code-of-Conduct_md.html","","<p>Contributor Covenant Code of Conduct\n<p>Our Pledge\n<p>In the interest of fostering an open and welcoming environment, …\n"],["Contributing","","Contributing_md.html","","<p>Contributing\n<p>I value any contribution to Diff::LCS you can provide: a bug report, a\nfeature request, or ...\n"],["History","","History_md.html","","<p>History\n<p>1.5.0 / 2021-12-23\n<p>Updated the CI configuration and monkey-patch Hoe.\n"],["License","","License_md.html","","<p>== License\n<p>This software is available under three licenses: the GNU GPL version 2 (or at\nyour option, ...\n"],["Manifest","","Manifest_txt.html","","<p>.rspec Code-of-Conduct.md Contributing.md History.md License.md Manifest.txt README.rdoc Rakefile bin/htmldiff …\n"],["README","","README_rdoc.html","","<p>Diff::LCS\n<p>home — github.com/halostatue/diff-lcs\n<p>code — github.com/halostatue/diff-lcs\n"],["COPYING","","docs/COPYING_txt.html","","\n<pre> GNU GENERAL PUBLIC LICENSE\n Version 2, June 1991\n\nCopyright (C) ...</pre>\n"],["artistic","","docs/artistic_txt.html","","<p>The “Artistic License”\n\n<pre class=\"ruby\"><span class=\"ruby-constant\">Preamble</span>\n</pre>\n<p>The intent of this document is to state the conditions under …\n"]]}}
\ No newline at end of file diff --git a/js/search_index.js.gz b/js/search_index.js.gz Binary files differnew file mode 100644 index 0000000..227a624 --- /dev/null +++ b/js/search_index.js.gz diff --git a/js/searcher.js b/js/searcher.js new file mode 100644 index 0000000..e200a16 --- /dev/null +++ b/js/searcher.js @@ -0,0 +1,229 @@ +Searcher = function(data) { + this.data = data; + this.handlers = []; +} + +Searcher.prototype = new function() { + // search is performed in chunks of 1000 for non-blocking user input + var CHUNK_SIZE = 1000; + // do not try to find more than 100 results + var MAX_RESULTS = 100; + var huid = 1; + var suid = 1; + var runs = 0; + + this.find = function(query) { + var queries = splitQuery(query); + var regexps = buildRegexps(queries); + var highlighters = buildHilighters(queries); + var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++}; + var _this = this; + + this.currentSuid = state.n; + + if (!query) return; + + var run = function() { + // stop current search thread if new search started + if (state.n != _this.currentSuid) return; + + var results = + performSearch(_this.data, regexps, queries, highlighters, state); + var hasMore = (state.limit > 0 && state.pass < 4); + + triggerResults.call(_this, results, !hasMore); + if (hasMore) { + setTimeout(run, 2); + } + runs++; + }; + runs = 0; + + // start search thread + run(); + } + + /* ----- Events ------ */ + this.ready = function(fn) { + fn.huid = huid; + this.handlers.push(fn); + } + + /* ----- Utilities ------ */ + function splitQuery(query) { + return query.split(/(\s+|::?|\(\)?)/).filter(function(string) { + return string.match(/\S/); + }); + } + + function buildRegexps(queries) { + return queries.map(function(query) { + return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i'); + }); + } + + function buildHilighters(queries) { + return queries.map(function(query) { + return query.split('').map(function(l, i) { + return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2); + }).join(''); + }); + } + + // function longMatchRegexp(index, longIndex, regexps) { + // for (var i = regexps.length - 1; i >= 0; i--){ + // if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false; + // }; + // return true; + // } + + + /* ----- Mathchers ------ */ + + /* + * This record matches if the index starts with queries[0] and the record + * matches all of the regexps + */ + function matchPassBeginning(index, longIndex, queries, regexps) { + if (index.indexOf(queries[0]) != 0) return false; + for (var i=1, l = regexps.length; i < l; i++) { + if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) + return false; + }; + return true; + } + + /* + * This record matches if the longIndex starts with queries[0] and the + * longIndex matches all of the regexps + */ + function matchPassLongIndex(index, longIndex, queries, regexps) { + if (longIndex.indexOf(queries[0]) != 0) return false; + for (var i=1, l = regexps.length; i < l; i++) { + if (!longIndex.match(regexps[i])) + return false; + }; + return true; + } + + /* + * This record matches if the index contains queries[0] and the record + * matches all of the regexps + */ + function matchPassContains(index, longIndex, queries, regexps) { + if (index.indexOf(queries[0]) == -1) return false; + for (var i=1, l = regexps.length; i < l; i++) { + if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) + return false; + }; + return true; + } + + /* + * This record matches if regexps[0] matches the index and the record + * matches all of the regexps + */ + function matchPassRegexp(index, longIndex, queries, regexps) { + if (!index.match(regexps[0])) return false; + for (var i=1, l = regexps.length; i < l; i++) { + if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) + return false; + }; + return true; + } + + + /* ----- Highlighters ------ */ + function highlightRegexp(info, queries, regexps, highlighters) { + var result = createResult(info); + for (var i=0, l = regexps.length; i < l; i++) { + result.title = result.title.replace(regexps[i], highlighters[i]); + result.namespace = result.namespace.replace(regexps[i], highlighters[i]); + }; + return result; + } + + function hltSubstring(string, pos, length) { + return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length); + } + + function highlightQuery(info, queries, regexps, highlighters) { + var result = createResult(info); + var pos = 0; + var lcTitle = result.title.toLowerCase(); + + pos = lcTitle.indexOf(queries[0]); + if (pos != -1) { + result.title = hltSubstring(result.title, pos, queries[0].length); + } + + result.namespace = result.namespace.replace(regexps[0], highlighters[0]); + for (var i=1, l = regexps.length; i < l; i++) { + result.title = result.title.replace(regexps[i], highlighters[i]); + result.namespace = result.namespace.replace(regexps[i], highlighters[i]); + }; + return result; + } + + function createResult(info) { + var result = {}; + result.title = info[0]; + result.namespace = info[1]; + result.path = info[2]; + result.params = info[3]; + result.snippet = info[4]; + result.badge = info[6]; + return result; + } + + /* ----- Searching ------ */ + function performSearch(data, regexps, queries, highlighters, state) { + var searchIndex = data.searchIndex; + var longSearchIndex = data.longSearchIndex; + var info = data.info; + var result = []; + var i = state.from; + var l = searchIndex.length; + var togo = CHUNK_SIZE; + var matchFunc, hltFunc; + + while (state.pass < 4 && state.limit > 0 && togo > 0) { + if (state.pass == 0) { + matchFunc = matchPassBeginning; + hltFunc = highlightQuery; + } else if (state.pass == 1) { + matchFunc = matchPassLongIndex; + hltFunc = highlightQuery; + } else if (state.pass == 2) { + matchFunc = matchPassContains; + hltFunc = highlightQuery; + } else if (state.pass == 3) { + matchFunc = matchPassRegexp; + hltFunc = highlightRegexp; + } + + for (; togo > 0 && i < l && state.limit > 0; i++, togo--) { + if (info[i].n == state.n) continue; + if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) { + info[i].n = state.n; + result.push(hltFunc(info[i], queries, regexps, highlighters)); + state.limit--; + } + }; + if (searchIndex.length <= i) { + state.pass++; + i = state.from = 0; + } else { + state.from = i; + } + } + return result; + } + + function triggerResults(results, isLast) { + this.handlers.forEach(function(fn) { + fn.call(this, results, isLast) + }); + } +} + diff --git a/js/searcher.js.gz b/js/searcher.js.gz Binary files differnew file mode 100644 index 0000000..04e4b07 --- /dev/null +++ b/js/searcher.js.gz |