PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 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 All 140 releases
← All changes | assets/js/dist/admin/pages/setup.js +36 -118 4.4.0 → 4.4.9 View file →
@@ -1,131 +1,49 @@
1 1 /******/ (() => { // webpackBootstrap
2 2 /*!*************************************************!*\
3 3 !*** ./assets/src/apps/js/admin/pages/setup.js ***!
4 4 \*************************************************/
5 -(function ($) {
6 - 'use strict';
7 -
8 - let $main, $setupForm;
9 - const checkForm = function checkForm($form) {
10 - const $emails = $form.find('input[type="email"]');
11 - let valid = true;
12 - $emails.each(function () {
13 - const $this = $(this);
14 - $this.css('border-color', '');
15 - switch ($this.attr('name')) {
16 - case 'settings[paypal][paypal_email]':
17 - case 'settings[paypal][paypal_sandbox_email]':
18 - if (!$this.closest('tr').prev().find('input[type="checkbox"]').is(':checked')) {
19 - return;
20 - }
21 - break;
5 +/**
6 + * Setup Wizard Script
7 + *
8 + * @since 4.2.8.6
9 + */
10 +class SetupWizard {
11 + static selectors = {
12 + elSetupForm: '#learn-press-setup-form',
13 + elPreviewPrice: '#preview-price'
14 + };
15 + init() {
16 + this.elSetupForm = document.querySelector(SetupWizard.selectors.elSetupForm);
17 + if (!this.elSetupForm) {
18 + return;
19 + }
20 + this.events();
21 + }
22 + events() {
23 + document.addEventListener('change', e => {
24 + if (e.target.closest('input, select')) {
25 + this.saveSettings();
22 26 }
23 - if (!isEmail(this.value)) {
24 - valid = false;
25 - $this.css('border-color', '#FF0000');
26 - }
27 27 });
28 - return valid;
29 - };
30 - const blockContent = function blockContent(block) {
31 - $main.toggleClass('loading', block === undefined ? true : block);
32 - };
33 - const getFormData = function getFormData(more) {
34 - $setupForm = $('#learn-press-setup-form');
35 - const data = $setupForm.serializeJSON();
36 - return $.extend(data, more || {});
37 - };
38 - const replaceMainContent = function replaceMainContent(newContent) {
39 - const $newContent = $(newContent);
40 - $main.replaceWith($newContent);
41 - $main = $newContent;
42 - };
28 + }
43 29
44 - /*const navPages = function navPages( e ) {
45 - e.preventDefault();
46 - if ( ! checkForm( $setupForm ) ) {
47 - return;
48 - }
49 - const loadUrl = $( this ).attr( 'href' );
50 - $main.addClass( 'loading' );
51 - $.post( {
52 - url: loadUrl,
53 - data: getFormData(),
54 - success( res ) {
55 - const $html = $( res );
56 - replaceMainContent( $html.contents().filter( '#main' ) );
57 - LP.setUrl( loadUrl );
58 - $( '.learn-press-dropdown-pages' ).LP( 'DropdownPages' );
59 - $( '.learn-press-tip' ).LP( 'QuickTip' );
60 - $main.removeClass( 'loading' );
61 - },
62 - } );
63 - };*/
64 -
65 - const updateCurrency = function updateCurrency() {
66 - const m = $(this).children(':selected').html().match(/\((.*)\)/),
67 - symbol = m ? m[1] : '';
68 - $('#currency-pos').children().each(function () {
69 - const $option = $(this);
70 - let text = $option.html();
71 - switch ($option.val()) {
72 - case 'left':
73 - text = text.replace(/\( (.*)69/, '( ' + symbol + '69');
74 - break;
75 - case 'right':
76 - text = text.replace(/9([^0-9]*) \)/, '9' + symbol + ' )');
77 - break;
78 - case 'left_with_space':
79 - text = text.replace(/\( (.*) 6/, '( ' + symbol + ' 6');
80 - break;
81 - case 'right_with_space':
82 - text = text.replace(/9 (.*) \)/, '9 ' + symbol + ' )');
83 - break;
30 + /* Post form data to current url, update preview price html with response */
31 + saveSettings() {
32 + const formData = new FormData(this.elSetupForm);
33 + fetch(window.location.href, {
34 + method: 'POST',
35 + body: formData
36 + }).then(response => response.text()).then(html => {
37 + const elPreviewPrice = document.querySelector(SetupWizard.selectors.elPreviewPrice);
38 + if (elPreviewPrice) {
39 + elPreviewPrice.innerHTML = html;
84 40 }
85 - $option.html(text);
86 41 });
87 - };
88 - const updatePrice = function updatePrice() {
89 - $.post({
90 - url: '',
91 - dataType: 'html',
92 - data: getFormData({
93 - 'lp-ajax': 'get-price-format'
94 - }),
95 - success(res) {
96 - $('#preview-price').html(res);
97 - }
98 - });
99 - };
100 - const createPages = function createPages(e) {
101 - e.preventDefault();
102 - blockContent();
103 - $.post({
104 - url: $(this).attr('href'),
105 - dataType: 'html',
106 - data: getFormData({
107 - 'lp-ajax': 'setup-create-pages'
108 - }),
109 - success(res) {
110 - replaceMainContent($(res).contents().filter('#main'));
111 - $('.learn-press-dropdown-pages').LP('DropdownPages');
112 - blockContent(false);
113 - }
114 - });
115 - };
116 - function isEmail(email) {
117 - 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,}))$/;
118 - return re.test(email);
119 42 }
120 - $(function () {
121 - $main = $('#main');
122 - $setupForm = $('#learn-press-setup-form');
123 - $('.learn-press-select2').select2();
124 - $(document).
125 - // on( 'click', '.buttons .button', navPages ).
126 - on('change', '#currency', updateCurrency).on('change', 'input, select', updatePrice).on('click', '#create-pages', createPages);
127 - });
128 -})(jQuery);
43 +}
44 +document.addEventListener('DOMContentLoaded', () => {
45 + new SetupWizard().init();
46 +});
129 47 /******/ })()
130 48 ;
131 49 //# sourceMappingURL=setup.js.map