PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 All 503 releases
jetpack / modules / widgets / milestone / milestone.js

milestone.js in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at modules/widgets/milestone/milestone.js

61 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global MilestoneConfig */
2
3 var Milestone = ( function () {
4 // eslint-disable-next-line no-shadow
5 var Milestone = function ( args ) {
6 var widget_content = document.getElementById( args.content_id ),
7 id = args.id,
8 refresh = args.refresh * 1000;
9
10 this.timer = function () {
11 var instance = this;
12 var xhr = new XMLHttpRequest();
13
14 xhr.onload = function () {
15 var response = JSON.parse( xhr.responseText ),
16 httpCheck = xhr.status >= 200 && xhr.status < 300,
17 responseCheck =
18 'undefined' !== typeof response.message && 'undefined' !== typeof response.refresh;
19
20 if ( httpCheck && responseCheck ) {
21 var countdownElement = widget_content.querySelector( '.milestone-countdown' );
22
23 countdownElement.outerHTML = response.message;
24 refresh = response.refresh * 1000;
25
26 if ( ! refresh ) {
27 return;
28 }
29
30 setTimeout( function () {
31 instance.timer();
32 }, refresh );
33 }
34 };
35
36 xhr.open( 'GET', MilestoneConfig.api_root + 'jetpack/v4/widgets/' + id );
37 xhr.send();
38 };
39
40 if ( refresh > 0 ) {
41 this.timer();
42 }
43 };
44 return function ( args ) {
45 return new Milestone( args );
46 };
47 } )();
48
49 ( function () {
50 var i,
51 MilestoneInstances = {};
52
53 if ( typeof MilestoneConfig === 'undefined' ) {
54 return;
55 }
56
57 for ( i = 0; i < MilestoneConfig.instances.length; i++ ) {
58 MilestoneInstances[ i ] = new Milestone( MilestoneConfig.instances[ i ] );
59 }
60 } )();
61