PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.2
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / js / frontend / copy-to-clipboard.js

copy-to-clipboard.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.2, at assets/src/js/frontend/copy-to-clipboard.js

95 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 function LPClick( element, iconBtn, inner ) {
2 const wrappers = document.querySelectorAll( element );
3
4 if ( ! wrappers.length ) {
5 return;
6 }
7
8 wrappers.forEach( ( wrapper ) => {
9 const clickBtn = wrapper.querySelector( iconBtn );
10 const class_open = element.replace( '.', '' ) + '__open';
11 const closeElement = wrapper.querySelector( element + '__close' );
12
13 const isOpenElement = () => wrapper.classList.contains( class_open );
14
15 const showElement = () => {
16 if ( ! isOpenElement() ) {
17 wrapper.classList.add( class_open );
18 }
19 };
20
21 const hideElement = () => {
22 if ( isOpenElement() ) {
23 wrapper.classList.remove( class_open );
24 }
25 };
26
27 const toggleElement = () => {
28 if ( isOpenElement() ) {
29 hideElement();
30 } else {
31 showElement();
32 }
33 };
34
35 const onKeyDown = ( e ) => {
36 if ( e.keyCode === 27 ) {
37 hideElement();
38 }
39 };
40
41 if ( clickBtn ) {
42 clickBtn.onclick = function ( e ) {
43 e.preventDefault();
44 toggleElement();
45 };
46 }
47
48 document.addEventListener( 'click', ( e ) => {
49 if ( ! isOpenElement() ) {
50 return;
51 }
52
53 const target = e.target;
54
55 if ( target.closest( inner ) || target.closest( iconBtn ) ) {
56 return;
57 }
58
59 hideElement();
60 } );
61
62 if ( closeElement ) {
63 closeElement.addEventListener( 'click', ( e ) => {
64 e.preventDefault();
65 hideElement();
66 } );
67 }
68
69 document.addEventListener( 'keydown', onKeyDown, false );
70 } );
71 }
72
73 export default function CopyToClipboard() {
74 LPClick(
75 '.social-share-toggle',
76 '.share-toggle-icon',
77 '.content-widget-social-share'
78 );
79
80 var copyTextareaBtn = document.querySelector( '.btn-clipboard' );
81 if ( copyTextareaBtn ) {
82 copyTextareaBtn.addEventListener( 'click', function ( event ) {
83 var copyTextarea = document.querySelector( '.clipboard-value' );
84 copyTextarea.focus();
85 copyTextarea.select();
86 try {
87 var successful = document.execCommand( 'copy' );
88 var msg = copyTextareaBtn.getAttribute( 'data-copied' );
89 copyTextareaBtn.innerHTML =
90 msg + '<span class="tooltip">' + msg + '</span>';
91 } catch ( err ) {}
92 } );
93 }
94 }
95