magnific-popup


Add data to items in Magnific Popup


I want to add additional data to go along with each additional item in a gallery, in this case a project name in addition to the caption. I have a working version on Codepen (also below) using the markupParse callback and storing the Project Name info in a separate array, but it seems like there is probably a more efficient method using the Magnific Popup API. Is there a way to store this information with the item object, maybe even have the rendered html be cached?
In the sample code I have created an extra div called <div class="my-project"></div> inside the markup variable and place the the Project Name data from the galleryProject array using the markupParse callback.
$('#gallery').magnificPopup({
type: 'image',
items: [
{
src: 'img1.jpg',
title: 'Caption 1'
},
{
src: 'img2.jpg',
title: 'Caption 2'
},
{
src: 'img3.jpg',
title: 'Caption 3'
}
],
gallery: {
enabled: true
},
image: {
markup: '<div class="mfp-figure">'+
'<div class="mfp-close"></div>'+
'<div class="mfp-img"></div>'+
'<div class="mfp-bottom-bar">'+
'<div class="my-project"></div>'+
'<div class="mfp-title"></div>'+
'<div class="mfp-counter"></div>'+
'</div>'+
'</div>'
},
callbacks: {
markupParse: function(template, values, item) {
var index = this.currItem.index;
template.find('.my-project').html( galleryProject[index] );
}
}
});
var galleryProject = ['Project 1','Project 2','Project 3'];
You're right, this is much simpler way:
$('#gallery').magnificPopup({
type: 'image',
items: [
{
src: 'img1.jpg',
title: 'Caption 1',
project: 'Project 1'
},
{
src: 'img2.jpg',
title: 'Caption 2',
project: 'Project 2'
},
{
src: 'img3.jpg',
title: 'Caption 3',
project: 'Project 3'
}
],
gallery: {
enabled: true
},
image: {
markup: '<div class="mfp-figure">'+
'<div class="mfp-close"></div>'+
'<div class="mfp-img"></div>'+
'<div class="mfp-bottom-bar">'+
'<div class="mfp-project"></div>'+
'<div class="mfp-title"></div>'+
'<div class="mfp-counter"></div>'+
'</div>'+
'</div>'
}
});

Related Links

How to generate a (magnific popup)-gallery without a-tags
Add data to items in Magnific Popup
How to set the divs to make Magnific Popup animations work
how to display map in mobile devices using magnific popup?
Magnific Popup - Counter in Videogallery
how to manually open and close the popup using Magnific-Popup
How to customize arrows and close button?
no closing “X” with inline content
How to prevent close
Magnific-Popup Loading iframe from non-video players URL
Magnific popup - put arrows inside of an image
magnific closeOnContentClick does not work
How can style popup iframe in Magnific Pop-Up?
Gallery with mixed content types
Title for iframe/video in magnific popup
Magnific Popup: Close floats to the right

Categories

HOME
sendgrid
yii2
winforms
hive
azure-data-factory
plone
office365api
session
relay
amortized-analysis
umd
google-project-tango
acquia
iggrid
maude-system
user-input
reactcsstransitiongroup
interop
jqwidget
google-cloud-speech
textfield
swingx
kryo
ml
xlsxwriter
functional-testing
tar
sox
kvc
realex-payments-api
trading
user-interaction
tooltipster
entitlements
fabric8
grails-3.1
kendo-ui-grid
commit
accelerate-framework
normal-distribution
catalog
restlet
withings
unspecified
az-application-insights
jna
opshub
glew
botbuilder
mime
modelmapper
gpx
slick-3.0
wptoolkit
fault
dds
alphabet
elgg
setter
diagnostics
composite-key
titanium-android
root-framework
url-pattern
heidisql
libpng
radtreelist
django-debug-toolbar
storekit
persist
ready-api
testng-dataprovider
hover-over
whois
ptrace
associative-array
photobucket
netmq
riak-cs
ionic
graph-drawing
nsmutabledictionary
ng-animate
xc16
tablelayout
rdtsc
titanium-modules
issuu
code-access-security
php-5.4
reactfx
html5-notifications
ivyde
batterylevel
android-screen-support
pysimplesoap
uiviewanimation-curve
ohm
whoosh
coercion
xmlspy
self-extracting
winbugs14
digest-authentication
mirah
ncqrs
nerddinner
port-number
putchar
private-members
commodore
3gp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App