All Projects → jkusa → Ember Cli Clipboard

jkusa / Ember Cli Clipboard

Licence: mit
A simple ember wrapper around clipboard.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ember Cli Clipboard

Ember Cli Chartist
Ember Addon for Chartist.js
Stars: ✭ 58 (-19.44%)
Mutual labels:  ember, ember-addon
Ember Paper
The Ember approach to Material Design.
Stars: ✭ 871 (+1109.72%)
Mutual labels:  ember, ember-addon
Ember I18n Changeset Validations
ember-i18n support for ember-changeset-validations messages
Stars: ✭ 11 (-84.72%)
Mutual labels:  ember, ember-addon
Ember Sticky Element
An ember component that mimics the functionality of `position: sticky`
Stars: ✭ 51 (-29.17%)
Mutual labels:  ember, ember-addon
Ember Cli Foundation 6 Sass
Stars: ✭ 65 (-9.72%)
Mutual labels:  ember, ember-addon
Ember Cp Validations
Ember computed property based validations
Stars: ✭ 442 (+513.89%)
Mutual labels:  ember, ember-addon
Ember Side Menu
Side menu component for Ember.js applications
Stars: ✭ 58 (-19.44%)
Mutual labels:  ember, ember-addon
Ember Cli Flash
Simple, highly configurable flash messages for ember-cli
Stars: ✭ 358 (+397.22%)
Mutual labels:  ember, ember-addon
Ember React Components
Render React components in Ember
Stars: ✭ 43 (-40.28%)
Mutual labels:  ember, ember-addon
Ember Accessibility
An EmberJS addon to help identify accessibility violations during development
Stars: ✭ 29 (-59.72%)
Mutual labels:  ember, ember-addon
Virtual Each
Ember infinite list component, inspired by react-infinite-list
Stars: ✭ 51 (-29.17%)
Mutual labels:  ember, ember-addon
Ember Styleguide
This is a UI addon that intends to help standardize the Ember family of websites and make it easier to make the Ember website an Ember app.
Stars: ✭ 69 (-4.17%)
Mutual labels:  ember, ember-addon
Ember Intl
Localization library for any Ember Application or Addon
Stars: ✭ 412 (+472.22%)
Mutual labels:  ember, ember-addon
Ember Bootstrap
Ember-cli addon for using Bootstrap as native Ember components.
Stars: ✭ 475 (+559.72%)
Mutual labels:  ember, ember-addon
Ember Decorators
Useful decorators for Ember applications.
Stars: ✭ 360 (+400%)
Mutual labels:  ember, ember-addon
Ember Api Feature Flags
API based, read-only feature flags for Ember
Stars: ✭ 11 (-84.72%)
Mutual labels:  ember, ember-addon
Ember Metrics
Send data to multiple analytics integrations without re-implementing new API
Stars: ✭ 356 (+394.44%)
Mutual labels:  ember, ember-addon
Ember Simple Auth Token
Ember Simple Auth extension that is compatible with token-based authentication like JWT.
Stars: ✭ 356 (+394.44%)
Mutual labels:  ember, ember-addon
Ember Polymer
Use Polymer in your ambitious Ember application! 💎
Stars: ✭ 20 (-72.22%)
Mutual labels:  ember, ember-addon
Docfy
Build fully personalized documentation sites; write content and demos in Markdown.
Stars: ✭ 48 (-33.33%)
Mutual labels:  ember, ember-addon

ember-cli-clipboard

Downloads Build Status Ember Observer Score

A simple ember wrapper around clipboard.js (no flash)

Demo Page

http://jkusa.github.io/ember-cli-clipboard

Usage

Angle Bracket Invocation

<!-- Set text directly -->
<CopyButton
  @clipboardText="text to be copied"
  @success={{this.onSuccess}}
  @error={{this.onError}}
>
  Click To Copy
</CopyButton>

<!-- Get text from action that returns a string -->
<CopyButton
  @clipboardText={{this.getClipboardText}}
  @success={{this.onSuccess}}
  @error={{this.onError}}
>
  Click To Copy
</CopyButton>

<!-- Get text from target element -->
<input id="url" type="text" value="https://github.com/jkusa/ember-cli-clipboard">
<CopyButton
  @clipboardTarget="#url"
  @success={{this.onSuccess}}
  @error={{this.onError}}
>
  Click To Copy
</CopyButton>

Classic Invocation

{{#copy-button
  clipboardText="text to be copied"
  success=(action "onSuccess")
  error=(action "onError")
}}
  Click To Copy
{{/copy-button}}

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)
  • container - selector string or element object of containing element. "For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value".
  • 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
  • buttonType - string value of the button's type attribute

Any HTML button attribute passed to the component will be "splatted" on the button element. The one exception to this is the type attribute due to this issue. The following legacy arguments are still supported:

Actions

The following clipboard.js custom events are sent as actions

  • success sent on successful copy
  • error sent on failed copy

More information about the clipboard.js events can be found here

Template Helper

The helper is-clipboard-supported can be used to check if clipboard.js is supported or not.

{{#if (is-clipboard-supported)}}
  <CopyButton @clipboardTarget="#url">
    Click To Copy
  </CopyButton>
{{/if}}

Test Helpers

Some browsers do not allow simulated clicks to fire execCommand('copy'). This makes testing difficult. To assist with integration testing, the following test helpers are available to test the wiring of the success and error action handlers.

Acceptance Test Helpers

  • triggerCopySuccess(selector='.copy-btn')
  • triggerCopyError(selector='.copy-btn')

If you are using the NEW Ember Testing API, available in ember-cli-qunit >= 4.2 and ember-cli-mocha >= 0.15.0, then you can simply import the test helpers where needed (for both acceptance and integration tests).

// tests/acceptance/my-test.js

import {
  triggerCopyError,
  triggerCopySuccess,
} from 'ember-cli-clipboard/test-support';

Otherwise, to use the helpers in acceptance tests you need to register them in the /tests/helpers/start-app.js file.

// tests/helpers/start-app.js

import registerClipboardHelpers from '../helpers/ember-cli-clipboard';

registerClipboardHelpers();

export default function startApp(attrs) {

...

Example:

// tests/acceptance/my-test.js

test('copy button message', async function (assert) {
  assert.expect(3);

  await visit('/');
  assert.dom('.alert').doesNotExist('no alert message is initially present');

  triggerCopySuccess();

  assert
    .dom('.alert.alert-success')
    .exists('a success message is displayed when a copy is successful');

  triggerCopyError();

  assert
    .dom('.alert.alert-info')
    .exists('an error message is displayed when a copy is unsuccessful');
});

Integration Test Helpers

  • New Testing API (ember-cli-qunit >= 4.2 or ember-cli-mocha >= 0.15.0)

    • triggerCopySuccess(selector='.copy-btn')
    • triggerCopyError(selector='.copy-btn')
  • Old Testing API

    • triggerSuccess(context, selector='.copy-btn')
    • triggerError(context, selector='.copy-btn')

Example:

// tests/integration/components/my-test.js

// if using NEW ember testing api
import {
  triggerCopyError,
  triggerCopySuccess
} from 'ember-cli-clipboard/test-support';

// if using OLD ember testing api
import {
  triggerError,
  triggerSuccess
} from '../../helpers/ember-cli-clipboard';

...

test('copy-button integration', async function(assert) {
  assert.expect(2);

  this.set('onSuccess', () => {
    assert.ok(true, '`success` action handler correctly fired');
  });

  this.set('onError', () => {
    assert.ok(true, '`error` action handler correctly fired');
  });

  await render(hbs`
    <CopyButton
      class="my-copy-btn"
      @clipboardText="text to be copied"
      @success={{this.onSuccess}}
      @error={{this.onError}}
    >
      Click To Copy
    </CopyButton>
  `);

  //If using NEW ember testing api
  triggerCopyError('.my-copy-btn');
  triggerCopySuccess('.my-copy-btn');

  //If using OLD ember testing api
  triggerError(this, '.my-copy-btn');
  triggerSuccess(this, '.my-copy-btn');
});

Browser Support

For browser support information, checkout the clipboard.js documentation:

https://github.com/zenorocha/clipboard.js/#browser-support

Contributing

Contributions are welcomed. Please read the contributing guidelines.

License

This project is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].