私はそれを把握することができました(1週間後)。ここで私が思いついたのは、知りたい人のためです。ポップアップにはPopper.jsというプラグインを使用しました。ここで
は私のHTML(component.htmlファイル)です。
import { Component, OnInit } from '@angular/core';
import * as Popper from 'popper.js/dist/umd/popper.js'; // plugin
@Component({
selector: 'share-highlight',
templateUrl: './share-highlight.component.html',
styleUrls: ['./share-highlight.component.scss']
})
export class ShareHighlightComponent implements OnInit {
selectedtext : string = '';
twitterlink : string = '';
linkedinlink : string = '';
emaillink : string = '';
showStyle : boolean = false;
showSelectedText(event) {
let element = event; // this was mostly for testing
var text = "";
if (window.getSelection) {
// Get the text that was selected
text = window.getSelection().toString();
if (text != "") {
// See where the selection is and attach popper to it
var selection = window.getSelection().getRangeAt(0);
// Setting up the tooltip (popper)
let popper = document.querySelector('.js-popper');
new Popper(selection,popper, {
placement: 'top'
});
// Show popper
this.showStyle = true;
} else {
// Hide popper
this.showStyle = false;
}
} else {
this.showStyle = false;
}
// Value of the selected Text
this.selectedtext = text;
// Building the share links with highlighted text and additional info you might want to add
this.twitterlink = "https://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.WebsiteLinkHere.com&text=" + this.selectedtext.split(' ').join('%20') + "%20via%[email protected] ";
this.linkedinlink = "https://www.linkedin.com/shareArticle?mini=true&url=http://www.WebsiteLinkHere.com&title=" + ("Title here.").split(' ').join('%20') + "&summary=" + this.selectedtext.split(' ').join('%20') + "&source=SourceHere";
this.emaillink = "mailto:?subject=" + ("Email subject line here.").split(' ').join('%20') + "&body=" + this.selectedtext.split(' ').join('%20') + (". Some additional text here if you want, http%3A%2F%2Fwww.WebsiteLinkHere.com.").split(' ').join('%20');
}
getStyle() {
if(this.showStyle) {
return "block";
} else {
return "none";
}
}
constructor() { }
ngOnInit() {
}
}
:
<div class="share-highlight" (mouseup)="showSelectedText($event)">
<p>Some test content here</p>
<!-- This here is the actual popup and links to social media -->
<div class="js-popper share-highlight__tooltip" [style.display]="getStyle()">
<div class="share-highlight__tooltip-arrow"></div>
<a target="_blank" class="share-highlight__social-icons" href="{{linkedinlink}}"><span class="fa fa-linkedin"></span></a> <a target="_blank" class="share-highlight__social-icons" href="{{twitterlink}}"><span class="fa fa-twitter"></span></a><a class="share-highlight__social-icons" href="{{emaillink}}"><span class="fa fa-envelope"></span></a>
</div>
</div>
そしてここでは、選択を処理し、共有リンクを構築し、私のcomponent.tsファイルには何かということです私はこれが似たようなことをしている誰かを助けることができれば嬉しいです