Learn how to use jQuery at the Blog

10 or Less « visit

  • Added 5 months ago
  • 672 Lines of Code shown
  • 1 Links of Interest
http://10orless.co.uk
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 10 or Less - http://10orless.co.uk

function forward(url,store,id){
	var hh = $("#holder").height();
	var content = 'Forwarding to store\'s website...';
	if (store!='') content = 'Forwarding to '+store+' website...';
	var my_id = '';
	if (id.indexOf("buylgi_")!=-1) my_id = id.replace("buylgi_","");
	if (id.indexOf("buylg_")!=-1) my_id = id.replace("buylg_","");
	if (id.indexOf("buyi_")!=-1) my_id = id.replace("buyi_","");
	if (id.indexOf("buy_")!=-1) my_id = id.replace("buy_","");
	if (id.indexOf("buyd_")!=-1) my_id = id.replace("buyd_","");
	$("#fwd_content").html('<p><img src="images/logo.jpg" alt="10OrLess" /></p><p style="text-align:center;">'+content+'</p>');
	$('#fwd').css("height",hh+"px");
	$('#fwd').fadeIn(function(){
		$.get("scripts/scr_recent.php?id="+my_id,function(){
			$.get("scripts/scr_click.php?id="+my_id,function(){
				var fwt = setTimeout("document.location.href = '"+url+"';",2000);
			});
		});
	});
}

function change_ptd(value,to_parse,add){
	document.location.href = '?p=store'+to_parse+'&ptd='+value+add;
}

function change_sort(value,to_parse,add){
	document.location.href = '?p=store'+to_parse+'&sort='+value+add;
}

$(document).ready(function(){
	var is_action = 0;


	$("#recent_empty").click(function(){
		if (confirm('Are you sure?')){
			return true;
		}
		else{
			return false;
		}
	
	});
	
	$("a.buy").live('click',function(){
		forward($(this).attr("href"),$(this).attr("title"),$(this).attr("id"));
		return false;
	});

	$("div.st_nav1 ul li a").click(function(){
		var page = $(this).attr("title");
		var my_link = $(this);
		var step = 600;
		var action_step = 0;
		if (is_action==0){
			is_action = 1;
			action_step = step*(page-1);
			$('div.prod_small_hc').animate({left:'-'+action_step},300,function(){
				$("div.st_nav1 ul li a").filter(".sel").removeClass("sel");
				my_link.addClass("sel");
				is_action = 0;
			});
			
		}
		return false;
	});

	$("a.ico_share").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="?p=login">here</a> to login or go to the <a href="?p=register">register page</a> to register for an account.</p>',0);
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("share_","");
			var name = $(this).attr("title");
			var share_form = '<form name="share_form" id="share_form" action="scripts/scr_share.php" method="post"><input type="hidden" name="id" value="'+my_id+'" /><div class="sfi"><label>To</label><div class="sfibg"><input type="text" name="share_to" id="share_to" value="" /></div></div><div class="sfi"><label>From</label><div class="sfibg"><input type="text" id="share_from" name="share_from" value="" /></div></div><div class="sfi"><label>Subject</label><div class="sfibg"><input type="text" id="share_subject" name="share_subject" value="Check out what I found at 10orLess!" /></div></div><div class="sfi" style="height:80px;"><label>Message</label><textarea name="share_message" id="share_message"></textarea></div><div class="btn_share"><a href="#" class="sshare">SUBMIT NOW</a></div></form>';
			tolalert('<h1>Share by email / '+name+'</h1><p id="tol_err">Enter one or more email addresses separated by commas.</p><div class="sh_form">'+share_form+'</div>',0);
			$("a.sshare").click(function(){
				$("#share_form").submit();
				return false;
			});
			$("#share_form").submit(function(){
				var error = 0;
				$("input#share_to").parent().removeClass("err");
				$("input#share_from").parent().removeClass("err");
				$("input#share_subject").parent().removeClass("err");
				if ($("input#share_to").val()==''){
					$("input#share_to").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_from").val()==''){
					$("input#share_from").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_subject").val()==''){
					$("input#share_subject").parent().addClass("err");
					error = 1;
				}
				if (error == 0){
					var my_form = document.share_form;
					var inputs = [];
					$(':input', my_form).each(function() {
						inputs.push(this.name + '=' + encodeURIComponent(this.value));
					})  
					jQuery.ajax({
						data: inputs.join('&'),
						url: my_form.action,
						timeout: 2000,
						error: function() {
							$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
							$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
						},
						success: function(r) {
							if (r==1){ 
								$("input#share_to").parent().removeClass("err");
								$("input#share_to").val('');
								$("input#share_from").val('');
								$("input#share_subject").val('Check out what I found at 10orLess!');
								$("textarea#share_message").val('');
								$("#tolalert_icontent p").html("Your message was succesfully sent.");
								$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								var tt = setTimeout('$("#tolalerth").fadeOut(function(){act_ta = 0;});',2000);

							}
							else{
								if (r==2){ 
									$("input#share_to").parent().addClass("err");
									$("#tolalert_icontent p").html("The email address is invalid.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								}
								else{
									$("input#share_to").val('');
									$("input#share_from").val('');
									$("input#share_subject").val('Check out what I found at 10orLess!');
									$("textarea#share_message").val('');
									$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});							
								}
							}
						}
					})						
				}
				return false; 
			});
		}
		return false;
	});
	
	
	
	$("a.ico_alert").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="?p=login">here</a> to login or go to the <a href="?p=register">register page</a> to register for an account.</p>',0);
		}
		else{
			alert('Inactive module');
		}
		return false;
	});
	$("a.ico_favourite").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="?p=login">here</a> to login or go to the <a href="?p=register">register page</a> to register for an account.</p>',0);
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("fav_","");
			var name = $(this).attr("title");
			$.post("scripts/scr_add_favourite.php", { id: my_id },
			  function(data){
			  	if (data=='1'){
			  		tolalert('<h1>My Favourites / '+name+'</h1><p>Item added to your Favourites</p>',1);
			  	}
			  	if (data=='2'){
			  		tolalert('<h1>My Favourites / '+name+'</h1><p>This item is already in your Favourites</p>',1);
			  	}
			  	if (data=='0'){
			  		tolalert('<h1>My Favourites / '+name+'</h1><p>Your request could not be processed.<br />Please try again later.</p>',0);
			  	}
			  });
		}
		return false;
	});
	$("a.ico_dfavourite").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="?p=login">here</a> to login or go to the <a href="?p=register">register page</a> to register for an account.</p>',0);
			return false;
		}
		else{
			if (confirm('Are you sure?')){
				return true;
			}
			else{
				return false;
			}
		}
	});
	$("a.ico_wish").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="?p=login">here</a> to login or go to the <a href="?p=register">register page</a> to register for an account.</p>',0);
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("wish_","");
			var name = $(this).attr("title");
			$.post("scripts/scr_add_wish.php", { id: my_id },
			  function(data){
			  	if (data=='1'){
			  		tolalert('<h1>My Wish List / '+name+'</h1><p>Item added to your Wish List</p>',1);
			  	}
			  	if (data=='2'){
			  		tolalert('<h1>My Wish List / '+name+'</h1><p>This item is already in your Wish List</p>',1);
			  	}
			  	if (data=='0'){
			  		tolalert('<h1>My Wish List / '+name+'</h1><p>Your request could not be processed.<br />Please try again later.</p>',0);
			  	}
			  });
  		}
		return false;
	});

	var showDelay = 500;    
	var hideDelay = 250;    
	var hideTimer = null;  
	var showTimer = null;  
	var container = "";
	var ccontainer = "";
	var is_detail = 0;

	$('div.showdetail').mouseenter(function(){
      	if (hideTimer)  
        	clearTimeout(hideTimer);  
      	if (showTimer)  
        	clearTimeout(showTimer);  
		var my_elem = $(this);

		if (container && ccontainer!=my_elem.children("div.detail_info").html()){
			container.css('display', 'none');  
			container.remove();
			is_detail = 0;
		}
		if (is_detail == 0){
			showTimer = setTimeout(function(){  
				$("#content").append('<div id="detail"><div class="darrow">&nbsp;</div><div id="detail_top">&nbsp;</div><div id="detail_content"><a href="#" class="dclose" href="#">CLOSE</a><div id="detail_icontent">&nbsp;</div></div><div id="detail_bottom">&nbsp;</div></div>');
				container = $("#content").children('#detail');
				container.css({"visibility":"hidden","display":"block"});
				var detail_content = my_elem.children("div.detail_info");
				ccontainer = my_elem.children("div.detail_info").html();
				$("#detail_icontent").html(detail_content.html()); 
		
		
				var pos = my_elem.offset();
				var width = my_elem.width();
				var height = my_elem.height();
				var distance_top = (pos.top-$('body').scrollTop())+24;
				var distance_bottom = ($('body').height()-height-(pos.top-$('body').scrollTop()))+24;
		
				var distance_left = pos.left-$("#content").offset().left;
				var distance_right = $("#content").width()-distance_left-width;
				
				var pos_top = 0;
				var pos_left = 0;
				var fpos = 1;
				container.children("div.darrow").removeClass("dbl");
				container.children("div.darrow").removeClass("dbr");
				container.children("div.darrow").removeClass("dtl");
				container.children("div.darrow").removeClass("dtr");
				if (distance_top>distance_bottom){
					if (distance_left>distance_right){
						fpos = 1;
					}
					else{
						fpos = 2;
					}
				}
				else{
					if (distance_left>distance_right){
						fpos = 4;
					}
					else{
						fpos = 3;
					}
					container.children("div.darrow").addClass("dtl");
					container.children("div.darrow").css("display","block");
				}
				if (fpos==1){ // DONE
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top-container.height()-16;
					pos_left = (pos.left - $("#content").offset().left - container.width()-48)+my_elem.outerWidth()/2;
					container.children("div.darrow").addClass("dbr");
				
				}
				if (fpos==2){ // DONE !
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top-container.height()-16;
					pos_left = (pos.left - $("#content").offset().left)+my_elem.outerWidth()/2+47;
					container.children("div.darrow").addClass("dbl");
				}
				if (fpos==3){ // DONE !
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top+8;
					pos_left = (pos.left - $("#content").offset().left)+my_elem.outerWidth()/2+47;
					container.children("div.darrow").addClass("dtl");
				
				}
				if (fpos==4){ // DONE
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top+8;
					pos_left = (pos.left - $("#content").offset().left - container.width()-48)+my_elem.outerWidth()/2;
					container.children("div.darrow").addClass("dtr");		
				}
				container.children("div.darrow").css("display","block");
		
				container.css({  
					left: pos_left + 'px',  
					top: pos_top + 'px'  
				}); 
		
				container.css("z-index","10000");
				container.appendTo("#content");
				container.css({"display":"block","visibility":"visible"});  
				is_detail = 1;
			}, showDelay);  
		}
	});  

	$('div.showdetail').mouseleave(function(){  
		if (hideTimer)  
			clearTimeout(hideTimer);  
		if (showTimer)  
			clearTimeout(showTimer);  
		hideTimer = setTimeout(function(){  
			if (container){
				container.css('display', 'none');  
				container.remove();  
				is_detail = 0;
			}
		}, hideDelay);  
	});  
	
	// Allow mouse over of details without hiding details  
	$('#detail').live('mouseover', function(){ 
		if (hideTimer)  
			clearTimeout(hideTimer);  
		if (showTimer)  
			clearTimeout(showTimer);  
	});  
	
	// Hide after mouseout  
	$('#detail').live('mouseout', function(){  
		if (hideTimer)  
			clearTimeout(hideTimer);  
		if (showTimer)  
			clearTimeout(showTimer);  
		hideTimer = setTimeout(function(){  
			if (container){
				container.css('display', 'none');  
				container.remove();
				is_detail = 0;
			}
		}, hideDelay);  
	});  
	$('a.dclose').live('click',function(){
		var a = $(this).parent().parent();
		a.css('display', 'none');
		a.remove();
		is_detail = 0;
		return false;
	});
	$('a.taclose').live('click',function(){
		hide_tolalert();
		return false;
	});
	$('a.tabclose').live('click',function(){
		hide_tolalert();
		return false;
	});

	var act_ta = 0;
	function tolalert(message,type){
		if (message!=''){
			var extra = '';
			if (type==0) extra = '<div id="ta_close"><a class="btn_close tabclose" href="#" title="Close">CLOSE</a></div>';
			$('body').append('<div id="tolalerth"><div id="tolalert"><div id="tolalert_top">&nbsp;</div><div id="tolalert_content"><a href="#" class="taclose" href="#">CLOSE</a><div id="tolalert_icontent">'+message+extra+'</div></div><div id="tolalert_bottom">&nbsp;</div></div></div>');
			$('#tolalerth').css({"visibility":"hidden","display":"block"});
			var hh = $(window).height();
			var hw = $(window).width();
			var left_pos = (hw-348)/2;
			var top_pos = ($('body').height()-$('#tolalert').height())/2;
			if (top_pos<0) top_pos = 0;
			if (left_pos<0) left_pos = 0;
			$('#tolalerth').css("width",$("#holder").width()+"px");
			$('#tolalerth').css("height",$("#holder").height()+"px");
			$('#tolalert').css("position","fixed");
			$('#tolalert').css("top",top_pos+"px");
			$('#tolalert').css("left",left_pos+"px");
			$('#tolalerth').css({"display":"none","visibility":"visible"});
			$('#tolalerth').fadeIn(function(){
				act_ta = 1;
				if (type == 1){
					var tt = setTimeout('$("#tolalerth").fadeOut(function(){act_ta = 0;});',3000);
				}
			});
		}
	}
	
	function hide_tolalert(){
		if (act_ta == 1){
			$('#tolalerth').fadeOut(function(){
				act_ta = 0;
				$('#tolalerth').remove();
			});	
		}
	
	}
})




$(document).ready(function(){
	$("a.btn_search").click(function(){
		$("#search_form").submit();
		return false;
	})

	$("#search_form").submit(function(){
		var error = 0;
		if ($("input#q").val()=='' || $("input#q").val()=='Search'){
			error = 1;
		}
		if (error == 1){
			return false;
		}
		else{
			return true;	
		}
	});

	$("#register_form").submit(function(){
		var my_form = document.register_form;
		var error = 0;
		$("input#cust_fname").parent().removeClass("err");
		$("input#cust_lname").parent().removeClass("err");
		$("input#cust_email").parent().removeClass("err");
		if ($("input#cust_fname").val()==''){
			$("input#cust_fname").parent().addClass("err");
			error = 1;
		}
		if ($("input#cust_lname").val()==''){
			$("input#cust_lname").parent().addClass("err");
			error = 1;
		}
		if ($("input#cust_email").val()==''){
			$("input#cust_email").parent().addClass("err");
			error = 1;
		}
		if (error == 1){
			alert('Please fill in the highlighted fields.')
			return false;
		}
		else{
			return true;	
		}
	});
	$("#asearch_form").submit(function(){
		var error = 0;
		$("input#aq").parent().removeClass("err");
		if ($("input#aq").val()==''){
			$("input#aq").parent().addClass("err");
			error = 1;
		}
		if (error == 1){
			return false;
		}
		else{
			return true;
		}
	});	
	$("div.btn_submit a.asearch").click(function(){
		$("#asearch_form").submit();
		return false;
	});

	$("div.btn_submit a.register").click(function(){
		$("#register_form").submit();
		return false;
	});

	$("div.btn_submit a.password").click(function(){
		$("#password_form").submit();
		return false;
	});

	$("div.btn_submit a.activate").click(function(){
		$("#activate_form").submit();
		return false;
	});

	$("div.btn_submit a.setpassword").click(function(){
		$("#setpassword_form").submit();
		return false;
	});

	$("div.btn_login a.login").click(function(){
		$("#login1_form").submit();
		return false;
	});

	$("div.btn_submit a.chpassword").click(function(){
		$("#chpassword_form").submit();
		return false;
	});

	$("#chpassword_form").submit(function(){
		var error = 0;
		$("input#cust_password").parent().removeClass("err");
		$("input#new_password").parent().removeClass("err");
		$("input#new_password1").parent().removeClass("err");
		if ($("input#cust_password").val()==''){
			$("input#cust_password").parent().addClass("err");
			error = 1;
		}
		if ($("input#new_password").val()==''){
			$("input#new_password").parent().addClass("err");
			error = 1;
		}
		if ($("input#new_password1").val()==''){
			$("input#new_password1").parent().addClass("err");
			error = 1;
		}
		if (error == 1){
			alert('Please fill in the highlighted fields.')
			return false;
		}
		else{
			if ($("input#new_password").val() != $("input#new_password1	").val()){
				alert('Your new passwords don\'t match!');
				return false;
			}
			else{
				return true;	
			}
		}
	});

	$("#password_form").submit(function(){
		var my_form = document.password_form;
		var error = 0;
		$("input#cust_email").parent().removeClass("err");
		if ($("input#cust_email").val()==''){
			$("input#cust_email").parent().addClass("err");
			error = 1;
		}
		if (error == 1){
			alert('Please fill in the highlighted fields.')
			return false;
		}
		else{
			return true;	
		}
	});

	$("#activate_form").submit(function(){
		var error = 0;
		$("input#cust_account").parent().removeClass("err");
		$("input#cust_password").parent().removeClass("err");
		$("input#cust_password1").parent().removeClass("err");
		if ($("input#cust_account").val()==''){
			$("input#cust_account").parent().addClass("err");
			error = 1;
		}
		if ($("input#cust_password").val()==''){
			$("input#cust_password").parent().addClass("err");
			error = 1;
		}
		if ($("input#cust_password1").val()==''){
			$("input#cust_password1").parent().addClass("err");
			error = 1;
		}
		if (error == 1){
			alert('Please fill in the highlighted fields.')
			return false;
		}
		else{
			if ($("input#cust_password").val() != $("input#cust_password1").val()){
				alert('Your passwords don\'t match!');
				return false;
			}
			else{
				return true;	
			}
		}
	});

	$("#setpassword_form").submit(function(){
		var error = 0;
		$("input#cust_password").parent().removeClass("err");
		$("input#cust_password1").parent().removeClass("err");
		if ($("input#cust_password").val()==''){
			$("input#cust_password").parent().addClass("err");
			error = 1;
		}
		if ($("input#cust_password1").val()==''){
			$("input#cust_password1").parent().addClass("err");
			error = 1;
		}
		if (error == 1){
			alert('Please fill in the highlighted fields.')
			return false;
		}
		else{
			if ($("input#cust_password").val() != $("input#cust_password1").val()){
				alert('Your passwords don\'t match!');
				return false;
			}
			else{
				return true;	
			}
		}
	});

	$("#login1_form").submit(function(){
		var error = 0;
		$("input#cust_account").parent().removeClass("err");
		$("input#cust_password").parent().removeClass("err");
		if ($("input#cust_account").val()==''){
			$("input#cust_account").parent().addClass("err");
			error = 1;
		}
		if ($("input#cust_password").val()==''){
			$("input#cust_password").parent().addClass("err");
			error = 1;
		}
		if (error == 1){
			alert("Please enter your username and password");
			return false;
		}
		else{
			return true;	
		}
	});

	$("a.btn_login").click(function(){
		$("#login_form").submit();	
		return false;
	});
	
	$("input#account").focus(function(){
		$("input#account").css("color","#666666");
	
	})
	$("input#password").focus(function(){
		$("input#password").css("color","#666666");
	
	})
	$("#login_form").submit(function(){
		var error = 0;
		$("input#account").css("color","#666666");
		$("input#password").css("color","#666666");
		if ($("input#account").val()=='' || $("input#account").val()=='Username'){
			$("input#account").css("color","#fd0374");
			error = 1;
		}
		if ($("input#password").val()=='' || $("input#password").val()=='Password'){
			$("input#password").css("color","#fd0374");
			error = 1;
		}
		if (error==1){
			alert("Please enter your username and password");
			return false;	
		}
		else{
			return true;
		}
	});

});