@@ -1058,15 +1058,82 @@ public function replace_customize_link( $wp_admin_bar ) {
1058
1058
* Underscore (JS) templates for dialog windows.
1059
1059
*/
1060
1060
public function render_templates () {
1061
+ $ data = $ this ->data_json ();
1061
1062
?>
1062
1063
<script type="text/html" id="tmpl-snapshot-preview-link">
1063
1064
<a href="#" target="frontend-preview" id="snapshot-preview-link" class="dashicons dashicons-welcome-view-site" title="<?php esc_attr_e ( 'View on frontend ' , 'customize-snapshots ' ) ?> ">
1064
1065
<span class="screen-reader-text"><?php esc_html_e ( 'View on frontend ' , 'customize-snapshots ' ) ?> </span>
1065
1066
</a>
1066
1067
</script>
1067
1068
1068
- <script type="text/html" id="tmpl-snapshot-edit-link">
1069
- <a href="{{ data.editLink }}" id="snapshot-edit-link" class="dashicons dashicons-calendar-alt" title="<?php esc_attr_e ( 'Edit Snapshot ' ,'customize-snapshots ' ); ?> "></a>
1069
+ <script type="text/html" id="tmpl-snapshot-toggle-button">
1070
+ <a href="#" id="snapshot-toggle-button" class="dashicons dashicons-calendar-alt" title="<?php esc_attr_e ( 'Schedule Snapshot ' ,'customize-snapshots ' ); ?> "></a>
1071
+ </script>
1072
+
1073
+ <script type="text/html" id="tmpl-snapshot-schedule-accordion">
1074
+ <div id="customize-schedule-box" class="accordion-section">
1075
+ <div class="accordion-section-title">
1076
+ <span class="preview-notice"><strong class="panel-title site-title"><?php esc_html_e ( 'Schedule Snapshot ' , 'customize-snapshots ' ); ?> </strong></span>
1077
+ <a href={{ data.editLink }} class="dashicons dashicons-edit" aria-expanded="false"></a>
1078
+ </div>
1079
+ <div class="customize-snapshot-control">
1080
+ <#
1081
+ _.defaults( data, <?php echo wp_json_encode ( $ data ) ?> );
1082
+ data.input_id_post_date = 'input-' + String( Math.random() );
1083
+ data.input_id_post_date_gmt = 'input-' + String( Math.random() );
1084
+ #>
1085
+ <# _.each( data.date_inputs, function( width, type ) { #>
1086
+ <# if ( 'month' === type ) { #>
1087
+ <select class="date-input {{ type }}">
1088
+ <# _.each( data.month_choices, function( choice ) { #>
1089
+ <# if ( _.isObject( choice ) && ! _.isUndefined( choice.text ) && ! _.isUndefined( choice.value ) ) {
1090
+ text = choice.text;
1091
+ value = choice.value;
1092
+ } #>
1093
+ <option value="{{ value }}">{{ text }}</option>
1094
+ <# } ); #>
1095
+ </select>
1096
+ <# } else { #>
1097
+ <input
1098
+ type="text"
1099
+ size="{{ width }}"
1100
+ maxlength="{{ width }}"
1101
+ autocomplete="off"
1102
+ class="date-input {{ type }}"
1103
+ />
1104
+ <# if ( 'year' === type ) { #>
1105
+ @
1106
+ <# } #>
1107
+ <# } #>
1108
+ <# }); #>
1109
+ <input
1110
+ id=""
1111
+ type="hidden"
1112
+ class="post-date"
1113
+ <# if ( data.setting_property ) { #>
1114
+ data-customize-setting-property-link="post_date"
1115
+ <# } #>
1116
+ />
1117
+ <input
1118
+ id=""
1119
+ type="hidden"
1120
+ class="post-date-gmt"
1121
+ value=""
1122
+ <# if ( data.setting_property ) { #>
1123
+ data-customize-setting-property-link="post_date_gmt"
1124
+ <# } #>
1125
+ />
1126
+ <input
1127
+ id=""
1128
+ type="hidden"
1129
+ class="post-status"
1130
+ value=""
1131
+ <# if ( data.setting_property ) { #>
1132
+ data-customize-setting-property-link="post_status"
1133
+ <# } #>
1134
+ />
1135
+ </div>
1136
+ </div>
1070
1137
</script>
1071
1138
1072
1139
<script type="text/html" id="tmpl-snapshot-save">
@@ -1088,4 +1155,45 @@ public function render_templates() {
1088
1155
</script>
1089
1156
<?php
1090
1157
}
1158
+
1159
+ /**
1160
+ * Get the data to export to the client via JSON.
1161
+ *
1162
+ * @return array Array of parameters passed to the JavaScript.
1163
+ */
1164
+ public function data_json () {
1165
+ $ exported ['month_choices ' ] = $ this ->get_month_choices ();
1166
+ // Type / width pairs.
1167
+ $ exported ['date_inputs ' ] = array (
1168
+ 'month ' => null ,
1169
+ 'day ' => 2 ,
1170
+ 'year ' => 4 ,
1171
+ 'hour ' => 2 ,
1172
+ 'min ' => 2 ,
1173
+ );
1174
+ return $ exported ;
1175
+ }
1176
+
1177
+ /**
1178
+ * Generate options for the month Select.
1179
+ *
1180
+ * Based on touch_time().
1181
+ *
1182
+ * @see touch_time()
1183
+ *
1184
+ * @return array
1185
+ */
1186
+ public function get_month_choices () {
1187
+ global $ wp_locale ;
1188
+ $ months = array ();
1189
+ for ( $ i = 1 ; $ i < 13 ; $ i = $ i + 1 ) {
1190
+ $ month_number = zeroise ( $ i , 2 );
1191
+ $ month_text = $ wp_locale ->get_month_abbrev ( $ wp_locale ->get_month ( $ i ) );
1192
+
1193
+ /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
1194
+ $ months [ $ i ]['text ' ] = sprintf ( __ ( '%1$s-%2$s ' , 'customize-snapshots ' ), $ month_number , $ month_text );
1195
+ $ months [ $ i ]['value ' ] = $ month_number ;
1196
+ }
1197
+ return $ months ;
1198
+ }
1091
1199
}
0 commit comments