summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/widgets/milestone/milestone.js')
-rw-r--r--plugins/jetpack/modules/widgets/milestone/milestone.js40
1 files changed, 25 insertions, 15 deletions
diff --git a/plugins/jetpack/modules/widgets/milestone/milestone.js b/plugins/jetpack/modules/widgets/milestone/milestone.js
index 3780dec6..4cc1a93d 100644
--- a/plugins/jetpack/modules/widgets/milestone/milestone.js
+++ b/plugins/jetpack/modules/widgets/milestone/milestone.js
@@ -1,41 +1,51 @@
/* global MilestoneConfig */
-var Milestone = ( function( $ ) {
- var Milestone = function( args ) {
- var $widget = $( '#' + args.id ),
+var Milestone = ( function () {
+ var Milestone = function ( args ) {
+ var widget_content = document.getElementById( args.content_id ),
id = args.id,
refresh = args.refresh * 1000;
- this.timer = function() {
+ this.timer = function () {
var instance = this;
+ var xhr = new XMLHttpRequest();
- $.ajax( {
- url: MilestoneConfig.api_root + 'jetpack/v4/widgets/' + id,
- success: function( result ) {
- $widget.find( '.milestone-countdown' ).replaceWith( result.message );
- refresh = result.refresh * 1000;
+ xhr.onload = function () {
+ var response = JSON.parse( xhr.responseText ),
+ httpCheck = xhr.status >= 200 && xhr.status < 300,
+ responseCheck =
+ 'undefined' !== typeof response.message && 'undefined' !== typeof response.refresh;
+
+ if ( httpCheck && responseCheck ) {
+ var countdownElement = widget_content.querySelector( '.milestone-countdown' );
+
+ countdownElement.outerHTML = response.message;
+ refresh = response.refresh * 1000;
if ( ! refresh ) {
return;
}
- setTimeout( function() {
+ setTimeout( function () {
instance.timer();
}, refresh );
- },
- } );
+ }
+ };
+
+ xhr.open( 'GET', MilestoneConfig.api_root + 'jetpack/v4/widgets/' + id );
+ xhr.send();
};
if ( refresh > 0 ) {
this.timer();
}
};
- return function( args ) {
+ return function ( args ) {
return new Milestone( args );
};
-} )( jQuery );
+} )();
-( function() {
+( function () {
var i,
MilestoneInstances = {};