From d602da20f657be7174ebf915e309e00ecaa6c6a1 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Fri, 15 Nov 2019 09:21:45 +0100 Subject: [PATCH] Fix flot overriding onselectstart/ondrag events (#20381) --- public/vendor/flot/jquery.flot.selection.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/public/vendor/flot/jquery.flot.selection.js b/public/vendor/flot/jquery.flot.selection.js index b34efd17775..10a11ffa9d6 100644 --- a/public/vendor/flot/jquery.flot.selection.js +++ b/public/vendor/flot/jquery.flot.selection.js @@ -323,7 +323,6 @@ The plugin allso adds the following methods to the plot object: } }); - plot.hooks.drawOverlay.push(function (plot, ctx) { // draw selection if (selection.show && selectionIsSane()) { @@ -356,8 +355,23 @@ The plugin allso adds the following methods to the plot object: eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousedown", onMouseDown); - if (mouseUpHandler) + if (mouseUpHandler) { $(document).unbind("mouseup", mouseUpHandler); + // grafana addition + // In L114 this plugin is overrinding document.onselectstart handler to prevent default or custom behaviour + // Then this patch is being restored during mouseup event. But, mouseup handler is unbound when this plugin is destroyed + // and the overriden onselectstart handler is not restored. The problematic behaviour surfaces when flot is re-rendered + // as a consequence of panel's model update. When i.e. options are applied via onBlur + // event on some input which results in flot re-render. The mouseup handler should be called to resture the original handlers + // but by the time the document mouseup event occurs, the event handler is no longer there, so onselectstart is permanently overriden. + // To fix that we are making sure that the overrides are reverted when this plugin is destroyed, the same way as they would + // via mouseup event handler (L138) + + if (document.onselectstart !== undefined) + document.onselectstart = savedhandlers.onselectstart; + if (document.ondrag !== undefined) + document.ondrag = savedhandlers.ondrag; + } }); }