forked from aptible/dashboard.aptible.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aptible#64 from rwjblue/clipboard-copy-rj
Upgrade ember-cli & Clipboard handling.
- Loading branch information
Showing
43 changed files
with
263 additions
and
153 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ignore_dirs": ["tmp"] | ||
} |
This file was deleted.
Oops, something went wrong.
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,29 +1,47 @@ | ||
/*global ZeroClipboard*/ | ||
/*global Clipboard*/ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Component.extend({ | ||
actionLabel: 'Copy', | ||
classNames: ['click-to-copy'], | ||
Clipboard: Clipboard, | ||
errorMessage: 'Press ⌘+C to copy', | ||
isTooltipped: false, | ||
message: null, | ||
successMessage: 'Copied!', | ||
tagName: 'span', | ||
copied: false, | ||
text: null, | ||
title: "Click to copy", | ||
|
||
'data-clipboard-text': Ember.computed.alias('text'), | ||
dataClipboardText: Ember.computed.alias('text'), | ||
|
||
attributeBindings: ['data-clipboard-text', 'title'], | ||
attributeBindings: ['dataClipboardText:data-clipboard-text', | ||
'message:data-message'], | ||
|
||
classNameBindings: ['isTooltipped:tooltipped'], | ||
|
||
setupClipboard: Ember.on('didInsertElement', function(){ | ||
this.clipboard = new ZeroClipboard( this.$() ); | ||
this.clipboard.on('aftercopy', Ember.run.bind(this, 'afterCopy')); | ||
this.clipboard = new this.Clipboard('#' + this.elementId); | ||
this.clipboard.on('success', Ember.run.bind(this, 'success')); | ||
this.clipboard.on('error', Ember.run.bind(this, 'error')); | ||
}), | ||
|
||
afterCopy: function(){ | ||
this.set('copied', true); | ||
Ember.run.later(this, 'set', 'copied', false, 1500); | ||
success: function(){ | ||
this.set('message', this.successMessage); | ||
this.showMessage(); | ||
}, | ||
|
||
error: function(){ | ||
this.set('message', this.errorMessage); | ||
this.showMessage(); | ||
}, | ||
|
||
teardownClipboard: Ember.on('willDestroyElement', function(){ | ||
if (this.clipboard) { | ||
this.clipboard.destroy(); | ||
} | ||
}) | ||
showMessage: function() { | ||
this.set('isTooltipped', true); | ||
|
||
Ember.run.later(() => { | ||
if (!this.isDestroying && !this.isDestroyed) { | ||
this.set('isTooltipped', 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,4 +94,4 @@ pre.code, | |
.instructions-section { | ||
margin: 0 0 15px; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
@import "layout"; | ||
@import "panels"; | ||
@import "sidebar"; | ||
@import "components/click-to-copy"; |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Click To Copy Component | ||
// See also | ||
// - app/templates/components/click-to-copy.hbs | ||
// - app/components/click-to-copy/component.js | ||
// Styles a span tag with expected attributes | ||
// `<span class="click-to-copy" data-message="Copied!" ... >Copy</span>` | ||
.click-to-copy { | ||
color: $color-bright-blue; | ||
cursor: pointer; | ||
&:hover { | ||
text-decoration: underline; | ||
} | ||
&.tooltipped { | ||
position: relative; | ||
// This is the tooltip bubble | ||
&:after { | ||
-webkit-font-smoothing: subpixel-antialiased; | ||
background-color: rgba(0,0,0,0.75); | ||
border-radius: 3px; | ||
color: white; | ||
content: attr(data-message); | ||
display: inline-block; | ||
font: normal normal 11px/1.5; | ||
letter-spacing: normal; | ||
margin-top: 5px; | ||
padding: 5px 8px; | ||
pointer-events: none; | ||
position: absolute; | ||
right: 50%; | ||
text-align: center; | ||
top: 100%; | ||
transform: translateX(50%); | ||
white-space: pre; | ||
z-index: 1000000; | ||
} | ||
// This is the tooltip arrow | ||
&:before { | ||
border: 5px solid transparent; | ||
border-bottom-color: rgba(0,0,0,0.75); | ||
bottom: -5px; | ||
color: rgba(0,0,0,0.75); | ||
content: ""; | ||
display: inline-block; | ||
height: 0; | ||
margin-right: -5px; | ||
pointer-events: none; | ||
position: absolute; | ||
right: 50%; | ||
top: auto; | ||
width: 0; | ||
z-index: 1000001; | ||
} | ||
} | ||
} |
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 +1 @@ | ||
{{yield copied}} | ||
{{actionLabel}} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* jshint node: true */ | ||
/* global require, module */ | ||
|
||
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); | ||
|
||
module.exports = function(defaults) { | ||
var addon = new EmberAddon(defaults, { | ||
// Add options here | ||
}); | ||
|
||
/* | ||
This build file specifes the options for the dummy test app of this | ||
addon, located in `/tests/dummy` | ||
This build file does *not* influence how the addon or the app using it | ||
behave. You most likely want to be modifying `./index.js` or app's build file | ||
*/ | ||
|
||
addon.import('bower_components/bootstrap-sass/assets/javascripts/bootstrap.js'); | ||
addon.import("bower_components/clipboard/dist/clipboard.js"); | ||
|
||
return addon.toTree(); | ||
} |
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 |
---|---|---|
|
@@ -87,5 +87,6 @@ | |
"strict": false, | ||
"white": false, | ||
"eqnull": true, | ||
"esnext": true | ||
"esnext": true, | ||
"unused": true | ||
} |
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,3 +1,3 @@ | ||
<h2 id="title">Welcome to Ember.js</h2> | ||
<h2 id="title">Welcome to Ember</h2> | ||
|
||
{{outlet}} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
|
||
// Clipboard Mock | ||
let clipboardInstance; | ||
function mockClipboard() { | ||
clipboardInstance = this; | ||
} | ||
mockClipboard.prototype.on = function(eventType, callback) { | ||
mockClipboard[eventType] = callback; | ||
}; | ||
|
||
moduleForComponent('click-to-copy', { | ||
integration: true | ||
}); | ||
|
||
test('basic attributes are set', function(assert) { | ||
this.set('mockClipboard', mockClipboard); | ||
this.render( | ||
hbs('{{click-to-copy text="copy this" Clipboard=mockClipboard}}') | ||
); | ||
|
||
let clickToCopy = this.$('.click-to-copy'); | ||
|
||
assert.equal(clickToCopy.attr('data-clipboard-text'), 'copy this'); | ||
assert.equal(clickToCopy.text().trim(), 'Copy'); | ||
assert.ok(clickToCopy.hasClass('click-to-copy')); | ||
|
||
mockClipboard.success(); | ||
assert.equal(clickToCopy.attr('data-message'), 'Copied!'); | ||
assert.ok(clickToCopy.hasClass('tooltipped')); | ||
|
||
mockClipboard.error(); | ||
assert.equal(clickToCopy.attr('data-message'), 'Press ⌘+C to copy'); | ||
assert.ok(clickToCopy.hasClass('tooltipped')); | ||
}); | ||
|
||
test('can set mutable attributes', function(assert) { | ||
this.set('mockClipboard', mockClipboard); | ||
this.render( | ||
hbs`{{click-to-copy text="copy this" Clipboard=mockClipboard | ||
actionLabel="Click Me!" successMessage="Yay!" errorMessage="Boo!"}}` | ||
); | ||
|
||
let clickToCopy = this.$('.click-to-copy'); | ||
assert.equal(clickToCopy.text().trim(), 'Click Me!'); | ||
|
||
mockClipboard.success(); | ||
assert.equal(clickToCopy.attr('data-message'), 'Yay!'); | ||
assert.ok(clickToCopy.hasClass('tooltipped')); | ||
|
||
mockClipboard.error(); | ||
assert.equal(clickToCopy.attr('data-message'), 'Boo!'); | ||
assert.ok(clickToCopy.hasClass('tooltipped')); | ||
}); |
Oops, something went wrong.