From 031afdee246f404c8ecaa635a58c457ac899c837 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke <marijnh@gmail.com> Date: Fri, 2 Oct 2015 23:46:20 +0200 Subject: [PATCH] Clean up allowDroppedFileTypes implementation, rename to allowDropFileTypes Make it actually work, document it, declare the option, make sure the code runs on pre-ES5 browsers. Issue #3550 --- doc/manual.html | 7 +++++++ lib/codemirror.js | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/manual.html b/doc/manual.html index e2a3269d6..095a80cd1 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -421,6 +421,13 @@ <dt id="option_dragDrop"><code><strong>dragDrop</strong>: boolean</code></dt> <dd>Controls whether drag-and-drop is enabled. On by default.</dd> + <dt id="option_allowDropFileTypes"><code><strong>allowDropFileTypes</strong>: array<string></code></dt> + <dd>When set (default is <code>null</code>) only files whose + type is in the array can be dropped into the editor. The strings + should be MIME types, and will be checked against + the <a href="https://w3c.github.io/FileAPI/#dfn-type"><code>type</code></a> + of the <code>File</code> object as reported by the browser.</dd> + <dt id="option_cursorBlinkRate"><code><strong>cursorBlinkRate</strong>: number</code></dt> <dd>Half-period in milliseconds used for cursor blinking. The default blink rate is 530ms. By setting this to zero, blinking can be disabled. A diff --git a/lib/codemirror.js b/lib/codemirror.js index 996978fc6..f0f8837ae 100644 --- a/lib/codemirror.js +++ b/lib/codemirror.js @@ -3821,7 +3821,8 @@ if (files && files.length && window.FileReader && window.File) { var n = files.length, text = Array(n), read = 0; var loadFile = function(file, i) { - if(this.options.allowDroppedFileTypes !== undefined && this.options.allowDroppedFileTypes.indexOf(file.type) === -1) + if (cm.options.allowDropFileTypes && + indexOf(cm.options.allowDropFileTypes, file.type) == -1) return; var reader = new FileReader; @@ -5408,6 +5409,7 @@ }); option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset();}, true); option("dragDrop", true, dragDropChanged); + option("allowDropFileTypes", null); option("cursorBlinkRate", 530); option("cursorScrollMargin", 0); -- GitLab