Skip to content

Commit 8a476df

Browse files
committed
more updates
1 parent 6c3c924 commit 8a476df

File tree

4 files changed

+167
-98
lines changed

4 files changed

+167
-98
lines changed

README.md

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ AjaxChimp is a jQuery plugin that lets you ajaxify your mailchimp form.
44

55
Use this if you hate the jarring transition to the mailchimp website upon submitting an email address to mailchimp.
66

7-
**Note**: This relies on an undocumented feature at mailchimp that uses JSONP to allow cross-domain ajax to work. You have been warned. (It has however, been around for at least 3 years that I know of, and probably more.)
7+
**Note**: This relies on an undocumented feature at mailchimp that uses JSONP to allow cross-domain ajax to work. You have been warned. (It has however, been around for at least 4 years that I know of, and probably more.)
88

99

1010
## Install
@@ -15,18 +15,18 @@ Just add the script to your webpage (along with jQuery ofcourse). Get it here:
1515
curl -O https://github.com/raw/scdoshi/jquery-ajaxchimp/master/jquery.ajaxchimp.js
1616
```
1717

18-
#### bower
18+
##### or via bower
1919

2020
```
2121
bower install ajaxchimp
2222
```
2323

24-
2524
## Requirements
2625

2726
* jQuery
2827

29-
**Note**: Developed with 1.9.1, but it should work with earlier versions. If it does or does not work with a particular version, please open an issue on github.
28+
**Note**: Developed with 2.1.4, but it should work with earlier versions. If it does or does not work with a particular version, please open an issue on github.
29+
3030

3131
## Use
3232

@@ -36,7 +36,7 @@ bower install ajaxchimp
3636
$('form-selector').ajaxChimp();
3737
```
3838

39-
## Label
39+
## Error / Success messages
4040

4141
If a label element is included in the form for the email input, then the success or error message will be displayed in it. A `valid` or `error` class will also be added accordingly.
4242

@@ -59,25 +59,30 @@ $('#mc-form').ajaxChimp({
5959

6060
## Options
6161

62-
### Callback
62+
### Callbacks
63+
64+
Optionally, you can specify a callback with either method to run after the ajax query to mailchimp succeeds or fails.
6365

64-
Optionally, you can specify a callback with either method to run after the
65-
ajax query to mailchimp succeeds or fails.
66+
The form element that triggered the ajax call is also passed in to the callbacks as the last argument.
6667

6768
```js
68-
$('form-selector').ajaxChimp({
69+
var formAjaxChimp = $('form-selector').ajaxChimp({
6970
callback: callbackFunction
7071
});
71-
```
7272

73-
The JSONP response from mailchimp will be passed to the callback function
73+
formAjaxChimp.done(function (data, textStatus, jqXHR, form) {
74+
// success callback code here
75+
});
76+
77+
formAjaxChimp.fail(function (jqXHR, textStatus, errorThrown, form) {
78+
// failure callback code here
79+
});
80+
81+
formAjaxChimp.always(function () {
82+
var form = arguments[3];
83+
// always callback code here
84+
});
7485

75-
```js
76-
function callbackFunction (resp) {
77-
if (resp.result === 'success') {
78-
// Do stuff
79-
}
80-
}
8186
```
8287

8388
### URL
@@ -96,14 +101,26 @@ The mailchimp post url will look like this:
96101
http://blahblah.us1.list-manage.com/subscribe/post?u=5afsdhfuhdsiufdba6f8802&id=4djhfdsh99f
97102
```
98103

99-
### Language Support
104+
### Custom messages
105+
106+
To display custom messages, override the default english translations.
107+
108+
Notice the use of `$1`, `$2` etc. These are regular expression groups from the original messages for the parts that are dynamic, such as the email address. You can omit them if you want to use a constant message.
100109

101-
For success and error messages in different languages:
110+
For e.g., to change the success message:
111+
112+
```js
113+
$.ajaxChimp.translations.en = {
114+
success: 'Why not say this instead, for the email address $1',
115+
}
116+
117+
```
118+
119+
### Multiple language support
102120

103121
- Specify the language as an option.
104122
- Include `jquery.ajaxchimp.langs.js` in the html file
105123

106-
107124
```js
108125
$('form-selector').ajaxChimp({
109126
language: 'es'
@@ -116,29 +133,39 @@ You can also add custom translations just for your website:
116133

117134
```js
118135
$.ajaxChimp.translations.es = {
119-
'submit': 'Grabación en curso...',
120-
0: 'Te hemos enviado un email de confirmación',
121-
1: 'Por favor, introduzca un valor',
122-
2: 'Una dirección de correo electrónico debe contener una sola @',
123-
3: 'La parte de dominio de la dirección de correo electrónico no es válida (la parte después de la @:)',
124-
4: 'La parte de usuario de la dirección de correo electrónico no es válida (la parte antes de la @:)',
125-
5: 'Esta dirección de correo electrónico se ve falso o no válido. Por favor, introduce una dirección de correo electrónico real'
136+
submit: 'Grabación en curso...',
137+
success: 'Te hemos enviado un email de confirmación $1',
138+
error: {
139+
1: 'Por favor, introduzca un valor',
140+
2: 'Una dirección de correo electrónico debe contener una sola @',
141+
3: 'La parte de dominio de la dirección de correo electrónico no es válida (la parte después de la @: $1)',
142+
4: 'La parte de usuario de la dirección de correo electrónico no es válida (la parte antes de la @: $1)',
143+
5: 'Esta dirección de correo electrónico se ve falso o no válido. Por favor, introduce una dirección de correo electrónico real',
144+
6: 'blah blah',
145+
7: 'blah',
146+
}
126147
}
127148
```
128149

129150
The mapping to english for mailchimp responses and the submit message are as follows:
130151

131152
```js
132153
// Submit Message
133-
// 'submit': 'Submitting...'
134-
135-
// Mailchimp Responses
136-
// 0: 'We have sent you a confirmation email'
137-
// 1: 'Please enter a value'
138-
// 2: 'An email address must contain a single @'
139-
// 3: 'The domain portion of the email address is invalid (the portion after the @: )'
140-
// 4: 'The username portion of the email address is invalid (the portion before the @: )'
141-
// 5: 'This email address looks fake or invalid. Please enter a real email address'
154+
// submit: 'Submitting...'
155+
156+
// Success Message
157+
// success: 'Please confirm by clicking on the link we just sent to $1.'
158+
159+
// Error Messages
160+
// errors: {
161+
// 1: 'Please enter a value',
162+
// 2: 'An email address must contain a single @',
163+
// 3: 'The domain portion of the email address is invalid (the portion after the @: $1 )',
164+
// 4: 'The username portion of the email address is invalid (the portion before the @: $1 )',
165+
// 5: 'This email address looks fake or invalid. Please enter a real email address',
166+
// 6: 'Too many subscribe attempts for this email address. Please try again in about 5 minutes.',
167+
// 7: '$1 is already subscribed to list $2'
168+
// }
142169

143170
```
144171

0 commit comments

Comments
 (0)