PluginProbe
Plugin Report / 1.8
Plugin Report v1.8
2.2.4 trunk 1.1 1.2 1.3 1.4 1.5 1.6 1.6.1 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9 1.9.1 1.9.2 1.9.3 2.0.0 2.0.1 2.0.2 2.1 2.1.1 2.2.0 2.2.1 All 27 releases
plugin-report / js / plugin-report.js

plugin-report.js in Plugin Report 1.8, at js/plugin-report.js

121 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready( function( $ ){
2
3 var rtpr_slugs = plugin_report_vars.plugin_slugs;
4 var rtpr_slugs_array = rtpr_slugs.split(',');
5 var rtpr_nrof_plugins = rtpr_slugs_array.length;
6 var rtpr_progress = 0;
7
8
9 function rtpr_process_next_plugin(){
10 if( rtpr_slugs_array.length > 0 ){
11 var slug = rtpr_slugs_array.shift();
12 if( $( '.plugin-report-row-temp-' + slug ).length ){
13 rtpr_get_plugin_info( slug );
14 } else {
15 rtpr_process_next_plugin();
16 }
17 }
18 // update the progress information on the page
19 var perc = Math.ceil( ( rtpr_progress / rtpr_nrof_plugins ) * 100 );
20 if( perc < 100 ){
21 if( ! $( '#plugin-report-progress' ).find( 'progress' ).length ){
22 $( '#plugin-report-progress' ).html( '<progress max="100" value="0"></progress>' );
23 }
24 $( '#plugin-report-progress progress' ).prop( 'value', perc );
25 rtpr_progress++;
26 } else {
27 // Remove the progress bar.
28 $('#plugin-report-progress').html( '' );
29 // initialize sorting on table
30 new Tablesort(document.getElementById('plugin-report-table'));
31 // Create the export button.
32 $('#plugin-report-buttons').append('<button class="button" href="#" id="plugin-report-export-btn">' + plugin_report_vars.export_btn + '</button>');
33 // Export button event handler.
34 $('#plugin-report-export-btn').click( function( e ){
35 // Call the function that does the exporting.
36 rtpr_export_table();
37 });
38 }
39 }
40
41
42 function rtpr_get_plugin_info( slug ){
43 var data = {
44 'action': 'rt_get_plugin_info',
45 'slug': slug,
46 'nonce': plugin_report_vars.ajax_nonce
47 };
48
49 jQuery.post( ajaxurl, data, function(response) {
50 // parse the response
51 obj = jQuery.parseJSON(response);
52 // replace the temporary table row with the new data
53 $('#plugin-report-table .plugin-report-row-temp-' + slug ).replaceWith( obj.html );
54 // on to the next...
55 rtpr_process_next_plugin();
56 });
57 }
58
59 // kick things off
60 rtpr_process_next_plugin();
61
62
63 // Export CSV file.
64 function rtpr_export_table(){
65 var csv_data = '';
66 var counter = 0;
67 // Loop trough the table header to add the header cells.
68 $('#plugin-report-table thead tr').each(function(){
69 // Use a column counter, because we'll need ot insert two extra columns.
70 counter = 0;
71 // Loop through the header cells.
72 $(this).find('th').each(function(){
73 // Remove any comma's from the cell contents, then add to output.
74 csv_data += $(this).text().replace(/,/g, ".") + ',';
75 // If this is the first column, add the plugin url column
76 if( counter == 0 ){
77 csv_data += plugin_report_vars.plugin_url_header + ',';
78 }
79 // If this is the second column, add the author url column
80 if( counter == 1 ){
81 csv_data += plugin_report_vars.author_url_header + ',';
82 }
83 counter++;
84 });
85 // End of the line.
86 csv_data += "\n";
87 });
88 // Loop through the regular rows to get their data
89 $('#plugin-report-table tbody tr').each(function(){
90 // Use a column counter to insert the two columns.
91 counter = 0;
92 // Loop through all regular cells.
93 $(this).find('td').each(function(){
94 // Remove any comma's from the cell contents, then add to output.
95 csv_data += $(this).text().replace(/,/g, ".") + ',';
96 // If this is one of the first two columns, add a url column.
97 if( counter <2 ){
98 var href = '';
99 $(this).find('a').each(function(){
100 // Get the href attribute, but strip any url vars to keep it short.
101 href = $(this).attr('href').split('#')[0].split('?')[0];
102 });
103 // Add to the output.
104 csv_data += href + ',';
105 }
106 counter++;
107 });
108 // End of the line.
109 csv_data += "\n";
110 });
111 // Create a link element, clickit and remove it.
112 var link = document.createElement( 'a' );
113 var now = new Date();
114 link.download = 'plugin-report-' + now.getFullYear() + '-' + String( '0' + now.getMonth() ).slice(-2) + '-' + String( '0' + now.getDate() ).slice(-2) + '.csv';
115 link.href = URL.createObjectURL( new Blob( [ "\ufeff", csv_data ], {type: 'text/csv; header=present'} ) );
116 link.click();
117 link.remove();
118 }
119
120 });
121