Sha256: b9e477cafb0e801645eaf7428090d1715d4576d07c04d0f0593aac29315b40a7

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 KB

Contents

var Heroku = Heroku || {};
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

Heroku.NewsletterSignup = (function() {
  function NewsletterSignup() {
    this.handleSubmit     = bind(this.handleSubmit, this);
    this.$container       = $("#bookends-newsletter");
    this.$honeyPot        = this.$container.find("#bookends-website");
    this.$input           = this.$container.find("input[type=email]");
    this.$submit          = this.$container.find(":submit");
    this.$resultContainer = $("#bookends-newsletter-result");

    this.$container.on("submit", this.handleSubmit);
  }

  NewsletterSignup.prototype.handleSubmit = function(e) {
    var val;
    var self;

    e.preventDefault();
    if(this.$honeyPot.val() !== "") {
      return this.handleSuccess();
    }

    val  = this.$input.val();
    self = this;
    $.ajax({
      url: "https://www.heroku.com/newsletter_signups",
      type: "POST",
      crossDomain: true,
      data: { newsletter_signup: { email: val } }
    })
   .done(function(res) {
      return self.handleSuccess();
    })
    .fail(function(err) {
      return self.handleFailure();
    });
  };

  NewsletterSignup.prototype.handleSuccess = function() {
    this.$input.replaceWith("<p>Check your email now to confirm your sign-up.</p>");
  };

  NewsletterSignup.prototype.handleFailure = function() {
    this.$input.val("");
    this.$resultContainer
      .removeClass("hide")
      .text("There was an error registering you. Please refresh.");
  };

  return NewsletterSignup;

})();

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bookends-2.3.4 lib/bookends/templates/newsletter.js
bookends-2.3.3 lib/bookends/templates/newsletter.js
bookends-2.3.1 lib/bookends/templates/newsletter.js
bookends-2.3.0 lib/bookends/templates/newsletter.js
bookends-2.2.1 lib/bookends/templates/newsletter.js
bookends-2.2.0 lib/bookends/templates/newsletter.js
bookends-2.1.3 lib/bookends/templates/newsletter.js
bookends-2.1.2 lib/bookends/templates/newsletter.js
bookends-2.1.1 lib/bookends/templates/newsletter.js
bookends-2.0.1 lib/bookends/templates/newsletter.js
bookends-2.0.0 lib/bookends/templates/newsletter.js