diff options
-rw-r--r-- | chimere/static/chimere/js/jquery.chimere.js | 115 |
1 files changed, 43 insertions, 72 deletions
diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js index a94b74e..9ee0c49 100644 --- a/chimere/static/chimere/js/jquery.chimere.js +++ b/chimere/static/chimere/js/jquery.chimere.js @@ -155,62 +155,6 @@ function transform(obj) { return v; }; })( jQuery ); -/* - * hovering management - */ - -var register_hovering = function(exp, handlers_to_deactivate){ - $(document).on({ - mouseenter: function(evt) { - $(evt.target).data('hovering', true); - if (handlers_to_deactivate){ - for (idx in handlers_to_deactivate){ - handlers_to_deactivate[idx].setActive(false); - } - } - }, - mouseleave: function(evt) { - $(evt.target).data('hovering', false); - if (handlers_to_deactivate){ - for (idx in handlers_to_deactivate){ - handlers_to_deactivate[idx].setActive(true); - } - } - } - }, exp); - $(exp).hover(function(){ - $(this).data('hovering', true); - if (handlers_to_deactivate){ - for (idx in handlers_to_deactivate){ - handlers_to_deactivate[idx].setActive(false); - } - } - }, function(){ - $(this).data('hover', false); - if (handlers_to_deactivate){ - for (idx in handlers_to_deactivate){ - handlers_to_deactivate[idx].setActive(true); - } - } - }); - -} - -var unregister_hovering = function(exp, handlers_to_deactivate){ - $(exp).data('hovering', false); - if (handlers_to_deactivate){ - for (idx in handlers_to_deactivate){ - handlers_to_deactivate[idx].setActive(true); - } - } -} - -// jQuery pseudo-expression :hovering -jQuery.expr[":"].hovering = function(elem) { - return $(elem).data('hovering') ? true : false; -}; - - (function ($) { /* * Chimere jQuery plugin @@ -404,6 +348,8 @@ jQuery.expr[":"].hovering = function(elem) { settings.DragPan = interaction; } }); + settings.deactivate_on_hover = [settings.MouseWheelZoom, + settings.DragPan]; // only display the first layer $.each(settings.map.getLayers().getArray(), function(i, layer){ @@ -569,16 +515,7 @@ jQuery.expr[":"].hovering = function(elem) { ); settings.current_feature = feature; if (!settings.edition){ - if ($('.popover-content').is(":hovering")){ - // the popup is no more visible bad info - if ($('.popover:visible').length == 0){ - unregister_hovering('.popover-content', - [settings.MouseWheelZoom, - settings.DragPan]); - } else { - return; - } - } + if (methods._is_popuphovering()) return; if (feature) { $(settings.popup_item).popover('destroy'); @@ -839,6 +776,43 @@ jQuery.expr[":"].hovering = function(elem) { methods.preload_images(); */ }, // end of init + /* + * hovering management + */ + _is_popuphovering: function(){ + if ($('.popover-content:hover').length > 0){ + for (idx in settings.deactivate_on_hover){ + settings.deactivate_on_hover[idx].setActive(false); + return true; + } + } else { + for (idx in settings.deactivate_on_hover){ + settings.deactivate_on_hover[idx].setActive(true); + return false; + } + } + }, + _register_popuphovering: function(){ + $(document).on({ + mouseenter: function(evt) { + for (idx in settings.deactivate_on_hover){ + settings.deactivate_on_hover[idx].setActive(false); + } + }, + mouseleave: function(evt) { + for (idx in settings.deactivate_on_hover){ + settings.deactivate_on_hover[idx].setActive(true); + } + } + }, '.popover-content'); + methods._is_popuphovering(); + + }, + _unregister_popuphovering: function(){ + for (idx in settings.deactivate_on_hover){ + settings.deactivate_on_hover[idx].setActive(true); + } + }, register_reload_on_move: function(){ var reload_on_move = function(evnt){ settings._revision += 1; @@ -1089,10 +1063,9 @@ jQuery.expr[":"].hovering = function(elem) { 'html': true, 'content': feature.get('name') }); + // when the popup is closed $(settings.popup_item).on('hidden.bs.popover', function () { - unregister_hovering('.popover-content', - [settings.MouseWheelZoom, - settings.DragPan]); + methods._unregister_popuphovering(); }) $(settings.popup_item).popover('show'); methods.display_feature_detail(feature.get('key'), feature.get('name')); @@ -2413,9 +2386,7 @@ jQuery.expr[":"].hovering = function(elem) { // to trigger autopan settings.popup.dispatchEvent('change:position'); $(".popover").removeClass('transparent'); - register_hovering('.popover-content', - [settings.MouseWheelZoom, - settings.DragPan]); + methods._register_popuphovering(); }, settings.animation_duration + 10 ); } |