📦 EqualifyEverything / equalify-wp-integration

📄 equalify-wp-integration-admin.js · 37 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37(function( $ ) {
	'use strict';

	$(function() {
		var $btn    = $( '#equalify-copy-url-btn' );
		var $notice = $( '#equalify-copy-notice' );

		if ( ! $btn.length ) {
			return;
		}

		$btn.on( 'click', function() {
			var url = $btn.data( 'url' );

			if ( navigator.clipboard && navigator.clipboard.writeText ) {
				navigator.clipboard.writeText( url ).then( function() {
					showCopied();
				} );
			} else {
				// Fallback for older browsers.
				var $input = $( '#equalify-feed-url-input' );
				$input.select();
				document.execCommand( 'copy' );
				showCopied();
			}
		} );

		function showCopied() {
			$notice.show();
			setTimeout( function() {
				$notice.fadeOut();
			}, 2500 );
		}
	} );

})( jQuery );