Learn how to use jQuery at the Blog

Vittana « visit

  • Added 8 months ago
  • 80 Lines of Code shown
  • 2 Links of Interest
http://vittana.org
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Vittana - http://vittana.org

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function init_auth_token_for_jquery(auth_token) {
  $(document).ajaxSend(function(event, request, settings) {
    if (typeof(auth_token) == "undefined") { return; }

    settings.data = settings.data || "";
    settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(auth_token);
  });
}

function add_tooltip_to_bar_graphs() {
  $('div.bargraph img').tooltip({
    track: true,
    delay: 245,
    showURL: false,
    showBody: " - ",
    fade: 325,
    extraClass: "left"
  });
}

function add_remove_action(id) {
  selector_id = '#' + id;
  $(selector_id + ' div.give a').click(function() {
      $(selector_id).fadeOut("slow");
  });
}

function add_submit_email_action(element) {
  element.click(function() {
    var email = $("#email").attr("value");
    $(this).replaceWith('<img id="loader" src="/images/loader.gif"/>');

    if (validate_email(email)) {
      var onSuccess = function(data, textStatus) {
        $("#loader").replaceWith("");
        $("#email").replaceWith("<span class='success'>Thanks, &quot;" + email + "&quot;!  We'll definitely keep you posted.</span>")
      };

      var onError = function(XMLHttpRequest, textStatus, errorThrown) {
        $("#loader").replaceWith("");
        $("#email").replaceWith("<span class='epicfail'>Oops! Something broke.  Please contact us at <a href='mailto:help@vittana.org'>help@vittana.org</a> and we'll get right on it.</span>");
      }

      $.ajax({
        type: "POST",
        url: "/index/signup",
        data: { email: email },
        success: onSuccess,
        error: onError
      });
    }

    return false;
  });
}

function validate_email(email) {
  var result = false;

  $.ajax({
    async: false,
    type: 'POST',
    url: '/index/verifyemail',
    data: { email: email },
    success: function() { result = true; },
    error: function() {
      $('#loader').replaceWith('<input id="button" type="submit" value=""/>');

      var button = $('#button');
      add_submit_email_action(button);
      alert('E-mail address is either invalid or has been registered with us already.  Please try again.');

      result = false;
    }
  });

  return result;
}