PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3.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 / apps / js / admin / pages / setup.js

setup.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.3.2, at assets/src/apps/js/admin/pages/setup.js

147 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function( $ ) {
2 'use strict';
3 let $main, $setupForm;
4
5 const checkForm = function checkForm( $form ) {
6 const $emails = $form.find( 'input[type="email"]' );
7 let valid = true;
8
9 $emails.each( function() {
10 const $this = $( this );
11 $this.css( 'border-color', '' );
12
13 switch ( $this.attr( 'name' ) ) {
14 case 'settings[paypal][paypal_email]':
15 case 'settings[paypal][paypal_sandbox_email]':
16 if ( ! $this.closest( 'tr' ).prev().find( 'input[type="checkbox"]' ).is( ':checked' ) ) {
17 return;
18 }
19 break;
20 }
21
22 if ( ! isEmail( this.value ) ) {
23 valid = false;
24 $this.css( 'border-color', '#FF0000' );
25 }
26 } );
27
28 return valid;
29 };
30
31 const blockContent = function blockContent( block ) {
32 $main.toggleClass( 'loading', block === undefined ? true : block );
33 };
34
35 const getFormData = function getFormData( more ) {
36 $setupForm = $( '#learn-press-setup-form' );
37 const data = $setupForm.serializeJSON();
38
39 return $.extend( data, more || {} );
40 };
41
42 const replaceMainContent = function replaceMainContent( newContent ) {
43 const $newContent = $( newContent );
44 $main.replaceWith( $newContent );
45 $main = $newContent;
46 };
47
48 /*const navPages = function navPages( e ) {
49 e.preventDefault();
50
51 if ( ! checkForm( $setupForm ) ) {
52 return;
53 }
54
55 const loadUrl = $( this ).attr( 'href' );
56
57 $main.addClass( 'loading' );
58 $.post( {
59 url: loadUrl,
60 data: getFormData(),
61 success( res ) {
62 const $html = $( res );
63 replaceMainContent( $html.contents().filter( '#main' ) );
64
65 LP.setUrl( loadUrl );
66
67 $( '.learn-press-dropdown-pages' ).LP( 'DropdownPages' );
68 $( '.learn-press-tip' ).LP( 'QuickTip' );
69 $main.removeClass( 'loading' );
70 },
71 } );
72 };*/
73
74 const updateCurrency = function updateCurrency() {
75 const m = $( this ).children( ':selected' ).html().match( /\((.*)\)/ ),
76 symbol = m ? m[ 1 ] : '';
77 $( '#currency-pos' ).children().each( function() {
78 const $option = $( this );
79 let text = $option.html();
80
81 switch ( $option.val() ) {
82 case 'left':
83 text = text.replace( /\( (.*)69/, '( ' + symbol + '69' );
84 break;
85 case 'right':
86 text = text.replace( /9([^0-9]*) \)/, '9' + symbol + ' )' );
87 break;
88 case 'left_with_space':
89 text = text.replace( /\( (.*) 6/, '( ' + symbol + ' 6' );
90 break;
91 case 'right_with_space':
92 text = text.replace( /9 (.*) \)/, '9 ' + symbol + ' )' );
93 break;
94 }
95 $option.html( text );
96 } );
97 };
98
99 const updatePrice = function updatePrice() {
100 $.post( {
101 url: '',
102 dataType: 'html',
103 data: getFormData( {
104 'lp-ajax': 'get-price-format',
105 } ),
106 success( res ) {
107 $( '#preview-price' ).html( res );
108 },
109 } );
110 };
111
112 const createPages = function createPages( e ) {
113 e.preventDefault();
114 blockContent();
115
116 $.post( {
117 url: $( this ).attr( 'href' ),
118 dataType: 'html',
119 data: getFormData( {
120 'lp-ajax': 'setup-create-pages',
121 } ),
122 success( res ) {
123 replaceMainContent( $( res ).contents().filter( '#main' ) );
124 $( '.learn-press-dropdown-pages' ).LP( 'DropdownPages' );
125 blockContent( false );
126 },
127 } );
128 };
129
130 function isEmail( email ) {
131 const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
132 return re.test( email );
133 }
134
135 $( function() {
136 $main = $( '#main' );
137 $setupForm = $( '#learn-press-setup-form' );
138 $( '.learn-press-select2' ).select2();
139
140 $( document ).
141 // on( 'click', '.buttons .button', navPages ).
142 on( 'change', '#currency', updateCurrency ).
143 on( 'change', 'input, select', updatePrice ).
144 on( 'click', '#create-pages', createPages );
145 } );
146 }( jQuery ) );
147