|
20 | 20 | _.extend( snapshot.data, snapshotsConfig );
|
21 | 21 | }
|
22 | 22 |
|
23 |
| - _.bindAll( snapshot, 'addTitleControl' ); |
| 23 | + _.bindAll( snapshot, 'addTitleControl', 'setupScheduledChangesetCountdown' ); |
24 | 24 |
|
25 | 25 | api.bind( 'ready', function() {
|
26 | 26 | // @todo Add snapshot-exists, snapshot-saved, snapshot-submitted states for back-compat? Skip if they are not used.
|
|
33 | 33 | api.state.create( 'changesetTitle', snapshot.data.title );
|
34 | 34 |
|
35 | 35 | snapshot.extendPreviewerQuery();
|
| 36 | + api.control( 'changeset_scheduled_date', snapshot.setupScheduledChangesetCountdown ); |
36 | 37 | api.section( 'publish_settings', snapshot.addTitleControl );
|
37 | 38 | api.trigger( 'snapshots-ready', snapshot );
|
38 | 39 | } );
|
|
88 | 89 | extendPreviewerQuery: function extendPreviewerQuery() {
|
89 | 90 | var snapshot = this, originalQuery = api.previewer.query;
|
90 | 91 |
|
| 92 | + // @todo See if can be done using 'save-request-params' event? |
91 | 93 | api.previewer.query = function() {
|
92 | 94 | var retval = originalQuery.apply( this, arguments );
|
93 | 95 |
|
|
135 | 137 | } );
|
136 | 138 |
|
137 | 139 | 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 | + } ); |
138 | 164 | }
|
139 | 165 | } );
|
140 | 166 |
|
|
0 commit comments