Sha256: 1e3a34dee1ad1d06fb608d7b3782c8483a3f1e22eb9ec8b45c8ee2fb42e2227b

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

// CytoAjax v0.5
// MacKinley Smith
(function($){
	$.cytoAjaxResponse = function(message,type,time){
		if (message==null) message = "Success!";
		if (type==null) type = "success";
		if (time==null) time = 0;
		
		$('.callback_message').hide();
		$('html,body').animate({scrollTop:0},400);
		$('#'+type+"_message").html(message).show(400,function(){
			var $this = $(this);
			if (time) setTimeout(function(){$this.hide(400);},time);
		});
	};
	$.cytoAjax = function(script,data_to_pass,success,error){
		// Set default parameters
		if (typeof script != "string" || script == "") return false;
		if (data_to_pass==null || typeof data_to_pass != "object") {
			if (typeof data_to_pass == "function") {
				if (typeof success == "function") error = success;
				success = data_to_pass;
			}
			data_to_pass = {ajax:script};
		} else data_to_pass = $.extend(true,{},{ajax:script},data_to_pass);
		
		// Make request
		$.ajax({
      url:script,
      type:'get',
      dataType:'html',
      processData:false,
      success:function(data,textStatus,jqXHR) {
      	try {
					data = $.parseJSON(data);
				} catch (e) {
					data = $.parseJSON('{"status":"Error","message":"AJAX Return Error: '+e.replace(/"/g,"'")+'<br />'+data.replace(/"/g,"'")+'"}');
				}
				if (data.status=="OK") {
					if (typeof success == "function") success.apply(this,[data]);
					else if (data.message!=null) $.cytoAjaxResponse(data.message);
					else $.cytoAjaxResponse(((typeof success == "string")?success:"Success!"));
				} else if (data.status=="Error") {
					if (data.message != null) $.cytoAjaxResponse(data.message,"error");
					if (typeof error == "function") error.apply(this,[data]);
				}
      },
      error:function(jqXHR,textStatus,errorThrown){
	      if (typeof error == "function") error.apply(this,[{status:"Error",message:errorThrown}]);
      }
    });
	};
})(jQuery);

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
cytoplasm-0.1.3 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.1.2 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.1.1 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.1.0 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.9.3 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.9.2 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.9.1 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.9 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.7 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.6 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.5 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.4 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.3 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.2 app/assets/javascripts/cytoplasm/cytoAjax.js.erb
cytoplasm-0.0.1 app/assets/javascripts/cytoplasm/cytoAjax.js.erb