|
99 | 99 | } |
100 | 100 | }; |
101 | 101 |
|
102 | | - if (!animDuration) animDuration = 300; |
| 102 | + if (typeof animDuration == "undefined") animDuration = 300; |
103 | 103 | if (!easing) easing = 'linear'; |
104 | 104 | if (resetAreas) options.areas = {}; |
105 | 105 | if (resetPlots) options.plots = {}; |
|
235 | 235 | options.href && $.fn.mapael.setHref(elem.textElem, options.href); |
236 | 236 | $.fn.mapael.setHoverOptions(elem.textElem, options.textAttrs, options.textAttrsHover); |
237 | 237 | $.fn.mapael.setHover(paper, elem.mapElem, elem.textElem); |
238 | | - $.fn.mapael.setCallbacks(options, elem.mapElem, elem.textElem); |
| 238 | + options.eventHandlers && $.fn.mapael.setEventHandlers(id, options, elem.mapElem, elem.textElem); |
239 | 239 | $(elem.textElem.node).attr('class', id); |
240 | 240 | } else { |
241 | 241 | $.fn.mapael.setHover(paper, elem.mapElem); |
242 | | - $.fn.mapael.setCallbacks(options, elem.mapElem); |
| 242 | + options.eventHandlers && $.fn.mapael.setEventHandlers(id, options, elem.mapElem); |
243 | 243 | } |
244 | 244 |
|
245 | 245 | if (options.tooltip && options.tooltip.content) { |
|
289 | 289 | }; |
290 | 290 |
|
291 | 291 | /** |
292 | | - * Set user defined callbacks on areas and plots |
| 292 | + * Set user defined handlers for events on areas and plots |
| 293 | + * @param id the id of the element |
293 | 294 | * @param elemOptions the element parameters |
294 | 295 | * @param mapElem the map element to set callback on |
295 | 296 | * @param textElem the optional text within the map element |
296 | 297 | */ |
297 | | - $.fn.mapael.setCallbacks = function(elemOptions, mapElem, textElem) { |
298 | | - var availableCallbacks = ['click', 'mouseover', 'mouseout'] |
299 | | - , callbackFct = {}; |
300 | | - |
301 | | - for(var i = 0, length = availableCallbacks.length; i < length; ++i) { |
302 | | - if (elemOptions["on" + availableCallbacks[i]]) { |
303 | | - callbackFct = elemOptions["on" + availableCallbacks[i]]; |
304 | | - $(mapElem.node).on(availableCallbacks[i], function() {!$.fn.mapael.panning && callbackFct(elemOptions, mapElem, textElem)}); |
305 | | - textElem && $(textElem.node).on(availableCallbacks[i], function() {!$.fn.mapael.panning && callbackFct(elemOptions, mapElem, textElem)}); |
306 | | - } |
| 298 | + $.fn.mapael.setEventHandlers = function(id, elemOptions, mapElem, textElem) { |
| 299 | + for(var event in elemOptions.eventHandlers) { |
| 300 | + (function(event) { |
| 301 | + $(mapElem.node).on(event, function() {!$.fn.mapael.panning && elemOptions.eventHandlers[event](id, mapElem, textElem)}); |
| 302 | + textElem && $(textElem.node).on(event, function() {!$.fn.mapael.panning && elemOptions.eventHandlers[event](id, mapElem, textElem)}); |
| 303 | + })(event); |
307 | 304 | } |
308 | 305 | } |
309 | 306 |
|
|
0 commit comments