| 311 | |
| 312 | |
| 313 | class SendTextDialog extends Dialog { |
| 314 | constructor() { |
| 315 | super('sendTextDialog'); |
| 316 | Events.on('text-recipient', e => this._onRecipient(e.detail)) |
| 317 | this.$text = this.$el.querySelector('#textInput'); |
| 318 | const button = this.$el.querySelector('form'); |
| 319 | button.addEventListener('submit', e => this._send(e)); |
| 320 | } |
| 321 | |
| 322 | _onRecipient(recipient) { |
| 323 | this._recipient = recipient; |
| 324 | this._handleShareTargetText(); |
| 325 | this.show(); |
| 326 | |
| 327 | const range = document.createRange(); |
| 328 | const sel = window.getSelection(); |
| 329 | |
| 330 | range.selectNodeContents(this.$text); |
| 331 | sel.removeAllRanges(); |
| 332 | sel.addRange(range); |
| 333 | |
| 334 | } |
| 335 | |
| 336 | _handleShareTargetText() { |
| 337 | if (!window.shareTargetText) return; |
| 338 | this.$text.textContent = window.shareTargetText; |
| 339 | window.shareTargetText = ''; |
| 340 | } |
| 341 | |
| 342 | _send(e) { |
| 343 | e.preventDefault(); |
| 344 | Events.fire('send-text', { |
| 345 | to: this._recipient, |
| 346 | text: this.$text.innerText |
| 347 | }); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | class ReceiveTextDialog extends Dialog { |
| 352 | constructor() { |
nothing calls this directly
no outgoing calls
no test coverage detected