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

Fancybox not working in sidebar #58

Open
juliettefabre opened this issue Sep 13, 2018 · 6 comments
Open

Fancybox not working in sidebar #58

juliettefabre opened this issue Sep 13, 2018 · 6 comments

Comments

@juliettefabre
Copy link

Hi,

I'm trying to use the Fancybox library in the sidebar of a map made with leaflet 1.3.1.
When I click on a marker, I get from the database a list of photos associated to the marker. Then I open the sidebar to display them inside the sidebar with Fancybox, but photos don't "open" with fancybox (then open in a new tab of the browser).
The code works fine if it's not contained in the leaflet sidebar.

<a class="fancybox thumbnail" rel="gallery" href=myphoto.jpg" title="myphoto">
<img class="img-responsive" src="myphoto.jpg"/>
</a>
<script>
$(function() {				
	$(".fancybox").fancybox({			
		'titlePosition'  : 'inside'		 
	});
});
</script>

I found a similar question about using fancybok in a leaflet popup, but it does not change anything when I specify in my leaflet map javascript:

$(function() {		
	my_map.control.sidebar.on('shown', function () {
		$(".fancybox").fancybox({			
			'titlePosition'  : 'inside'		 
		});
	});
});

Any idea?
Thanks!

@adriennn
Copy link

adriennn commented Sep 13, 2018 via email

@juliettefabre
Copy link
Author

Thanks Adrien for your answer,

The fancybox links are located inside the sidebar.
Actually here is the initial map workflow (that you can see here):

I create a Leaflet map with some features (stations).

Inside the "map" div, I create an HTML "sidebar" div for the sidebar, and inside this another "all_info_station" div for the dynamic station information. In the "sidebar" div, I create a sidebar control.

When a station is clicked:

  • I perform an Ajax request to get HTML formatted station information (from the database).
  • This HTML code contains the fancybox links for a set of photos (see the "Photos" tab), and the javascript to call fancybox:
<a class="fancybox thumbnail" rel="gallery" href=myphoto.jpg" title="myphoto">
<img class="img-responsive" src="myphoto.jpg"/>
</a>
$(function() {				
	$(".fancybox").fancybox({ 'titlePosition'  : 'inside' });
});
  • I finally put the HTML station information inside the "all_info_station" div, and show the sidebar:
 $.ajax({
	type: "POST",
	url: my_url,
	data: my_data,
	dataType: 'html',
	success: function (output) {
		$('#all_info_station').html(output);
		sidebar.show();
	}
});

I guess there's something I don't really get because we use a homemade javascript library to help us to create our leaflet maps, and I don't really master it :)

@adriennn
Copy link

adriennn commented Sep 14, 2018 via email

@juliettefabre
Copy link
Author

thanks Adrien, the only (and not good!) solution working for the moment is to use fancybox2 and to specify an HTML "onclick" in my links:

<a class="fancybox thumbnail" rel="gallery" href=myphoto.jpg" title="myphoto" onclick="$.fancybox(this);return false;">
<img class="img-responsive" src="myphoto.jpg"/>
</a>

Moreover, this solution does not seem to support the gallery.
To use the api and .open() method I need to get my images in json, while what I get with my ajax request is HTML formatted data. And for now I don't see how to separate these two operations in my workflow..
I'll see later if we finally integrate a real web developer in my team! :)

@adriennn
Copy link

adriennn commented Sep 17, 2018 via email

@juliettefabre
Copy link
Author

Thanks Adrien.
The javascript is indeed parsed in the pre-rendered html, and the ajax dataType is html.
The ajax is called in our generic homemade library ..

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

No branches or pull requests

3 participants