Skip to content

Instantly share code, notes, and snippets.

@kingkool68
Created March 6, 2014 22:25
Show Gist options
  • Save kingkool68/9401084 to your computer and use it in GitHub Desktop.
Save kingkool68/9401084 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Pew Scripts
Description: Scripts that are used on multiple sites can be registered and maintained in one place through this plugin.
Version: 1.2
Author: Russell Heimlich
Author URI: http://www.russellheimlich.com
*/
function pew_register_global_scripts() {
$js_path = plugins_url() . '/pew-scripts';
$suffix = '.min.js';
// All scripts registered in this plugin should have minified (ending with .min.js) and non-minified (ending with .js) versions for production and debugging!
// Minify your scripts at http://jscompress.com/
if( defined('WP_DEBUG') && WP_DEBUG === true ) {
$suffix = '.js';
}
if( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG === true ) {
$suffix = '.js';
}
if( !is_admin() ) {
//We don't need internationalization script on the front end. All of our sites are in English for now.
wp_deregister_script( 'l10n' );
//Relocate jQuery
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1/jquery' . $suffix, array(), NULL );
/*
Hmmm? This doesn't make as much sense to load jQuery UI from Google because they bundle everything together (~60KB).
If you only need jQuery UI Core then it can be loaded for ~5KB from WordPress.
If you need effects it's ~15KB and comes in seperate files.
Still thinking this through.
-RH 3/15/2013
*/
wp_deregister_script( 'jquery-ui-core' );
wp_register_script( 'jquery-ui-core', '//ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui' . $suffix, array('jquery'), NULL, true);
}
//High Charts
wp_register_script( 'highcharts', $js_path . '/js/highcharts' . $suffix, array('jquery'), NULL, true);
wp_register_script( 'highcharts-more', $js_path . '/js/highcharts-more' . $suffix, array('highcharts', 'jquery'), NULL, true);
//Expando Search Box
wp_register_script( 'expando-search-box', $js_path . '/js/expando-search-box' . $suffix, array('jquery'), NULL, true);
//Tiny Sort
wp_register_script( 'tinysort', $js_path . '/js/tinysort' . $suffix, array('jquery'), NULL, true);
//jQuery Validation plugin
wp_register_script( 'validate', 'http://ajax.microsoft.com/ajax/jquery.validate/1.9/jquery.validate' . $suffix, array('jquery'), NULL, true);
//iOS Orientation Fix
wp_register_script( 'ios-orientation-fix', $js_path . '/js/ios-orientation-fix' . $suffix, array('jquery'), NULL, false);
//Hammer.js
wp_register_script( 'hammer', $js_path . '/js/hammer' . $suffix, array('jquery'), NULL, true);
//Pew Carousel
wp_register_script( 'pew-carousel', $js_path . '/js/pew-carousel' . $suffix, array('jquery', 'hammer'), NULL, true);
//Organic Tabs
wp_register_script( 'organic-tabs', $js_path . '/js/organic-tabs' . $suffix, array('jquery'), NULL, true);
//stickyHeader - https://github.com/kingkool68/stickyHeader
wp_register_script( 'stickyHeader', $js_path . '/js/stickyHeader' . $suffix, array('jquery'), NULL, true );
//countTo - https://github.com/mhuggins/jquery-countTo
wp_register_script( 'countTo', $js_path . '/js/countTo' . $suffix, array('jquery'), NULL, true );
//The nav script for making the open and closing of menus on smaller screens work.
wp_register_script( 'nav', $js_path . '/js/nav.js', array('jquery'), NULL, true );
//jVector Map
wp_register_script( 'jvectormap', $js_path . '/js/jvectormap' . $suffix, array('jquery'), NULL, true);
wp_register_script( 'world-map-mercator', $js_path . '/js/jvectormap-world-mercator.min.js', array('jvectormap'), NULL, true);
wp_register_script( 'world-map-miller', $js_path . '/js/jvectormap-world-miller.min.js', array('jvectormap'), NULL, true);
wp_register_script( 'europe-map-mercator', $js_path . '/js/jvectormap-europe-mercator.min.js', array('jvectormap'), NULL, true);
wp_register_script( 'europe-map-miller', $js_path . '/js/jvectormap-europe-miller.min.js', array('jvectormap'), NULL, true);
wp_register_script( 'usa-map-lambert', $js_path . '/js/jvectormap-usa-lambert.min.js', array('jvectormap'), NULL, true);
//D3 Library
wp_register_script( 'd3', $js_path . '/js/d3.v3' . $suffix, array('jquery'), NULL, false);
wp_register_script( 'd3-sankey', $js_path . '/js/d3.sankey.js', array('d3'), NULL, false);
wp_register_script( 'd3-geo', $js_path . '/js/d3.geo.projection.v0.min.js', array('d3'), NULL, false);
wp_register_script( 'topojson', $js_path . '/js/topojson.v1.min.js', array('d3', 'd3-geo'), NULL, false);
//Pew Comments includes /wp-includes/js/comment-reply.js to reduce # of requests.
wp_register_script( 'pew-comments', $js_path . '/js/pew-comments' . $suffix, array('jquery'), NULL, true);
//Tracks events on the homepages.
wp_register_script( 'pew-event-analytics', $js_path . '/js/pew-event-analytics' . $suffix, array('jquery'), NULL, true);
//jQuery Validate plugin http://jqueryvalidation.org/
wp_register_script( 'validate', $js_path . '/js/jquery.validate' . $suffix, array('jquery'), NULL, true);
//jQuery Waypoints (http://imakewebthings.com/jquery-waypoints/)
wp_register_script( 'waypoints', $js_path . '/js/waypoints' . $suffix, array('jquery'), NULL, true);
//Modernizr.js - http://modernizr.com/
wp_register_script( 'modernizr', $js_path . '/js/modernizr' . $suffix, array('jquery'), NULL, true);
//Pew Infinite Scroll
wp_register_script( 'pew-infinite-scroll', $js_path . '/js/pew-infinite-scroll' . $suffix, array('jquery'), NULL, true);
}
add_action('init', 'pew_register_global_scripts');
function print_html5_shiv() {
//This need to come after any CSS files are loaded in the <head> in order to work properly. See https://github.com/aFarkas/html5shiv
$js_path = plugins_url() . '/pew-scripts';
?>
<!--[if lt IE 9]><script src="<?=$js_path?>/js/html5shiv-printshiv.min.js"></script><![endif]-->
<?php
}
add_action( 'wp_head', 'print_html5_shiv' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment