PageSourceSearch

https://musicautor.org/js/ajaxChimp.js?v=1.3

js musicautor.org collected 2026-10-02 12:16:13 UTC 7,056 bytes, 176 lines download raw bytes

1/*!
2Mailchimp Ajax Submit
3jQuery Plugin
4Author: Siddharth Doshi
5Use:
6===
7$('#form_id').ajaxchimp(options);
8- Form should have one <input> element with attribute 'type=email'
9- Form should have one label element with attribute 'for=email_input_id' (used to display error/success message)
10- All options are optional.
11Options:
12=======
13options = {
14    language: 'en',
15    callback: callbackFunction,
16    url: 'http://blahblah.us1.list-manage.com/subscribe/post?u=5afsdhfuhdsiufdba6f8802&id=4djhfdsh99f'
17}
18Notes:
19=====
20To get the mailchimp JSONP url (undocumented), change 'post?' to 'post-json?' and add '&c=?' to the end.
21For e.g. 'http://blahblah.us1.list-manage.com/subscribe/post-json?u=5afsdhfuhdsiufdba6f8802&id=4djhfdsh99f&c=?',
22*/
23
24(function ($) {
25  'use strict';
26
27  $.ajaxChimp = {
28      responses: {
29          'We have sent you a confirmation email'                                             : 0,
30          'Please enter a value'                                                              : 1,
31          'An email address must contain a single @'                                          : 2,
32          'The domain portion of the email address is invalid (the portion after the @: )'    : 3,
33          'The username portion of the email address is invalid (the portion before the @: )' : 4,
34          'This email address looks fake or invalid. Please enter a real email address'       : 5
35      },
36      translations: {
37          'en': null,
38      },
39      init: function (selector, options) {
40          $(selector).ajaxChimp(options);
41      }
42  };
43
44  $.fn.ajaxChimp = function (options) {
45      $(this).each(function(i, elem) {
46          var form = $(elem);
47          var email = form.find('input[type=email]');
48          var label = form.find('label[for=' + email.attr('id') + ']');
49          var errorMsg = form.find('#mce-error-response')
50          var successMsg = form.find('#mce-success-response')
51
52          var settings = $.extend({
53              'url': form.attr('action'),
54              'language': 'en'
55          }, options);
56
57          var url = settings.url.replace('/post?', '/post-json?').concat('&c=?');
58
59          form.attr('novalidate', 'true');
60          email.attr('name', 'EMAIL');
61
62          form.submit(function () {
63              var msg;
64              function successCallback(resp) {
65                  if (resp.result === 'success') {
66                      msg = 'We have sent you a confirmation email';
67                      form.removeClass('error').addClass('valid');
68                      successMsg.show().text(resp.msg)
69                      errorMsg.hide()
70                  } else {
71                      form.removeClass('valid').addClass('error');
72                      errorMsg.show().text(resp.msg)
73                      successMsg.hide()
74                      var index = -1;
75                      try {
76                          var parts = resp.msg.split(' - ', 2);
77                          if (parts[1] === undefined) {
78                              msg = resp.msg;
79                          } else {
80                              var i = parseInt(parts[0], 10);
81                              if (i.toString() === parts[0]) {
82                                  index = parts[0];
83                                  msg = parts[1];
84                              } else {
85                                  index = -1;
86                                  msg = resp.msg;
87                              }
88                          }
89                      }
90                      catch (e) {
91                          index = -1;
92                          msg = resp.msg;
93                      }
94                  }
95
96                  // Translate and display message
97                  if (
98                      settings.language !== 'en'
99                      && $.ajaxChimp.responses[msg] !== undefined
100                      && $.ajaxChimp.translations
101                      && $.ajaxChimp.translations[settings.language]
102                      && $.ajaxChimp.translations[settings.language][$.ajaxChimp.responses[msg]]
103                  ) {
104                      msg = $.ajaxChimp.translations[settings.language][$.ajaxChimp.responses[msg]];
105                  }
106                  label.html(msg);
107
108                  label.show(2000);
109                  if (settings.callback) {
110                      settings.callback(resp);
111                  }
112              }
113
114              var data = {};
115              var dataArray = form.serializeArray();
116              $.each(dataArray, function (index, item) {
117                  data[item.name] = item.value;
118              });
119
120              $.ajax({
121                  url: url,
122                  data: data,
123                  success: successCallback,
124                  dataType: 'jsonp',
125                  error: function (resp, text) {
126                      console.log('mailchimp ajax submit error: ' + text);
127                  }
128              });
129
130              // Translate and display submit message
131              var submitMsg = 'Submitting...';
132              if(
133                  settings.language !== 'en'
134                  && $.ajaxChimp.translations
135                  && $.ajaxChimp.translations[settings.language]
136                  && $.ajaxChimp.translations[settings.language]['submit']
137              ) {
138                  submitMsg = $.ajaxChimp.translations[settings.language]['submit'];
139              }
140              label.html(submitMsg).show(2000);
141
142              return false;
143          });
144      });
145      return this;
146  };
147})(jQuery);
148
149(function ($) {
150  'use strict';
151
152  // ISO-693-1 Language codes: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
153
154  // Submit Message
155  // 'submit': 'Submitting...'
156
157  // Mailchimp Responses
158  // 0: 'We have sent you a confirmation email'
159  // 1: 'Please enter a value'
160  // 2: 'An email address must contain a single @'
161  // 3: 'The domain portion of the email address is invalid (the portion after the @: )'
162  // 4: 'The username portion of the email address is invalid (the portion before the @: )'
163  // 5: 'This email address looks fake or invalid. Please enter a real email address'
164
165  $.ajaxChimp.translations = {
166      // Translation via https://github.com/lifeisfoo
167      'bg': {
168        'Изпратихме ви имейл за потвърждение'                                           : 0,
169        'Полето не може да бъде празно'                                                 : 1,
170        'Имейлът трябва да съдържа @'                                                   : 2,
171        'Имейлът е невалиден (невалиден е след този символ @: )'                        : 3,
172        'Името на имейл адреса е невалиден (имейлът е невалиден преди този символ @: )' : 4,
173        'Имейлът излгежда фалшив или невалиден. Моля въведи реален имейл адрес'         : 5
174      },
175  };
176})(jQuery);

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