Merge pull request #1422 from roots/move-jquery-google-cdn-to-soil
Move jQuery CDN feature to Soil
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
### HEAD
|
### HEAD
|
||||||
|
* Move jQuery CDN feature to Soil ([#1422](https://github.com/roots/sage/issues/1422))
|
||||||
|
* Bump `gulp-load-plugins` to 0.10.0 ([#1419](https://github.com/roots/sage/issues/1419))
|
||||||
|
* Switch from [yargs](https://github.com/bcoe/yargs) to [minimist](https://github.com/substack/minimist) ([#1418](https://github.com/roots/sage/issues/1418))
|
||||||
* Remove `$content_width` ([#1417](https://github.com/roots/sage/issues/1417))
|
* Remove `$content_width` ([#1417](https://github.com/roots/sage/issues/1417))
|
||||||
* Lowercase `X-UA-Compatible` ([#1409](https://github.com/roots/sage/issues/1409))
|
* Lowercase `X-UA-Compatible` ([#1409](https://github.com/roots/sage/issues/1409))
|
||||||
* Remove mention of Google Analytics from the config ([#1384](https://github.com/roots/sage/issues/1384))
|
* Remove mention of Google Analytics from the config ([#1384](https://github.com/roots/sage/issues/1384))
|
||||||
* Switch from [yargs](https://github.com/bcoe/yargs) to [minimist](https://github.com/substack/minimist)
|
|
||||||
* Bump `gulp-load-plugins` to 0.10.0
|
|
||||||
|
|
||||||
### 8.1.1: March 31st, 2015
|
### 8.1.1: March 31st, 2015
|
||||||
* Remove pleeease dependency in favor of vanilla gulp-autoprefixer and gulp-minify-css ([#1402](https://github.com/roots/sage/issues/1402))
|
* Remove pleeease dependency in favor of vanilla gulp-autoprefixer and gulp-minify-css ([#1402](https://github.com/roots/sage/issues/1402))
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ For more installation notes, refer to the [Install gulp and Bower](#install-gulp
|
|||||||
* [asset-builder](https://github.com/austinpray/asset-builder) for the JSON file based asset pipeline
|
* [asset-builder](https://github.com/austinpray/asset-builder) for the JSON file based asset pipeline
|
||||||
* [Bootstrap](http://getbootstrap.com/)
|
* [Bootstrap](http://getbootstrap.com/)
|
||||||
* [Theme wrapper](https://roots.io/sage/docs/theme-wrapper/)
|
* [Theme wrapper](https://roots.io/sage/docs/theme-wrapper/)
|
||||||
* [HTML5 Boilerplate](http://html5boilerplate.com/)
|
|
||||||
* The latest [jQuery](http://jquery.com/) via Google CDN, with a local fallback
|
|
||||||
* The latest [Modernizr](http://modernizr.com/) build for feature detection
|
|
||||||
* ARIA roles and microformats
|
* ARIA roles and microformats
|
||||||
* Cleaner HTML output of navigation menus
|
* Cleaner HTML output of navigation menus
|
||||||
* Posts use the [hNews](http://microformats.org/wiki/hnews) microformat
|
* Posts use the [hNews](http://microformats.org/wiki/hnews) microformat
|
||||||
@@ -43,6 +40,8 @@ Install the [Soil](https://github.com/roots/soil) plugin to enable additional fe
|
|||||||
* Cleaner output of `wp_head` and enqueued assets
|
* Cleaner output of `wp_head` and enqueued assets
|
||||||
* Root relative URLs
|
* Root relative URLs
|
||||||
* Nice search (`/search/query/`)
|
* Nice search (`/search/query/`)
|
||||||
|
* Google CDN jQuery snippet from [HTML5 Boilerplate](http://html5boilerplate.com/)
|
||||||
|
* Google Analytics snippet from [HTML5 Boilerplate](http://html5boilerplate.com/)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,8 @@ namespace Roots\Sage\Assets;
|
|||||||
* 1. /theme/dist/styles/main.css
|
* 1. /theme/dist/styles/main.css
|
||||||
*
|
*
|
||||||
* Enqueue scripts in the following order:
|
* Enqueue scripts in the following order:
|
||||||
* 1. Latest jQuery via Google CDN (if enabled in config.php)
|
* 1. /theme/dist/scripts/modernizr.js
|
||||||
* 2. /theme/dist/scripts/modernizr.js
|
* 2. /theme/dist/scripts/main.js
|
||||||
* 3. /theme/dist/scripts/main.js
|
|
||||||
*
|
|
||||||
* Google Analytics is loaded after enqueued scripts if:
|
|
||||||
* - An ID has been defined in config.php
|
|
||||||
* - You're not logged in as an administrator
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class JsonManifest {
|
class JsonManifest {
|
||||||
@@ -70,74 +65,14 @@ function asset_path($filename) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function bower_map_to_cdn($dependency, $fallback) {
|
|
||||||
static $bower;
|
|
||||||
|
|
||||||
if (empty($bower)) {
|
|
||||||
$bower_path = get_template_directory() . '/bower.json';
|
|
||||||
$bower = new JsonManifest($bower_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$templates = [
|
|
||||||
'google' => '//ajax.googleapis.com/ajax/libs/%name%/%version%/%file%'
|
|
||||||
];
|
|
||||||
|
|
||||||
$version = $bower->getPath('dependencies.' . $dependency['name']);
|
|
||||||
|
|
||||||
if (isset($version) && preg_match('/^(\d+\.){2}\d+$/', $version)) {
|
|
||||||
$search = ['%name%', '%version%', '%file%'];
|
|
||||||
$replace = [$dependency['name'], $version, $dependency['file']];
|
|
||||||
return str_replace($search, $replace, $templates[$dependency['cdn']]);
|
|
||||||
} else {
|
|
||||||
return $fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function assets() {
|
function assets() {
|
||||||
wp_enqueue_style('sage_css', asset_path('styles/main.css'), false, null);
|
wp_enqueue_style('sage_css', asset_path('styles/main.css'), false, null);
|
||||||
|
|
||||||
/**
|
|
||||||
* Grab Google CDN's latest jQuery with a protocol relative URL; fallback to local if offline
|
|
||||||
* jQuery & Modernizr load in the footer per HTML5 Boilerplate's recommendation: http://goo.gl/nMGR7P
|
|
||||||
* If a plugin enqueues jQuery-dependent scripts in the head, jQuery will load in the head to meet the plugin's dependencies
|
|
||||||
* To explicitly load jQuery in the head, change the last wp_enqueue_script parameter to false
|
|
||||||
*/
|
|
||||||
if (!is_admin() && current_theme_supports('jquery-cdn')) {
|
|
||||||
wp_deregister_script('jquery');
|
|
||||||
|
|
||||||
wp_register_script('jquery', bower_map_to_cdn([
|
|
||||||
'name' => 'jquery',
|
|
||||||
'cdn' => 'google',
|
|
||||||
'file' => 'jquery.min.js'
|
|
||||||
], asset_path('scripts/jquery.js')), [], null, true);
|
|
||||||
|
|
||||||
add_filter('script_loader_src', __NAMESPACE__ . '\\jquery_local_fallback', 10, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_single() && comments_open() && get_option('thread_comments')) {
|
if (is_single() && comments_open() && get_option('thread_comments')) {
|
||||||
wp_enqueue_script('comment-reply');
|
wp_enqueue_script('comment-reply');
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_enqueue_script('modernizr', asset_path('scripts/modernizr.js'), [], null, true);
|
wp_enqueue_script('modernizr', asset_path('scripts/modernizr.js'), [], null, true);
|
||||||
wp_enqueue_script('jquery');
|
wp_enqueue_script('sage_js', asset_path('scripts/main.js'), ['jquery'], null, true);
|
||||||
wp_enqueue_script('sage_js', asset_path('scripts/main.js'), [], null, true);
|
|
||||||
}
|
}
|
||||||
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\assets', 100);
|
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\assets', 100);
|
||||||
|
|
||||||
// http://wordpress.stackexchange.com/a/12450
|
|
||||||
function jquery_local_fallback($src, $handle = null) {
|
|
||||||
static $add_jquery_fallback = false;
|
|
||||||
|
|
||||||
if ($add_jquery_fallback) {
|
|
||||||
echo '<script>window.jQuery || document.write(\'<script src="' . $add_jquery_fallback .'"><\/script>\')</script>' . "\n";
|
|
||||||
$add_jquery_fallback = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($handle === 'jquery') {
|
|
||||||
$add_jquery_fallback = apply_filters('script_loader_src', asset_path('scripts/jquery.js'), 'jquery-fallback');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $src;
|
|
||||||
}
|
|
||||||
add_action('wp_head', __NAMESPACE__ . '\\jquery_local_fallback');
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ use Roots\Sage\ConditionalTagCheck;
|
|||||||
add_theme_support('soil-clean-up'); // Enable clean up from Soil
|
add_theme_support('soil-clean-up'); // Enable clean up from Soil
|
||||||
add_theme_support('soil-relative-urls'); // Enable relative URLs from Soil
|
add_theme_support('soil-relative-urls'); // Enable relative URLs from Soil
|
||||||
add_theme_support('soil-nice-search'); // Enable nice search from Soil
|
add_theme_support('soil-nice-search'); // Enable nice search from Soil
|
||||||
|
add_theme_support('soil-jquery-cdn'); // Enable to load jQuery from the Google CDN
|
||||||
add_theme_support('bootstrap-gallery'); // Enable Bootstrap's thumbnails component on [gallery]
|
add_theme_support('bootstrap-gallery'); // Enable Bootstrap's thumbnails component on [gallery]
|
||||||
add_theme_support('jquery-cdn'); // Enable to load jQuery from the Google CDN
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration values
|
* Configuration values
|
||||||
|
|||||||
Reference in New Issue
Block a user