| Conditions | 1 |
| Paths | 2 |
| Total Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | /** global: GLSR, jQuery */ |
||
| 2 | ;(function( x ) { |
||
| 3 | |||
| 4 | 'use strict'; |
||
| 5 | |||
| 6 | GLSR.Ajax = { |
||
| 7 | /** @return void */ |
||
| 8 | post: function( request, callback ) { // object, function|void |
||
| 9 | var data = { |
||
| 10 | action: GLSR.action, |
||
| 11 | request: request, |
||
| 12 | }; |
||
| 13 | x.post( GLSR.ajaxurl, data, function( response ) { |
||
| 14 | if( typeof callback !== 'function' )return; |
||
| 15 | callback( response ); |
||
| 16 | }); |
||
| 17 | }, |
||
| 18 | |||
| 19 | /** @return void */ |
||
| 20 | postFromEvent: function( ev, request, callback ) { // Event, object, function|void |
||
| 21 | ev.preventDefault(); |
||
| 22 | var el = x( ev.target ); |
||
| 23 | if( el.is( ':disabled' ))return; |
||
| 24 | request.nonce = request.nonce || el.closest( 'form' ).find( '#_wpnonce' ).val(); |
||
| 25 | var data = { |
||
| 26 | action: GLSR.action, |
||
| 27 | request: request, |
||
| 28 | }; |
||
| 29 | el.prop( 'disabled', true ); |
||
| 30 | x.post( GLSR.ajaxurl, data, function( response ) { |
||
| 31 | if( typeof callback === 'function' ) { |
||
| 32 | callback( response ); |
||
| 33 | } |
||
| 34 | el.prop( 'disabled', false ); |
||
| 35 | }); |
||
| 36 | }, |
||
| 37 | }; |
||
| 38 | })( jQuery ); |
||
| 39 |