From af89a57e7ccfe04cdf7e179cf1d023fd3c3e4fba Mon Sep 17 00:00:00 2001 From: Scott Walkinshaw Date: Mon, 11 Jul 2011 11:56:00 -0600 Subject: [PATCH] Refactored CSS framework code: added in default classes, added stylesheet_link_tag function, added a no framework option, cleaned up code --- inc/js/theme-options.js | 25 ++++++- inc/roots-actions.php | 38 +++++++---- inc/roots-options.php | 146 ++++++++++++++++++++++++++-------------- 3 files changed, 144 insertions(+), 65 deletions(-) diff --git a/inc/js/theme-options.js b/inc/js/theme-options.js index 3bb8488..b91ceb6 100644 --- a/inc/js/theme-options.js +++ b/inc/js/theme-options.js @@ -2,5 +2,28 @@ 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(); + + 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; + + // 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); + + }); -}); \ No newline at end of file +}); diff --git a/inc/roots-actions.php b/inc/roots-actions.php index 6353a4a..a0b43b7 100644 --- a/inc/roots-actions.php +++ b/inc/roots-actions.php @@ -77,21 +77,21 @@ function roots_get_stylesheets() { $styles = ''; if ($roots_css_framework === 'blueprint') { - $styles .= "\n"; + $styles .= stylesheet_link_tag('/blueprint/screen.css'); } elseif ($roots_css_framework === '960gs_12' || $roots_css_framework === '960gs_16') { - $styles .= "\n"; - $styles .= "\t\n"; - $styles .= "\t\n"; + $styles .= stylesheet_link_tag('/960/reset.css'); + $styles .= stylesheet_link_tag('/960/text.css', 1); + $styles .= stylesheet_link_tag('/960/960.css', 1); } elseif ($roots_css_framework === '960gs_24') { - $styles .= "\n"; - $styles .= "\t\n"; - $styles .= "\t\n"; + $styles .= stylesheet_link_tag('/960/reset.css'); + $styles .= stylesheet_link_tag('/960/text.css', 1); + $styles .= stylesheet_link_tag('/960/960_24_col.css', 1); } elseif ($roots_css_framework === '1140') { - $styles .= "\n"; + $styles .= stylesheet_link_tag('/1140/1140.css'); } elseif ($roots_css_framework === 'adapt') { - $styles .= "\n"; + $styles .= stylesheet_link_tag('/adapt/master.css'); $styles .= "\t\n"; } @@ -99,17 +99,27 @@ function roots_get_stylesheets() { $styles .= "\t\n"; } - $styles .= "\t\n"; + $styles .= stylesheet_link_tag('/style.css', 1); if ($roots_css_framework === 'blueprint') { - $styles .= "\t\n"; + $styles .= "\t\n"; } elseif ($roots_css_framework === '1140') { - $styles .= "\t\n"; + $styles .= "\t\n"; } echo $styles; } +function stylesheet_link_tag($file, $tabs = 0, $newline = true) { + $i = 0; + $indent = ''; + while ($i < $tabs) { + $indent .= "\t"; + $i++; + } + return $indent . '' . ($newline ? "\n" : ""); +} + function roots_1140_header_before() { global $roots_options; $roots_css_framework = $roots_options['css_framework']; @@ -153,4 +163,4 @@ function roots_page_breadcrumb() { } } -?> \ No newline at end of file +?> diff --git a/inc/roots-options.php b/inc/roots-options.php index cf5d5a9..7b3e320 100644 --- a/inc/roots-options.php +++ b/inc/roots-options.php @@ -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); +?> + + '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; ?>
@@ -110,13 +162,13 @@ function theme_options_render_page() { -
+