Source Code Documentation


s2member\includes\s2member.js


  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. jQuery(document).ready (function($)
  20. {
  21. var runningBuddyPress = '<?php echo c_ws_plugin__s2member_utils_conds::bp_is_installed ("query-active-plugins") ? "1" : ""; ?>';
  22. var filesBaseDir = '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (c_ws_plugin__s2member_utils_dirs::basename_dir_app_data ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"])); ?>';
  23. var skipAllFileConfirmations = ( typeof ws_plugin__s2member_skip_all_file_confirmations !== 'undefined' && ws_plugin__s2member_skip_all_file_confirmations) ? true : false;
  24. var uniqueFilesDownloadedInPage = /* Real-time counts in a single page/instance. */ [];
  25.  
  26. if (S2MEMBER_CURRENT_USER_IS_LOGGED_IN && S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY < S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED && !skipAllFileConfirmations)
  27. {
  28. $('a[href*="s2member_file_download="], a[href*="/s2member-files/"], a[href^="s2member-files/"], a[href*="/' + filesBaseDir.replace (/([\:\.\[\]])/g, '\\$1') + '/"], a[href^="' + filesBaseDir.replace (/([\:\.\[\]])/g, '\\$1') + '/"]').click (function()
  29. {
  30. if (!this.href.match /* Do NOT prompt on downloads issued with a Key. */ (/s2member[_\-]file[_\-]download[_\-]key[\=\-].+/i))
  31. {
  32. var c = '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Confirm File Download —", "s2member-front", "s2member")); ?>' + '\n\n';
  33. 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';
  34. 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)));
  35.  
  36. if ((this.href.match (/s2member[_\-]skip[_\-]confirmation/i) && !this.href.match (/s2member[_\-]skip[_\-]confirmation[\=\-](0|no|false)/i)) || confirm(c))
  37. {
  38. if ($.inArray (this.href, uniqueFilesDownloadedInPage) === -1)
  39. S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY++, uniqueFilesDownloadedInPage.push (this.href);
  40.  
  41. return /* Allow. */ true;
  42. }
  43. else // Disallow.
  44. return false;
  45. }
  46. else // Allow.
  47. return true;
  48. });
  49. }
  50.  
  51. if (!location.href.match (/\/wp-admin(\/|\?|$)/))
  52. {
  53. $('input#ws-plugin--s2member-profile-password1, input#ws-plugin--s2member-profile-password2').keyup (function()
  54. {
  55. 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'));
  56. });
  57.  
  58. $('form#ws-plugin--s2member-profile').submit ( /* Validate Profile. */function()
  59. {
  60. var context = this, label = '', error = '', errors = '';
  61.  
  62. var $password1 = $('input#ws-plugin--s2member-profile-password1', context);
  63. var $password2 = $('input#ws-plugin--s2member-profile-password2', context);
  64.  
  65. var $submissionButton = $('input#ws-plugin--s2member-profile-submit', context);
  66.  
  67. $(':input', context).each ( /* Go through them all together. */function()
  68. {
  69. var id = /* Remove numeric suffixes. */ $.trim ($(this).attr ('id')).replace (/---[0-9]+$/g, '');
  70.  
  71. if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().children ('strong').first ().text ().replace (/[\r\n\t]+/g, ' '))))
  72. {
  73. if (error = ws_plugin__s2member_validationErrors(label, this, context))
  74. errors += /* Collect errors. */ error + '\n\n';
  75. }
  76. });
  77.  
  78. if (errors = $.trim (errors))
  79. {
  80. alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
  81.  
  82. return false;
  83. }
  84.  
  85. else if ($.trim ($password1.val ()) && $.trim ($password1.val ()) !== $.trim ($password2.val ()))
  86. {
  87. 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")); ?>');
  88.  
  89. return false;
  90. }
  91.  
  92. else if ($.trim ($password1.val ()) && /* Enforce minimum length requirement here. */ $.trim ($password1.val ()).length < 6)
  93. {
  94. 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")); ?>');
  95.  
  96. return false;
  97. }
  98.  
  99. ws_plugin__s2member_animateProcessing($submissionButton);
  100.  
  101. return true;
  102. });
  103. }
  104.  
  105. if (location.href.match (/\/wp-signup\.php/))
  106. {
  107. $('div#content > div.mu_register > form#setupform').submit (function()
  108. {
  109. var context = this, label = '', error = '', errors = '';
  110.  
  111. $('input#user_email', context).attr ('data-expected', 'email');
  112.  
  113. var $submissionButton = $('p.submit input[type="submit"]', context);
  114.  
  115. $('input#user_name, input#user_email, input#blogname, input#blog_title, input#captcha_code', context).attr ({'aria-required': 'true'});
  116.  
  117. $(':input', context).each ( /* Go through them all together. */function()
  118. {
  119. var id = /* Remove numeric suffixes. */ $.trim ($(this).attr ('id')).replace (/---[0-9]+$/g, '');
  120.  
  121. if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
  122. {
  123. if (error = ws_plugin__s2member_validationErrors(label, this, context))
  124. errors += /* Collect errors. */ error + '\n\n';
  125. }
  126. });
  127.  
  128. if (errors = $.trim (errors))
  129. {
  130. alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
  131.  
  132. return false;
  133. }
  134.  
  135. ws_plugin__s2member_animateProcessing($submissionButton);
  136.  
  137. return true;
  138. });
  139. }
  140.  
  141. if (location.href.match (/\/wp-login\.php/))
  142. {
  143. $('div#login > form#registerform input#user_login').attr('tabindex', '10');
  144. $('div#login > form#registerform input#user_email').attr('tabindex', '20');
  145. $('div#login > form#registerform input#wp-submit').attr ('tabindex', '1000');
  146.  
  147. $('input#ws-plugin--s2member-custom-reg-field-user-pass1, input#ws-plugin--s2member-custom-reg-field-user-pass2').keyup (function()
  148. {
  149. 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'));
  150. });
  151. $('div#login > form#registerform').submit (function()
  152. {
  153. var context = this, label = '', error = '', errors = '';
  154.  
  155. $('input#user_email', context).attr ('data-expected', 'email');
  156.  
  157. var $pass1 = $('input#ws-plugin--s2member-custom-reg-field-user-pass1[aria-required="true"]', context);
  158. var $pass2 = $('input#ws-plugin--s2member-custom-reg-field-user-pass2', context);
  159.  
  160. var $submissionButton = /* Registration submission button. */ $('input#wp-submit', context);
  161.  
  162. $('input#user_login, input#user_email, input#captcha_code', context).attr ({'aria-required': 'true'});
  163.  
  164. $(':input', context).each ( /* Go through them all together. */function()
  165. {
  166. var id = /* Remove numeric suffixes. */ $.trim ($(this).attr ('id')).replace (/---[0-9]+$/g, '');
  167.  
  168. if /* No for="" attribute on these fields. */ ($.inArray (id, ['user_login', 'user_email', 'captcha_code']) !== -1)
  169. {
  170. if /* Use label. */ ((label = $.trim ($(this).parent ('label').text ().replace (/[\r\n\t]+/g, ' '))))
  171. {
  172. if (error = ws_plugin__s2member_validationErrors(label, this, context))
  173. errors += /* Collect errors. */ error + '\n\n';
  174. }
  175. }
  176. else if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().children ('span').first ().text ().replace (/[\r\n\t]+/g, ' '))))
  177. {
  178. if (error = ws_plugin__s2member_validationErrors(label, this, context))
  179. errors += /* Collect errors. */ error + '\n\n';
  180. }
  181. });
  182.  
  183. if (errors = $.trim (errors))
  184. {
  185. alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
  186.  
  187. return false;
  188. }
  189.  
  190. else if ($pass1.length && $.trim ($pass1.val ()) !== $.trim ($pass2.val ()))
  191. {
  192. 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")); ?>');
  193.  
  194. return false;
  195. }
  196.  
  197. else if /* Enforce minimum length requirement here. */ ($pass1.length && $.trim ($pass1.val ()).length < 6)
  198. {
  199. 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")); ?>');
  200.  
  201. return false;
  202. }
  203.  
  204. ws_plugin__s2member_animateProcessing($submissionButton);
  205.  
  206. return true;
  207. });
  208. }
  209.  
  210. if (location.href.match (/\/wp-admin\/(user\/)?profile\.php/))
  211. {
  212. $('form#your-profile').submit ( /* Validation. */function()
  213. {
  214. var context = this, label = '', error = '', errors = '';
  215.  
  216. $('input#email', context).attr ('data-expected', 'email');
  217.  
  218. $(':input[id^="ws-plugin--s2member-profile-"]', context).each ( /* Go through them all together. */function()
  219. {
  220. var id = /* Remove numeric suffixes. */ $.trim ($(this).attr ('id')).replace (/---[0-9]+$/g, '');
  221.  
  222. if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
  223. {
  224. if (error = ws_plugin__s2member_validationErrors(label, this, context))
  225. errors += /* Collect errors. */ error + '\n\n';
  226. }
  227. });
  228.  
  229. if (errors = $.trim (errors))
  230. {
  231. alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
  232.  
  233. return false;
  234. }
  235.  
  236. return true;
  237. });
  238. }
  239.  
  240. if /* Attach form submission handler to `/register` for BuddyPress. */ (runningBuddyPress)
  241. {
  242. $('body.registration form div#ws-plugin--s2member-custom-reg-fields-4bp-section').closest ('form').submit (function()
  243. {
  244. var context = this, label = '', error = '', errors = '';
  245.  
  246. $('input#signup_email', context).attr ('data-expected', 'email');
  247.  
  248. $('input#signup_username, input#signup_email, input#signup_password, input#field_1', context).attr ({'aria-required': 'true'});
  249.  
  250. $(':input', context).each ( /* Go through them all together. */function()
  251. {
  252. var id = /* Remove numeric suffixes. */ $.trim ($(this).attr ('id')).replace (/---[0-9]+$/g, '');
  253.  
  254. if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
  255. {
  256. if (error = ws_plugin__s2member_validationErrors(label, this, context))
  257. errors += /* Collect errors. */ error + '\n\n';
  258. }
  259. });
  260.  
  261. if (errors = $.trim (errors))
  262. {
  263. alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
  264.  
  265. return false;
  266. }
  267.  
  268. return true;
  269. });
  270.  
  271. $('body.logged-in.profile.profile-edit :input.ws-plugin--s2member-profile-field-4bp').closest ('form').submit (function()
  272. {
  273. var context = this, label = '', error = '', errors = '';
  274.  
  275. $('input#field_1', context).attr ({'aria-required': 'true'});
  276.  
  277. $(':input', context).each ( /* Go through them all together. */function()
  278. {
  279. var id = /* Remove numeric suffixes. */ $.trim ($(this).attr ('id')).replace (/---[0-9]+$/g, '');
  280.  
  281. if (id && (label = $.trim ($('label[for="' + id + '"]', context).first ().text ().replace (/[\r\n\t]+/g, ' '))))
  282. {
  283. if (error = ws_plugin__s2member_validationErrors(label, this, context))
  284. errors += /* Collect errors. */ error + '\n\n';
  285. }
  286. });
  287.  
  288. if (errors = $.trim (errors))
  289. {
  290. alert('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("— Oops, you missed something: —", "s2member-front", "s2member")); ?>' + '\n\n' + errors);
  291.  
  292. return false;
  293. }
  294.  
  295. return true;
  296. });
  297. }
  298.  
  299. ws_plugin__s2member_passwordStrength = function($username, $pass1, $pass2, $result)
  300. {
  301. if ($username instanceof jQuery && $pass1 instanceof jQuery && $pass2 instanceof jQuery && $result instanceof jQuery && typeof passwordStrength === 'function' && typeof pwsL10n === 'object')
  302. {
  303. $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');
  304.  
  305. switch /* Uses WordPress® script: `password-strength-meter` and `pwsL10n`. */ (passwordStrength($pass1.val (), $username.val (), $pass2.val ()))
  306. {
  307. case 1:
  308. $result.addClass ('ws-plugin--s2member-password-strength-short').html (pwsL10n['short']);
  309. break;
  310. case 2:
  311. $result.addClass ('ws-plugin--s2member-password-strength-bad').html (pwsL10n['bad']);
  312. break;
  313. case 3:
  314. $result.addClass ('ws-plugin--s2member-password-strength-good').html (pwsL10n['good']);
  315. break;
  316. case 4:
  317. $result.addClass ('ws-plugin--s2member-password-strength-strong').html (pwsL10n['strong']);
  318. break;
  319. case 5:
  320. $result.addClass ('ws-plugin--s2member-password-strength-mismatch').html (pwsL10n['mismatch']);
  321. break;
  322. default:
  323. $result.addClass ('ws-plugin--s2member-password-strength-short').html (pwsL10n['short']);
  324. }
  325. }
  326.  
  327. return;
  328. };
  329.  
  330. ws_plugin__s2member_validationErrors = function(label, field, context, required, expected)
  331. {
  332. if (typeof label === 'string' && label && typeof field === 'object' && typeof context === 'object')
  333. if (typeof field.tagName === 'string' && field.tagName.match (/^(input|textarea|select)$/i) && !field.disabled)
  334. {
  335. var tag = field.tagName.toLowerCase (), $field = $(field), type = $.trim ($field.attr ('type')).toLowerCase (), name = $.trim ($field.attr ('name')), value = $field.val ();
  336. var required = ( typeof required === 'boolean') ? required : ($field.attr ('aria-required') === 'true'), expected = ( typeof expected === 'string') ? expected : $.trim ($field.attr ('data-expected'));
  337.  
  338. var forcePersonalEmails = ('<?php echo strlen($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_force_personal_emails"]); ?>' > 0) ? true : false;
  339. 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');
  340.  
  341. if (tag === 'input' && type === 'checkbox' && name.match (/\[\]$/))
  342. {
  343. if (typeof field.id === 'string' && field.id.match (/-0$/))
  344. if (required && !$('input[name="' + name.replace (/([\[\]])/g, '\$1') + '"]:checked', context).length)
  345. 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")); ?>';
  346. }
  347. else if (tag === 'input' && type === 'checkbox')
  348. {
  349. if (required && !field.checked)
  350. return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Required. This box must be checked.", "s2member-front", "s2member")); ?>';
  351. }
  352. else if (tag === 'input' && type === 'radio')
  353. {
  354. if (typeof field.id === 'string' && field.id.match (/-0$/))
  355. if (required && !$('input[name="' + name.replace (/([\[\]])/g, '\$1') + '"]:checked', context).length)
  356. return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please select one of the options.", "s2member-front", "s2member")); ?>';
  357. }
  358. else if (tag === 'select' && $field.attr ('multiple'))
  359. {
  360. if (required && (!(value instanceof Array) || !value.length))
  361. 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")); ?>';
  362. }
  363. else if (typeof value !== 'string' || (required && !(value = $.trim (value)).length))
  364. {
  365. 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")); ?>';
  366. }
  367. else if ((value = $.trim (value)).length && ((tag === 'input' && type.match (/^(text|password)$/i)) || tag === 'textarea') && typeof expected === 'string' && expected.length)
  368. {
  369. if (expected === 'numeric-wp-commas' && (!value.match (/^[0-9\.,]+$/) || isNaN(value.replace (/,/g, ''))))
  370. {
  371. 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")); ?>';
  372. }
  373. else if (expected === 'numeric' && (!value.match (/^[0-9\.]+$/) || isNaN(value)))
  374. {
  375. 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")); ?>';
  376. }
  377. else if (expected === 'integer' && (!value.match (/^[0-9]+$/) || isNaN(value)))
  378. {
  379. 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")); ?>';
  380. }
  381. else if (expected === 'integer-gt-0' && (!value.match (/^[0-9]+$/) || isNaN(value) || value <= 0))
  382. {
  383. 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")); ?>';
  384. }
  385. else if (expected === 'float' && (!value.match (/^[0-9\.]+$/) || !value.match (/[0-9]/) || !value.match (/\./) || isNaN(value)))
  386. {
  387. 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")); ?>';
  388. }
  389. else if (expected === 'float-gt-0' && (!value.match (/^[0-9\.]+$/) || !value.match (/[0-9]/) || !value.match (/\./) || isNaN(value) || value <= 0))
  390. {
  391. 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")); ?>';
  392. }
  393. else if (expected === 'date' && !value.match (/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/))
  394. {
  395. 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")); ?>';
  396. }
  397. 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))
  398. {
  399. return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Must be a valid email address.", "s2member-front", "s2member")); ?>';
  400. }
  401. else if (expected === 'email' && forcePersonalEmails && value.match (nonPersonalEmailUsers))
  402. {
  403. 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]);
  404. }
  405. else if (expected === 'url' && !value.match (/^http(s?)\:\/\/(.{5,})$/i))
  406. {
  407. 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")); ?>';
  408. }
  409. else if (expected === 'domain' && !value.match (/^([a-z0-9]+)(((-*)([a-z0-9]+))*)(((\.)([a-z0-9]+)(((-*)([a-z0-9]+))*))*)(\.)([a-z]{2,6})$/i))
  410. {
  411. 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")); ?>';
  412. }
  413. else if (expected === 'phone' && (!value.match (/^[0-9 \(\)\-]+$/) || value.replace (/[^0-9]/g, '').length !== 10))
  414. {
  415. 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")); ?>';
  416. }
  417. else if (expected === 'uszip' && !value.match (/^[0-9]{5}(-[0-9]{4})?$/))
  418. {
  419. 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")); ?>';
  420. }
  421. else if (expected === 'cazip' && !value.match (/^[0-9A-Z]{3}( ?)[0-9A-Z]{3}$/i))
  422. {
  423. 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")); ?>';
  424. }
  425. else if (expected === 'uczip' && !value.match (/^[0-9]{5}(-[0-9]{4})?$/) && !value.match (/^[0-9A-Z]{3}( ?)[0-9A-Z]{3}$/i))
  426. {
  427. 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")); ?>';
  428. }
  429. else if (expected.match (/^alphanumerics-spaces-punctuation-([0-9]+)(-e)?$/) && !value.match (/^[a-z 0-9,\.\/\?\:;"'\{\}\[\]\|\\\+\=_\-\(\)\*&\^%\$#@\!`~]+$/i))
  430. {
  431. return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use alphanumerics, spaces & punctuation only.", "s2member-front", "s2member")); ?>';
  432. }
  433. else if (expected.match (/^alphanumerics-spaces-([0-9]+)(-e)?$/) && !value.match (/^[a-z 0-9]+$/i))
  434. {
  435. return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use alphanumerics & spaces only.", "s2member-front", "s2member")); ?>';
  436. }
  437. else if (expected.match (/^alphanumerics-punctuation-([0-9]+)(-e)?$/) && !value.match (/^[a-z0-9,\.\/\?\:;"'\{\}\[\]\|\\\+\=_\-\(\)\*&\^%\$#@\!`~]+$/i))
  438. {
  439. 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")); ?>';
  440. }
  441. else if (expected.match (/^alphanumerics-([0-9]+)(-e)?$/) && !value.match (/^[a-z0-9]+$/i))
  442. {
  443. 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")); ?>';
  444. }
  445. else if (expected.match (/^alphabetics-([0-9]+)(-e)?$/) && !value.match (/^[a-z]+$/i))
  446. {
  447. 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")); ?>';
  448. }
  449. else if (expected.match (/^numerics-([0-9]+)(-e)?$/) && !value.match (/^[0-9]+$/i))
  450. {
  451. return label + '\n' + '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Please use numeric digits only.", "s2member-front", "s2member")); ?>';
  452. }
  453. else if (expected.match (/^(any|alphanumerics-spaces-punctuation|alphanumerics-spaces|alphanumerics-punctuation|alphanumerics|alphabetics|numerics)-([0-9]+)(-e)?$/))
  454. {
  455. var split = expected.split ('-'), length = Number(split[1]), exactLength = (split.length > 2 && split[2] === 'e') ? true : false;
  456.  
  457. if /* An exact length is required? */ (exactLength && value.length !== length)
  458. 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")); ?>')));
  459.  
  460. else if /* Otherwise, we interpret as the minimum length. */ (value.length < length)
  461. 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")); ?>')));
  462. }
  463. }
  464. }
  465.  
  466. return '';
  467. };
  468.  
  469. ws_plugin__s2member_animateProcessingConfig = {originalText: '', interval: null, speed: 100}, ws_plugin__s2member_animateProcessing = function($obj, reset)
  470. {
  471. if /* This function expects a valid jQuery object. */ ($obj instanceof jQuery)
  472. {
  473. if /* Resets back to originalText value (also clears interval). */ (reset)
  474. {
  475. clearInterval(ws_plugin__s2member_animateProcessingConfig.interval);
  476.  
  477. if (ws_plugin__s2member_animateProcessingConfig.originalText)
  478. $obj.val (ws_plugin__s2member_animateProcessingConfig.originalText);
  479.  
  480. return; // No need to proceed any further.
  481. }
  482.  
  483. $obj.first ().each ( /* Interval routine configured here. */function()
  484. {
  485. var $this = $(this), i = 0, dir = 'r', dots = ['.', '..', '...'];
  486.  
  487. ws_plugin__s2member_animateProcessingConfig.originalText = $this.val ();
  488.  
  489. clearInterval(ws_plugin__s2member_animateProcessingConfig.interval);
  490.  
  491. ws_plugin__s2member_animateProcessingConfig.interval = setInterval(function()
  492. {
  493. if /* Right... */ (dir === 'r')
  494. {
  495. if (i + 1 <= dots.length - 1)
  496. i = i + 1, dir = 'r';
  497. else // Switch direction.
  498. i = i - 1, dir = 'l';
  499. }
  500.  
  501. else if /* Left.. */ (dir === 'l')
  502. {
  503. if (i - 1 >= 0)
  504. i = i - 1, dir = 'l';
  505. else // Switch direction.
  506. i = i + 1, dir = 'r';
  507. }
  508.  
  509. for (var _dots = dots[i], l = dots[i].length; l < dots.length; l++)
  510. {
  511. _dots += /* Prevents jumping. */ ' ';
  512. }
  513.  
  514. $this.val ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Processing", "s2member-front", "s2member")); ?>' + _dots);
  515. }, ws_plugin__s2member_animateProcessingConfig.speed);
  516. });
  517. }
  518. };
  519. });

s2member\includes\s2member.js

Source Code Documentation