Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax type loading post content + Gallery mode #1177

Open
quentin-th opened this issue Dec 6, 2021 · 0 comments
Open

Ajax type loading post content + Gallery mode #1177

quentin-th opened this issue Dec 6, 2021 · 0 comments

Comments

@quentin-th
Copy link

Hello,

on a page displaying posts on a list, I would like to use magniufic popup to load the post content (.flower-item) in a popup. I managed to load what I needed in ajax, however I can't manage the gallery part, does magnific popup allow to use ajax and gallery mode at the same time or not ?

My structure is something ike that (Wordpress website) :

<div  class="month-wrapper">
	<div data-href="/link-to-flower-single-post" class="flower-item ajax-popup-link">
		<img src="">>
		<h3>Flower name</h3>
	</div>
	<div data-href="/link-to-flower-single-post" class="flower-item ajax-popup-link">
		<img src="">>
		<h3>Flower name</h3>
	</div>
</div>
<div  class="month-wrapper">
	<div data-href="/link-to-flower-single-post" class="flower-item ajax-popup-link">
		<img src="">>
		<h3>Flower name</h3>
	</div>
	<div data-href="/link-to-flower-single-post" class="flower-item ajax-popup-link">
		<img src="">>
		<h3>Flower name</h3>
	</div>
</div>

And here is the JS working but without gallery mode enabled

jQuery('.ajax-popup-link').on('click', function (e) {
	jQuery.magnificPopup.open({
		items: {
			type: 'ajax',
			src: jQuery(this).data('href')
		},
		callbacks: {
		  parseAjax: function(mfpResponse) {
			mfpResponse.data = jQuery(mfpResponse.data).filter('.fleur-modal-body');
			console.log('Ajax content loaded:', mfpResponse);
		  },
		  ajaxContentAdded: function() {
			// Ajax content is loaded and appended to DOM
			console.log(this.content);
		  }
		}
	});
});

Now, if I'm adding the gallery mode, it output an error "Uncaught TypeError: c.split is not a function".

I suppose the problem is src because when I console.log it's undefined, I tried replacing by src: jQuery(".div.flower-item").data('href') or something but same problem, I can't target my data-href, any idea how ? Or should I change something on the html structure ?

jQuery('.month-wrapper').each(function() {
	//console.log(jQuery(this));

	jQuery(this).magnificPopup({
		delegate: 'div.flower-item',
		items: {
			type: 'ajax',
			src: jQuery(this).data('href')
		},
		gallery: {
			enabled: true 
		},
		callbacks: {
			parseAjax: function(mfpResponse) {
				console.log('test');
				mfpResponse.data = jQuery(mfpResponse.data).filter('.fleur-modal-body');

				console.log('Ajax content loaded:', mfpResponse);
			},
			ajaxContentAdded: function() {
				// Ajax content is loaded and appended to DOM
				console.log(this.content);
			}
		}
	});
});

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@quentin-th and others