From 07a1f8456b219feae3fbaf4db1e6fee1ad48d530 Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Tue, 1 Mar 2016 15:38:25 -0800 Subject: [PATCH] Throws error when disabled or readonly attributes are used on target element Fixes #41 --- src/clipboard-action.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/clipboard-action.js b/src/clipboard-action.js index f9863ff..da0496d 100644 --- a/src/clipboard-action.js +++ b/src/clipboard-action.js @@ -179,6 +179,14 @@ class ClipboardAction { set target(target) { if (target !== undefined) { if (target && typeof target === 'object' && target.nodeType === 1) { + if (this.action === 'copy' && target.hasAttribute('disabled')) { + throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); + } + + if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { + throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); + } + this._target = target; } else {