diff options
author | Nina Vyedin <nina.vyedin@gmail.com> | 2013-03-05 02:56:19 +0400 |
---|---|---|
committer | Nina Vyedin <nina.vyedin@gmail.com> | 2013-03-05 07:54:32 +0400 |
commit | a17ec4720a373150ac199e6687291726b5eccd54 (patch) | |
tree | 85932e7808d11c5647005ebfd0e86c36334c1064 /webdoc | |
parent | 3f3bfb6c970574d31c446318164e0a01e353e79e (diff) |
[webdoc] add the search plugin
Diffstat (limited to 'webdoc')
-rw-r--r-- | webdoc/plugins/search-plugin/fullsearch.js | 40 | ||||
-rw-r--r-- | webdoc/plugins/search-plugin/search.css | 87 | ||||
-rw-r--r-- | webdoc/plugins/search-plugin/search.html | 24 | ||||
-rw-r--r-- | webdoc/plugins/search-plugin/search.js | 143 |
4 files changed, 294 insertions, 0 deletions
diff --git a/webdoc/plugins/search-plugin/fullsearch.js b/webdoc/plugins/search-plugin/fullsearch.js new file mode 100644 index 00000000..07229793 --- /dev/null +++ b/webdoc/plugins/search-plugin/fullsearch.js @@ -0,0 +1,40 @@ +//support for a full page of search results /monodoc.ashx?search= + +var spinner = $('#s_spinner'); +function process_hash () { + var query = window.location.hash; + if (query == null || query.length < 2) + return; + var ul = $('#s_results ul'); + ul.empty (); + var currentNumber = 0; + var count = 0; + // Remove hash '#' symbol + query = query.substring(1); + $('#s_term').text (query); + var fetch_and_add_results = function (url) { + spinner.toggleClass ('hidden'); + $.getJSON (url, function (data) { + spinner.toggleClass ('hidden'); + count = data.count; + currentNumber += data.result.length; + if (data.result.length == 0) { + $('<div/>', { 'class': 's_message' }).text('No more results').replaceAll($('#s_morebtn')).fadeOut(4000, function () { $(this).remove(); }); + } else { + var lis = $.map (data.result, function (element) { + return '<li><a href="/monodoc.ashx?link=' + element.url + '"><span class="name">' + + element.name + '</span> ' + + (element.fulltitle.length > 0 ? '<span class="fulltitle">(' + element.fulltitle + ')</span>' : '') + '</a></li>'; + }); + ul.append (lis.join ('')); + } + }); + }; + fetch_and_add_results ('/monodoc.ashx?search=' + query + '&callback=?'); + $('#s_morebtn input').click (function () { + fetch_and_add_results ('/monodoc.ashx?search=' + query + '&start=' + currentNumber + '&count=' + count + '&callback=?'); + }); +} + +process_hash (); +window.addEventListener("hashchange", process_hash, false); diff --git a/webdoc/plugins/search-plugin/search.css b/webdoc/plugins/search-plugin/search.css new file mode 100644 index 00000000..d50ab4f5 --- /dev/null +++ b/webdoc/plugins/search-plugin/search.css @@ -0,0 +1,87 @@ +#s_spinner, #s_header, #s_morebtn, .s_message { + text-align: center; +} + +#s_header { + margin-bottom: 1em; +} + +div.hidden { + display: none; + visibility: hidden; +} + +#s_results a { + color: #777; +} + +#s_results a:hover { + color: black; +} + +#s_results span.fulltitle { + font-style: italic; + font-size: 80%; +} + +#s_results li { + margin-bottom: 0.5em; +} + +#s_morebtn input { + font-size: x-large; + padding: 5px 14px 6px; +} + +#s_morebtn { + margin-bottom: 1em; +} + +.s_message { + font-size: xx-large; +} +#fsearch_window { + display: none; + opacity: 0; + position: absolute; + z-index: 60; + text-align: left; + width: 25em; + right: 80px; + top: 40px; + border: 1px solid black; + background: white; + padding: 5px; + overflow: hidden; + -webkit-transition: opacity 200ms linear 0; + -moz-transition: opacity 200ms linear 0; + -o-transition: opacity 200ms linear 0; +} + +#fsearch_window a { + color: blue; + text-decoration: none; + font-family: monospace; +} + +#fsearch_window .threedots { + color: #333; + font-size: x-small; + font-family: sans-serif; +} + +#fsearch_window .selected { + background-color: 679ef1; + color: white; +} + +#fsearch_companion { + display:none; + position: absolute; + z-index: 60; + top: 40px; + right:410px; + color: grey; + background-color: white; +} + diff --git a/webdoc/plugins/search-plugin/search.html b/webdoc/plugins/search-plugin/search.html new file mode 100644 index 00000000..95a16dbb --- /dev/null +++ b/webdoc/plugins/search-plugin/search.html @@ -0,0 +1,24 @@ +<html> + <head> + <title></title> + <link rel="stylesheet" type="text/css" href="search.css" /> + </head> + <script type="text/javascript"> + function printFrame() { + window.print(); + return false; + } + //pass the function object to parent + parent.printFrame = printFrame; + </script> + <body> + <div id="search_wrapper"> + <div id="s_header"><h1>Search result(s) for '<span id="s_term"></span>'</h1></div> + <div id="s_results"><ul></ul></div> + <div id="s_morebtn"><input type="button" value="Show more results"></div> + <div id="s_spinner" class="hidden"><img src="/images/spinner.gif" alt="spinner" /></div> + </div> + <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> + <script type="text/javascript" src="plugins/search-plugin/fullsearch.js"></script> + </body> +</html> diff --git a/webdoc/plugins/search-plugin/search.js b/webdoc/plugins/search-plugin/search.js new file mode 100644 index 00000000..cbd253c7 --- /dev/null +++ b/webdoc/plugins/search-plugin/search.js @@ -0,0 +1,143 @@ +var search_input = $('#fsearch'); +var search_window = $('#fsearch_window'); +var content_frame = $('#content_frame'); +var page_link = $('#pageLink'); +var lis = null; +var page_top_offset = $('#main_part').offset().top; + +change_page = function (pagename) { + content_frame.attr ('src', 'monodoc.ashx?link=' + pagename); + page_link.attr ('href', '?link=' + pagename); + if (window.history && window.history.pushState) + window.history.pushState (null, '', '/?link=' + pagename); +}; +page_link.attr ('href', document.location.search); + +var is_shown = false; +var hide = function () { + if (!is_shown) + return; + search_window.css ({'display' : 'none', 'opacity' : 0}); + is_shown = false; +}; +var show = function () { + if (is_shown) + return; + search_window.css ({'display' : 'block', 'height' : 'auto', 'opacity' : 1.0, 'width': search_input.width() + 'px', 'top': page_top_offset + 'px' }); + is_shown = true; +}; + +var param = document.URL.split('#')[1]; +if(param) { + $('#content_frame').attr('src', 'search.html#' + param); +} + +search_input.blur (function () { + window.setTimeout (hide, 200); + if (search_input.val ().length == 0) + search_input.css ('width', '19em'); +}); +search_input.focus (function () { + search_input.css ('width', '29em'); + if (search_window.text().length > 0 && search_input.val().length > 0) + show (); + window.setTimeout (function () { + search_input[0].select (); + }, 10); +}); + +search_input.keyup (function (event) { + if ($(this).val () == "") + hide(); + + // Only process if we receive an alnum or backspace or del + if (event.which != 8 && event.which != 46 + && (event.which < 'A'.charCodeAt(0) || event.which > 'Z'.charCodeAt(0)) + && (event.which < '0'.charCodeAt(0) || event.which > '9'.charCodeAt(0))) + return; + + var callback = function (data) { + if (data == null || data.length == 0) + return; + + var items = []; + + $.each (data, function(key, val) { + var item = val.name; + var url = val.url.replace (/[<>]/g, function (c) { return c == '<' ? '{' : '}'; }); + items.push('<li><a href="#" onclick="change_page(\''+url+'\')" title="'+(val.fulltitle == '' ? val.name : val.fulltitle)+'">' + item + '</a></li>'); + }); + + var uls = $('<ul/>', { html: items.join (''), 'style': 'list-style-type:none; margin: 0; padding:0' }); + lis = uls.children ('li'); + var companion = $('#fsearch_companion'); + lis.hover (function () { + var childA = $(this).children('a'); + var offset = childA.offset (); + companion.css ({ 'top': offset.top + 'px', 'right': $('html').outerWidth () - offset.left + 10, 'display': 'block'}); + companion.text(childA.attr ('title')); + }, function () { + companion.css ('display', 'none'); + }); + search_window.empty(); + uls.appendTo ('#fsearch_window'); + show (); + }; + $.getJSON ('monodoc.ashx?fsearch=' + $(this).val (), callback); +}); + +document.getElementById ('fsearch').onsearch = function () { + if (search_input.val () == "") { + hide (); + search_input.blur (); + } +}; + +search_input.keydown (function (event) { + if (lis == null) + return; + var selected = lis.filter('.selected'); + var newSelection = null; + $('#fsearch_companion').css ('display', 'none'); + + switch (event.which) + { + case 13: // return + if (selected.length != 0) { + selected.children ('a').click (); + } else { + // Show full search page + content_frame.attr('src', 'search.html#' + encodeURI(search_input.val ())); + } + hide (); + search_input.blur (); + return false; + case 38: // up + if (selected.length != 0) { + var prev = selected.prev (); + newSelection = prev; + } else { + newSelection = lis.last (); + } + break; + case 40: // down + if (selected.length != 0) { + var next = selected.next (); + if (next.length != 0) + newSelection = next; + } else { + newSelection = lis.first (); + } + break; + } + + if (newSelection != null) { + newSelection.addClass ('selected'); + if (selected != null) { + selected.removeClass ('selected'); + selected.mouseleave(); + } + newSelection.mouseenter(); + selected = newSelection; + } +}); |