Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 86722c8

Browse files
committed
Show countdown timer in schedule date
1 parent 0b5ef52 commit 86722c8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

css/customize-snapshots.css

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

22
#customize-control-changeset_title {
33
margin-top: 15px;
4+
}
5+
6+
.snapshot-countdown-container {
7+
margin-top: 10px;
48
}

js/customize-snapshots.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
_.extend( snapshot.data, snapshotsConfig );
2121
}
2222

23-
_.bindAll( snapshot, 'addTitleControl' );
23+
_.bindAll( snapshot, 'addTitleControl', 'setupScheduledChangesetCountdown' );
2424

2525
api.bind( 'ready', function() {
2626
// @todo Add snapshot-exists, snapshot-saved, snapshot-submitted states for back-compat? Skip if they are not used.
@@ -33,6 +33,7 @@
3333
api.state.create( 'changesetTitle', snapshot.data.title );
3434

3535
snapshot.extendPreviewerQuery();
36+
api.control( 'changeset_scheduled_date', snapshot.setupScheduledChangesetCountdown );
3637
api.section( 'publish_settings', snapshot.addTitleControl );
3738
api.trigger( 'snapshots-ready', snapshot );
3839
} );
@@ -88,6 +89,7 @@
8889
extendPreviewerQuery: function extendPreviewerQuery() {
8990
var snapshot = this, originalQuery = api.previewer.query;
9091

92+
// @todo See if can be done using 'save-request-params' event?
9193
api.previewer.query = function() {
9294
var retval = originalQuery.apply( this, arguments );
9395

@@ -135,6 +137,30 @@
135137
} );
136138

137139
return queryVars;
140+
},
141+
142+
/**
143+
* Setup scheduled changeset countdown.
144+
*
145+
* @param {wp.customize.Control} control Changeset schedule date control.
146+
* @return {void}
147+
*/
148+
setupScheduledChangesetCountdown: function( control ) {
149+
var template, countdownContainer;
150+
151+
template = wp.template( 'snapshot-scheduled-countdown' );
152+
countdownContainer = $( '<div>', {
153+
'class': 'snapshot-countdown-container'
154+
} );
155+
156+
control.deferred.embedded.done( function() {
157+
control.container.append( countdownContainer );
158+
api.state( 'remainingTimeToPublish' ).bind( function( time ) {
159+
countdownContainer.html( template( {
160+
remainingTime: time
161+
} ) );
162+
} );
163+
} );
138164
}
139165
} );
140166

0 commit comments

Comments
 (0)