From de8d3e2b828f55f1b525cd08d9cacc24b0d39658 Mon Sep 17 00:00:00 2001 From: "olau@iola.dk" Date: Fri, 29 Feb 2008 11:45:56 +0000 Subject: [PATCH] Fixed IE 7 problem with selecting git-svn-id: https://flot.googlecode.com/svn/trunk@48 1e0a6537-2640-0410-bfb7-f154510ff394 --- NEWS.txt | 4 +++- jquery.flot.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/NEWS.txt b/NEWS.txt index 74d0558..20fd1ec 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -27,7 +27,9 @@ The option axis.tickFormatter now takes a function with two parameters, the second parameter is an optional object with information about the axis. It has min, max, tickDecimals, tickSize. -Fixed a bug in handling single-item bar series (reported by Emil Filipov). +Fixed a bug in handling single-item bar series (reported by Emil +Filipov). Fixed erratic behaviour when selecting with IE 7 (reported +by Lau Bech Lauritzen). diff --git a/jquery.flot.js b/jquery.flot.js index 482d094..52c6000 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -95,6 +95,9 @@ var hozScale = 0; var vertScale = 0; + // dedicated to storing data for buggy standard compliance cases + var workarounds = {}; + // initialize series = parseData(data_); parseOptions(options_); @@ -172,6 +175,11 @@ function bindEvents() { if (options.selection.mode != null) { $(overlay).mousedown(onMouseDown); + + // we put the mouse down on canvas too, because IE 7 sometimes + // has trouble with the stacking order + $(canvas).mousedown(onMouseDown); + // FIXME: temp. work-around until jQuery bug 1871 is fixed target.get(0).onmousemove = onMouseMove; } @@ -1302,6 +1310,21 @@ if (e.which != 1) // only accept left-click return; + // cancel out any text selections + document.body.focus(); + + // prevent text selection in IE + if ($.browser == "msie") { + if (workarounds.onselectstart == null) { + workarounds.onselectstart = document.onselectstart; + document.onselectstart = function () { return false; }; + } + if (workarounds.ondrag == null) { + workarounds.ondrag = document.ondrag; + document.ondrag = function () { return false; }; + } + } + setSelectionPos(selection.first, e); if (selectionInterval != null) @@ -1357,6 +1380,11 @@ } function onSelectionMouseUp(e) { + if ($.browser == "msie") { + document.onselectstart = workarounds.onselectstart; + document.ondrag = workarounds.ondrag; + } + if (selectionInterval != null) { clearInterval(selectionInterval); selectionInterval = null;