2021-07-06 15:56:36 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
2019-07-01 20:19:11 +00:00
|
|
|
import Clipboard from 'clipboard';
|
2019-06-21 10:42:40 +00:00
|
|
|
|
|
|
|
class ClipboardCallback extends Clipboard {
|
2021-07-06 15:56:36 +00:00
|
|
|
constructor(trigger, options, cb) {
|
|
|
|
super(trigger, options);
|
2019-06-21 10:42:40 +00:00
|
|
|
this._cb = cb;
|
|
|
|
}
|
|
|
|
onClick(e) {
|
|
|
|
this._cb(this.text(e.delegateTarget || e.currentTarget));
|
|
|
|
// Clipboard uses/extends `tiny-emitter`
|
|
|
|
// TODO: We should probably fill this out to match the obj passed from
|
|
|
|
// os implementation
|
|
|
|
this.emit('success', {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class LocalStorageService extends Service {
|
2021-07-06 15:56:36 +00:00
|
|
|
@service('-document') doc;
|
2020-11-09 09:25:35 +00:00
|
|
|
key = 'clipboard';
|
|
|
|
|
2021-07-06 15:56:36 +00:00
|
|
|
execute(trigger, options) {
|
2022-09-15 08:43:17 +00:00
|
|
|
return new ClipboardCallback(trigger, options, (val) => {
|
2021-07-06 15:56:36 +00:00
|
|
|
this.doc.defaultView.localStorage.setItem(this.key, val);
|
2019-06-21 10:42:40 +00:00
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|