Refactored CSS framework code: added in default classes, added

stylesheet_link_tag function, added a no framework option, cleaned up
code
This commit is contained in:
Scott Walkinshaw
2011-07-11 11:56:00 -06:00
parent 12dd0fae09
commit af89a57e7c
3 changed files with 144 additions and 65 deletions

View File

@@ -43,46 +43,97 @@ function roots_theme_options_add_page() {
}
add_action('admin_menu', 'roots_theme_options_add_page');
function roots_css_framework() {
$framework_options = array(
'blueprint' => array(
'value' => 'blueprint',
'label' => __('Blueprint CSS', 'roots'),
),
'960gs_12' => array(
'value' => '960gs_12',
'label' => __('960gs (12 cols)', 'roots'),
),
'960gs_16' => array(
'value' => '960gs_16',
'label' => __('960gs (16 cols)', 'roots'),
),
'960gs_24' => array(
'value' => '960gs_24',
'label' => __('960gs (24 cols)', 'roots'),
),
'1140' => array(
'value' => '1140',
'label' => __('1140', 'roots'),
),
'adapt' => array(
'value' => 'adapt',
'label' => __('Adapt.js', 'roots'),
),
);
return apply_filters('roots_css_framework', $framework_options);
global $roots_css_frameworks;
$roots_css_frameworks = 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(
'name' => '960gs_12',
'label' => __('960gs (12 cols)', 'roots'),
'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(
'name' => '960gs_24',
'label' => __('960gs (24 cols)', 'roots'),
'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(
'name' => 'adapt',
'label' => __('Adapt.js', 'roots'),
'classes' => array(
'container' => 'container_12 clearfix',
'main' => 'grid_7 suffix_1',
'sidebar' => 'grid_4'
)
),
'none' => array(
'name' => 'none',
'label' => __('None', 'roots'),
'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);
?>
<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];
$default_theme_options = array(
'css_framework' => 'blueprint',
'container_class' => 'span-24',
'main_class' => 'span-14 append-1',
'sidebar_class' => 'span-8 prepend-1 last',
'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);
@@ -93,6 +144,7 @@ function roots_get_theme_options() {
}
function theme_options_render_page() {
global $roots_css_frameworks;
?>
<div class="wrap">
<?php screen_icon(); ?>
@@ -110,13 +162,13 @@ function theme_options_render_page() {
<tr valign="top" class="radio-option"><th scope="row"><?php _e('CSS Grid Framework', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('CSS Grid Framework', 'roots'); ?></span></legend>
<fieldset class="roots_css_frameworks"><legend class="screen-reader-text"><span><?php _e('CSS Grid Framework', 'roots'); ?></span></legend>
<?php
foreach (roots_css_framework() as $css_framework) {
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['value']); ?>" <?php checked($roots_options['css_framework'], $css_framework['value']); ?> />
<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>
@@ -134,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 printf( __('Default: %s', 'roots'), $roots_default_options['main_class']); ?></small>
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['main_class']; ?></span></small>
</fieldset>
</td>
</tr>
@@ -144,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 printf( __('Default: %s', 'roots'), $roots_default_options['sidebar_class']); ?></small>
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['sidebar_class']; ?></span></small>
</fieldset>
</td>
</tr>
@@ -207,21 +259,15 @@ function theme_options_render_page() {
}
function roots_theme_options_validate($input) {
global $roots_css_frameworks;
$output = $defaults = roots_get_default_theme_options();
if (isset($input['css_framework']) && array_key_exists($input['css_framework'], roots_css_framework()))
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
switch ($input['css_framework']) {
case 'blueprint': $output['container_class'] = 'span-24'; break;
case '960gs_12': $output['container_class'] = 'container_12'; break;
case '960gs_16': $output['container_class'] = 'container_16'; break;
case '960gs_24': $output['container_class'] = 'container_24'; break;
case '1140': $output['container_class'] = 'container'; break;
case 'adapt': $output['container_class'] = 'container_12 clearfix'; break;
}
$output['container_class'] = $roots_css_frameworks[$output['css_framework']]['classes']['container'];
if (isset($input['main_class']))
$output['main_class'] = $input['main_class'];