Created
July 13, 2018 11:27
-
-
Save derekmisler/9228b7d0a4dfae68b08086eb9ee798cb to your computer and use it in GitHub Desktop.
clipboard example
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
import { inject, bindable, viewResources, containerless } from 'aurelia-framework'; | |
import { EventAggregator } from 'aurelia-event-aggregator'; | |
import ClipBoard from 'clipboard'; | |
import { userType } from 'services/permissions'; | |
import uuid from 'uuid/v4'; | |
@bindable('text') | |
@inject(EventAggregator) | |
@containerless | |
@viewResources('components/info-message') | |
export class ClipboardCopy { | |
constructor(ea) { | |
this.ea = ea; | |
this.isAdmin = userType === 'admin'; | |
this.id = `clipboard-${uuid()}`; | |
} | |
attached() { | |
const self = this; | |
if (ClipBoard.isSupported() && this.isAdmin) { | |
this.clipboardjs = new ClipBoard(`#${this.id}`, { | |
text() { | |
return self.text; | |
} | |
}); | |
this.clipboardRef.setAttribute('data-tooltip', 'Click to copy to clipboard'); | |
} | |
} | |
publishFeedback() { | |
if (this.clipboardjs) { | |
this.ea.publish('infoMessageOpen', { | |
id: this.id, | |
text: `Copied '${this.text}' to clipboard!`, | |
dismissible: false, | |
shouldReload: 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
template | |
span(id.bind='id' click.delegate='publishFeedback()' ref="clipboardRef") ${text} | |
info-message(info_id.bind='id') |
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
template | |
.row | |
.col-xs-12 | |
h1 ${carrier.legal_name} | |
.row.flex.items-center | |
.vertically-center(class.bind='carrier.state_name === "Active" || carrier.state_name === "Fresh" ? "col-lg-2" : "col-lg-3"') | |
img.icon.inline(src.bind='carrierStatusIcon') | |
span.fixed-width.align-right.align-bottom(class.bind='carrierStatusTextColor') ${carrier.state_name} | |
.col-lg-3(if.bind='carrier.mc_number') | |
p MC: #[clipboard-copy(text.bind="carrier.mc_number")] | |
.col-lg-3(if.bind='carrier.dot_number') | |
p DOT: #[clipboard-copy(text.bind="carrier.dot_number")] | |
.col-lg-3 | |
p ID: #[clipboard-copy(text.bind="carrier.id")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment