From 94ec04a2f68f3afde5128f53aa1e5585a4ebabd2 Mon Sep 17 00:00:00 2001 From: ValeryYafremau Date: Wed, 30 Dec 2015 16:16:57 +0300 Subject: [PATCH] JS-370: Gallery. Missconfiguration on theme level should not break JS application --- .../templates/product/view/gallery.phtml | 62 ++++++++++++++----- lib/web/mage/gallery/gallery.js | 6 +- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml b/app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml index e756ae52c4550..dc1591ef633f4 100644 --- a/app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml +++ b/app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml @@ -47,32 +47,60 @@ "data": getGalleryImagesJson(); ?>, "options": { "nav": "getVar("gallery/nav"); ?>", - "loop": getVar("gallery/loop"); ?>, - "keyboard": getVar("gallery/keyboard"); ?>, - "arrows": getVar("gallery/arrows"); ?>, - "allowfullscreen": getVar("gallery/allowfullscreen"); ?>, - "showCaption": getVar("gallery/caption"); ?>, - "width": getImageAttribute('product_page_image_medium', 'width'); ?>, - "thumbwidth": getImageAttribute('product_page_image_small', 'width'); ?>, - "thumbheight": getImageAttribute('product_page_image_small', 'height') + getVar("gallery/loop"))): ?> + "loop": getVar("gallery/loop"); ?>, + + getVar("gallery/keyboard"))): ?> + "keyboard": getVar("gallery/keyboard"); ?>, + + getVar("gallery/arrows"))): ?> + "arrows": getVar("gallery/arrows"); ?>, + + getVar("gallery/allowfullscreen"))): ?> + "allowfullscreen": getVar("gallery/allowfullscreen"); ?>, + + getVar("gallery/caption"))): ?> + "showCaption": getVar("gallery/caption"); ?>, + + "width": "getImageAttribute('product_page_image_medium', 'width'); ?>", + "thumbwidth": "getImageAttribute('product_page_image_small', 'width'); ?>", + getImageAttribute('product_page_image_small', 'height') || $block->getImageAttribute('product_page_image_small', 'width')): ?> + "thumbheight": getImageAttribute('product_page_image_small', 'height') ?: $block->getImageAttribute('product_page_image_small', 'width'); ?>, - "height": getImageAttribute('product_page_image_medium', 'height') + + getImageAttribute('product_page_image_medium', 'height') || $block->getImageAttribute('product_page_image_medium', 'width')): ?> + "height": getImageAttribute('product_page_image_medium', 'height') ?: $block->getImageAttribute('product_page_image_medium', 'width'); ?>, - "transitionduration": getVar("gallery/transition/duration"); ?>, + + getVar("gallery/transition/duration")): ?> + "transitionduration": getVar("gallery/transition/duration"); ?>, + "transition": "getVar("gallery/transition/effect"); ?>", - "navarrows": getVar("gallery/navarrows"); ?>, + getVar("gallery/navarrows"))): ?> + "navarrows": getVar("gallery/navarrows"); ?>, + "navtype": "getVar("gallery/navtype"); ?>", "navdir": "getVar("gallery/navdir"); ?>" }, "fullscreen": { "nav": "getVar("gallery/fullscreen/nav"); ?>", - "loop": getVar("gallery/fullscreen/loop"); ?>, - "navdir": "getVar("gallery/fullscreen/navdir"); ?>", - "navarrows": getVar("gallery/fullscreen/navarrows"); ?>, + getVar("gallery/fullscreen/loop")): ?> + "loop": getVar("gallery/fullscreen/loop"); ?>, + + "navdir": "getVar("gallery/navdir"); ?>", + getVar("gallery/transition/navarrows")): ?> + "navarrows": getVar("gallery/fullscreen/navarrows"); ?>, + "navtype": "getVar("gallery/fullscreen/navtype"); ?>", - "arrows": getVar("gallery/fullscreen/arrows"); ?>, - "showCaption": getVar("gallery/fullscreen/caption"); ?>, - "transitionduration": getVar("gallery/fullscreen/transition/duration"); ?>, + getVar("gallery/fullscreen/arrows")): ?> + "arrows": getVar("gallery/fullscreen/arrows"); ?>, + + getVar("gallery/fullscreen/caption")): ?> + "showCaption": getVar("gallery/fullscreen/caption"); ?>, + + getVar("gallery/fullscreen/transition/duration")): ?> + "transitionduration": getVar("gallery/fullscreen/transition/duration"); ?>, + "transition": "getVar("gallery/fullscreen/transition/effect"); ?>" }, "breakpoints": getBreakpoints(); ?> diff --git a/lib/web/mage/gallery/gallery.js b/lib/web/mage/gallery/gallery.js index 31b32c99e6e8e..c7c6653eda4a3 100644 --- a/lib/web/mage/gallery/gallery.js +++ b/lib/web/mage/gallery/gallery.js @@ -181,7 +181,7 @@ define([ settings.api.updateOptions(settings.defaultConfig.options, true); settings.api.updateOptions(settings.fullscreenConfig, true); - if (!_.isEqual(settings.activeBreakpoint, {})) { + if (!_.isEqual(settings.activeBreakpoint, {}) && settings.breakpoints) { settings.api.updateOptions(settings.activeBreakpoint.options, true); } settings.isFullscreen = true; @@ -196,7 +196,7 @@ define([ settings.focusableEnd.unbind('focusin', this._focusSwitcher); settings.closeIcon.hide(); - if (!_.isEqual(settings.activeBreakpoint, {})) { + if (!_.isEqual(settings.activeBreakpoint, {}) && settings.breakpoints) { settings.api.updateOptions(settings.activeBreakpoint.options, true); } settings.isFullscreen = false; @@ -442,7 +442,7 @@ define([ configuration.breakpoints = null; if (!isInternal) { - !_.isEqual(settings.activeBreakpoint, {}) ? + !_.isEqual(settings.activeBreakpoint, {} && settings.brekpoints) ? $.extend(true, settings.activeBreakpoint.options, configuration) : settings.isFullscreen ?