view js/main.js @ 37:deebff30e816

added login form
author Atul Varma <avarma@mozilla.com>
date Sat, 24 Apr 2010 13:33:41 -0700
parents eb2cc1f89869
children 1cf0cdbc18cc
line wrap: on
line source

$(window).ready(
  function() {
    const BASE_TITLE = document.title;

    function onLoginChange() {
      var username = $("#login-username").val();
      var password = $("#login-password").val();
      var title = BASE_TITLE;

      if (username) {
        $("#login").fadeOut();
        title = username + "'s " + BASE_TITLE;

        $(".requires-login").show();
        if (password) {
          $(".requires-auth-login").show();
        } else {
          $(".requires-auth-login").hide();
        }
      } else {
        $("#login").fadeIn();
        $(".requires-login").hide();
        $(".requires-auth-login").hide();
      }

      if (document.title != title) {
        document.title = title;
        $("#header .title").text(title);
      }
    }

    $("#header .menu li").click(
      function(event) {
        var dialog = $("#" + this.title);
        if (dialog.length == 0)
          throw new Error("dialog not found: " + this.title);
        dialog.fadeIn();
      });

    $("#login-form").submit(
      function(event) {
        event.preventDefault();
        onLoginChange();
      });

    onLoginChange();
  });