-
AuthorPosts
-
matgray87 Friend
matgray87
- Join date:
- November 2011
- Posts:
- 159
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 33
- Thanked:
- 8 times in 1 posts
October 12, 2014 at 8:29 pm #202011Hi,
I’m trying to get Magnific Popup to work in JA-Biz the same as it works in JA-Decor…
I’ve added into the templateHelper to create the image gallery in K2 items:public static function photogallery($introtext){
if(preg_match_all('#<img[^>]+>#iU', $introtext, $imgs)){
//remove the text
$introtext = preg_replace('#<img[^>]+>#iU', '', $introtext);
//collect all images
$img_data = array();
// parse image attributes
foreach( $imgs[0] as $img_tag){
$img_data[$img_tag] = JUtility::parseAttributes($img_tag);
}
$total = count($img_data);if($total > 0) :
$introtext .= '<ul class="itemthumbnails'.($total>1?'':' no-slide').'">';
$j = 0;
foreach ($img_data as $img => $attr) :
$introtext .= '<li class="'.($j == 0 ? 'col-xs-12' : 'col-sm-6 col-xs-12').'">'
.($total>1?'<a title="'.$attr['alt'].'" href="'.(isset($attr['src']) ? $attr['src'] : '').'" class="itemthumbnail'.($j == 0 ? ' active' : '').'">':'')
.$img
.($total>1?'</a>':'').
'</li>';
$j++;
endforeach;
$introtext .= '</ul>';
endif;return $introtext;
} else {
return $introtext;
}
}
And I’ve also added the jquery.magnific-popup.js and jquery.magnific-popup.min.js into the template JS folder, and I’ve added this into head.php:
<script>
$(document).ready(function() {
// Thumbnail gallery
if($('.itemthumbnails').length >0 && !$('.itemthumbnails').hasClass('no-slide')){
$('.itemthumbnails').magnificPopup({
delegate: 'a',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
titleSrc: function(item) {
return item.el.attr('title');
}
}
});
}
});
</script>
but it’s not working… I can’t for the life of me see what I’m missing… Example page here…
Does the ‘image’ type support PNGs as well as JPGs?
Cheers,
MattEragon H FriendEragon H
- Join date:
- July 2014
- Posts:
- 468
- Downloads:
- 1
- Uploads:
- 39
- Thanks:
- 5
- Thanked:
- 156 times in 149 posts
October 13, 2014 at 4:01 am #552679Hi Matt,
You can add the below code to the file root/templates/ja_biz/js/scripts.js
(function($){
$(document).ready(function() {if($('.itemthumbnails').length >0 && !$('.itemthumbnails').hasClass('no-slide')){
$('.itemthumbnails').magnificPopup({
delegate: 'a',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
titleSrc: function(item) {
return item.el.attr('title');
}
}
});
}});
})(jQuery);You may need to clear browser cache to see the change
Best regards
1 user says Thank You to Eragon H for this useful post
matgray87 Friendmatgray87
- Join date:
- November 2011
- Posts:
- 159
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 33
- Thanked:
- 8 times in 1 posts
October 13, 2014 at 12:53 pm #552756Perfect – works great… What was I doing wrong then, and why is it different adding it into scripts.js as opposed to the head.php file as the code is identical?
Cheers,
MattEragon H FriendEragon H
- Join date:
- July 2014
- Posts:
- 468
- Downloads:
- 1
- Uploads:
- 39
- Thanks:
- 5
- Thanked:
- 156 times in 149 posts
October 14, 2014 at 4:47 am #552838Hi Matt,
1. It’s nice to know my suggestion helped.
2. If you add this code to the head.php, it still work
<script>
(function($){
$(document).ready(function() {if($('.itemthumbnails').length >0 && !$('.itemthumbnails').hasClass('no-slide')){
$('.itemthumbnails').magnificPopup({
delegate: 'a',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
titleSrc: function(item) {
return item.el.attr('title');
}
}
});
}
});
})(jQuery);
</script>3. I suggested to add to the file scripts.js because it’s easier to control and maintain.
Best regards.
1 user says Thank You to Eragon H for this useful post
-
AuthorPosts
This topic contains 5 replies, has 2 voices, and was last updated by matgray87 10 years ago.
We moved to new unified forum. Please post all new support queries in our New Forum