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