PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.3
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.3
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 / inc / admin / meta-box / assets / email-content.js

email-content.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.3, at inc/admin/meta-box/assets/email-content.js

76 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function( $ ) {
2 $( '.lp-metabox-field__email-content' ).each( function() {
3 const $field = $( this ),
4 $select = $field.find( 'select.lp-email-format' ),
5 $templates = $field.find( '.learn-press-email-template' ),
6 $variables = $field.find( '.learn-press-email-variables' );
7
8 function _insertVariableToEditor( edId, variable ) {
9 let editorId = null;
10 const activeEditor = tinyMCE.activeEditor;
11
12 for ( editorId in tinyMCE.editors ) {
13 if ( editorId == edId ) {
14 break;
15 }
16 editorId = null;
17 }
18
19 if ( ! editorId ) {
20 _insertVariableToTextarea( edId, variable );
21 return;
22 }
23
24 if ( activeEditor && $( activeEditor.getElement() ).attr( 'id' ) == editorId ) {
25 activeEditor.execCommand( 'insertHTML', false, variable );
26
27 if ( $( activeEditor.getElement() ).is( ':visible' ) ) {
28 _insertVariableToTextarea( edId, variable );
29 }
30 }
31 }
32
33 function _insertVariableToTextarea( eId, varibale ) {
34 const $el = $( '#' + eId ).get( 0 );
35
36 if ( document.selection ) {
37 $el.focus();
38 sel = document.selection.createRange();
39 sel.text = varibale;
40 $el.focus();
41 } else if ( $el.selectionStart || $el.selectionStart == '0' ) {
42 const startPos = $el.selectionStart;
43 const endPos = $el.selectionEnd;
44 const scrollTop = $el.scrollTop;
45 $el.value = $el.value.substring( 0, startPos ) + varibale + $el.value.substring( endPos, $el.value.length );
46 $el.focus();
47 $el.selectionStart = startPos + varibale.length;
48 $el.selectionEnd = startPos + varibale.length;
49 $el.scrollTop = scrollTop;
50 } else {
51 $el.value += varibale;
52 $el.focus();
53 }
54 }
55
56 $select.on( 'change', function() {
57 if ( this.value ) {
58 $templates.filter( '.' + this.value ).removeClass( 'hide-if-js' ).siblings().addClass( 'hide-if-js' );
59 }
60 } ).trigger( 'change' );
61
62 $variables.each( function() {
63 const $list = $( this ),
64 hasEditor = $list.hasClass( 'has-editor' );
65
66 $list.on( 'click', 'li', function() {
67 if ( hasEditor ) {
68 _insertVariableToEditor( $list.attr( 'data-target' ), $( this ).data( 'variable' ) );
69 } else {
70 _insertVariableToTextarea( $list.attr( 'data-target' ), $( this ).data( 'variable' ) );
71 }
72 } );
73 } );
74 } );
75 }( jQuery ) );
76