changing the radio inputs into select lists, code formatting cleanup

This commit is contained in:
Ben Word
2011-07-22 08:17:42 -06:00
parent dd77a89b34
commit 103c4c5bd5
2 changed files with 110 additions and 136 deletions

View File

@@ -2,28 +2,27 @@ jQuery.noConflict();
jQuery(document).ready(function(){
var $main = jQuery('#main_class');
var $sidebar = jQuery('#sidebar_class');
var framework = jQuery('.roots_css_frameworks input:checked').val();
var user_main_class = $main.val();
var user_sidebar_class = $sidebar.val();
var $main = jQuery('#main_class');
var $sidebar = jQuery('#sidebar_class');
var framework = jQuery('.roots_css_frameworks select option:selected').val();
var user_main_class = $main.val();
var user_sidebar_class = $sidebar.val();
jQuery('.roots_css_frameworks input').change(function (e) {
var main_class = roots_css_frameworks[this.value].classes.main;
var sidebar_class = roots_css_frameworks[this.value].classes.sidebar;
jQuery('.roots_css_frameworks select').change(function (e) {
var main_class = roots_css_frameworks[this.value].classes.main;
var sidebar_class = roots_css_frameworks[this.value].classes.sidebar;
// if the selected framework was the one originally set, load the original classes instead of the defaults
if (this.value === framework) {
$main.val(user_main_class);
$sidebar.val(user_sidebar_class);
} else {
$main.val(main_class);
$sidebar.val(sidebar_class);
}
// if the selected framework was the one originally set, load the original classes instead of the defaults
if (this.value === framework) {
$main.val(user_main_class);
$sidebar.val(user_sidebar_class);
} else {
$main.val(main_class);
$sidebar.val(sidebar_class);
}
$main.siblings('small').children().text(main_class);
$sidebar.siblings('small').children().text(sidebar_class);
});
$main.siblings('small').children().text(main_class);
$sidebar.siblings('small').children().text(sidebar_class);
});
});

View File

@@ -35,7 +35,7 @@ function roots_theme_options_add_page() {
__('Theme Options', 'roots'),
'edit_theme_options',
'theme_options',
'theme_options_render_page'
'roots_theme_options_render_page'
);
if (!$theme_page)
@@ -45,104 +45,104 @@ add_action('admin_menu', 'roots_theme_options_add_page');
global $roots_css_frameworks;
$roots_css_frameworks = array(
'blueprint' => array(
'blueprint' => array(
'name' => 'blueprint',
'label' => __('Blueprint CSS', 'roots'),
'classes' => array(
'container' => 'span-24',
'main' => 'span-14 append-1',
'sidebar' => 'span-8 prepend-1 last'
)
),
'960gs_12' => array(
'classes' => array(
'container' => 'span-24',
'main' => 'span-14 append-1',
'sidebar' => 'span-8 prepend-1 last'
)
),
'960gs_12' => array(
'name' => '960gs_12',
'label' => __('960gs (12 cols)', 'roots'),
'classes' => array(
'container' => 'container_12',
'main' => 'grid_7 suffix_1',
'sidebar' => 'grid_4'
)
),
'960gs_16' => array(
'classes' => array(
'container' => 'container_12',
'main' => 'grid_7 suffix_1',
'sidebar' => 'grid_4'
)
),
'960gs_16' => array(
'name' => '960gs_16',
'label' => __('960gs (16 cols)', 'roots'),
'classes' => array(
'container' => 'container_16',
'main' => 'grid_9 suffix_1',
'sidebar' => 'grid_6'
)
),
'960gs_24' => array(
'classes' => array(
'container' => 'container_16',
'main' => 'grid_9 suffix_1',
'sidebar' => 'grid_6'
)
),
'960gs_24' => array(
'name' => '960gs_24',
'label' => __('960gs (24 cols)', 'roots'),
'classes' => array(
'container' => 'container_24',
'main' => 'grid_15 suffix_1',
'sidebar' => 'grid_8'
)
),
'1140' => array(
'classes' => array(
'container' => 'container_24',
'main' => 'grid_15 suffix_1',
'sidebar' => 'grid_8'
)
),
'1140' => array(
'name' => '1140',
'label' => __('1140', 'roots'),
'classes' => array(
'container' => 'container',
'main' => 'sevencol',
'sidebar' => 'fourcol last'
)
),
'adapt' => array(
'classes' => array(
'container' => 'container',
'main' => 'sevencol',
'sidebar' => 'fourcol last'
)
),
'adapt' => array(
'name' => 'adapt',
'label' => __('Adapt.js', 'roots'),
'classes' => array(
'container' => 'container_12 clearfix',
'main' => 'grid_7 suffix_1',
'sidebar' => 'grid_4'
)
),
'less' => array(
'classes' => array(
'container' => 'container_12 clearfix',
'main' => 'grid_7 suffix_1',
'sidebar' => 'grid_4'
)
),
'less' => array(
'name' => 'less',
'label' => __('Less Framework 4', 'roots'),
'classes' => array(
'container' => 'container',
'main' => '',
'sidebar' => ''
)
),
'none' => array(
'classes' => array(
'container' => 'container',
'main' => '',
'sidebar' => ''
)
),
'none' => array(
'name' => 'none',
'label' => __('None', 'roots'),
'classes' => array(
'container' => '',
'main' => '',
'sidebar' => ''
)
)
'classes' => array(
'container' => '',
'main' => '',
'sidebar' => ''
)
)
);
// Write the above array of CSS frameworks into a script tag
function roots_add_frameworks_object_script() {
global $roots_css_frameworks;
$json = json_encode($roots_css_frameworks);
global $roots_css_frameworks;
$json = json_encode($roots_css_frameworks);
?>
<script>
var roots_css_frameworks = <?php echo $json; ?>;
</script>
<?php
<script>
var roots_css_frameworks = <?php echo $json; ?>;
</script>
<?php
}
add_action('admin_head', 'roots_add_frameworks_object_script');
function roots_get_default_theme_options() {
global $roots_css_frameworks;
$default_framework = 'blueprint';
$default_framework_settings = $roots_css_frameworks[$default_framework];
global $roots_css_frameworks;
$default_framework = 'blueprint';
$default_framework_settings = $roots_css_frameworks[$default_framework];
$default_theme_options = array(
'css_framework' => $default_framework,
'container_class' => $default_framework_settings['classes']['container'],
'main_class' => $default_framework_settings['classes']['main'],
'sidebar_class' => $default_framework_settings['classes']['sidebar'],
'css_framework' => $default_framework,
'container_class' => $default_framework_settings['classes']['container'],
'main_class' => $default_framework_settings['classes']['main'],
'sidebar_class' => $default_framework_settings['classes']['sidebar'],
'google_analytics_id' => '',
'clean_menu' => true,
'fout_b_gone' => false
'clean_menu' => true,
'fout_b_gone' => false
);
return apply_filters('roots_default_theme_options', $default_theme_options);
@@ -152,8 +152,8 @@ function roots_get_theme_options() {
return get_option('roots_theme_options', roots_get_default_theme_options());
}
function theme_options_render_page() {
global $roots_css_frameworks;
function roots_theme_options_render_page() {
global $roots_css_frameworks;
?>
<div class="wrap">
<?php screen_icon(); ?>
@@ -172,20 +172,11 @@ function theme_options_render_page() {
<tr valign="top" class="radio-option"><th scope="row"><?php _e('CSS Grid Framework', 'roots'); ?></th>
<td>
<fieldset class="roots_css_frameworks"><legend class="screen-reader-text"><span><?php _e('CSS Grid Framework', 'roots'); ?></span></legend>
<?php
foreach ($roots_css_frameworks as $css_framework) {
?>
<div class="layout">
<label class="description">
<input type="radio" name="roots_theme_options[css_framework]" value="<?php echo esc_attr($css_framework['name']); ?>" <?php checked($roots_options['css_framework'], $css_framework['name']); ?> />
<span>
<?php echo $css_framework['label']; ?>
</span>
</label>
</div>
<?php
}
?>
<select name="roots_theme_options[css_framework]" id="roots_theme_options[css_framework]">
<?php foreach ($roots_css_frameworks as $css_framework) { ?>
<option value="<?php echo esc_attr($css_framework['name']); ?>" <?php selected($roots_options['css_framework'], $css_framework['name']); ?>><?php echo $css_framework['label']; ?></option>
<?php } ?>
</select>
</fieldset>
</td>
</tr>
@@ -195,7 +186,7 @@ function theme_options_render_page() {
<fieldset><legend class="screen-reader-text"><span><?php _e('#main CSS Classes', 'roots'); ?></span></legend>
<input type="text" name="roots_theme_options[main_class]" id="main_class" value="<?php echo esc_attr($roots_options['main_class']); ?>" class="regular-text" />
<br />
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['main_class']; ?></span></small>
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['main_class']; ?></span></small>
</fieldset>
</td>
</tr>
@@ -205,7 +196,7 @@ function theme_options_render_page() {
<fieldset><legend class="screen-reader-text"><span><?php _e('#sidebar CSS Classes', 'roots'); ?></span></legend>
<input type="text" name="roots_theme_options[sidebar_class]" id="sidebar_class" value="<?php echo esc_attr($roots_options['sidebar_class']); ?>" class="regular-text" />
<br />
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['sidebar_class']; ?></span></small>
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['sidebar_class']; ?></span></small>
</fieldset>
</td>
</tr>
@@ -223,18 +214,10 @@ function theme_options_render_page() {
<tr valign="top"><th scope="row"><?php _e('Cleanup Menu Output', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('Cleanup Menu Output', 'roots'); ?></span></legend>
<div>
<label class="description">
<input type="radio" name="roots_theme_options[clean_menu]" value="yes" <?php checked($roots_options['clean_menu'], true); ?> />
<span><?php echo _e('Yes', 'roots'); ?></span>
</label>
</div>
<div>
<label class="description">
<input type="radio" name="roots_theme_options[clean_menu]" value="no" <?php checked($roots_options['clean_menu'], false); ?> />
<span><?php echo _e('No', 'roots'); ?></span>
</label>
</div>
<select name="roots_theme_options[clean_menu]" id="roots_theme_options[clean_menu]">
<option value="yes" <?php selected($roots_options['clean_menu'], true); ?>><?php echo _e('Yes', 'roots'); ?></option>
<option value="no" <?php selected($roots_options['clean_menu'], false); ?>><?php echo _e('No', 'roots'); ?></option>
</select>
</fieldset>
</td>
</tr>
@@ -242,18 +225,10 @@ function theme_options_render_page() {
<tr valign="top"><th scope="row"><?php _e('Enable FOUT-B-Gone', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('Enable FOUT-B-Gone', 'roots'); ?></span></legend>
<div>
<label class="description">
<input type="radio" name="roots_theme_options[fout_b_gone]" value="yes" <?php checked($roots_options['fout_b_gone'], true); ?> />
<span><?php echo _e('Yes', 'roots'); ?></span>
</label>
</div>
<div>
<label class="description">
<input type="radio" name="roots_theme_options[fout_b_gone]" value="no" <?php checked($roots_options['fout_b_gone'], false); ?> />
<span><?php echo _e('No', 'roots'); ?></span>
</label>
</div>
<select name="roots_theme_options[fout_b_gone]" id="roots_theme_options[fout_b_gone]">
<option value="yes" <?php selected($roots_options['fout_b_gone'], true); ?>><?php echo _e('Yes', 'roots'); ?></option>
<option value="no" <?php selected($roots_options['fout_b_gone'], false); ?>><?php echo _e('No', 'roots'); ?></option>
</select>
</fieldset>
</td>
</tr>
@@ -268,14 +243,14 @@ function theme_options_render_page() {
}
function roots_theme_options_validate($input) {
global $roots_css_frameworks;
global $roots_css_frameworks;
$output = $defaults = roots_get_default_theme_options();
if (isset($input['css_framework']) && array_key_exists($input['css_framework'], $roots_css_frameworks))
$output['css_framework'] = $input['css_framework'];
// set the value of the main container class depending on the selected grid framework
$output['container_class'] = $roots_css_frameworks[$output['css_framework']]['classes']['container'];
$output['container_class'] = $roots_css_frameworks[$output['css_framework']]['classes']['container'];
if (isset($input['main_class']))
$output['main_class'] = $input['main_class'];