Throws error when disabled or readonly attributes are used on target element

Fixes #41
This commit is contained in:
Zeno Rocha 2016-03-01 15:38:25 -08:00
parent ff3cd2c722
commit 07a1f8456b

View File

@ -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 {