Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tao 1239 large preview #546

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define([
'ui/progressbar',
'ui/previewer',
'ui/modal',
'ui/waitForMedia',
'filereader'
], function ($, _, __, context, tpl, containerHelper, instructionMgr) {
'use strict';
Expand Down Expand Up @@ -83,27 +84,75 @@ define([
var $previewArea = $container.find('.file-upload-preview');

$previewArea
.toggleClass('visible-file-upload-preview runtime-visible-file-upload-preview', visibleFileUploadPreview.isPreviewable)
.toggleClass('visible-file-upload-preview runtime-visible-file-upload-preview', !visibleFileUploadPreview.isPreviewable)
.previewer({
url: reader.result,
name: filename,
type: filetype.substr(0, filetype.indexOf('/'))
});

var $previewImg = $('img', $previewArea),
$largeDisplayer = $('.file-upload-preview-popup'),
$modalBody = $largeDisplayer.find('.modal-body');
// we wait for the image to be completely loaded
$previewArea.waitForMedia(function(){

var $originalImg = $previewArea.find('img'), // the previewable image
imgNaturalWidth = $originalImg[0].naturalWidth,
imgNaturalHeight = $originalImg[0].naturalHeight;

// if the image natural width is smaller than the qti-item, we do nothing
if( imgNaturalWidth <= $('.qti-item').width() ) {
return;
}

// otherwise, we allow the user to see the preview image in its natural width inside the modal

$originalImg.addClass('cursor-pointer');

$previewArea.on('click', function(){

var $self = $(this),
clickedImgNatWidth = $self.find('img')[0].naturalWidth;

if( clickedImgNatWidth <= $('.qti-item').width() ) {
return;
}

var $popupImg = $originalImg.clone(),
$largeDisplayer = $('.file-upload-preview-popup'),
$modalBody = $largeDisplayer.find('.modal-body'),
winWidth = $(window).width(),
winHeight = $(window).height(),
$modalOverlay = $container.find('.modal-bg'),
$taoItemScope = $('.tao-item-scope');

$previewImg.on('click', function (e) {
// remove any previous unnecessary content
$modalBody.empty();

// remove any previous unnecessary content before inserting the preview image
$modalOverlay.remove();
$modalBody.empty().append($popupImg);

$popupImg.wrap('<div>');

$largeDisplayer
.on('opened.modal', function(){

// setting the modal width depending on the size of the popup image
var width = Math.min(winWidth, imgNaturalWidth);
var height = Math.min(winHeight, imgNaturalHeight);

$largeDisplayer.width(width);
$largeDisplayer.height(height);

// prevents the rest of the page from scrolling when modal is open
$taoItemScope.css('overflow', 'hidden');
})
.on('closed.modal', function(){
// make the page scrollable again
$taoItemScope.css('overflow', 'auto');
})
.modal();

});

var $clonedImg = $(this).clone();
$modalBody.append($clonedImg);

$largeDisplayer.modal();

});

Expand Down
36 changes: 28 additions & 8 deletions views/scss/qti/_upload.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@
height: auto;
position: relative;
overflow: hidden;
cursor: pointer;
display: none;

&.visible-file-upload-preview {
display: block;
}
//display: none;

//&.visible-file-upload-preview {
// display: block;
//}

&.runtime-visible-file-upload-preview {
min-width: unset;
min-height: unset;
height: auto;
background: transparent;
//cursor: pointer;
}

p.nopreview {
Expand All @@ -72,21 +73,40 @@
display: block !important;
}
}

img.cursor-pointer {
cursor: pointer;
}
}

.file-upload-preview-popup {
padding: 40px 0;
max-width: 100%;
width: auto !important;
overflow: auto;
top: 0 !important;
//width: auto !important;

// position absolute allows the scroll on the a big picture
&.modal {
position: absolute;
//&.modal {
// position: absolute;
//}

.modal-body {
overflow: auto;
height: 100%;
width: 100%;

div {
height: 100%;
width: 100%;
}
}

img {
display: block;
margin: auto;
max-width: none;
overflow: auto;
}
}
}