| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/*!*************************************************!*\ |
| 3 |
!*** ./assets/src/apps/js/admin/pages/setup.js ***! |
| 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; |
| 22 |
} |
| 23 |
if (!isEmail(this.value)) { |
| 24 |
valid = false; |
| 25 |
$this.css('border-color', '#FF0000'); |
| 26 |
} |
| 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 |
}; |
| 43 |
|
| 44 |
/*const navPages = function navPages( e ) { |
| 45 |
e.preventDefault(); |
| 46 |
|
| 47 |
if ( ! checkForm( $setupForm ) ) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
const loadUrl = $( this ).attr( 'href' ); |
| 52 |
|
| 53 |
$main.addClass( 'loading' ); |
| 54 |
$.post( { |
| 55 |
url: loadUrl, |
| 56 |
data: getFormData(), |
| 57 |
success( res ) { |
| 58 |
const $html = $( res ); |
| 59 |
replaceMainContent( $html.contents().filter( '#main' ) ); |
| 60 |
|
| 61 |
LP.setUrl( loadUrl ); |
| 62 |
|
| 63 |
$( '.learn-press-dropdown-pages' ).LP( 'DropdownPages' ); |
| 64 |
$( '.learn-press-tip' ).LP( 'QuickTip' ); |
| 65 |
$main.removeClass( 'loading' ); |
| 66 |
}, |
| 67 |
} ); |
| 68 |
};*/ |
| 69 |
|
| 70 |
const updateCurrency = function updateCurrency() { |
| 71 |
const m = $(this).children(':selected').html().match(/\((.*)\)/), |
| 72 |
symbol = m ? m[1] : ''; |
| 73 |
$('#currency-pos').children().each(function () { |
| 74 |
const $option = $(this); |
| 75 |
let text = $option.html(); |
| 76 |
switch ($option.val()) { |
| 77 |
case 'left': |
| 78 |
text = text.replace(/\( (.*)69/, '( ' + symbol + '69'); |
| 79 |
break; |
| 80 |
case 'right': |
| 81 |
text = text.replace(/9([^0-9]*) \)/, '9' + symbol + ' )'); |
| 82 |
break; |
| 83 |
case 'left_with_space': |
| 84 |
text = text.replace(/\( (.*) 6/, '( ' + symbol + ' 6'); |
| 85 |
break; |
| 86 |
case 'right_with_space': |
| 87 |
text = text.replace(/9 (.*) \)/, '9 ' + symbol + ' )'); |
| 88 |
break; |
| 89 |
} |
| 90 |
$option.html(text); |
| 91 |
}); |
| 92 |
}; |
| 93 |
const updatePrice = function updatePrice() { |
| 94 |
$.post({ |
| 95 |
url: '', |
| 96 |
dataType: 'html', |
| 97 |
data: getFormData({ |
| 98 |
'lp-ajax': 'get-price-format' |
| 99 |
}), |
| 100 |
success(res) { |
| 101 |
$('#preview-price').html(res); |
| 102 |
} |
| 103 |
}); |
| 104 |
}; |
| 105 |
const createPages = function createPages(e) { |
| 106 |
e.preventDefault(); |
| 107 |
blockContent(); |
| 108 |
$.post({ |
| 109 |
url: $(this).attr('href'), |
| 110 |
dataType: 'html', |
| 111 |
data: getFormData({ |
| 112 |
'lp-ajax': 'setup-create-pages' |
| 113 |
}), |
| 114 |
success(res) { |
| 115 |
replaceMainContent($(res).contents().filter('#main')); |
| 116 |
$('.learn-press-dropdown-pages').LP('DropdownPages'); |
| 117 |
blockContent(false); |
| 118 |
} |
| 119 |
}); |
| 120 |
}; |
| 121 |
function isEmail(email) { |
| 122 |
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,}))$/; |
| 123 |
return re.test(email); |
| 124 |
} |
| 125 |
$(function () { |
| 126 |
$main = $('#main'); |
| 127 |
$setupForm = $('#learn-press-setup-form'); |
| 128 |
$('.learn-press-select2').select2(); |
| 129 |
$(document). |
| 130 |
// on( 'click', '.buttons .button', navPages ). |
| 131 |
on('change', '#currency', updateCurrency).on('change', 'input, select', updatePrice).on('click', '#create-pages', createPages); |
| 132 |
}); |
| 133 |
})(jQuery); |
| 134 |
/******/ })() |
| 135 |
; |
| 136 |
//# sourceMappingURL=setup.js.map |