Reputation: 2491
I have a website that displays a big amMap. The map doesn't need to be visible all the time, so I want to hide the map and only display it when a user clicks a button. Bootstrap's popover seems like the perfect way to handle this.
Here's the basic idea:
<button id="mapbutton" type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="right">Map</button>
<div id="mapcontent" style="display: none;">
<div id="map" style="width: 500px; height: 500px;"></div>
</div>
$(function() {
$('#mapbutton').popover({
html: true,
content: function() {
return $('#mapcontent').html();
}
});
});
Here's what I see:
I have 2 problems:
How can I solve these problems?
Upvotes: 0
Views: 2023
Reputation: 13425
Question 1
Bind the events after popover content be loaded, using event shown.bs.popover
:
$('#mapbutton').on('shown.bs.popover', function () {
$('#mapMinus').click(MyMap.ZoomOut);
$('#mapPlus').click(MyMap.ZoomIn);
$('#mapLeft').click(MyMap.GoLeft);
[...]
})
** UPDATE:
Creating your own "popover", by reusing bootstrap classes:
<a id="mypopover">
Lorem Ipsum
</a>
<div id="popoverContent" class="popover fade bottom in">
<div class="arrow" style="left: 9.375%;"></div>
<div class="popover-content">
<a id="clickmewouldntwork">Event: Click me! (after load page, not binding after popover)</a>
<div id="gotit"></div>
</div>
</div>
CSS:
.popover {
max-width: none;
top: 20px;
}
JS:
$('#clickmewouldntwork').click(function(){
$('#gotit').append('#');
});
$('#mypopover').click(function(){
var $target = $('#popoverContent');
$target.toggle(!$target.is(':visible'));
});
Question 2
You have to overwrite bootstrap .popover { max-width: 276px; }
:
.popover {
max-width: none;
}
Upvotes: 1