diff --git a/src/clipboard-action.js b/src/clipboard-action.js index 8346b81..dbb1e62 100644 --- a/src/clipboard-action.js +++ b/src/clipboard-action.js @@ -7,15 +7,15 @@ class ClipboardAction { * @param {Object} options */ constructor(options) { - this.resolveOptions(options); - this.initSelection(); + this._resolveOptions(options); + this._initSelection(); } /** * Defines base properties passed from constructor. * @param {Object} options */ - resolveOptions(options = {}) { + _resolveOptions(options = {}) { this.action = options.action; this.emitter = options.emitter; this.target = options.target; @@ -29,7 +29,7 @@ class ClipboardAction { * Decides which selection strategy is going to be applied based * on the existence of `text` and `target` properties. */ - initSelection() { + _initSelection() { if (this.text && this.target) { throw new Error('Multiple attributes declared, use either "target" or "text"'); } @@ -37,7 +37,7 @@ class ClipboardAction { this.selectFake(); } else if (this.target) { - this.selectTarget(); + this._selectTarget(); } else { throw new Error('Missing required attributes, use either "target" or "text"'); @@ -63,7 +63,7 @@ class ClipboardAction { document.body.appendChild(this.fakeElem); this.fakeElem.select(); - this.copyText(); + this._copyText(); } /** @@ -85,7 +85,7 @@ class ClipboardAction { /** * Selects the content from element passed on `target` property. */ - selectTarget() { + _selectTarget() { if (this.target.nodeName === 'INPUT' || this.target.nodeName === 'TEXTAREA') { this.target.select(); this.selectedText = this.target.value; @@ -99,13 +99,13 @@ class ClipboardAction { this.selectedText = selection.toString(); } - this.copyText(); + this._copyText(); } /** * Executes the copy operation based on the current selection. */ - copyText() { + _copyText() { let succeeded; try { diff --git a/src/clipboard.js b/src/clipboard.js index 5f2bcd0..89413a7 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -16,8 +16,8 @@ class Clipboard extends Emitter { constructor(selector, options) { super(); - this.resolveOptions(options); - this.delegateClick(selector); + this._resolveOptions(options); + this._delegateClick(selector); } /** @@ -25,17 +25,17 @@ class Clipboard extends Emitter { * or custom functions that were passed in the constructor. * @param {Object} options */ - resolveOptions(options = {}) { + _resolveOptions(options = {}) { this.action = (typeof options.action === 'function') ? options.action : this.setAction; this.target = (typeof options.target === 'function') ? options.target : this.setTarget; this.text = (typeof options.text === 'function') ? options.text : this.setText; } /** - * Delegates a click event on the passed selector. + * Delegates a click event to the passed selector. * @param {String} selector */ - delegateClick(selector) { + _delegateClick(selector) { Delegate.bind(document.body, selector, 'click', (e) => this.initialize(e)); } diff --git a/test/clipboard-action.js b/test/clipboard-action.js index ace0825..6c634aa 100644 --- a/test/clipboard-action.js +++ b/test/clipboard-action.js @@ -19,7 +19,7 @@ describe('ClipboardAction', () => { document.body.innerHTML = ''; }); - describe('#resolveOptions', () => { + describe('_resolveOptions', () => { it('should set base properties', () => { let clip = new ClipboardAction({ emitter: new Emitter(), @@ -35,7 +35,7 @@ describe('ClipboardAction', () => { }); }); - describe('#initSelection', () => { + describe('_initSelection', () => { it('should throw an error since both "text" and "target" were passed', done => { try { new ClipboardAction({ @@ -113,7 +113,7 @@ describe('ClipboardAction', () => { }); }); - describe('#selectTarget', () => { + describe('_selectTarget', () => { it('should select text from editable element', () => { let clip = new ClipboardAction({ emitter: new Emitter(), diff --git a/test/clipboard.js b/test/clipboard.js index b62e859..4f95be5 100644 --- a/test/clipboard.js +++ b/test/clipboard.js @@ -18,7 +18,7 @@ describe('Clipboard', () => { document.body.innerHTML = ''; }); - describe('#resolveOptions', function() { + describe('_resolveOptions', function() { before(() => { global.fn = function() {}; }); @@ -48,7 +48,7 @@ describe('Clipboard', () => { }); }); - describe('#delegateClick', function() { + describe('_delegateClick', function() { before(() => { global.spy = sinon.spy(Delegate, 'bind'); });