Skip to content

Commit 1d0d61b

Browse files
committed
Don't try to use drag-and-drop on browsers that don't support it
1 parent 9a7c474 commit 1d0d61b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/codemirror.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ var CodeMirror = (function() {
275275
} else { lastClick = now; }
276276

277277
var last = start, going;
278-
if (!posLess(start, sel.from) && !posLess(sel.to, start)) {
278+
if (dragAndDrop && !posLess(start, sel.from) && !posLess(sel.to, start)) {
279279
// Let the drag handler handle this.
280280
return;
281281
}
@@ -2009,6 +2009,15 @@ var CodeMirror = (function() {
20092009
pre.innerHTML = " "; return !pre.innerHTML;
20102010
})();
20112011

2012+
// Detect drag-and-drop
2013+
var dragAndDrop = (function() {
2014+
// IE8 has ondragstart and ondrop properties, but doesn't seem to
2015+
// actually support ondragstart the way it's supposed to work.
2016+
if (/MSIE [1-8]\b/.test(navigator.userAgent)) return false;
2017+
var div = document.createElement('div');
2018+
return "ondragstart" in div && "ondrop" in div;
2019+
})();
2020+
20122021
var gecko = /gecko\/\d{7}/i.test(navigator.userAgent);
20132022
var ie = /MSIE \d/.test(navigator.userAgent);
20142023
var safari = /Apple Computer/.test(navigator.vendor);
@@ -2184,5 +2193,4 @@ var CodeMirror = (function() {
21842193
CodeMirror.defineMIME("text/plain", "null");
21852194

21862195
return CodeMirror;
2187-
})()
2188-
;
2196+
})();

0 commit comments

Comments
 (0)