PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 111003
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v111003
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / includes / s2member.js

s2member.js in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 111003, at includes/s2member.js

537 lines 31.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Core JavaScript file for the s2Member plugin.
3 *
4 * This is the development version of the code.
5 * Which ultimately produces s2member-min.js.
6 *
7 * Copyright: © 2009-2011
8 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
9 * ( coded in the USA )
10 *
11 * Released under the terms of the GNU General Public License.
12 * You should have received a copy of the GNU General Public License,
13 * along with this software. In the main directory, see: /licensing/
14 * If not, see: {@link http://www.gnu.org/licenses/}.
15 *
16 * @package s2Member
17 * @since 3.0
18 */
19 /*
20 Scripting routines handled on document ready state.
21 */
22 jQuery(document).ready (function($)
23 {
24 ws_plugin__s2member_uniqueFilesDownloaded = []; /* Real-time counts. */
25 /* This is used in case a user downloads multiple files from a single page. */
26 /**/
27 var runningBuddyPress = '<?php echo c_ws_plugin__s2member_utils_conds::bp_is_installed ("query-active-plugins") ? "1" : ""; ?>';
28 /**/
29 if (S2MEMBER_CURRENT_USER_IS_LOGGED_IN && S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY < S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED)
30 {
31 $('a[href*="s2member_file_download"], a[href*="s2member-file"').click (function()
32 {
33 if (!this.href.match (/s2member_file_download_key\=(.+)/i))
34 {
35 var c = '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Confirm File Download —", "s2member-front", "s2member")); ?>' + '\n\n';
36 c += $.sprintf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("You`ve downloaded %s protected %s in the last %s.", "s2member-front", "s2member")); ?>', S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY, ((S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("file", "s2member-front", "s2member")); ?>' : '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("files", "s2member-front", "s2member")); ?>'), ((S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("24 hours", "s2member-front", "s2member")); ?>' : $.sprintf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("%s days", "s2member-front", "s2member")); ?>', S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS))) + '\n\n';
37 c += (S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("You`re entitled to UNLIMITED downloads though ( so, no worries ).", "s2member-front", "s2member")); ?>' : $.sprintf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("You`re entitled to %s unique %s %s.", "s2member-front", "s2member")); ?>', S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED, ((S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("download", "s2member-front", "s2member")); ?>' : '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("downloads", "s2member-front", "s2member")); ?>'), ((S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("each day", "s2member-front", "s2member")); ?>' : $.sprintf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("every %s-day period", "s2member-front", "s2member")); ?>', S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS)));
38 /**/
39 if (this.href.match (/s2member[_\-]skip[_\-]confirmation/i) && !this.href.match (/s2member[_\-]skip[_\-]confirmation[\=\-](0|no|false)/i) || confirm(c))
40 {
41 if ($.inArray (this.href, ws_plugin__s2member_uniqueFilesDownloaded) === -1)
42 ws_plugin__s2member_uniqueFilesDownloaded.push (this.href), S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY++;
43 return true; /* Allow. */
44 }
45 else /* Disallow. */
46 return false;
47 }
48 else /* Allow. */
49 return true;
50 });
51 }
52 /*
53 Deals with form field validation on Profile editing panels.
54 `[s2Member-Profile /]` could appear on any Post/Page/Widget.
55 */
56 if (!location.href.match (/\/wp-admin(\/|$)/))
57 {
58 $('input#ws-plugin--s2member-profile-password1, input#ws-plugin--s2member-profile-password2').keyup (function()
59 {
60 ws_plugin__s2member_passwordStrength($('input#ws-plugin--s2member-profile-login'), $('input#ws-plugin--s2member-profile-password1'), $('input#ws-plugin--s2member-profile-password2'), $('div#ws-plugin--s2member-profile-password-strength'));
61 });
62 /**/
63 $('form#ws-plugin--s2member-profile').submit (function()
64 {
65 var context = this, label = '', error = '', errors = '';
66 /**/
67 var $password1 = $('input#ws-plugin--s2member-profile-password1', context);
68 var $password2 = $('input#ws-plugin--s2member-profile-password2', context);
69 /**/
70 var $submissionButton = $('input#ws-plugin--s2member-profile-submit', context);
71 /**/
72 $(':input', context).each (function() /* Go through them all together. */
73 {
74 var id = $.trim ($(this).attr ('id')).replace (/-[0-9]+$/g, ''); /* Remove numeric suffixes. */
75 /**/
76 if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().children ('strong').first ().text ().replace (/[\r\n\t]+/g, ' '))))
77 {
78 if (error = ws_plugin__s2member_validationErrors(label, this, context))
79 errors += error + '\n\n'; /* Collect errors. */
80 }
81 });
82 /**/
83 if (errors = $.trim (errors))
84 {
85 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
86 /**/
87 return false;
88 }
89 /**/
90 else if ($.trim ($password1.val ()) && $.trim ($password1.val ()) !== $.trim ($password2.val ()))
91 {
92 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Passwords do not match up. Please try again.", "s2member-front", "s2member")); ?>');
93 /**/
94 return false;
95 }
96 /**/
97 else if ($.trim ($password1.val ()) && $.trim ($password1.val ()).length < 6) /* Enforce minimum length requirement here. */
98 {
99 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Password MUST be at least 6 characters. Please try again.", "s2member-front", "s2member")); ?>');
100 /**/
101 return false;
102 }
103 /**/
104 ws_plugin__s2member_animateProcessing($submissionButton);
105 /**/
106 return true;
107 });
108 }
109 /*
110 Attach form submission handler to `/wp-signup.php`.
111 */
112 if (location.href.match (/\/wp-signup\.php/))
113 {
114 $('div#content > div.mu_register > form#setupform').submit (function()
115 {
116 var context = this, label = '', error = '', errors = '';
117 /**/
118 $('input#user_email', context).attr ('data-expected', 'email');
119 /**/
120 var $submissionButton = $('p.submit input[type="submit"]', context);
121 /**/
122 $('input#user_name, input#user_email, input#blogname, input#blog_title, input#captcha_code', context).attr ({'aria-required': 'true'});
123 /**/
124 $(':input', context).each (function() /* Go through them all together. */
125 {
126 var id = $.trim ($(this).attr ('id')).replace (/-[0-9]+$/g, ''); /* Remove numeric suffixes. */
127 /**/
128 if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
129 {
130 if (error = ws_plugin__s2member_validationErrors(label, this, context))
131 errors += error + '\n\n'; /* Collect errors. */
132 }
133 });
134 /**/
135 if (errors = $.trim (errors))
136 {
137 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
138 /**/
139 return false;
140 }
141 /**/
142 ws_plugin__s2member_animateProcessing($submissionButton);
143 /**/
144 return true;
145 });
146 }
147 /*
148 Attach form submission handler to `/wp-login.php?action=register`.
149 */
150 if (location.href.match (/\/wp-login\.php/))
151 {
152 $('input#ws-plugin--s2member-custom-reg-field-user-pass1, input#ws-plugin--s2member-custom-reg-field-user-pass2').keyup (function()
153 {
154 ws_plugin__s2member_passwordStrength($('input#user_login'), $('input#ws-plugin--s2member-custom-reg-field-user-pass1'), $('input#ws-plugin--s2member-custom-reg-field-user-pass2'), $('div#ws-plugin--s2member-custom-reg-field-user-pass-strength'));
155 });
156 /**/
157 $('div#login > form#registerform input#wp-submit').attr ('tabindex', '1000'); /* Makes plenty of room ( i.e. tab indexes ) for Custom Registration Fields. */
158 /**/
159 $('div#login > form#registerform').submit (function()
160 {
161 var context = this, label = '', error = '', errors = '';
162 /**/
163 $('input#user_email', context).attr ('data-expected', 'email');
164 /**/
165 var $pass1 = $('input#ws-plugin--s2member-custom-reg-field-user-pass1[aria-required="true"]', context);
166 var $pass2 = $('input#ws-plugin--s2member-custom-reg-field-user-pass2', context);
167 /**/
168 var $submissionButton = $('input#wp-submit', context); /* Registration submission button. */
169 /**/
170 $('input#user_login, input#user_email, input#captcha_code', context).attr ({'aria-required': 'true'});
171 /**/
172 $(':input', context).each (function() /* Go through them all together. */
173 {
174 var id = $.trim ($(this).attr ('id')).replace (/-[0-9]+$/g, ''); /* Remove numeric suffixes. */
175 /**/
176 if ($.inArray (id, ['user_login', 'user_email', 'captcha_code']) !== -1) /* No for="" attribute on these fields. */
177 {
178 if ((label = $.trim ($(this).parent ('label').text ().replace (/[\r\n\t]+/g, ' ')))) /* Use label. */
179 {
180 if (error = ws_plugin__s2member_validationErrors(label, this, context))
181 errors += error + '\n\n'; /* Collect errors. */
182 }
183 }
184 else if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().children ('span').first ().text ().replace (/[\r\n\t]+/g, ' '))))
185 {
186 if (error = ws_plugin__s2member_validationErrors(label, this, context))
187 errors += error + '\n\n'; /* Collect errors. */
188 }
189 });
190 /**/
191 if (errors = $.trim (errors))
192 {
193 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
194 /**/
195 return false;
196 }
197 /**/
198 else if ($pass1.length && $.trim ($pass1.val ()) !== $.trim ($pass2.val ()))
199 {
200 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Passwords do not match up. Please try again.", "s2member-front", "s2member")); ?>');
201 /**/
202 return false;
203 }
204 /**/
205 else if ($pass1.length && $.trim ($pass1.val ()).length < 6) /* Enforce minimum length requirement here. */
206 {
207 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Password MUST be at least 6 characters. Please try again.", "s2member-front", "s2member")); ?>');
208 /**/
209 return false;
210 }
211 /**/
212 ws_plugin__s2member_animateProcessing($submissionButton);
213 /**/
214 return true;
215 });
216 }
217 /*
218 Attach form submission handler to `/wp-admin/(user/)?profile.php`.
219 */
220 if (location.href.match (/\/wp-admin\/(user\/)?profile\.php/))
221 {
222 $('form#your-profile').submit (function() /* Validation. */
223 {
224 var context = this, label = '', error = '', errors = '';
225 /**/
226 $('input#email', context).attr ('data-expected', 'email');
227 /**/
228 $(':input[id^="ws-plugin--s2member-profile-"]', context).each (function() /* Go through them all together. */
229 {
230 var id = $.trim ($(this).attr ('id')).replace (/-[0-9]+$/g, ''); /* Remove numeric suffixes. */
231 /**/
232 if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
233 {
234 if (error = ws_plugin__s2member_validationErrors(label, this, context))
235 errors += error + '\n\n'; /* Collect errors. */
236 }
237 });
238 /**/
239 if (errors = $.trim (errors))
240 {
241 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
242 /**/
243 return false;
244 }
245 /**/
246 return true;
247 });
248 }
249 /*
250 We can ONLY check if BuddyPress is installed. We can't test BP slugs inside: `/s2member-o.php`.
251 */
252 if (runningBuddyPress) /* Attach form submission handler to `/register` for BuddyPress. */
253 {
254 $('body.registration form div#ws-plugin--s2member-custom-reg-fields-4bp-section').closest ('form').submit (function()
255 {
256 var context = this, label = '', error = '', errors = '';
257 /**/
258 $('input#signup_email', context).attr ('data-expected', 'email');
259 /**/
260 $('input#signup_username, input#signup_email, input#signup_password, input#field_1', context).attr ({'aria-required': 'true'});
261 /**/
262 $(':input', context).each (function() /* Go through them all together. */
263 {
264 var id = $.trim ($(this).attr ('id')).replace (/-[0-9]+$/g, ''); /* Remove numeric suffixes. */
265 /**/
266 if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
267 {
268 if (error = ws_plugin__s2member_validationErrors(label, this, context))
269 errors += error + '\n\n'; /* Collect errors. */
270 }
271 });
272 /**/
273 if (errors = $.trim (errors))
274 {
275 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
276 /**/
277 return false;
278 }
279 /**/
280 return true;
281 });
282 /*
283 Attach form submission handler to `/profile/edit/` for BuddyPress.
284 */
285 $('body.logged-in.profile.profile-edit input.ws-plugin--s2member-profile-field-4bp[type = "text"]').closest ('form').submit (function()
286 {
287 var context = this, label = '', error = '', errors = '';
288 /**/
289 $('input#field_1', context).attr ({'aria-required': 'true'});
290 /**/
291 $(':input', context).each (function() /* Go through them all together. */
292 {
293 var id = $.trim ($(this).attr ('id')).replace (/-[0-9]+$/g, ''); /* Remove numeric suffixes. */
294 /**/
295 if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
296 {
297 if (error = ws_plugin__s2member_validationErrors(label, this, context))
298 errors += error + '\n\n'; /* Collect errors. */
299 }
300 });
301 /**/
302 if (errors = $.trim (errors))
303 {
304 alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
305 /**/
306 return false;
307 }
308 /**/
309 return true;
310 });
311 }
312 /*
313 Password strength. Accecpts jQuery objects.
314 */
315 ws_plugin__s2member_passwordStrength = function($username, $pass1, $pass2, $result)
316 {
317 if ($username instanceof jQuery && $pass1 instanceof jQuery && $pass2 instanceof jQuery && $result instanceof jQuery && typeof passwordStrength === 'function' && typeof pwsL10n === 'object')
318 {
319 $result.removeClass ('ws-plugin--s2member-password-strength-short ws-plugin--s2member-password-strength-bad ws-plugin--s2member-password-strength-good ws-plugin--s2member-password-strength-strong ws-plugin--s2member-password-strength-mismatch');
320 /**/
321 switch (passwordStrength($pass1.val (), $username.val (), $pass2.val ())) /* Uses WordPress® script: `password-strength-meter` and `pwsL10n`. */
322 {
323 case 1:
324 $result.addClass ('ws-plugin--s2member-password-strength-short').html (pwsL10n['short']);
325 break;
326 case 2:
327 $result.addClass ('ws-plugin--s2member-password-strength-bad').html (pwsL10n['bad']);
328 break;
329 case 3:
330 $result.addClass ('ws-plugin--s2member-password-strength-good').html (pwsL10n['good']);
331 break;
332 case 4:
333 $result.addClass ('ws-plugin--s2member-password-strength-strong').html (pwsL10n['strong']);
334 break;
335 case 5:
336 $result.addClass ('ws-plugin--s2member-password-strength-mismatch').html (pwsL10n['mismatch']);
337 break;
338 default:
339 $result.addClass ('ws-plugin--s2member-password-strength-short').html (pwsL10n['short']);
340 }
341 }
342 /**/
343 return; /* Return for uniformity. */
344 };
345 /*
346 Handles JavaScript validation errors.
347 */
348 ws_plugin__s2member_validationErrors = function(label, field, context, required, expected)
349 {
350 if (typeof label === 'string' && label && typeof field === 'object' && typeof context === 'object')
351 if (typeof field.tagName === 'string' && field.tagName.match (/^(input|textarea|select)$/i) && !field.disabled)
352 {
353 var tag = field.tagName.toLowerCase (), $field = $(field), type = $.trim ($field.attr ('type')).toLowerCase (), name = $.trim ($field.attr ('name')), value = $field.val ();
354 var required = ( typeof required === 'boolean') ? required : ($field.attr ('aria-required') === 'true'), expected = ( typeof expected === 'string') ? expected : $.trim ($field.attr ('data-expected'));
355 /**/
356 var forcePersonalEmails = ('<?php echo strlen($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_force_personal_emails"]); ?>' > 0) ? true : false;
357 var nonPersonalEmailUsers = new RegExp('^(<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (implode ("|", preg_split ("/[\r\n\t ;,]+/", preg_quote ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_force_personal_emails"], "/")))); ?>)@', 'i');
358 /**/
359 if (tag === 'input' && type === 'checkbox' && name.match (/\[\]$/))
360 {
361 if (typeof field.id === 'string' && field.id.match (/-0$/))
362 if (required && !$('input[name="' + name.replace (/([\[\]])/g, '\$1') + '"]:checked', context).length)
363 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please check at least one of the boxes.", "s2member-front", "s2member")); ?>';
364 }
365 else if (tag === 'input' && type === 'checkbox')
366 {
367 if (required && !field.checked)
368 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Required. This box must be checked.", "s2member-front", "s2member")); ?>';
369 }
370 else if (tag === 'input' && type === 'radio')
371 {
372 if (typeof field.id === 'string' && field.id.match (/-0$/))
373 if (required && !$('input[name="' + name.replace (/([\[\]])/g, '\$1') + '"]:checked', context).length)
374 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please select one of the options.", "s2member-front", "s2member")); ?>';
375 }
376 else if (tag === 'select' && $field.attr ('multiple'))
377 {
378 if (required && (!(value instanceof Array) || !value.length))
379 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please select at least one of the options.", "s2member-front", "s2member")); ?>';
380 }
381 else if (typeof value !== 'string' || (required && !(value = $.trim (value)).length))
382 {
383 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("This is a required field, please try again.", "s2member-front", "s2member")); ?>';
384 }
385 else if ((value = $.trim (value)).length && ((tag === 'input' && type.match (/^(text|password)$/i)) || tag === 'textarea') && typeof expected === 'string' && expected.length)
386 {
387 if (expected === 'numeric-wp-commas' && (!value.match (/^[0-9\.,]+$/) || isNaN(value.replace (/,/g, ''))))
388 {
389 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be numeric ( with or without decimals, commas allowed ).", "s2member-front", "s2member")); ?>';
390 }
391 else if (expected === 'numeric' && (!value.match (/^[0-9\.]+$/) || isNaN(value)))
392 {
393 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be numeric ( with or without decimals, no commas ).", "s2member-front", "s2member")); ?>';
394 }
395 else if (expected === 'integer' && (!value.match (/^[0-9]+$/) || isNaN(value)))
396 {
397 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be an integer ( a whole number, without any decimals ).", "s2member-front", "s2member")); ?>';
398 }
399 else if (expected === 'integer-gt-0' && (!value.match (/^[0-9]+$/) || isNaN(value) || value <= 0))
400 {
401 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be an integer > 0 ( whole number, no decimals, greater than 0 ).", "s2member-front", "s2member")); ?>';
402 }
403 else if (expected === 'float' && (!value.match (/^[0-9\.]+$/) || !value.match (/[0-9]/) || !value.match (/\./) || isNaN(value)))
404 {
405 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a float ( floating point number, decimals required ).", "s2member-front", "s2member")); ?>';
406 }
407 else if (expected === 'float-gt-0' && (!value.match (/^[0-9\.]+$/) || !value.match (/[0-9]/) || !value.match (/\./) || isNaN(value) || value <= 0))
408 {
409 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a float > 0 ( floating point number, decimals required, greater than 0 ).", "s2member-front", "s2member")); ?>';
410 }
411 else if (expected === 'date' && !value.match (/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/))
412 {
413 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a date ( required date format: dd/mm/yyyy ).", "s2member-front", "s2member")); ?>';
414 }
415 else if (expected === 'email' && !value.match (/^([a-z_~0-9\+\-]+)(((\.?)([a-z_~0-9\+\-]+))*)(@)([a-z0-9]+)(((-*)([a-z0-9]+))*)(((\.)([a-z0-9]+)(((-*)([a-z0-9]+))*))*)(\.)([a-z]{2,6})$/i))
416 {
417 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a valid email address.", "s2member-front", "s2member")); ?>';
418 }
419 else if (expected === 'email' && forcePersonalEmails && value.match (nonPersonalEmailUsers))
420 {
421 return label + '\n' + $.sprintf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use a personal email address.\nAddresses like <%s@> are problematic.", "s2member-front", "s2member")); ?>', value.split ('@')[0]);
422 }
423 else if (expected === 'url' && !value.match (/^http(s?)\:\/\/(.{5,})$/i))
424 {
425 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a full URL ( starting with http or https ).", "s2member-front", "s2member")); ?>';
426 }
427 else if (expected === 'domain' && !value.match (/^([a-z0-9]+)(((-*)([a-z0-9]+))*)(((\.)([a-z0-9]+)(((-*)([a-z0-9]+))*))*)(\.)([a-z]{2,6})$/i))
428 {
429 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a domain name ( domain name only, without http ).", "s2member-front", "s2member")); ?>';
430 }
431 else if (expected === 'phone' && (!value.match (/^[0-9 \(\)\-]+$/) || value.replace (/[^0-9]/g, '').length !== 10))
432 {
433 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a phone # ( 10 digits w/possible hyphens,spaces,brackets ).", "s2member-front", "s2member")); ?>';
434 }
435 else if (expected === 'uszip' && !value.match (/^[0-9]{5}(-[0-9]{4})?$/))
436 {
437 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a US zipcode ( 5-9 digits w/possible hyphen ).", "s2member-front", "s2member")); ?>';
438 }
439 else if (expected === 'cazip' && !value.match (/^[0-9A-Z]{3}( ?)[0-9A-Z]{3}$/i))
440 {
441 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a Canadian zipcode ( 6 alpha-numerics w/possible space ).", "s2member-front", "s2member")); ?>';
442 }
443 else if (expected === 'uczip' && !value.match (/^[0-9]{5}(-[0-9]{4})?$/) && !value.match (/^[0-9A-Z]{3}( ?)[0-9A-Z]{3}$/i))
444 {
445 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a zipcode ( either a US or Canadian zipcode ).", "s2member-front", "s2member")); ?>';
446 }
447 else if (expected.match (/^alphanumerics-spaces-punctuation-([0-9]+)(-e)?$/) && !value.match (/^[a-z 0-9,\.\/\?\:;"'\{\}\[\]\|\\\+\=_\-\(\)\*&\^%\$#@\!`~]+$/i))
448 {
449 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use alphanumerics, spaces & punctuation only.", "s2member-front", "s2member")); ?>';
450 }
451 else if (expected.match (/^alphanumerics-spaces-([0-9]+)(-e)?$/) && !value.match (/^[a-z 0-9]+$/i))
452 {
453 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use alphanumerics & spaces only.", "s2member-front", "s2member")); ?>';
454 }
455 else if (expected.match (/^alphanumerics-punctuation-([0-9]+)(-e)?$/) && !value.match (/^[a-z0-9,\.\/\?\:;"'\{\}\[\]\|\\\+\=_\-\(\)\*&\^%\$#@\!`~]+$/i))
456 {
457 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use alphanumerics & punctuation only ( no spaces ).", "s2member-front", "s2member")); ?>';
458 }
459 else if (expected.match (/^alphanumerics-([0-9]+)(-e)?$/) && !value.match (/^[a-z0-9]+$/i))
460 {
461 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use alphanumerics only ( no spaces/punctuation ).", "s2member-front", "s2member")); ?>';
462 }
463 else if (expected.match (/^alphabetics-([0-9]+)(-e)?$/) && !value.match (/^[a-z]+$/i))
464 {
465 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use alphabetics only ( no digits/spaces/punctuation ).", "s2member-front", "s2member")); ?>';
466 }
467 else if (expected.match (/^numerics-([0-9]+)(-e)?$/) && !value.match (/^[0-9]+$/i))
468 {
469 return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use numeric digits only.", "s2member-front", "s2member")); ?>';
470 }
471 else if (expected.match (/^(any|alphanumerics-spaces-punctuation|alphanumerics-spaces|alphanumerics-punctuation|alphanumerics|alphabetics|numerics)-([0-9]+)(-e)?$/))
472 {
473 var split = expected.split ('-'), length = Number(split[1]), exactLength = (split.length > 2 && split[2] === 'e') ? true : false;
474 /**/
475 if (exactLength && value.length !== length) /* An exact length is required? */
476 return label + '\n' + $.sprintf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be exactly %s %s.", "s2member-front", "s2member")); ?>', length, ((split[0] === 'numerics') ? ((length === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("digit", "s2member-front", "s2member")); ?>' : '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("digits", "s2member-front", "s2member")); ?>') : ((length === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("character", "s2member-front", "s2member")); ?>' : '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("characters", "s2member-front", "s2member")); ?>')));
477 /**/
478 else if (value.length < length) /* Otherwise, we interpret as the minimum length. */
479 return label + '\n' + $.sprintf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be at least %s %s.", "s2member-front", "s2member")); ?>', length, ((split[0] === 'numerics') ? ((length === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("digit", "s2member-front", "s2member")); ?>' : '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("digits", "s2member-front", "s2member")); ?>') : ((length === 1) ? '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("character", "s2member-front", "s2member")); ?>' : '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("characters", "s2member-front", "s2member")); ?>')));
480 }
481 }
482 }
483 /**/
484 return '';
485 };
486 /**/
487 ws_plugin__s2member_animateProcessingConfig = {originalText: '', interval: null, speed: 100}, ws_plugin__s2member_animateProcessing = function($obj, reset)
488 {
489 if ($obj instanceof jQuery) /* This function expects a valid jQuery object. */
490 {
491 if (reset) /* Resets back to originalText value ( also clears interval ). */
492 {
493 clearInterval(ws_plugin__s2member_animateProcessingConfig.interval);
494 /**/
495 if (ws_plugin__s2member_animateProcessingConfig.originalText) /* ? */
496 $obj.val (ws_plugin__s2member_animateProcessingConfig.originalText);
497 /**/
498 return; /* No need to proceed any further. Return now upon reset. */
499 }
500 /**/
501 $obj.first ().each (function() /* Interval routine configured here. */
502 {
503 var $this = $(this), i = 0, dir = 'r', dots = ['.', '..', '...'];
504 /**/
505 ws_plugin__s2member_animateProcessingConfig.originalText = $this.val ();
506 /**/
507 clearInterval(ws_plugin__s2member_animateProcessingConfig.interval);
508 /**/
509 ws_plugin__s2member_animateProcessingConfig.interval = setInterval(function()
510 {
511 if (dir === 'r') /* Right... */
512 {
513 if (i + 1 <= dots.length - 1)
514 i = i + 1, dir = 'r';
515 else /* Switch direction. */
516 i = i - 1, dir = 'l';
517 }
518 /**/
519 else if (dir === 'l') /* Left.. */
520 {
521 if (i - 1 >= 0)
522 i = i - 1, dir = 'l';
523 else /* Switch direction. */
524 i = i + 1, dir = 'r';
525 }
526 /**/
527 for (var _dots = dots[i], l = dots[i].length; l < dots.length; l++)
528 {
529 _dots += ' '; /* Prevents jumping. */
530 }
531 /**/
532 $this.val ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Processing", "s2member-front", "s2member")); ?>' + _dots);
533 }, ws_plugin__s2member_animateProcessingConfig.speed);
534 });
535 }
536 };
537 });