File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ( function ( ) {
2+ 'use strict' ;
3+
4+ // Constructor function for the ShareButtonPlugin
5+ function ShareButtonPlugin ( ) {
6+ // Create the share button element
7+ this . shareButton = document . createElement ( 'button' ) ;
8+ this . shareButton . className = 'share-button' ;
9+ this . shareButton . innerHTML = '↩' ; // Unicode arrow symbol
10+
11+ // Attach the click event listener to the share button
12+ this . shareButton . addEventListener ( 'click' , this . share . bind ( this ) ) ;
13+
14+ // Append the share button to the body
15+ document . body . appendChild ( this . shareButton ) ;
16+ }
17+
18+ ShareButtonPlugin . prototype . share = async function ( ) {
19+ // Check if the Web Share API is supported in the browser
20+ if ( navigator . share ) {
21+ try {
22+ // Share the current URL using the Web Share API
23+ await navigator . share ( {
24+ title : document . title ,
25+ url : window . location . href
26+ } ) ;
27+ } catch ( error ) {
28+ console . error ( 'Error sharing:' , error ) ;
29+ }
30+ } else {
31+ console . error ( 'Web Share API is not supported in this browser.' ) ;
32+ }
33+ } ;
34+
35+ // Export the ShareButtonPlugin as a global function or as an ES module
36+ if ( typeof window === 'object' ) {
37+ window . ShareButtonPlugin = ShareButtonPlugin ;
38+ }
39+ if ( typeof exports === 'object' ) {
40+ module . exports = ShareButtonPlugin ;
41+ }
42+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ /* Basic styles for the share button */
2+ .share-button {
3+ position : fixed;
4+ top : 20px ;
5+ right : 20px ;
6+ background-color : # 007bff ;
7+ color : # fff ;
8+ border : none;
9+ border-radius : 50% ;
10+ width : 50px ;
11+ height : 50px ;
12+ font-size : 24px ;
13+ cursor : pointer;
14+ box-shadow : 0px 4px 6px rgba (0 , 0 , 0 , 0.1 );
15+ }
You can’t perform that action at this time.
0 commit comments