|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Auto Load Next Post: Theme Customizer Scripts |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.5.0 |
|
6
|
|
|
* @author Sébastien Dumont |
|
7
|
|
|
* @category Classes |
|
8
|
|
|
* @package Auto Load Next Post/Classes/Customizer |
|
9
|
|
|
* @license GPL-2.0+ |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
// Exit if ALNP_Customizer_Scripts class already exists. |
|
18
|
|
|
if ( !class_exists( 'ALNP_Customizer_Scripts' ) ) { |
|
19
|
|
|
|
|
20
|
|
|
class ALNP_Customizer_Scripts { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @since 1.5.0 |
|
26
|
|
|
* @access public |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() { |
|
29
|
|
|
add_action( 'customize_preview_init', array( $this, 'alnp_add_customizer_preview_scripts' ) ); |
|
30
|
|
|
add_action( 'customize_controls_print_scripts', array( $this, 'alnp_add_scripts' ), 30 ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Adds script to the previewer to send data to the customizer. |
|
35
|
|
|
* |
|
36
|
|
|
* @since 1.5.0 |
|
37
|
|
|
*/ |
|
38
|
|
|
public function alnp_add_customizer_preview_scripts() { |
|
39
|
|
|
Auto_Load_Next_Post::load_file( 'alnp-theme-customizer', '/assets/js/customizer/theme-customizer.js', true, array( 'customize-preview' ), '', true ); |
|
40
|
|
|
} // END alnp_add_customizer_preview_scripts() |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Adds script to help the controls in the customizer. |
|
44
|
|
|
* |
|
45
|
|
|
* @since 1.5.0 |
|
46
|
|
|
*/ |
|
47
|
|
|
public function alnp_add_scripts() { |
|
48
|
|
|
?> |
|
49
|
|
|
<script type="text/javascript"> |
|
50
|
|
|
jQuery( document ).ready( function( $ ) { |
|
51
|
|
|
'use strict'; |
|
52
|
|
|
|
|
53
|
|
|
var is_page_single = false; // Is the page the user viewing a single post? |
|
54
|
|
|
|
|
55
|
|
|
wp.customize.bind( 'ready', function() { |
|
56
|
|
|
wp.customize.previewer.bind( 'alnp_is_page_single', function( data ) { |
|
57
|
|
|
is_page_single = data; // Returns response and updates variable. |
|
58
|
|
|
} ); |
|
59
|
|
|
} ); |
|
60
|
|
|
|
|
61
|
|
|
// Auto Load Next Post Theme Selectors Section. |
|
62
|
|
|
wp.customize.section( 'auto_load_next_post_theme_selectors', function( section ) { |
|
63
|
|
|
section.expanded.bind( function( isExpanded ) { |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Load a random post if the theme selectors section is expanded |
|
67
|
|
|
* but we are not viewing a single post. |
|
68
|
|
|
*/ |
|
69
|
|
|
if ( isExpanded && !is_page_single ) { |
|
70
|
|
|
wp.customize.previewer.previewUrl.set( '<?php echo esc_js( alnp_get_random_page_permalink() ); ?>' ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} ); |
|
74
|
|
|
} ); |
|
75
|
|
|
} ); |
|
76
|
|
|
</script> |
|
77
|
|
|
<?php |
|
78
|
|
|
} // END alnp_add_scripts() |
|
79
|
|
|
|
|
80
|
|
|
} // END class |
|
81
|
|
|
|
|
82
|
|
|
} // END if class exists. |
|
83
|
|
|
|
|
84
|
|
|
new ALNP_Customizer_Scripts(); |
|
85
|
|
|
|