-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
11,423 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
{ | ||
'use strict'; | ||
|
||
process.env.EMBER_VERSION = 'OCTANE'; | ||
|
||
module.exports = { | ||
/** | ||
Ember CLI sends analytics information by default. The data is completely | ||
anonymous, but there are times when you might want to disable this behavior. | ||
Setting `disableAnalytics` to true will prevent any data from being sent. | ||
*/ | ||
"disableAnalytics": false | ||
} | ||
disableAnalytics: false | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
/.env* | ||
/.eslintignore | ||
/.eslintrc.js | ||
/.git/ | ||
/.gitignore | ||
/.template-lintrc.js | ||
/.travis.yml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
extends: 'recommended' | ||
extends: 'octane' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,94 @@ | ||
import Component from '@ember/component'; | ||
import { set } from '@ember/object'; | ||
import { action } from '@ember/object'; | ||
import { guidFor } from '@ember/object/internals'; | ||
import layout from '../templates/components/copy-button'; | ||
|
||
const CLIPBOARD_EVENTS = ['success', 'error']; | ||
|
||
export default Component.extend({ | ||
layout: layout, | ||
tagName: 'button', | ||
classNames: ['copy-btn'], | ||
attributeBindings: [ | ||
'clipboardText:data-clipboard-text', | ||
'clipboardTarget:data-clipboard-target', | ||
'clipboardAction:data-clipboard-action', | ||
'buttonType:type', | ||
'disabled', | ||
'aria-label', | ||
'title' | ||
], | ||
export default class CopyButtonComponent extends Component { | ||
layout = layout; | ||
tagName = ""; | ||
|
||
/** | ||
* @property {String} buttonType - type attribute for button element | ||
* If true - scope event listener to this element | ||
* If false - scope event listener to document.body (ClipboardJS) | ||
* @property {Boolean} delegateClickEvent | ||
*/ | ||
buttonType: 'button', | ||
delegateClickEvent = true; | ||
|
||
/** | ||
* @property {Boolean} disabled - disabled state for button element | ||
* Assigns button element an id | ||
* @returns {Void} | ||
*/ | ||
disabled: false, | ||
@action | ||
setupElement(element) { | ||
element.id = guidFor(this); | ||
this._buttonElement = element; | ||
} | ||
|
||
/** | ||
* If true - scope event listener to this element | ||
* If false - scope event listener to document.body (ClipboardJS) | ||
* @property {Boolean} delegateClickEvent | ||
* Registers ClipboardJS object with component | ||
* @private | ||
* @returns {Void} | ||
*/ | ||
delegateClickEvent: true, | ||
@action | ||
registerClipboard() { | ||
if (this.clipboard) { | ||
this.clipboard.destroy(); | ||
} | ||
|
||
const clipboard = this._createClipboard(); | ||
this._registerActions(clipboard); | ||
this.clipboard = clipboard; | ||
} | ||
|
||
/** | ||
* Destroys `ClipboardJS` instance | ||
* @returns {Void} | ||
*/ | ||
@action | ||
destroyClipboard() { | ||
if (this.clipboard) { | ||
this.clipboard.destroy(); | ||
} | ||
} | ||
|
||
/** | ||
* Creates new `ClipboardJS` instance | ||
* @method _createClipboard | ||
* @private | ||
* @returns {Object} newly created ClipboardJS object | ||
*/ | ||
_createClipboard() { | ||
const { clipboardText: text } = this; | ||
const trigger = this.delegateClickEvent | ||
? `#${this.elementId}` | ||
: this.element; | ||
const { clipboardText: text, delegateClickEvent } = this; | ||
const trigger = delegateClickEvent === false | ||
? this._buttonElement | ||
: `#${this._buttonElement.id}`; | ||
|
||
|
||
return new window.ClipboardJS(trigger, { | ||
text: typeof text === 'function' ? text : undefined | ||
}); | ||
}, | ||
} | ||
|
||
/** | ||
* Registers Ember Actions with ClipboardJS events | ||
* @method _registerActions | ||
* @private | ||
* @param {Object} clipboard - ClipboardJS object | ||
* @returns {Void} | ||
*/ | ||
_registerActions(clipboard) { | ||
CLIPBOARD_EVENTS.forEach(event => { | ||
clipboard.on(event, () => { | ||
if (!this.disabled) { | ||
const action = this[event] || (() => {}); | ||
if (!this._buttonElement.disabled) { | ||
const action = this[event]; | ||
if (typeof action === 'string') { | ||
// eslint-disable-next-line ember/closure-actions | ||
this.sendAction(action, ...arguments); | ||
} else { | ||
action(...arguments); | ||
action && action(...arguments); | ||
} | ||
} | ||
}); | ||
}); | ||
}, | ||
|
||
/** | ||
* Registers ClipboardJS object with component | ||
* @method _registerClipboard | ||
* @private | ||
* @returns {Void} | ||
*/ | ||
_registerClipboard() { | ||
if (this.clipboard) { | ||
this.clipboard.destroy(); | ||
} | ||
|
||
const clipboard = this._createClipboard(); | ||
this._registerActions(clipboard); | ||
set(this, 'clipboard', clipboard); | ||
}, | ||
|
||
didInsertElement() { | ||
this._super(...arguments); | ||
this._registerClipboard(); | ||
}, | ||
|
||
didUpdateAttrs() { | ||
this._super(...arguments); | ||
this._registerClipboard(); | ||
}, | ||
|
||
willDestroyElement() { | ||
if (this.clipboard) { | ||
this.clipboard.destroy(); | ||
} | ||
} | ||
}); | ||
} |
Oops, something went wrong.