| | 194 | <!-- custom Template selection div --> |
| | 195 | <div id="templateselector" class="templateselector alignright"> |
| | 196 | <strong><label for="templateselect"><?php _e('Select template or style to edit:'); ?> </label></strong> |
| | 197 | <select name="templateselect" id="templateselect"> |
| | 198 | <?php |
| | 199 | if ( $allowed_files ) : |
| | 200 | $previous_file_type = ''; |
| | 201 | |
| | 202 | foreach ( $allowed_files as $filename => $absolute_filename ) : |
| | 203 | $file_type = substr( $filename, strrpos( $filename, '.' ) ); |
| | 204 | |
| | 205 | if ( $file_type !== $previous_file_type ) { |
| | 206 | |
| | 207 | switch ( $file_type ) { |
| | 208 | |
| | 209 | case '.php': |
| | 210 | if ( $has_templates || $theme->parent() ) : |
| | 211 | echo "\t<optgroup label=\"" . __( 'Templates' ) . "\">"; |
| | 212 | endif; |
| | 213 | break; |
| | 214 | |
| | 215 | case '.css': |
| | 216 | echo "\t<optgroup label=\"" . __( 'Styles' ) . "\">"; |
| | 217 | break; |
| | 218 | } |
| | 219 | } |
| | 220 | |
| | 221 | $file_description = get_file_description( $filename ); |
| | 222 | $previous_file_type = $file_type; |
| | 223 | ?> |
| | 224 | <option value="<?php echo urlencode( $filename ) ?>&theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></option> |
| | 225 | <?php |
| | 226 | endforeach; |
| | 227 | ?> |
| | 228 | </optgroup> |
| | 229 | <?php endif; ?> |
| | 230 | </select> |
| | 231 | <?php submit_button( __( 'Select' ), 'submit', 'selectmytemplate', false ); ?> |
| | 232 | </div> |
| | 233 | <!-- end of custom Template selection div --> |
| | 332 | |
| | 333 | // Redirect to selected template page |
| | 334 | $('#selectmytemplate').on('click', function() { |
| | 335 | var url = $('#templateselect').val(); // get the selected value |
| | 336 | if (url) { // require a URL |
| | 337 | window.location = '?file=' + url; // redirect |
| | 338 | } |
| | 339 | return false; |
| | 340 | }); |
| | 341 | |
| | 342 | // Mark the current file as selected |
| | 343 | var getUrlParameter = function getUrlParameter(sParam) { |
| | 344 | var sPageURL = decodeURIComponent(window.location.search.substring(1)), |
| | 345 | sURLVariables = sPageURL.split('&'), |
| | 346 | sParameterName, |
| | 347 | i; |
| | 348 | |
| | 349 | for (i = 0; i < sURLVariables.length; i++) { |
| | 350 | sParameterName = sURLVariables[i].split('='); |
| | 351 | |
| | 352 | if (sParameterName[0] === sParam) { |
| | 353 | return sParameterName[1] === undefined ? true : sParameterName[1]; |
| | 354 | } |
| | 355 | } |
| | 356 | }; |
| | 357 | var currentFile = getUrlParameter('file'); |
| | 358 | $('#templateselect option[value*="'+currentFile+'"]').prop('selected', true); |
| | 359 | |