Skip to content

Commit

Permalink
Use jQuery for triggering events only if CustomEvent constructor is n…
Browse files Browse the repository at this point in the history
…ot available (fixes #27, fixes #34)
  • Loading branch information
leplatrem committed Sep 18, 2013
1 parent 9a80a31 commit c14ff11
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
* Renamed Leaflet map fragment template
* Leaflet map geometry widgets for adminsite and forms (requires Django 1.6)
* Fix geometry type restriction in form fields (fixes #32)
* Use jQuery for triggering events, only if CustomEvent constructor is not available (fixes #27, fixes #34)

0.7.4 (2013-08-28)
------------------
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -74,7 +74,7 @@ grab a reference on the just initialized map and options.

**Using Javascript callback function**

Simple brutish way :
The easy way :

::

Expand All @@ -91,7 +91,7 @@ Simple brutish way :

**Using events**

More refined and flexible :
If you don't want to expose global callbacks :

::

Expand Down
10 changes: 5 additions & 5 deletions leaflet/static/leaflet/leaflet.extras.js
Expand Up @@ -206,15 +206,15 @@ L.Map.djangoMap = function (id, options) {


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

0 comments on commit c14ff11

Please sign in to comment.