Skip to content

Commit 2b76f28

Browse files
author
Anthony Burchell
committed
messy messy checkpoint that adds jquery and localized vars for plugin and theme lists
1 parent cb3532d commit 2b76f28

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

plugin/lib/class-php-compatibility-checker.php

+33-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,37 @@ public static function instance() {
4646
return self::$instance;
4747
}
4848

49+
/**
50+
* Registers available blocks.
51+
*
52+
* @since 1.0.0
53+
*/
54+
public function set_up_ajax() {
55+
$ajax_js = '../scripts/scan-runner.js';
56+
57+
global $wp_query;
58+
59+
wp_register_script( 'tide-checker', plugins_url( $ajax_js, __FILE__ ), array( 'jquery' ), '1.0', true );
60+
61+
wp_enqueue_script(
62+
'tide-checker',
63+
plugins_url( $ajax_js, __FILE__ ),
64+
array( 'jquery' ),
65+
'1.0',
66+
true
67+
);
68+
69+
wp_localize_script(
70+
'tide-checker',
71+
'checkerList',
72+
array(
73+
'pluginList' => $this->generate_directory_list(),
74+
'themeList' => 'tbd',
75+
'userOptions' => 'some user options',
76+
)
77+
);
78+
}
79+
4980
/**
5081
* Tool Page initialization.
5182
*/
@@ -60,6 +91,7 @@ public function init() {
6091

6192
// Load our JavaScript.
6293
add_action( 'admin_enqueue_scripts', array( $instance, 'admin_enqueue' ) );
94+
add_action( 'admin_enqueue_scripts', array( $instance, 'set_up_ajax' ) );
6395

6496
// The action to run the compatibility test.
6597
// add_action( 'wp_ajax_wpephpcompat_start_test', array( $instance, 'start_test' ) );
@@ -452,7 +484,7 @@ public function admin_enqueue( $hook ) {
452484
wp_enqueue_style( 'wpephpcompat-style', plugins_url( '/styles/css/style.css', __FILE__ ), array(), $version );
453485

454486
// Scripts.
455-
wp_enqueue_script( 'wpephpcompat-ajax', plugins_url( '/scripts/starter-script.js', __FILE__ ), array( 'jquery' ), $version );
487+
// wp_enqueue_script( 'wpephpcompat-ajax', plugins_url( '/scripts/starter-script.js', __FILE__ ), array( 'jquery' ), $version );
456488

457489
/**
458490
* Strings for i18n.

plugin/scripts/scan-runner.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(function($) {
2+
function build_rest_route( plugin_list ) {
3+
var base_route = 'somesite.com/' + plugin_list;
4+
return base_route;
5+
}
6+
7+
function render_result_item( attributes ) {
8+
$('#wpe_php_compat_results').append('<article class="'+ attributes.slug + '">');
9+
$('#wpe_php_compat_results .' + attributes.slug ).append('<li class="' + attributes.slug + '"><b>Status:</b> ' + attributes.status + '</li>');
10+
$('#wpe_php_compat_results').append('</article>');
11+
}
12+
$( document ).ready(function() {
13+
// maybe we'll need to do some priming.
14+
});
15+
16+
$(document).on( 'click', '#runButton', function( event ) {
17+
event.preventDefault();
18+
console.log( checkerList );
19+
// placeholder.
20+
var plugin_list = 'akismet';
21+
});
22+
23+
$(document).on( 'click', '#finalRunButton', function( event ) {
24+
event.preventDefault();
25+
console.log('hey, listen!');
26+
// placeholder.
27+
var plugin_list = 'akismet';
28+
var endpoint = build_rest_route( plugin_list );
29+
$.ajax({
30+
url: endpoint,
31+
beforeSend: function (xhr) {
32+
// maybe in future state send header.
33+
// xhr.setRequestHeader( 'X-WP-Nonce', ajaxpagination.rest_nonce);
34+
},
35+
type: 'GET',
36+
success: function( html, status, request ) {
37+
// a way to check for rest pages left..maybe we'll need some pagination. $total_pages = parseInt(request.getResponseHeader('X-WP-TotalPages'), 10);
38+
39+
// an element removal if needed: $('#wpe_dynamic_rest_block').find( 'article' ).remove();
40+
$.each( html, function(){
41+
render_result_item( this );
42+
});
43+
// a value we can track as we progress through batches: value = 'something';
44+
},
45+
error: function () {
46+
//@todo maybe alert if the endpoints arent available?
47+
}
48+
});
49+
50+
});
51+
})(jQuery);

plugin/scripts/starter-script.js

-3
This file was deleted.

0 commit comments

Comments
 (0)