diff --git a/includes/theme.inc b/includes/theme.inc index cdd8b2f..adaa83b 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -279,9 +279,14 @@ function bootstrap_css_alter(&$css) { // Load excluded CSS files from theme. $excludes = _bootstrap_alter(bootstrap_theme_get_info('exclude'), 'css'); // Add Bootstrap CDN file and overrides. - if (theme_get_setting('bootstrap_cdn')){ + $bootstrap_cdn = theme_get_setting('bootstrap_cdn'); + if ($bootstrap_cdn){ // Add CDN. - $cdn = '//netdna.bootstrapcdn.com/bootstrap/'. theme_get_setting('bootstrap_cdn') .'/css/bootstrap.min.css'; + if(theme_get_setting('bootstrap_bootswatch')) { + $cdn = '//netdna.bootstrapcdn.com/bootswatch/'. $bootstrap_cdn .'/'.theme_get_setting('bootstrap_bootswatch').'/bootstrap.min.css'; + } else { + $cdn = '//netdna.bootstrapcdn.com/bootstrap/'. $bootstrap_cdn .'/css/bootstrap.min.css'; + } $css[$cdn] = array( 'data' => $cdn, 'type' => 'external', diff --git a/js/bootswatch.admin.js b/js/bootswatch.admin.js new file mode 100644 index 0000000..be3ce10 --- /dev/null +++ b/js/bootswatch.admin.js @@ -0,0 +1,25 @@ +(function ($) { + + Drupal.behaviors.bootstrapBootswatch = { + + attach: function (context, settings) { + $.get("http://api.bootswatch.com/3/", function (data) { + var themes = data.themes; + var previews = ''; + for(var i = 0, len = themes.length; i < len; i++){ + previews += '
'; + }; + $('#bootswatch-previews').append(previews); + $('select[name="bootstrap_bootswatch"]').change(function () { + var selected = $('select[name="bootstrap_bootswatch"]').find(':selected').text(); + $('.bootswatch-preview').addClass('hidden'); + if (selected !== '') { + var show = '#' + selected; + $(show).removeClass('hidden'); + } + }).change(); + }, "json"); + } + }; + +})(jQuery); diff --git a/theme-settings.php b/theme-settings.php index 96f0b61..c0618dd 100644 --- a/theme-settings.php +++ b/theme-settings.php @@ -40,6 +40,24 @@ function bootstrap_form_system_theme_settings_alter(&$form, $form_state, $form_i )), ); + $bootswatch_request = drupal_http_request('http://api.bootswatch.com/3/'); + $bootswatch_api = drupal_json_decode($bootswatch_request->data); + $bootswatch_themes = array(); + foreach ($bootswatch_api['themes'] AS $val) { + $bootswatch_themes[strtolower($val['name'])] = $val['name']; + } + + $form['bootstrap']['bootstrap_bootswatch'] = array( + '#type' => 'select', + '#title' => t('Bootswatch Theme'), + '#options' => $bootswatch_themes, + '#empty_option' => t('Bootstrap'), + '#empty_value' => NULL, + '#default_value' => theme_get_setting('bootstrap_bootswatch'), + '#description' => t('Use !bootstrapcdn to serve a Bootswatch Theme. Choose Bootswatch Theme here.', array('!bootstrapcdn' => l('BootstrapCDN', 'http://bootstrapcdn.com', array('external' => TRUE)))) . '', + ); + $form['#attached']['js'] = array(drupal_get_path('theme', 'bootstrap') . '/js/bootswatch.admin.js'); + $form['bootstrap']['bootstrap_rebuild_registry'] = array( '#type' => 'checkbox', '#title' => t('Rebuild theme registry on every page.'),