Passed
Push — master ( 689fa7...f96565 )
by Fernando
02:57
created

scripts.php ➔ lsx_scripts_child_theme()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) return; // Exit if accessed directly
3
4
/**
5
 * Enqueue scripts and styles.
6
 *
7
 * @package 	lsx
8
 * @subpackage	scripts
9
 */
10
function lsx_scripts() {
11
	global $content_width;
12
	
13
	wp_enqueue_style('lsx_main_style', get_template_directory_uri() . '/style.css', array(), LSX_VERSION);
14
	
15
	wp_enqueue_style('lsx_main', get_template_directory_uri() . '/css/app.css', array( 'lsx_main_style', 'fontawesome', 'medium-break' ), LSX_VERSION);
16
	
17
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
18
		wp_enqueue_script( 'comment-reply' );
19
	}
20
21
	wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/vendor/bootstrap.min.js', array('jquery'), LSX_VERSION, false);
22
	wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/vendor/modernizr-2.7.0.min.js', array('jquery'), LSX_VERSION, false);
23
	wp_enqueue_script('mousewheel', get_template_directory_uri() . '/js/vendor/jquery.mousewheel.min.js', array('jquery'), LSX_VERSION, false);
24
	wp_enqueue_script('smoothscroll', get_template_directory_uri() . '/js/vendor/jquery.simplr.smoothscroll.min.js', array('jquery'), LSX_VERSION, false);
25
	wp_enqueue_script('sticky', get_template_directory_uri() . '/js/vendor/jquery.sticky.min.js', array('jquery'), LSX_VERSION, false);
26
	wp_enqueue_script('picturefill', get_template_directory_uri() . '/js/vendor/picturefill.min.js', array(), LSX_VERSION, false);
27
28
	wp_enqueue_script('masonry');
29
	wp_enqueue_script('imagesLoaded', get_template_directory_uri().'/js/vendor/imagesloaded.pkgd.min.js', array('jquery','masonry'), LSX_VERSION);	
30
	if(defined('WP_DEBUG') && true === WP_DEBUG){
31
		wp_enqueue_script('lsx_script', get_template_directory_uri() . '/js/lsx-script.js', array('masonry'), LSX_VERSION, false);
32
	}else{
33
		wp_enqueue_script('lsx_script', get_template_directory_uri() . '/js/lsx-script.min.js', array('masonry'), LSX_VERSION, false);
34
	}
35
	
36
	//Set some parameters that we can use in the JS
37
	$is_portfolio = false;
38
	if(is_post_type_archive('jetpack-portfolio') || is_tax('jetpack-portfolio-type') || is_tax('jetpack-portfolio-tag') || is_page_template('page-templates/template-portfolio.php')){
39
		$is_portfolio = true;
40
	}
41
	$param_array = array(
42
			'is_portfolio' => $is_portfolio
43
	);
44
	//Set the columns for the archives
45
	$param_array['columns'] = apply_filters('lsx_archive_column_number',3);
46
	wp_localize_script( 'lsx_script', 'lsx_params', $param_array );
47
48
	wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), LSX_VERSION );
49
	
50
	wp_enqueue_style('medium-break', get_template_directory_uri() . '/css/medium-nav-break.css', array(), LSX_VERSION);
51
	
52
	$font = get_theme_mod('lsx_font','raleway_open_sans');
53
	switch($font){
54
		case 'raleway_open_sans':
55
			$header_font_location = 'Raleway';
56
			$body_font_location = 'Open+Sans';
57
		break;
58
59
		case 'noto_serif_noto_sans':
60
			$header_font_location = 'Noto+Serif';
61
			$body_font_location = 'Noto+Sans';
62
		break;
63
		
64
		case 'noto_sans_noto_sans':
65
			$header_font_location = 'Noto+Sans';
66
			$body_font_location = 'Noto+Sans';
67
		break;		
68
69
		case 'alegreya_open_sans':
70
			$header_font_location = 'Alegreya';
71
			$body_font_location = 'Open+Sans';
72
		break;	
73
				
74
		//raleway_open_sans
75
		default:
76
			$header_font_location = 'Raleway'; 
77
			$body_font_location = 'Open+Sans';
78
		break;
79
	}
80
	
81
	$http_var = 'http';
82
	if(is_ssl()){ $http_var .= 's'; }
83
	
84
	//Call the Google Fonts and then Enque them.
85
	wp_register_style('lsx-header-font', $http_var.'://fonts.googleapis.com/css?family='.$header_font_location);
86
	wp_register_style('lsx-body-font', $http_var.'://fonts.googleapis.com/css?family='.$body_font_location);
87
	wp_enqueue_style( 'lsx-header-font' );
88
	wp_enqueue_style( 'lsx-body-font' );
89
	
90
	wp_enqueue_style('lsx_font_scheme', esc_url( get_template_directory_uri() . '/css/'.$font.'.css' ), array(), LSX_VERSION);
91
	
92
}
93
add_action( 'wp_enqueue_scripts', 'lsx_scripts' );
94
95
/**
96
 * Enqueue scripts and styles (for child theme).
97
 *
98
 * @package 	lsx
99
 * @subpackage	scripts
100
 */
101
function lsx_scripts_child_theme() {
102
	global $content_width;
103
	if(is_child_theme() && file_exists(get_stylesheet_directory() . '/custom.css')) {
104
		wp_enqueue_style( 'child-css', get_stylesheet_directory_uri() . '/custom.css', array( 'lsx_main' ), LSX_VERSION );
105
	}
106
}
107
add_action( 'wp_enqueue_scripts', 'lsx_scripts_child_theme', 1999 );
108
109
/**
110
 * Defer JavaScript
111
 *
112
 * @package 	lsx
113
 * @subpackage	scripts
114
 */
115
function lsx_scripts_defer_parsing( $url ) {
116
	if ( ! ( is_admin() ) ) {
117
		if ( FALSE === strpos( $url, '.js' ) ) return $url;
118
		if ( strpos( $url, 'jquery.js' ) ) return $url;
119
		if ( strpos( $url, ' defer ' ) ) return $url;
120
		return "$url' defer onload='";
121
	}
122
123
	return $url;
124
}
125
add_filter( 'clean_url', 'lsx_scripts_defer_parsing', 11, 1 );
126