EduardET

Customzie the magnificPopup in Divi

May 6th, 2020
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(function($) {
  2.     $(document).ready(function() {
  3.         if ($('.dt-gallery').length) {
  4.             $('.dt-gallery .et_pb_gallery_item a').each(function() {
  5.                 //Store the actual Title in a variable called title
  6.                 var title = $(this).attr('title');
  7.  
  8.                 //remove the title attribute on the links - so no title will be shown on hover
  9.                 $(this).removeAttr('title');
  10.  
  11.                 //set a custom data attribute containing the title - will be used in a custom call for of magnificPopup Library
  12.                 $(this).attr('data-title', title)
  13.             });
  14.  
  15.             //Load a custom instance of magnificPopup Library to be able to set again the titles values - which were removed previously
  16.             $('.dt-gallery .et_pb_gallery_item .et_pb_gallery_image').magnificPopup({
  17.                 type: 'image',
  18.                 delegate: 'a',
  19.                 gallery: {
  20.                     enabled: true
  21.                 },
  22.                 //Set the title for the images (when enlarged) by using the data-title attribute - which was set on line 12.
  23.                 image: {
  24.                     titleSrc: function (item) {
  25.                         return '<p class="gallery-image-title">' + item.el.data('title')  +'</p>';
  26.                     }
  27.                 }              
  28.             });
  29.         }
  30.     });
  31. });
Advertisement
Add Comment
Please, Sign In to add comment