diff --git a/app/helpers/pdf_viewer_helper.rb b/app/helpers/pdf_viewer_helper.rb new file mode 100644 index 000000000..6603026e4 --- /dev/null +++ b/app/helpers/pdf_viewer_helper.rb @@ -0,0 +1,20 @@ +module PdfViewerHelper + def viewer_url(path) + "/web/viewer.html?file=#{path}##{query_param}" + end + + def query_param + return unless search_query + "search=#{search_query}&phrase=true" + end + + private + + def search_query + search && search.respond_to?(:query_params) && search.query_params[:q] + end + + def search + current_search_session + end +end diff --git a/app/views/hyrax/file_sets/media_display/_pdf.html.erb b/app/views/hyrax/file_sets/media_display/_pdf.html.erb index 3346795fc..534ddc33c 100644 --- a/app/views/hyrax/file_sets/media_display/_pdf.html.erb +++ b/app/views/hyrax/file_sets/media_display/_pdf.html.erb @@ -5,7 +5,7 @@ + title="PDF Document" src="<%= viewer_url(download_path(file_set)) %>"> <% else %>
<%= image_tag thumbnail_url(file_set), diff --git a/public/web/viewer-find-custom.js b/public/web/viewer-find-custom.js new file mode 100644 index 000000000..64260c6a2 --- /dev/null +++ b/public/web/viewer-find-custom.js @@ -0,0 +1,18 @@ +// fills in the findInput search box with the +// provided query term (when present), only on load +document.addEventListener('pagerendered', function (ev) { + var findInput = document.getElementById('findInput') + var app = PDFViewerApplication + + app.eventBus.on('pagesloaded', function () { + var findController = app.findController || {} + var state = findController.state || {} + var query = state.query || null + + if (!query) { + return + } + + findInput.value = query + }) +}) diff --git a/public/web/viewer.html b/public/web/viewer.html index e8a140501..fce48bd56 100644 --- a/public/web/viewer.html +++ b/public/web/viewer.html @@ -354,5 +354,8 @@
+ + +