Skip to content

Commit

Permalink
Merge pull request #471 from magento-vanilla/JS-461
Browse files Browse the repository at this point in the history
[Epam] Gallery
  • Loading branch information
Momotenko,Natalia(nmomotenko) committed Mar 23, 2016
2 parents b2e5e71 + ddf3167 commit 4c437c3
Show file tree
Hide file tree
Showing 26 changed files with 1,993 additions and 1,633 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@
</div>
</div>
</div>
<!--Fix for jumping content. Loader must be the same size as gallery.-->
<script>
var config = {
"width": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'width'); ?>,
"thumbheight": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'height')
?: $block->getImageAttribute('product_page_image_small', 'width'); ?>,
"navtype": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/navtype"); ?>",
"height": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'height'); ?>
},
thumbBarHeight = 0,
loader = document.querySelectorAll('[data-gallery-role="gallery-placeholder"] [data-role="loader"]')[0];

if (config.navtype === 'horizontal') {
thumbBarHeight = config.thumbheight;
}

loader.style.paddingBottom = ( config.height / config.width * 100) + "%";
</script>
<script type="text/x-magento-init">
{
"[data-gallery-role=gallery-placeholder]": {
Expand All @@ -29,30 +47,60 @@
"data": <?php /* @escapeNotVerified */ echo $block->getGalleryImagesJson(); ?>,
"options": {
"nav": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/nav"); ?>",
"loop": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/loop"); ?>,
"keyboard": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/keyboard"); ?>,
"arrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/arrows"); ?>,
"allowfullscreen": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/allowfullscreen"); ?>,
"showCaption": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/caption"); ?>,
"width": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'width'); ?>,
"thumbwidth": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'width'); ?>,
"thumbheight": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'height')
<?php if (($block->getVar("gallery/loop"))): ?>
"loop": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/loop"); ?>,
<?php endif; ?>
<?php if (($block->getVar("gallery/keyboard"))): ?>
"keyboard": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/keyboard"); ?>,
<?php endif; ?>
<?php if (($block->getVar("gallery/arrows"))): ?>
"arrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/arrows"); ?>,
<?php endif; ?>
<?php if (($block->getVar("gallery/allowfullscreen"))): ?>
"allowfullscreen": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/allowfullscreen"); ?>,
<?php endif; ?>
<?php if (($block->getVar("gallery/caption"))): ?>
"showCaption": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/caption"); ?>,
<?php endif; ?>
"width": "<?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'width'); ?>",
"thumbwidth": "<?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'width'); ?>",
<?php if ($block->getImageAttribute('product_page_image_small', 'height') || $block->getImageAttribute('product_page_image_small', 'width')): ?>
"thumbheight": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'height')
?: $block->getImageAttribute('product_page_image_small', 'width'); ?>,
"height": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'height')
<?php endif; ?>
<?php if ($block->getImageAttribute('product_page_image_medium', 'height') || $block->getImageAttribute('product_page_image_medium', 'width')): ?>
"height": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'height')
?: $block->getImageAttribute('product_page_image_medium', 'width'); ?>,
"transitionduration": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/transition/duration"); ?>,
<?php endif; ?>
<?php if ($block->getVar("gallery/transition/duration")): ?>
"transitionduration": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/transition/duration"); ?>,
<?php endif; ?>
"transition": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/transition/effect"); ?>",
"navarrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/navarrows"); ?>,
<?php if (($block->getVar("gallery/navarrows"))): ?>
"navarrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/navarrows"); ?>,
<?php endif; ?>
"navtype": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/navtype"); ?>",
"navdir": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/navdir"); ?>"
},
"fullscreen": {
"nav": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/nav"); ?>",
"loop": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/loop"); ?>,
<?php if ($block->getVar("gallery/fullscreen/loop")): ?>
"loop": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/loop"); ?>,
<?php endif; ?>
"navdir": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/navdir"); ?>",
"arrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/arrows"); ?>,
"showCaption": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/caption"); ?>,
"transitionduration": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/transition/duration"); ?>,
<?php if ($block->getVar("gallery/transition/navarrows")): ?>
"navarrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/navarrows"); ?>,
<?php endif; ?>
"navtype": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/navtype"); ?>",
<?php if ($block->getVar("gallery/fullscreen/arrows")): ?>
"arrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/arrows"); ?>,
<?php endif; ?>
<?php if ($block->getVar("gallery/fullscreen/caption")): ?>
"showCaption": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/caption"); ?>,
<?php endif; ?>
<?php if ($block->getVar("gallery/fullscreen/transition/duration")): ?>
"transitionduration": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/transition/duration"); ?>,
<?php endif; ?>
"transition": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/transition/effect"); ?>"
},
"breakpoints": <?php /* @escapeNotVerified */ echo $block->getBreakpoints(); ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ $_attributes = $block->decorateArray($block->getAllowAttributes());
{
"#product_addtocart_form": {
"configurable": {
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>,
"onlyMainImg": <?php /* @escapeNotVerified */ echo $block->getVar('change_only_base_image', 'Magento_ConfigurableProduct') ?: 'false'; ?>
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ define([
' <%- data.finalPrice.formatted %>' +
'<% } %>',
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
mediaGalleryInitial: null
mediaGalleryInitial: null,
onlyMainImg: false
},

/**
Expand Down Expand Up @@ -253,14 +254,45 @@ define([
* @private
*/
_changeProductImage: function () {
var images = this.options.spConfig.images[this.simpleProduct],
var images,
initialImages = $.extend(true, [], this.options.mediaGalleryInitial),
galleryObject = $(this.options.mediaGallerySelector).data('gallery');

if (this.options.spConfig.images[this.simpleProduct]) {
images = $.extend(true, [], this.options.spConfig.images[this.simpleProduct]);
}

function updateGallery(imagesArr) {
var imgToUpdate,
mainImg;

mainImg = imagesArr.filter(function (img) {
return img.isMain;
});

imgToUpdate = mainImg.length ? mainImg[0] : imagesArr[0];
galleryObject.updateDataByIndex(0, imgToUpdate);
galleryObject.seek(1);
}

if (galleryObject) {
if (images) {
galleryObject.updateData(images);
images.map(function (img) {
img.type = 'image';
});

if (this.options.onlyMainImg) {
updateGallery(images);
} else {
galleryObject.updateData(images)
}
} else {
galleryObject.updateData(this.options.mediaGalleryInitial);
if (this.options.onlyMainImg) {
updateGallery(initialImages);
} else {
galleryObject.updateData(this.options.mediaGalleryInitial);
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
{
"[data-gallery-role=gallery-placeholder]": {
"Magento_ProductVideo/js/fotorama-add-video-events": {
"fotoramaVideoData": <?php /* @escapeNotVerified */ echo $block->getMediaGalleryDataJson(); ?>,
"fotoramaVideoSettings": <?php /* @escapeNotVerified */ echo $block->getVideoSettingsJson(); ?>,
"fotoramaOptionsVideoData": <?php /* @noEscape */ echo $block->getOptionsMediaGalleryDataJson(); ?>
"videoData": <?php /* @escapeNotVerified */ echo $block->getMediaGalleryDataJson(); ?>,
"videoSettings": <?php /* @escapeNotVerified */ echo $block->getVideoSettingsJson(); ?>,
"optionsVideoData": <?php /* @noEscape */ echo $block->getOptionsMediaGalleryDataJson(); ?>
}
}
}
Expand Down
Loading

0 comments on commit 4c437c3

Please sign in to comment.