mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Source formatting #63
This commit is contained in:
parent
c666150278
commit
0b9a0402b9
@ -2,23 +2,6 @@ import ClipboardAction from './clipboard-action';
|
|||||||
import Delegate from 'delegate-events';
|
import Delegate from 'delegate-events';
|
||||||
import Emitter from 'tiny-emitter';
|
import Emitter from 'tiny-emitter';
|
||||||
|
|
||||||
const prefix = 'data-clipboard-';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to retrieve attribute value.
|
|
||||||
* @param {String} suffix
|
|
||||||
* @param {Element} element
|
|
||||||
*/
|
|
||||||
function getAttributeValue(suffix, element) {
|
|
||||||
let attribute = prefix + suffix;
|
|
||||||
|
|
||||||
if (!element.hasAttribute(attribute)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return element.getAttribute(attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class which takes a selector, delegates a click event to it,
|
* Base class which takes a selector, delegates a click event to it,
|
||||||
* and instantiates a new `ClipboardAction` on each click.
|
* and instantiates a new `ClipboardAction` on each click.
|
||||||
@ -41,9 +24,9 @@ class Clipboard extends Emitter {
|
|||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
*/
|
*/
|
||||||
resolveOptions(options = {}) {
|
resolveOptions(options = {}) {
|
||||||
this.action = (typeof options.action === 'function') ? options.action : this.setAction;
|
this.action = (typeof options.action === 'function') ? options.action : this.defaultAction;
|
||||||
this.target = (typeof options.target === 'function') ? options.target : this.setTarget;
|
this.target = (typeof options.target === 'function') ? options.target : this.defaultTarget;
|
||||||
this.text = (typeof options.text === 'function') ? options.text : this.setText;
|
this.text = (typeof options.text === 'function') ? options.text : this.defaultText;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,7 +59,7 @@ class Clipboard extends Emitter {
|
|||||||
* Default `action` lookup function.
|
* Default `action` lookup function.
|
||||||
* @param {Element} trigger
|
* @param {Element} trigger
|
||||||
*/
|
*/
|
||||||
setAction(trigger) {
|
defaultAction(trigger) {
|
||||||
return getAttributeValue('action', trigger);
|
return getAttributeValue('action', trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,21 +67,37 @@ class Clipboard extends Emitter {
|
|||||||
* Default `target` lookup function.
|
* Default `target` lookup function.
|
||||||
* @param {Element} trigger
|
* @param {Element} trigger
|
||||||
*/
|
*/
|
||||||
setTarget(trigger) {
|
defaultTarget(trigger) {
|
||||||
let selector = getAttributeValue('target', trigger);
|
let selector = getAttributeValue('target', trigger);
|
||||||
|
|
||||||
if ('string' === typeof selector) {
|
if (selector) {
|
||||||
return document.querySelector(selector);
|
return document.querySelector(selector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defualt `text` lookup function.
|
* Default `text` lookup function.
|
||||||
* @param {Element} trigger
|
* @param {Element} trigger
|
||||||
*/
|
*/
|
||||||
setText(trigger) {
|
defaultText(trigger) {
|
||||||
return getAttributeValue('text', trigger);
|
return getAttributeValue('text', trigger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to retrieve attribute value.
|
||||||
|
* @param {String} suffix
|
||||||
|
* @param {Element} element
|
||||||
|
*/
|
||||||
|
function getAttributeValue(suffix, element) {
|
||||||
|
let attribute = `data-clipboard-${suffix}`;
|
||||||
|
|
||||||
|
if (!element.hasAttribute(attribute)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return element.getAttribute(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
export default Clipboard;
|
export default Clipboard;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user