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

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

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