Learn how to use jQuery at the Blog

impressions « visit

  • Added 8 months ago
  • 273 Lines of Code shown
  • 1 Links of Interest
http://impressions.tipic.ro
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 impressions - http://impressions.tipic.ro

function process_post()
		{
			var post_title = $("#post_title").val();
			var post_body = $("#post_body").val();
			var status = true;
			if(post_title.length < 5)
			{
				alert("The tilte for the impressions is to short! min 5 chars");
				status = false;
			}
			if(post_body.length < 20)
			{
				alert ("The body for this impression is to short! min 20 chars");
				status = false;
			}
			
			var drafts = $("#draft").attr("checked") == true ? "yes" : "no";
			
			if (status == true ){
				$("body").fadeIn("slow",function () 
				{
					$("#new_post").append("<div id=\"widget_overlay\" class=\"ui-widget-overlay\"><\/div>");
					$("#widget_overlay").height($(document).height());
					$("#button_add").attr("disabled","disabled");
					
				});
				
				$.post("ajax-process.php",{
					action:"add",
					post_title: $("#post_title").val(),
					post_body: $("#post_body").val(),
					draft : drafts
					},function (r) {
						
						if(r.status == true)
						{
							render_dialog('Succes',r.error,true)
							
						}
						else if(r.status == false)
						{
							render_dialog('Failure',"<div class=\"ui-state-error ui-corner-all\" style=\"padding: 0 .7em;\"><div class=\"ui-icon ui-icon-alert\" style=\"float: left;\"><\/div>"+r.error+"<\/div>",false)
						}
					} ,'json');
			
			}
		}
		function render_dialog(title,msg,clear)
		{
		$("body").after("<div id=\"msg\">"+msg+"<\/div>");
		$("#msg").dialog({
			autoOpen: true,
			show: 'block',
			resizable:false,
			draggable:false,
			title: title,
			width: 200,
			buttons: {
			"OK": function() 
			{ 
				$(this).dialog('destroy');
				remove_post(clear);
				
			} 
			},
			close :  function() { 
				$(this).dialog('destroy');
				remove_post(clear);
			} 
			});
			$("div[class^='ui-dialog']").fadeIn("slow");
			
		}
		function remove_post(clear)
		{
			getlist();
			$("#msg").remove();
			$("#button_add").removeAttr("disabled");
			$("#widget_overlay").remove();
			$("#loader").fadeOut("fast");
			if(clear == true)
			{
				$("#draft").removeAttr("checked");
				$("#post_title").val('');
				$("#post_body").val('');
				$("#rem_title").empty();
				$("#rem_body").empty();
			}
		}
		function getlist()
		{
			$("#holder_impression").fadeIn("slow",function(){
			$.post("ajax-process.php",{action:"getlist"}, function (data) {
				$("#holder_impression").html(data);
			},"html");
			});
		}
		function info_slide(id)
		{
			if($("#info_"+id).is(":hidden"))
			{
				$("#info_"+id).slideDown("normal");
			}
			else
				$("#info_"+id).slideUp("normal");
		}
		function delete_dialog(id,title)
		{
			$("body").append("<div id=\"widget_overlay_delete\" class=\"ui-widget-overlay\"><\/div><div id=\"confirm_"+id+"\"><\/div>");
			$("#widget_overlay_delete").height($(document).height());
			$("#confirm_"+id).html("<div class=\"ui-state-error ui-corner-all\" style=\"padding: 0 .7em;height:25px;padding-top:4px;\"><div class=\"ui-icon ui-icon-alert\" style=\"float: left;\"><\/div>You are about to delete <b>"+title+"<\/b><\/div>");
			$("#confirm_"+id).dialog({
			autoOpen: true,
			resizable:false,
			title: 'Delete confirmation',
			width: 400,
			buttons: {
				"Confirm" : function()
				{
					$("#widget_overlay_delete").remove();
					$(this).dialog('destroy');
					delete_impression(id);
					getlist();
				},
				"Cancel" : function ()
				{
				$(this).dialog('destroy');
				$("#widget_overlay_delete").remove();
				}
				},
			close :  function() 
			{ 
				$("#widget_overlay_delete").remove();
			} 
			});
			
			$("#confirm_"+id).dialog('open');
			$("#confirm_"+id).fadeIn("slow");
			
		}
		function delete_impression(imp)
		{
			$.post("ajax-process.php",{action:"delete",impression:imp});
		}
		function render_box(id,title,body,user,name)
	{
		if($("#holder_"+id).hasClass("hholder"))
		return;
			//delete all the box
			$("div[id^='holder_']").each(
			function (){
				var id = $(this).attr("id").substr(7);
				close_box(id)
			});
			$("body").append("<div id=\"holder_"+id+"\"><\/div>");
			$("#holder_"+id).addClass("hholder");
			$("#holder_"+id).css("top", MouseY+10+"px");
			$("#holder_"+id).css("left", MouseX+10+"px");
			$("#holder_"+id).css("z-index", (200+(MouseY+MouseY)/2));
			//adding close div
			var holder_position = $("#holder_"+id).position();
			$("#holder_"+id).after("<div id=\"close_"+id+"\" style=\"cursor:pointer;position:absolute;\" title=\"Close me!\" align=\"right\" class=\"ui-icon ui-icon-circle-close\" onclick=\"close_box("+id+")\"><\/div>");
			$("#close_"+id).css("top",holder_position.top-6+"px");
			$("#close_"+id).css("left",holder_position.left-6+"px");
			$("#close_"+id).css("z-index",parseInt($("#holder_"+id).css("z-index"))+1);
			
			//adding second div
			$("#holder_"+id).append("<div id=\"content_"+id+"\"><\/div>");
			$("#content_"+id).addClass("hcontent")
			$("#content_"+id).append("<b>"+title+"<\/b>&nbsp;<font class=\"small\">by&nbsp;<a href=\"user.php?id="+user+"\">"+name+"<\/a><\/font>");
			$("#content_"+id).append("<hr/>");
			$("#content_"+id).append(body);
			$("#content_"+id).append("<div class=\"ui-corner-all\" style=\"border: 1px solid #5F5A59;padding:5px;display:none;\" id=\"rate_"+id+"\"><\/div>");
			getRate(id);
			
			
		
	}
	function close_box(id)
	{
		$("#holder_"+id).fadeOut("slow",function () {$("#holder_"+id).remove();} );
		$("#close_"+id).fadeOut("slow",function () {$("#close_"+id).remove() } );
	}
	
	function getRate(id)
		{
			 $.post("rating-process.php",{action:"getrate",impression:id},
				function(r)
				{
					$("rate_holder_"+id).empty().append(r);
				});
		}
		
	function rateImpression(rate,id)
		{
			if(rate < 1 || rate > 5)
			return;
			$("#rating_loader_"+id).fadeIn("slow",function () { 
				$.post("rating-process.php",{action:"rate",impression:id,rating:rate},
				function ()
				{
					$.post("rating-process.php",{action:"getrate",impression:id},
					function(r)
					{
					$("#rate_holder_"+id).empty().append(r);
					$("#rating_loader_"+id).fadeOut("slow");
					});
					
				});
			});
			
		}
function edit_title(id)
		{
			if($("#title_"+id).attr("alt") == "editing")
			return;
			
			var title = $("#title_"+id).html();
			$("#title_"+id).attr("alt","editing");
			$("#title_"+id).empty().append("<input class=\"ui-corner-all\" type=\"text\" size=\"40\" value=\""+title+"\" id=\"title_edit_"+id+"\"/>");
			$("#title_edit_"+id).after("<input type=\"button\" value=\"Edit\" onclick=\"do_edit_title("+id+")\" class=\"ui-corner-all\"/><input type=\"button\" value=\"Cancel\"  class=\"ui-corner-all\" onclick=\"remove_edit_title("+id+")\"/>")
		
		}
		function edit_body(id)
		{
			if($("#body_"+id).attr("alt") == "editing")
			return;
			
			var body = $("#body_"+id).html();
			$("#body_"+id).attr("alt","editing");
			$("#body_"+id).empty().append("<textarea class=\"ui-corner-all\" cols=\"30\" rows=\"3\" id=\"body_edit_"+id+"\" /><\/textarea>");
			$("#body_edit_"+id).css("width",$("#body_"+id).width()-10);
			$("#body_edit_"+id).html(body);
			$("#body_edit_"+id).after("<input type=\"button\" value=\"Edit\" onclick=\"do_edit_body("+id+")\" class=\"ui-corner-all\"/><input type=\"button\" value=\"Cancel\"  class=\"ui-corner-all\" onclick=\"remove_edit_body("+id+")\"/>")
		
		}
		function remove_edit_title(id)
		{
			var eTitle = $("#title_edit_"+id).val();
			$("#title_"+id).empty().html(eTitle)
			$("#title_"+id).removeAttr("alt");
		}
		function remove_edit_body(id)
		{
			var eBody = $("#body_edit_"+id).html();
			$("#body_"+id).empty().html(eBody)
			$("#body_"+id).removeAttr("alt");
		}
		function do_edit_title(id)
		{
			var edTitle = $("#title_edit_"+id).val();
			$.post("ajax-process.php",{action:"edit_title",post_title:edTitle,impression:id},
			function (r)
			{
				$("#title_"+id).empty();
				$("#title_"+id).fadeIn(1000,function () {$("#title_"+id).html(r);});
				$("#title_"+id).removeAttr("alt");
			}
			);
		}
		function do_edit_body(id)
		{
			var edBody = $("#body_edit_"+id).val();
			$.post("ajax-process.php",{action:"edit_body",post_body:edBody,impression:id},
			function (r)
			{
				$("#body_"+id).empty();
				$("#body_"+id).fadeIn(1000,function () {$("#body_"+id).html(r);});
				$("#body_"+id).removeAttr("alt");
			}
			
			);
		}