Skip to content

Commit

Permalink
Upgrade to Ember 3.15
Browse files Browse the repository at this point in the history
  • Loading branch information
jkusa committed Jan 13, 2020
1 parent 5456aa3 commit e91952d
Show file tree
Hide file tree
Showing 32 changed files with 11,423 additions and 480 deletions.
10 changes: 7 additions & 3 deletions .ember-cli → .ember-cli.js
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
};
14 changes: 10 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
},
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
env: {
browser: true
},
rules: {},
rules: {
'ember/no-jquery': 'error'
},
overrides: [
// node files
{
files: [
'.ember-cli.js',
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
Expand All @@ -30,8 +37,7 @@ module.exports = {
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
sourceType: 'script'
},
env: {
browser: false,
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
/coverage/
/libpeerconnection.log
/npm-debug.log*
/package-lock.json
/testem.log
/yarn-error.log
/jsconfig.json

# ember-try
/.node_modules.ember-try/
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/.env*
/.eslintignore
/.eslintrc.js
/.git/
/.gitignore
/.template-lintrc.js
/.travis.yml
Expand Down
2 changes: 1 addition & 1 deletion .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'recommended'
extends: 'octane'
};
46 changes: 33 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,69 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- '8'
- '10'

sudo: true
sudo: false
dist: trusty

addons:
chrome: stable

cache:
directories:
- $HOME/.npm
- $HOME/.cache # includes bowers cache
yarn: true

env:
global:
# See https://git.io/vdao3 for details.
- JOBS=1

branches:
only:
- master
# npm version tags
- /^v\d+\.\d+\.\d+/

jobs:
fail_fast: true

allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

include:
# runs linting and tests with current locked deps
- stage: "Tests"
name: "Tests"
script:
- yarn lint:hbs
- yarn lint:js
- yarn test

- stage: 'Tests'
name: 'Tests'
- name: 'Floating Dependencies'
script:
- yarn test

- stage: "Additional Tests"
name: "Floating Dependencies"
install:
- npm install --no-package-lock
script:
- npm run lint:hbs
- npm run lint:js
- npm test

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- stage: 'Additional Tests'
env: EMBER_TRY_SCENARIO=ember-lts-2.18
- env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-lts-3.8
- env: EMBER_TRY_SCENARIO=ember-lts-3.12
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-classic

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --no-lockfile --non-interactive

script:
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO
24 changes: 12 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

## Installation

* `git clone <repository-url>`
* `cd my-addon`
* `npm install`
- `git clone <repository-url>`
- `cd ember-cli-clipboard`
- `yarn install`

## Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js -- --fix`
- `yarn lint:hbs`
- `yarn lint:js`
- `yarn lint:js --fix`

## Running tests

* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions
- `ember test` – Runs the test suite on the current Ember version
- `ember test --server` – Runs the test suite in "watch mode"
- `ember try:each` – Runs the test suite against multiple Ember versions

## Running the dummy application

* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).
- `ember serve`
- Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ http://jkusa.github.io/ember-cli-clipboard
{{/copy-button}}
```

### Properties
### Arguments

- `clipboardText` - string value or action that returns a string to be copied
- `clipboardTarget` - selector string of element from which to copy text
- `clipboardAction` - string value of operation: `copy` or `cut` (default is copy)
- `delegateClickEvent` - clipboard.js defaults event listeners to the body in order to reduce memory footprint if there are hundreds of event listeners on a page. If you want to scope the event listener to the copy button, set this property to `false`
- `title` - string value of the button's [title attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title)
- `buttonType` - string value of the button's [type attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Attributes)

Any HTML [button attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Attributes) passed to the component will be "splatted" on the button element. The one exception to this is the `type` attribute due to this [issue](https://github.com/emberjs/ember.js/issues/18232). The following legacy arguments are still supported:

- `title` - string value of the button's [title attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title)
- `disabled` - boolean value of the button's [disabled attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Attributes)
- `aria-label` - string value of the button's [aria-label attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute)

Expand Down Expand Up @@ -196,7 +199,7 @@ test('copy-button integration', function(assert) {

this.render(hbs`
<CopyButton
@classNames="my-copy-btn"
class="my-copy-btn"
@clipboardText="text to be copied"
@success={{action "success"}}
@error={{action "error"}}
Expand Down
116 changes: 51 additions & 65 deletions addon/components/copy-button.js
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();
}
}
});
}
Loading

0 comments on commit e91952d

Please sign in to comment.