PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / features / Protected_Content / password-form.js

password-form.js in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.78, at includes/features/Protected_Content/password-form.js

93 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Protected Content Password Form Handler.
3 *
4 * Handles password form submission and cookie management.
5 *
6 * @package King_Addons
7 */
8 (function ($) {
9 'use strict';
10
11 /**
12 * Initialize password forms.
13 */
14 const initPasswordForms = () => {
15 $(document).on('submit', '.king-addons-password-form', function (e) {
16 e.preventDefault();
17
18 const $form = $(this);
19 const $input = $form.find('.king-addons-password-input');
20 const $error = $form.find('.king-addons-password-error');
21 const $submitText = $form.find('.king-addons-password-submit-text');
22 const $submitLoading = $form.find('.king-addons-password-submit-loading');
23
24 const password = $input.val();
25 const elementId = $form.data('element-id');
26 const postId = $form.data('post-id');
27 const scope = $form.data('scope');
28 const globalKey = $form.data('global-key');
29 const days = $form.data('days') || 7;
30
31 const strings = (window.kingAddonsProtectedContent && window.kingAddonsProtectedContent.strings)
32 ? window.kingAddonsProtectedContent.strings
33 : {};
34
35 const enterPasswordText = strings.enterPassword || 'Please enter a password';
36 const incorrectPasswordText = strings.incorrectPassword || 'Incorrect password';
37 const errorOccurredText = strings.errorOccurred || 'An error occurred. Please try again.';
38
39 if (!password) {
40 $error.text(enterPasswordText).show();
41 return;
42 }
43
44 // Show loading state.
45 $submitText.hide();
46 $submitLoading.show();
47 $error.hide();
48 $input.prop('disabled', true);
49
50 $.ajax({
51 url: kingAddonsProtectedContent.ajaxUrl,
52 type: 'POST',
53 data: {
54 action: 'king_addons_verify_password',
55 nonce: kingAddonsProtectedContent.nonce,
56 password: password,
57 element_id: elementId,
58 post_id: postId,
59 scope: scope,
60 global_key: globalKey,
61 days: days
62 },
63 success: function (response) {
64 if (response.success) {
65 // Reload page to show unlocked content.
66 window.location.reload();
67 } else {
68 $error.text(response.data.message || incorrectPasswordText).show();
69 $input.prop('disabled', false).val('').focus();
70 $submitText.show();
71 $submitLoading.hide();
72 }
73 },
74 error: function () {
75 $error.text(errorOccurredText).show();
76 $input.prop('disabled', false);
77 $submitText.show();
78 $submitLoading.hide();
79 }
80 });
81 });
82
83 // Clear error on input.
84 $(document).on('input', '.king-addons-password-input', function () {
85 $(this).closest('.king-addons-password-form').find('.king-addons-password-error').hide();
86 });
87 };
88
89 // Initialize when DOM is ready.
90 $(document).ready(initPasswordForms);
91
92 }(jQuery));
93