Skip to content

Commit 063d293

Browse files
committed
Refactor class into a separate file
Stops using the half-implemented Singleton pattern for the class.
1 parent 89e58f3 commit 063d293

File tree

2 files changed

+67
-75
lines changed

2 files changed

+67
-75
lines changed

genesis-js-no-js.php

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* elements depending if JavaScript is active or not.
1111
*
1212
* @package GenesisJsNoJs
13-
* @author Gary Jones, Gamajo Tech <gamajo@gamajo.com>
14-
* @license GPL-2.0+
13+
* @author Gary Jones
1514
* @link https://github.com/GaryJones/genesis-js-no-js
16-
* @copyright 2014 Gary Jones, Gamajo Tech
15+
* @copyright 2011 Gary Jones, Gamajo Tech
16+
* @license GPL-2.0+
1717
*
1818
* @wordpress-plugin
1919
* Plugin Name: Genesis js / no-js
@@ -30,76 +30,7 @@
3030
* GitHub Branch: master
3131
*/
3232

33-
/**
34-
* Plugin class for Genesis js / no-js
35-
*
36-
* @package GenesisJsNoJs
37-
*/
38-
class Genesis_Js_No_Js {
39-
40-
/**
41-
* Holds copy of instance, so other plugins can remove our hooks.
42-
*
43-
* @since 1.0.0
44-
* @link http://core.trac.wordpress.org/attachment/ticket/16149/query-standard-format-posts.php
45-
* @link http://twitter.com/#!/markjaquith/status/66862769030438912
46-
*
47-
* @var Genesis_Js_No_Js
48-
*/
49-
static $instance;
50-
51-
/**
52-
* Constructor.
53-
*
54-
* @since 1.0.0
55-
*/
56-
public function __construct() {
57-
self::$instance = $this;
58-
add_action( 'init', array( &$this, 'init' ) );
59-
}
60-
61-
/**
62-
* Add action and filter.
63-
*
64-
* @since 1.0.0
65-
*/
66-
public function init() {
67-
add_filter( 'body_class', array( $this, 'body_class' ) );
68-
add_action( 'genesis_before', array( $this, 'script' ), 1 );
69-
}
70-
71-
/**
72-
* Add 'no-js' class to the body class values.
73-
*
74-
* @since 1.0.0
75-
*
76-
* @param array $classes Existing classes
77-
* @return array
78-
*/
79-
public function body_class( $classes ) {
80-
$classes[] = 'no-js';
81-
return $classes;
82-
}
83-
84-
/**
85-
* Echo out the script that changes 'no-js' class to 'js'.
86-
*
87-
* @since 1.0.0
88-
*/
89-
public function script() {
90-
?>
91-
<script type="text/javascript">
92-
//<![CDATA[
93-
(function(){
94-
var c = document.body.className;
95-
c = c.replace(/no-js/, 'js');
96-
document.body.className = c;
97-
})();
98-
//]]>
99-
</script>
100-
<?php
101-
}
102-
103-
}
33+
require plugin_dir_path( __FILE__ ) . 'includes/class-genesis-js-no-js.php';
10434

105-
new Genesis_Js_No_Js;
35+
$genesis_js_no_js = new Genesis_Js_No_Js;
36+
$genesis_js_no_js->run();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Genesis Header Nav
4+
*
5+
* @package GenesisJsNoJs
6+
* @author Gary Jones
7+
* @link https://github.com/GaryJones/genesis-header-nav
8+
* @copyright 2011 Gary Jones, Gamajo Tech
9+
* @license GPL-2.0+
10+
*/
11+
12+
/**
13+
* Plugin class.
14+
*
15+
* @package GenesisJsNoJs
16+
* @author Gary Jones
17+
*/
18+
class Genesis_Js_No_Js {
19+
20+
/**
21+
* Add action and filter.
22+
*
23+
* @since 1.0.0
24+
*/
25+
public function run() {
26+
add_filter( 'body_class', array( $this, 'body_class' ) );
27+
add_action( 'genesis_before', array( $this, 'script' ), 1 );
28+
}
29+
30+
/**
31+
* Add 'no-js' class to the body class values.
32+
*
33+
* @since 1.0.0
34+
*
35+
* @param array $classes Existing classes
36+
* @return array
37+
*/
38+
public function body_class( $classes ) {
39+
$classes[] = 'no-js';
40+
return $classes;
41+
}
42+
43+
/**
44+
* Echo out the script that changes 'no-js' class to 'js'.
45+
*
46+
* @since 1.0.0
47+
*/
48+
public function script() {
49+
?>
50+
<script type="text/javascript">
51+
//<![CDATA[
52+
(function(){
53+
var c = document.body.className;
54+
c = c.replace(/no-js/, 'js');
55+
document.body.className = c;
56+
})();
57+
//]]>
58+
</script>
59+
<?php
60+
}
61+
}

0 commit comments

Comments
 (0)