Fixing the Fancybox redirection/disappearance
authorLaury GvR <laury@gaslightmedia.com>
Tue, 9 May 2017 13:33:56 +0000 (09:33 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 9 May 2017 13:33:56 +0000 (09:33 -0400)
This was a problem for the images on the shop page. Every time a
 fancybox would open the original image would disappear and not
 come back. We think it may have been due to some javascript
 interference from the WooCommerce plugin.

js/app.js
js/custom/pageSetup.js

index e03715a..b814de8 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -19,27 +19,22 @@ $(document).ready(function () {
     });
 
     $(".woocommerce-LoopProduct-link").each(function() {
-        // This makes fancybox not work
-        //$(this).attr("href", "#");
-
-        // Fancybox works but <a> is display: none on image click
-        //$(this).attr("href", "");
-
-        // Not doing anything leaves the link active
-    });
-
-
-    $(".woocommerce-LoopProduct-link").on("click",function( event ) {
-        // Doing this makes fancybox not work
-        //event.preventDefault();
+        // Removing all the anchors from the products so that you won't
+        //  navigate away when clicking in one, allowing fancybox to display
+        $(this).attr("href", "");
     });
 
-
     $(".woocommerce-LoopProduct-link").fancybox({
         helpers: {
             overlay: {  locked: false,
                     },
              title: { type: 'inside'},
+        },
+        afterLoad: function(){
+            this.title = $(this.element).find('img').attr('alt');
+        },
+        afterClose: function() {
+            $(this.element).show();
         }
 
     });
index 6a3ff6c..aa3e02b 100644 (file)
@@ -10,27 +10,22 @@ $(document).ready(function () {
     });
 
     $(".woocommerce-LoopProduct-link").each(function() {
-        // This makes fancybox not work
-        //$(this).attr("href", "#");
-
-        // Fancybox works but <a> is display: none on image click
-        //$(this).attr("href", "");
-
-        // Not doing anything leaves the link active
-    });
-
-
-    $(".woocommerce-LoopProduct-link").on("click",function( event ) {
-        // Doing this makes fancybox not work
-        //event.preventDefault();
+        // Removing all the anchors from the products so that you won't
+        //  navigate away when clicking in one, allowing fancybox to display
+        $(this).attr("href", "");
     });
 
-
     $(".woocommerce-LoopProduct-link").fancybox({
         helpers: {
             overlay: {  locked: false,
                     },
              title: { type: 'inside'},
+        },
+        afterLoad: function(){
+            this.title = $(this.element).find('img').attr('alt');
+        },
+        afterClose: function() {
+            $(this.element).show();
         }
 
     });