Skip to content

Commit

Permalink
Update the height of the file viewer based on the number of resources…
Browse files Browse the repository at this point in the history
… being displayed.
  • Loading branch information
jkeck committed Aug 31, 2016
1 parent 957a1b1 commit 9432e6c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/embed/viewer/file.rb
Expand Up @@ -65,7 +65,23 @@ def file_type_icon(mimetype)
end

def default_body_height
400 - (header_height + footer_height)
file_specific_body_height - (header_height + footer_height)
end

# This is neccessary because the file viewer's height is meant to be dynamic,
# however we need to specify the exact height of the containing iframe (which
# will give us extra whitespace below the embed viewer unless we do this)
def file_specific_body_height
case @purl_object.all_resource_files.count
when 1
200
when 2
275
when 3
375
else
400
end
end

def preview_file_toggle(file, doc, file_count)
Expand Down
2 changes: 1 addition & 1 deletion spec/features/embed_this_panel_spec.rb
Expand Up @@ -22,7 +22,7 @@
end
it 'includes height and width attributes' do
page.find('[data-sul-embed-toggle="sul-embed-embed-this-panel"]', match: :first).trigger('click')
expect(page.find('.sul-embed-embed-this-panel textarea').value).to match(/<iframe.*height='400px'.*\/>/)
expect(page.find('.sul-embed-embed-this-panel textarea').value).to match(/<iframe.*height='200px'.*\/>/)
expect(page.find('.sul-embed-embed-this-panel textarea').value).to match(/<iframe.*width='100%'.*\/>/)
end
end
Expand Down
13 changes: 12 additions & 1 deletion spec/lib/embed/viewer/file_spec.rb
Expand Up @@ -23,15 +23,26 @@
end
describe 'body_height' do
it 'defaults to 400 minus the footer and header height' do
stub_request(request)
stub_purl_response_and_request(multi_resource_multi_type_purl, request)
expect(file_viewer.send(:body_height)).to eq 307
end

it 'consumer requested maxheight minus the header/footer height' do
height_request = Embed::Request.new(url: 'http://purl.stanford.edu/abc123', maxheight: '500')
stub_request(height_request)
viewer = Embed::Viewer::File.new(height_request)
expect(viewer.send(:body_height)).to eq 407
end

it 'reduces the height based on the number of files in the object (1 file)' do
stub_purl_response_and_request(file_purl, request)
expect(file_viewer.send(:body_height)).to eq 107
end

it 'reduces the height based on the number of files in the object (2 files)' do
stub_purl_response_and_request(image_purl, request)
expect(file_viewer.send(:body_height)).to eq 182
end
end
describe 'header tools' do
it 'includes the search in the header tools' do
Expand Down

0 comments on commit 9432e6c

Please sign in to comment.