Skip to content

Commit

Permalink
Fix attached data for events with jQuery fallback (fixes #38)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Oct 2, 2013
1 parent 484c14b commit cc48de9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG
------------------

* Fix drawing of multi-polygon (fixes #37)
* Fix attached data for events with jQuery fallback (fixes #38)


0.8.1 (2013-09-30)
Expand Down
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,24 @@ If you don't want to expose global callbacks :

<script type="text/javascript">
window.addEventListener("map:init", function (e) {
var detail = e.detail;
...
L.marker([50.5, 30.5]).addTo(e.map);
L.marker([50.5, 30.5]).addTo(detail.map);
...
}, false);
</script>

Event object has two properties : ``map`` and ``options`` (initialization).

For Internet Explorer 6,7,8 support, we fallback on jQuery if available ::
For Internet Explorer support, we fallback on jQuery if available ::

$(window).on('map:init', function (e) { ... });
$(window).on('map:init', function (e) {
var detail = e.originalEvent ?
e.originalEvent.detail : e.detail;
...
L.marker([50.5, 30.5]).addTo(detail.map);
...
});

If you want to support archaic browsers **and** still avoid jQuery,
*django-leaflet* comes with a minimalist polyfill for events.
Expand Down
5 changes: 2 additions & 3 deletions leaflet/static/leaflet/leaflet.extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,12 @@ L.Map.djangoMap = function (id, options) {

function triggerEvent(target, type, data) {
if (typeof window.CustomEvent == 'function') {
var evt = new CustomEvent(type, data);
var evt = new CustomEvent(type, {detail: data});
target.dispatchEvent(evt);
}
else if (window.jQuery) {
var evt = jQuery.Event(type);
for (var k in data)
evt[k] = data[k];
evt.detail = data;
jQuery(target).trigger(evt);
}
}
Expand Down

0 comments on commit cc48de9

Please sign in to comment.