Advertisement
Guest User

mailchimp-widget

a guest
Jun 21st, 2012
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //'use strict';
  2.  
  3. (function ($) {
  4.  
  5.     $.fn.ns_mc_widget = function (options) {
  6.  
  7.         var defaults, eL, opts;
  8.         defaults = {
  9.             'url' : '/',
  10.             'cookie_id' : false,
  11.             'cookie_value' : ''
  12.         };
  13.         opts = jQuery.extend(defaults, options);
  14.         eL = $(this);
  15.         eL.submit(function () {
  16.  
  17.             var ajax_loader;
  18.             ajax_loader = jQuery('<div></div>');
  19.             ajax_loader.css({
  20.                 'background-image' : 'url(' + opts.loader_graphic + ')',
  21.                 'background-position' : 'center center',
  22.                 'background-repeat' : 'no-repeat',
  23.                 'height' : '100%',
  24.                 'left' : '0',
  25.                 'position' : 'absolute',
  26.                 'top' : '0',
  27.                 'width' : '100%',
  28.                 'z-index' : '100'
  29.             });
  30.  
  31.             eL.css({
  32.                 'height' : '100%',
  33.                 'position' : 'relative',
  34.                 'width' : '100%'
  35.             });
  36.  
  37.             eL.children().hide();
  38.             eL.append(ajax_loader);
  39.  
  40.             $.getJSON(opts.url, eL.serialize(), function (data, textStatus) {
  41.                 var cookie_date, error_container, new_content;
  42.                 if ('success' === textStatus) {
  43.                     if (true === data.success) {
  44.                         new_content = jQuery('<p>' + data.success_message + '</p>');
  45.                         new_content.hide();
  46.                         eL.fadeTo(400, 0, function () {
  47.                             eL.html(new_content);
  48.                             new_content.show();
  49.                             eL.fadeTo(400, 1);
  50.  
  51.                         });
  52.  
  53.                     } else {
  54.                         error_container = jQuery('.error', eL);
  55.                         if (0 === error_container.length) {
  56.                             ajax_loader.remove();
  57.                             eL.children().show();
  58.                             error_container = jQuery('<div class="error"></div>');
  59.                             error_container.prependTo(eL);
  60.                         } else {
  61.                             ajax_loader.remove();
  62.                             eL.children().show();
  63.                         }
  64.                         error_container.html(data.error);
  65.                     }
  66.                 }
  67.                 return false;
  68.             });
  69.             return false;
  70.         });
  71.     };
  72. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement