Skip to content

Commit

Permalink
embed search query into pdf viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs committed Mar 8, 2018
1 parent 4176667 commit 6f9fe7b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/helpers/pdf_viewer_helper.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/views/hyrax/file_sets/media_display/_pdf.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<iframe id="pdf-viewer" width="100%" height="600px" frameborder="0"
scrolling="no" marginheight="0" marginwidth="0"
title="PDF Document" src="/web/viewer.html?file=<%= hyrax.download_path(file_set) %>"></iframe>
title="PDF Document" src="<%= viewer_url(download_path(file_set)) %>"></iframe>
<% else %>
<div>
<%= image_tag thumbnail_url(file_set),
Expand Down
18 changes: 18 additions & 0 deletions public/web/viewer-find-custom.js
Original file line number Diff line number Diff line change
@@ -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
})
})
3 changes: 3 additions & 0 deletions public/web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,8 @@

</div> <!-- outerContainer -->
<div id="printContainer"></div>

<!-- fill in the search bar if a query exists + the bar isn't filled already -->
<script src="viewer-find-custom.js"></script>
</body>
</html>

0 comments on commit 6f9fe7b

Please sign in to comment.