Skip to content

Commit 8f59b1f

Browse files
committed
fixes parisholley#3 - Ability to exclude files by filename or queue id from being loaded asynchronously
1 parent 5887bdd commit 8f59b1f

File tree

422 files changed

+5496
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+5496
-9
lines changed

README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ This plugin will not work out the box with the following plugins (unless they ar
4343

4444
== Changelog ==
4545

46+
= 1.3.0 =
47+
* Ability to exclude files by filename or queue id from being loaded asynchronously
48+
4649
= 1.2.1 =
4750
* Fixed static reference for PHP < 5.2.3
4851

asynchronous-javascript.php

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Asynchronous Javascript
44
Plugin URI: http://wordpress.org/extend/plugins/asynchronous-javascript/
55
Description: Improve page load performance by asynchronously loading javascript using head.js
6-
Version: 1.2.1
6+
Version: 1.3.0
77
Author: Paris Holley
88
Author URI: http://www.linkedin.com/in/parisholley
99
Author Email: mail@parisholley.com
@@ -25,6 +25,11 @@
2525
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2626
2727
*/
28+
29+
if(!class_exists('NHP_Options')){
30+
require_once( dirname( __FILE__ ) . '/lib/nhp/options/options.php' );
31+
}
32+
2833
class AsynchronousJS {
2934
private static $queue = array();
3035
private static $depends = array();
@@ -36,9 +41,58 @@ function init() {
3641
add_filter('script_loader_src', array('AsynchronousJS', 'filter_queue_script'), 10, 2 );
3742
add_filter('print_footer_scripts', array('AsynchronousJS', 'filter_headjs') );
3843
add_filter('print_head_scripts', array('AsynchronousJS', 'filter_headjs') );
44+
}else{
45+
add_action('init', array('AsynchronousJS', 'admin'));
3946
}
4047
}
4148

49+
function admin(){
50+
$args = array();
51+
52+
$args['share_icons']['twitter'] = array(
53+
'link' => 'http://twitter.com/parisholley',
54+
'title' => 'Folow me on Twitter',
55+
'img' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_322_twitter.png'
56+
);
57+
58+
$args['share_icons']['linked_in'] = array(
59+
'link' => 'http://www.linkedin.com/in/parisholley',
60+
'title' => 'Find me on LinkedIn',
61+
'img' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_337_linked_in.png'
62+
);
63+
64+
$args['opt_name'] = 'asyncjs';
65+
$args['menu_title'] = 'Async JS';
66+
$args['page_title'] = 'Asynchronous Javascript';
67+
$args['page_slug'] = 'asyncjs';
68+
$args['show_import_export'] = false;
69+
$args['page_position'] = 102419882;
70+
$args['dev_mode'] = false;
71+
72+
$sections = array(array(
73+
'icon' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_280_settings.png',
74+
'title' => 'Settings',
75+
'fields' => array(
76+
'exclude_name' => array(
77+
'id' => 'exclude_name',
78+
'type' => 'textarea',
79+
'title' => 'Exclude by Name',
80+
'desc' => 'Enter a comma delimited list (ie: "jquery,jqueryui").',
81+
'sub_desc' => 'The name is the key used to queue the javascript file within wordpress.'
82+
),
83+
'exclude_js' => array(
84+
'id' => 'exclude_js',
85+
'type' => 'textarea',
86+
'title' => 'Exclude by File',
87+
'desc' => 'Enter a comma delimited list (ie: "file1.js,file2.js").',
88+
'sub_desc' => 'If you do not know the script key, you exclude based on the file name.'
89+
)
90+
)
91+
));
92+
93+
new NHP_Options($sections, $args);
94+
}
95+
4296
/**
4397
* Prevent wordpress from outputing scripts to page
4498
**/
@@ -66,20 +120,39 @@ function filter_queue_script($src, $handle) {
66120
* Outputs headjs code in header or footer
67121
**/
68122
function filter_headjs(){
123+
$options = get_option('asyncjs');
124+
$names = split(',', $options['exclude_name']);
125+
$files = split(',', $options['exclude_js']);
126+
69127
if(count(self::$depends) > 0){
70-
if(!self::$head_loaded){
71-
echo '<script type="text/javascript" src="' . plugins_url( '/js/head.load.min.js', __FILE__ ) . '"></script>';
72-
73-
self::$head_loaded = true;
74-
}
75-
76128
$handles = array();
77129

78130
foreach(self::$depends as $handle => $depend){
79-
$handles[] = '{"' . $handle . '": "' . $depend['src'] . '"}';
131+
$exclude = false;
132+
133+
foreach($files as $file){
134+
if(strpos($depend['src'], $file) !== false){
135+
$exclude = true;
136+
break;
137+
}
138+
}
139+
140+
if(!in_array($handle, $names) && !$exclude){
141+
$handles[] = '{"' . $handle . '": "' . $depend['src'] . '"}';
142+
}else{
143+
echo '<script type="text/javascript" src="' . $depend['src'] . '"></script>';
144+
}
80145
}
81146

82-
echo '<script type="text/javascript">head.js(' . implode(',', $handles) . ');</script>';
147+
if(count($handles) > 0){
148+
if(!self::$head_loaded){
149+
echo '<script type="text/javascript" src="' . plugins_url( '/js/head.load.min.js', __FILE__ ) . '"></script>';
150+
151+
self::$head_loaded = true;
152+
}
153+
154+
echo '<script type="text/javascript">head.js(' . implode(',', $handles) . ');</script>';
155+
}
83156

84157
self::$depends = array();
85158
}

lib/nhp/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

lib/nhp/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# NHP Theme Options V1.0.6 #
2+
3+
Theme options framework which uses the [WordPress Settings API](http://codex.wordpress.org/Settings_API "WordPress Settings API"), Custom Error/Validation Handling, Custom Field/Validation Types (which are easily extendable), and import/export functionality.
4+
5+
## Donate to the Framework ##
6+
7+
[![Donate to the framework](https://www.paypalobjects.com/en_GB/i/btn/btn_donate_SM.gif "Donate to the framework")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GWS9DVBAWP4L4)
8+
9+
## Simple Usage ##
10+
11+
12+
Simply include the ```nhp-options.php``` file in your themes ```functions.php``` file, like so:
13+
14+
```php
15+
get_template_part('nhp', 'options');
16+
```
17+
18+
Then change the settings as written in the ```nhp-options.php``` file.
19+
20+
## Features ##
21+
22+
* Uses the [WordPress Settings API](http://codex.wordpress.org/Settings_API "WordPress Settings API")
23+
* Multiple built in field types: [View WIKI](/leemason/NHP-Theme-Options-Framework/wiki "View WIKI")
24+
* Multple layout field types: [View WIKI](/leemason/NHP-Theme-Options-Framework/wiki "View WIKI")
25+
* Fields can be over-ridden with a callback function, for custom field types
26+
* Easily extendable by creating Field Classes (more info in the [View WIKI](/leemason/NHP-Theme-Options-Framework/wiki "View WIKI"))
27+
* Built in Validation Classes: [View WIKI](/leemason/NHP-Theme-Options-Framework/wiki title="View WIKI")
28+
* Easily extendable by creating Validation Classes (more in the [View WIKI](/leemason/NHP-Theme-Options-Framework/wiki "View WIKI"))
29+
* Custom Validation error handling, including error counts for each section, and custom styling for error fields
30+
* Custom Validation warning handling, including warning counts for each section, and custom styling for warning fields
31+
* Multiple Hook Points for customisation
32+
* Import / Export Functionality - including cross site importing of settings
33+
* Easily add page help through the class
34+
* Much more

0 commit comments

Comments
 (0)