Learn how to use jQuery at the Blog

Cnpe « visit

  • Added 8 months ago
  • 134 Lines of Code shown
  • 2 Links of Interest
http://cnpe.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 Cnpe - http://cnpe.org

/* login globals */
    function pageAdjustForLoggedIn(){
      //override on a per page basis
    }

    function pageAdjustForLoggedOut(){
      //override on a per page basis
    }

    function adjustForLoggedIn(){
      $('a.member-login').hide();
      $('a.member-logout').show();
      pageAdjustForLoggedIn(); 
    }

    function adjustForLoggedOut(){
      $('a.member-logout').hide();
      $('a.member-login').show();  
      pageAdjustForLoggedOut();
    }

$(function () {
      $('a.member-logout').click(function(){
        $.ajax({
          type: "DELETE",
          url: $(this).attr('href'),
          complete: adjustForLoggedOut
        });
        $.cookie('member-name', null, {path: '/'});       
        return false;
      });

      if($.cookie('member-name')){
        adjustForLoggedIn();
      }

		$("label.text-input").each(function()
		{
		var inputId = $(this).attr("for");
		var inputField = document.getElementById(inputId);
		var tempValue = this.innerHTML;
		$(inputField).each(function()
		{
			if(this.type == "password")
			{	
				var pwField = this;
				$(pwField).after('<input type="text" class="tempPW" value="' + tempValue + '" id="' + this.id + '" />');
				$(".tempPW").addClass(this.className);
				$(pwField).hide();
				$(".tempPW").focus(function()
				{	
					$(".tempPW").hide();
					$(pwField).show();
					$(pwField).focus();
				});
				$(pwField).blur(function()
				{	
					if(pwField.value == "")
					{
						$(pwField).hide();
						$(".tempPW").show();
					}
				});
			}	
		});
		inputField.value = tempValue;
		$(inputField).focus(function()
		{
		   if(this.value==tempValue)
		   {
		      this.value = "";
		   }
		});
		$(inputField).blur(function()
		{	   
		   if(this.value=="")
		   {
		      this.value = tempValue;
		   }
		});
		$(this).hide();
		});	


/* cancel form fields button */
if(document.referrer != '')
{
  $('input[type="submit"].button').after('<a href="#cancel" class="cancel">cancel</a>');
  $("a.cancel").click(function()
  {
    window.location = document.referrer;
  });
}

  /* show/hide the credit card payment fields   */
  if($("fieldset:has(legend:contains('Payment')) li:first input:checked").val() != 'credit_card'){
    $("fieldset:has(legend:contains('Payment')) li:nth-child(1n+2)").hide();   
  }
  $("fieldset:has(legend:contains('Payment')) li:first input:radio").change(function() {
    if($("fieldset:has(legend:contains('Payment')) li:first input:checked").val() == 'credit_card') {
      $("fieldset:has(legend:contains('Payment')) li:nth-child(1n+2)").slideDown('fast', function() {$(this).css('display', 'list-item')});
    } else {
      $("fieldset:has(legend:contains('Payment')) li:nth-child(1n+2)").slideUp('fast');
    }
  });


/* new here/frequent visitor tabs on homepage */
$("h4#new-here").click(function () 
{
  $("h4#frequent-visitor").removeClass("active");
  $("h4#frequent-visitor").addClass("inactive");
  $(this).removeClass("inactive");
  $(this).addClass("active");
  $(".frequent-visitor").hide();
  $(".new-here").show();
});
$("h4#frequent-visitor").click(function () 
{
  $("h4#new-here").removeClass("active");
  $("h4#new-here").addClass("inactive");
  $(this).removeClass("inactive");
  $(this).addClass("active");
  $(".new-here").hide();
  $(".frequent-visitor").show();
});

// randomized green heading box
var rndNum = Math.floor(Math.random() * 2);
if(rndNum == 1)
{
   $("#page-info").addClass("green");
}
});