Rename data-attributes to prefix "clipboard"

This PR renames all the data-attributes for data-clipboard-X, this is due the possibility of conflict with projects that already uses these data-attributes.
This commit is contained in:
Mauricio Soares
2015-09-28 14:06:22 -03:00
parent d5a4ba1ff0
commit 157b0fb5a2
5 changed files with 24 additions and 22 deletions

View File

@ -16,7 +16,7 @@ class ClipboardAction {
this.selectedText = '';
if (this.text && this.target) {
throw new Error('Multiple attributes declared, use either "data-target" or "data-text"');
throw new Error('Multiple attributes declared, use either "data-clipboard-target" or "data-clipboard-text"');
}
else if (this.text) {
this.selectFake();
@ -25,7 +25,7 @@ class ClipboardAction {
this.selectTarget();
}
else {
throw new Error('Missing required attributes, use either "data-target" or "data-text"');
throw new Error('Missing required attributes, use either "data-clipboard-target" or "data-clipboard-text"');
}
}
@ -144,7 +144,7 @@ class ClipboardAction {
this._action = action || 'copy';
if (this._action !== 'copy' && this._action !== 'cut') {
throw new Error('Invalid "data-action" value, use either "copy" or "cut"');
throw new Error('Invalid "data-clipboard-action" value, use either "copy" or "cut"');
}
}
@ -166,7 +166,7 @@ class ClipboardAction {
this._target = document.getElementById(target);
if (!this._target) {
throw new Error('Invalid "data-target" selector, use a value that matches an ID');
throw new Error('Invalid "data-clipboard-target" selector, use a value that matches an ID');
}
}
}

View File

@ -30,10 +30,12 @@ class Clipboard extends Emitter {
this.clipboardAction = null;
}
const prefix = 'data-clipboard-';
this.clipboardAction = new ClipboardAction({
action : e.delegateTarget.getAttribute('data-action'),
target : e.delegateTarget.getAttribute('data-target'),
text : e.delegateTarget.getAttribute('data-text'),
action : e.delegateTarget.getAttribute(prefix + 'action'),
target : e.delegateTarget.getAttribute(prefix + 'target'),
text : e.delegateTarget.getAttribute(prefix + 'text'),
trigger : e.delegateTarget,
emitter : this
});