wp/wp-includes/js/wp-ajax-response.js
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    10 			r[p[0]] = p[1];
    10 			r[p[0]] = p[1];
    11 		}
    11 		}
    12 		return r;
    12 		return r;
    13 	},
    13 	},
    14 	parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission
    14 	parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission
    15 		var parsed = {}, re = jQuery('#' + r).html(''), err = '';
    15 		var parsed = {}, re = jQuery('#' + r).empty(), err = '';
    16 
    16 
    17 		if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) {
    17 		if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) {
    18 			parsed.responses = [];
    18 			parsed.responses = [];
    19 			parsed.errors = false;
    19 			parsed.errors = false;
    20 			jQuery('response', x).each( function() {
    20 			jQuery('response', x).each( function() {
    22 				response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') };
    22 				response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') };
    23 				response.data = jQuery( 'response_data', child ).text();
    23 				response.data = jQuery( 'response_data', child ).text();
    24 				response.supplemental = {};
    24 				response.supplemental = {};
    25 				if ( !jQuery( 'supplemental', child ).children().each( function() {
    25 				if ( !jQuery( 'supplemental', child ).children().each( function() {
    26 					response.supplemental[this.nodeName] = jQuery(this).text();
    26 					response.supplemental[this.nodeName] = jQuery(this).text();
    27 				} ).size() ) { response.supplemental = false }
    27 				} ).size() ) { response.supplemental = false; }
    28 				response.errors = [];
    28 				response.errors = [];
    29 				if ( !jQuery('wp_error', child).each( function() {
    29 				if ( !jQuery('wp_error', child).each( function() {
    30 					var code = jQuery(this).attr('code'), anError, errorData, formField;
    30 					var code = jQuery(this).attr('code'), anError, errorData, formField;
    31 					anError = { code: code, message: this.firstChild.nodeValue, data: false };
    31 					anError = { code: code, message: this.firstChild.nodeValue, data: false };
    32 					errorData = jQuery('wp_error_data[code="' + code + '"]', x);
    32 					errorData = jQuery('wp_error_data[code="' + code + '"]', x);
    52 	invalidateForm: function ( selector ) {
    52 	invalidateForm: function ( selector ) {
    53 		return jQuery( selector ).addClass( 'form-invalid' ).find('input:visible').change( function() { jQuery(this).closest('.form-invalid').removeClass( 'form-invalid' ); } );
    53 		return jQuery( selector ).addClass( 'form-invalid' ).find('input:visible').change( function() { jQuery(this).closest('.form-invalid').removeClass( 'form-invalid' ); } );
    54 	},
    54 	},
    55 	validateForm: function( selector ) {
    55 	validateForm: function( selector ) {
    56 		selector = jQuery( selector );
    56 		selector = jQuery( selector );
    57 		return !wpAjax.invalidateForm( selector.find('.form-required').filter( function() { return jQuery('input:visible', this).val() == ''; } ) ).size();
    57 		return !wpAjax.invalidateForm( selector.find('.form-required').filter( function() { return jQuery('input:visible', this).val() === ''; } ) ).size();
    58 	}
    58 	}
    59 }, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'An unidentified error has occurred.' } );
    59 }, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'An unidentified error has occurred.' } );
    60 
    60 
    61 // Basic form validation
    61 // Basic form validation
    62 jQuery(document).ready( function($){
    62 jQuery(document).ready( function($){