raw
mp-wp_genesis           1 wpAjax = jQuery.extend( {
mp-wp_genesis 2 unserialize: function( s ) {
mp-wp_genesis 3 var r = {}; if ( !s ) { return r; }
mp-wp_genesis 4 var q = s.split('?'); if ( q[1] ) { s = q[1]; }
mp-wp_genesis 5 var pp = s.split('&');
mp-wp_genesis 6 for ( var i in pp ) {
mp-wp_genesis 7 if ( jQuery.isFunction(pp.hasOwnProperty) && !pp.hasOwnProperty(i) ) { continue; }
mp-wp_genesis 8 var p = pp[i].split('=');
mp-wp_genesis 9 r[p[0]] = p[1];
mp-wp_genesis 10 }
mp-wp_genesis 11 return r;
mp-wp_genesis 12 },
mp-wp_genesis 13 parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission
mp-wp_genesis 14 var parsed = {};
mp-wp_genesis 15 var re = jQuery('#' + r).html('');
mp-wp_genesis 16 if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) {
mp-wp_genesis 17 parsed.responses = [];
mp-wp_genesis 18 parsed.errors = false;
mp-wp_genesis 19 var err = '';
mp-wp_genesis 20 jQuery('response', x).each( function() {
mp-wp_genesis 21 var th = jQuery(this);
mp-wp_genesis 22 var child = jQuery(this.firstChild);
mp-wp_genesis 23 var response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') };
mp-wp_genesis 24 response.data = jQuery( 'response_data', child ).text();
mp-wp_genesis 25 response.supplemental = {};
mp-wp_genesis 26 if ( !jQuery( 'supplemental', child ).children().each( function() {
mp-wp_genesis 27 response.supplemental[this.nodeName] = jQuery(this).text();
mp-wp_genesis 28 } ).size() ) { response.supplemental = false }
mp-wp_genesis 29 response.errors = [];
mp-wp_genesis 30 if ( !jQuery('wp_error', child).each( function() {
mp-wp_genesis 31 var code = jQuery(this).attr('code');
mp-wp_genesis 32 var anError = { code: code, message: this.firstChild.nodeValue, data: false };
mp-wp_genesis 33 var errorData = jQuery('wp_error_data[code="' + code + '"]', x);
mp-wp_genesis 34 if ( errorData ) { anError.data = errorData.get(); }
mp-wp_genesis 35 var formField = jQuery( 'form-field', errorData ).text();
mp-wp_genesis 36 if ( formField ) { code = formField; }
mp-wp_genesis 37 if ( e ) { wpAjax.invalidateForm( jQuery('#' + e + ' :input[name="' + code + '"]' ).parents('.form-field:first') ); }
mp-wp_genesis 38 err += '<p>' + anError.message + '</p>';
mp-wp_genesis 39 response.errors.push( anError );
mp-wp_genesis 40 parsed.errors = true;
mp-wp_genesis 41 } ).size() ) { response.errors = false; }
mp-wp_genesis 42 parsed.responses.push( response );
mp-wp_genesis 43 } );
mp-wp_genesis 44 if ( err.length ) { re.html( '<div class="error">' + err + '</div>' ); }
mp-wp_genesis 45 return parsed;
mp-wp_genesis 46 }
mp-wp_genesis 47 if ( isNaN(x) ) { return !re.html('<div class="error"><p>' + x + '</p></div>'); }
mp-wp_genesis 48 x = parseInt(x,10);
mp-wp_genesis 49 if ( -1 == x ) { return !re.html('<div class="error"><p>' + wpAjax.noPerm + '</p></div>'); }
mp-wp_genesis 50 else if ( 0 === x ) { return !re.html('<div class="error"><p>' + wpAjax.broken + '</p></div>'); }
mp-wp_genesis 51 return true;
mp-wp_genesis 52 },
mp-wp_genesis 53 invalidateForm: function ( selector ) {
mp-wp_genesis 54 return jQuery( selector ).addClass( 'form-invalid' ).change( function() { jQuery(this).removeClass( 'form-invalid' ); } );
mp-wp_genesis 55 },
mp-wp_genesis 56 validateForm: function( selector ) {
mp-wp_genesis 57 selector = jQuery( selector );
mp-wp_genesis 58 return !wpAjax.invalidateForm( selector.find('.form-required').andSelf().filter('.form-required:has(:input[value=""]), .form-required:input[value=""]') ).size();
mp-wp_genesis 59 }
mp-wp_genesis 60 }, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'An unidentified error has occurred.' } );