Total Complexity | 8 |
Complexity/F | 2 |
Lines of Code | 28 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | /** global: GLSR, site_reviews, x */ |
||
2 | GLSR.status = function( selector ) { |
||
3 | var elements = document.querySelectorAll( selector ); |
||
4 | if( !elements.length )return; |
||
5 | elements.forEach( function( el ) { |
||
6 | el.addEventListener( 'click', this.onClick ); |
||
7 | }.bind( this )); |
||
8 | }; |
||
9 | |||
10 | GLSR.status.prototype = { |
||
11 | |||
12 | onClick: function( ev ) { |
||
13 | var post_id = ev.target.href.match(/post=([0-9]+)/); |
||
14 | var status = ev.target.href.match(/action=([a-z]+)/); |
||
15 | if( post_id === null || status === null )return; |
||
16 | var request = { |
||
17 | action: 'change-review-status', |
||
18 | nonce: site_reviews.status_nonce, |
||
19 | post_id: post_id[1], |
||
20 | status: status[1], |
||
21 | }; |
||
22 | GLSR.postAjax( ev, request, function( response ) { |
||
23 | if( !response.class )return; |
||
24 | var el = x( ev.target ); |
||
25 | el.closest( 'tr' ).removeClass( 'status-pending status-publish' ).addClass( response.class ); |
||
26 | el.closest( 'td.column-title' ).find( 'strong' ).html( response.link ); |
||
27 | }); |
||
28 | }, |
||
29 | }; |
||
30 |