From 1a5f051a0ed2bd2adad745c889b0735ae9fa2d14 Mon Sep 17 00:00:00 2001 From: llj Date: Fri, 16 May 2014 17:36:28 +0800 Subject: [PATCH] highlight keywords in 'search result' and 'file view' page; bug fix for pdf view --- media/css/seahub.css | 4 +++ media/js/pdf2html.js | 3 ++ .../templates/snippets/office_convert_js.html | 7 +++- seahub/templates/view_file_base.html | 36 +++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/media/css/seahub.css b/media/css/seahub.css index 61c6f96e6b..4436b42aeb 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -2846,6 +2846,10 @@ textarea:-moz-placeholder {/* for FF */ #search-results a { font-weight: normal; } +#search-results b { + font-weight: bold; + background:#ffe761; +} .search-results-item { margin-top:15px; } diff --git a/media/js/pdf2html.js b/media/js/pdf2html.js index 2cffbc4fd4..8d5655590b 100644 --- a/media/js/pdf2html.js +++ b/media/js/pdf2html.js @@ -181,6 +181,9 @@ var pdf2htmlEX = (function(){ _.find_pages(); _.schedule_render(); _.load_page(idx+1); + if (highlight_kw) { + highlight_kw($('#file-view')); + } }); } }, diff --git a/seahub/templates/snippets/office_convert_js.html b/seahub/templates/snippets/office_convert_js.html index 89c44251be..e2ea3ed240 100644 --- a/seahub/templates/snippets/office_convert_js.html +++ b/seahub/templates/snippets/office_convert_js.html @@ -27,7 +27,6 @@ has_outline = $.trim(outline); } - $('#converted-html').append('
'); if (has_outline) { var sidebar = $('#sidebar'), page_container = $('#page-container'), @@ -36,6 +35,11 @@ $('#outline .l').removeAttr('data-dest-detail'); // make the anchor links work sidebar.removeClass('hide'); + if (highlight_kw) { + highlight_kw(sidebar); + } + + $('#converted-html').append('
'); var toolbar = $('#pdf2html-toolbar-1'); toolbar.append(''); toolbar.append(''); @@ -85,6 +89,7 @@ var file_cont = $('#file-view'), //file container orig_pg_total_h; + $('#zoom-in, #zoom-out').click(function() { // get orig data before zoom in/out var op = $(this).attr('id'), diff --git a/seahub/templates/view_file_base.html b/seahub/templates/view_file_base.html index 5a1fb9ae05..16d2459acf 100644 --- a/seahub/templates/view_file_base.html +++ b/seahub/templates/view_file_base.html @@ -177,6 +177,42 @@ $('#file-op .history').click(function () { location.href = $(this).data('url'); }); +// if referrer is 'search result' page, define function highlight_kw +var ref_list = document.referrer.split('?'); +if (ref_list.length > 1 && ref_list[0].indexOf('search') > 0) { + var search_params = ref_list[1].split('&'); + var search_keyword = search_params[0].substr(2); // get 'xx' from 'q=xx' + + var highlight_kw = function(hl_area) { + if (window.find && window.getSelection) { + hl_area.attr('contenteditable', true).attr('spellcheck', false); + var sel = window.getSelection(); + sel.collapse(document.body, 0); + + while (window.find(search_keyword)) { + document.execCommand("HiliteColor", false, "yellow"); + sel.collapseToEnd(); + } + hl_area.attr('contenteditable', false); + } else if (document.body.createTextRange) { + var textRange = document.body.createTextRange(); + while (textRange.findText(search_keyword)) { + textRange.execCommand("BackColor", false, "yellow"); + textRange.collapse(false); + } + } + }; +} + +$(window).load(function() { + if (highlight_kw) { + // hl kw in file title + highlight_kw($('#view-hd')); + // hl kw in file content + setTimeout(function(){ highlight_kw($('#file-view')); }, 100); // delay 100ms for 'text' file + } +}); + //bottom bar {% include "snippets/bottom_bar.html" %} $('#main-panel').css('margin-bottom',0);