PageSourceSearch

https://arabicpost.net/wp-content/themes/arabicpost/deco-framework…/js/suggest-correction.js?ver=1790269076

js arabicpost.net collected 2026-09-24 17:39:49 UTC 5,343 bytes, 208 lines download raw bytes

1var Suggest_Correction = {
2
3	suggestForm: jQuery('#js__send-correction-suggest'),
4
5	openSuggestCorrectionModal: function () {
6
7		jQuery(document).on('click', '.js__suggest_correction', function (e) {
8			e.preventDefault();
9			var modal = jQuery('#js__suggest-correction-modal');
10			if (!modal.hasClass('active')) {
11				jQuery('body').addClass('fixed-body');
12				modal.addClass('active');
13				jQuery('#overlay').fadeIn();
14			}
15
16			var postTitle = jQuery(this).attr('data-post-title');
17			if (postTitle.length > 0) {
18				var modalSubtitle = modal.find('.js__subtitle-field');
19				if (modalSubtitle.length > 0) {
20					modalSubtitle.text(postTitle);
21				}
22			}
23
24		});
25
26		jQuery(document).on('click', '#js__suggest-correction-modal .modal_close', function (e) {
27			e.preventDefault();
28			jQuery('#js__suggest-correction-modal').removeClass('active');
29			jQuery('body').removeClass('fixed-body');
30			jQuery('#overlay').fadeOut();
31			Suggest_Correction.suggestForm.find('.buttons-container').removeClass('is-disabled');
32
33		});
34
35		jQuery(document).on('click', function (e) {
36			if(e.target.id === 'overlay') {
37				jQuery('#js__suggest-correction-modal').removeClass('active');
38				jQuery('body').removeClass('fixed-body');
39				jQuery('#overlay').fadeOut();
40				Suggest_Correction.suggestForm.find('.buttons-container').removeClass('is-disabled');
41			}
42		});
43
44		jQuery(document).on('keyup', function (e) {
45			if(e.keyCode === 27) {
46				jQuery('#js__suggest-correction-modal').removeClass('active');
47				jQuery('body').removeClass('fixed-body');
48				jQuery('#overlay').fadeOut();
49				Suggest_Correction.suggestForm.find('.buttons-container').removeClass('is-disabled');
50			}
51		})
52
53	},
54
55	setPostId: function () {
56
57		var self = this;
58
59		try {
60			jQuery(document).on('click', '[data-modal="blog-modal"]', function () {
61				var suggestPostId = jQuery(this).attr('data-post-id');
62				try {
63					if (suggestPostId.length > 0) {
64						try {
65							var postIdField = self.suggestForm.find('input[name="post_id"]');
66							if (postIdField.length === 1) {
67								try {
68									postIdField.val(suggestPostId);
69								} catch (e) {
70									console.log(e);
71								}
72							}
73						} catch (e) {
74							console.log(e);
75						}
76					}
77				} catch (e) {
78					console.log(e);
79				}
80			});
81		} catch (e) {
82			console.log(e);
83		}
84
85	},
86
87	validateEmail: function (email) {
88		var pattern = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
89		return pattern.test(email);
90	},
91
92	formValid: function () {
93
94		var self = this;
95		var result = {
96			'valid': true,
97			'error': []
98		};
99
100		var fieldsToValidate = this.suggestForm.find('[data-required="yes"]');
101		if (fieldsToValidate.length > 0) {
102			fieldsToValidate.each(function () {
103				var fieldType = jQuery(this).attr('data-type');
104				var fieldValue = jQuery(this).val();
105				if (fieldType.length > 0 && fieldType === 'email' && fieldValue.length > 0) {
106					if (self.validateEmail(fieldValue) === false) {
107						result.valid = false;
108						result.error.push('رجاء، أدخل عنوان البريد الإلكتروني الصحيح');
109					}
110				} else {
111					if (fieldValue.length === 0) {
112						result.valid = false;
113						if (result.error.indexOf('لو سمحت أملأ كل الحقول!') == '-1') {
114							result.error.push('لو سمحت أملأ كل الحقول!');
115						}
116					}
117				}
118			});
119		}
120
121		return result;
122
123	},
124
125	cleanUpForm: function () {
126		var inputs = this.suggestForm.find('input:not(.btn-def)');
127		if (inputs.length > 0) {
128			inputs.each(function () {
129				jQuery(this).val('');
130			})
131		}
132		var textarea = this.suggestForm.find('textarea');
133		if (textarea.length > 0) {
134			textarea.each(function () {
135				jQuery(this).val('');
136			});
137		}
138	},
139
140	submitForm: function () {
141
142		var self = this;
143
144		if (self.suggestForm.length === 1) {
145			try {
146				self.suggestForm.on('submit', function (e) {
147
148					var formValidation = self.formValid();
149
150					var messageField = self.suggestForm.find('.js__form-message');
151
152					if (formValidation.valid === false) {
153						// console.log(formValidation.error);
154						messageField.html(formValidation.error);
155						messageField.removeClass('error-block--success');
156						return false;
157					}
158
159					e.preventDefault();
160					var data = self.suggestForm.serialize();
161
162					jQuery.ajax({
163						url     : deco_vars.ajaxurl,
164						type    : "POST",
165						dataType: 'json',
166						data    : 'action=deco_send_suggest_correction&' + data,
167						success : function (response) {
168							if (response.success === true) {
169								self.cleanUpForm();
170								messageField.addClass('error-block--success');
171							} else {
172								messageField.removeClass('error-block--success');
173							}
174
175							if (messageField.length > 0 && response.data.msg.length > 0) {
176								messageField.append(response.data.msg);
177								messageField.html(response.data.msg);
178							}
179
180							Suggest_Correction.suggestForm.find('.buttons-container').addClass('is-disabled');
181
182							console.log(response);
183						},
184						error   : function (e) {
185							console.log(e);
186						}
187					});
188					console.log(data);
189				});
190			} catch (e) {
191				console.log(e);
192			}
193		}
194
195	},
196
197	init: function () {
198
199		this.openSuggestCorrectionModal();
200		this.submitForm();
201		this.setPostId();
202
203	}
204};
205
206jQuery(document).ready(function () {
207	Suggest_Correction.init();
208});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.