1(function($) { 2 3 /************************************************************************************************************************** 4 * Serialize Object > Form Submissions to Objects 5 **************************************************************************************************************************/ 6 $.fn.serializeObject = function() { 7 var o = {}, 8 a = this.serializeArray(); 9 $.each(a, function() { 10 if (o[this.name] !== undefined) { 11 if (!o[this.name].push) { o[this.name] = [o[this.name]]; } 12 o[this.name].push(this.value || ''); 13 } else { o[this.name] = this.value || ''; } 14 }); 15 return o; 16 }; 17 /************************************************************************************************************************** 18 * Serialize Object > Form Submissions to Objects 19 **************************************************************************************************************************/ 20 var playme_form = $("#PlayMe"); 21 var playme_stat = $("#PlayMe_status"); 22 $("#PlayMe_submit").on("click", function(){ 23 var vals = playme_form.serializeObject(); 24 for(v in vals){ 25 vals[v] = cleanup(vals[v]); 26 thislab = $("#"+v).closest("label"); 27 if(thislab.hasClass("required") && vals[v].length<3){ 28 thislab.addClass("flagged"); 29 alert(thislab.data("label")+" is required"); 30 return; //one alert is enough 31 } else { 32 thislab.removeClass("flagged"); 33 } 34 } 35 36 37 //proceed 38 if(playme_form.find(" label.flagged").length<1){ 39 vals.action = "playme_submitrequest"; 40 var jqxhr = $.post(ajax_object.ajaxurl, vals, function(data) { 41 //on success 42 playme_form.find("input[type='text'], textarea").val(""); 43 playme_stat.removeClass("notice-error").addClass("notice-success").html(JSON.parse(data).statustext); 44 45 }).fail(function(data, status, jqxhr){ 46 //on failure 47 response = JSON.parse(data.responseText); 48 statustext = (typeof(response.statustext)!="undefined" ? response.statustext : "Bad Request."); 49 playme_stat.removeClass("notice-success").addClass("notice-error").html(statustext); 50 }); 51 } 52 53 }); 54 55})( jQuery ); 56/************************************************************************************************************************** 57 * More universal trim function 58 **************************************************************************************************************************/ 59function cleanup(x) { return x.replace(/^\s+|\s+$/gm, ''); }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.