PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.2.0
Ever Compare – Products Compare Plugin for WooCommerce v1.2.0
1.3.7 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / includes / classes / Assets.php

Assets.php in Ever Compare – Products Compare Plugin for WooCommerce 1.2.0, at includes/classes/Assets.php

249 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EverCompare;
3 /**
4 * Assets handlers class
5 */
6 class Assets {
7
8 /**
9 * [$_instance]
10 * @var null
11 */
12 private static $_instance = null;
13
14 /**
15 * [$suffix]
16 * @var [string]
17 */
18 public $suffix = '';
19
20 /**
21 * [instance] Initializes a singleton instance
22 * @return [Base]
23 */
24 public static function instance() {
25 if ( is_null( self::$_instance ) ) {
26 self::$_instance = new self();
27 }
28 return self::$_instance;
29 }
30
31 /**
32 * Class constructor
33 */
34 private function __construct() {
35 $this->suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
36 add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
37 add_action( 'admin_enqueue_scripts', [ $this, 'register_assets' ] );
38 }
39
40 /**
41 * All available scripts
42 *
43 * @return array
44 */
45 public function get_scripts() {
46
47 $script_list = [
48 'evercompare-admin' => [
49 'src' => EVERCOMPARE_ASSETS . '/js/admin.js',
50 'version' => EVERCOMPARE_VERSION,
51 'deps' => [ 'jquery' ]
52 ],
53 'evercompare-frontend' => [
54 'src' => EVERCOMPARE_ASSETS . '/js/frontend'.$this->suffix.'.js',
55 'version' => EVERCOMPARE_VERSION,
56 'deps' => [ 'jquery' ]
57 ],
58 ];
59
60 return $script_list;
61
62 }
63
64 /**
65 * All available styles
66 *
67 * @return array
68 */
69 public function get_styles() {
70
71 $style_list = [
72 'evercompare-admin' => [
73 'src' => EVERCOMPARE_ASSETS . '/css/admin.css',
74 'version' => EVERCOMPARE_VERSION,
75 ],
76 'evercompare-frontend' => [
77 'src' => EVERCOMPARE_ASSETS . '/css/frontend'.$this->suffix.'.css',
78 'version' => EVERCOMPARE_VERSION,
79 ],
80 ];
81
82 return $style_list;
83
84 }
85
86 /**
87 * Register scripts and styles
88 *
89 * @return void
90 */
91 public function register_assets() {
92 $scripts = $this->get_scripts();
93 $styles = $this->get_styles();
94
95 foreach ( $scripts as $handle => $script ) {
96 $deps = isset( $script['deps'] ) ? $script['deps'] : false;
97
98 wp_register_script( $handle, $script['src'], $deps, $script['version'], true );
99 }
100
101 foreach ( $styles as $handle => $style ) {
102 $deps = isset( $style['deps'] ) ? $style['deps'] : false;
103
104 wp_register_style( $handle, $style['src'], $deps, $style['version'] );
105 }
106
107 // Inline CSS
108 wp_add_inline_style( 'evercompare-frontend', $this->inline_style() );
109
110 // Frontend Localize data
111 $option_data = array();
112 $localize_data = array(
113 'ajaxurl' => admin_url( 'admin-ajax.php' ),
114 'popup' => ( ever_compare_get_option( 'open_popup', 'ever_compare_settings_tabs', 'on' ) === 'on' ) ? 'yes' : 'no',
115 'option_data' => $option_data,
116 );
117
118 // Admin Localize data
119 $setting_page = 0;
120 if( isset( $_GET['page'] ) && $_GET['page'] == 'evercompare' ){
121 $setting_page = 1;
122 }
123 $admin_option_data = array(
124 'shop_btn_position' => ever_compare_get_option( 'shop_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
125 'product_btn_position' => ever_compare_get_option( 'product_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
126 'button_icon_type' => ever_compare_get_option( 'button_icon_type','ever_compare_settings_tabs','none' ),
127 'added_button_icon_type'=> ever_compare_get_option( 'added_button_icon_type','ever_compare_settings_tabs','none' ),
128 'enable_shareable_link' => ever_compare_get_option( 'enable_shareable_link','ever_compare_table_settings_tabs','off' ),
129 'button_style' => ever_compare_get_option( 'button_style','ever_compare_style_tabs','theme' ),
130 'table_style' => ever_compare_get_option( 'table_style','ever_compare_style_tabs','default' ),
131 );
132 $admin_localize_data = array(
133 'is_settings'=> $setting_page,
134 'option_data'=> $admin_option_data,
135 );
136 wp_localize_script( 'evercompare-frontend', 'evercompare', $localize_data );
137 wp_localize_script( 'evercompare-admin', 'evercompare', $admin_localize_data );
138
139 }
140
141 /**
142 * [inline_style]
143 * @return [CSS String]
144 */
145 public function inline_style(){
146
147 $inline_css = '';
148
149 // Button Custom Style
150 if( 'custom' === ever_compare_get_option( 'button_style', 'ever_compare_style_tabs', 'theme' ) ){
151
152 $btn_padding = ever_compare_dimensions( 'button_custom_padding','ever_compare_style_tabs','padding' );
153 $btn_margin = ever_compare_dimensions( 'button_custom_margin','ever_compare_style_tabs','margin' );
154 $btn_border_radius = ever_compare_dimensions( 'button_custom_border_radius','ever_compare_style_tabs','border-radius' );
155 $btn_border_width = ever_compare_dimensions( 'button_custom_border','ever_compare_style_tabs','border-width' );
156 $btn_border_style = !empty( $btn_border_width ) ? 'border-style:solid;' : '';
157
158 $btn_border_color = ever_compare_generate_css('button_custom_border_color','ever_compare_style_tabs','border-color');
159 $btn_color = ever_compare_generate_css('button_color','ever_compare_style_tabs','color');
160 $btn_bg_color = ever_compare_generate_css('background_color','ever_compare_style_tabs','background-color');
161
162 // Hover
163 $btn_hover_color = ever_compare_generate_css('button_hover_color','ever_compare_style_tabs','color');
164 $btn_hover_bg_color = ever_compare_generate_css('hover_background_color','ever_compare_style_tabs','background-color');
165
166 $inline_css .= "
167 .htcompare-btn{
168 {$btn_padding}
169 {$btn_margin}
170 {$btn_color}
171 {$btn_bg_color}
172 {$btn_border_width}
173 {$btn_border_style}
174 {$btn_border_color}
175 {$btn_border_radius}
176 }
177 .htcompare-btn:hover{
178 {$btn_hover_color}
179 {$btn_hover_bg_color}
180 }
181 ";
182
183 }
184
185 // Table style
186 if( 'custom' === ever_compare_get_option( 'table_style', 'ever_compare_style_tabs', 'default' ) ){
187
188 $border_color = ever_compare_generate_css('table_border_color','ever_compare_style_tabs','border-color');
189 $column_padding = ever_compare_dimensions( 'table_column_padding','ever_compare_style_tabs','padding' );
190
191 $event_bg_color = ever_compare_generate_css('table_event_color','ever_compare_style_tabs','background-color');
192 $odd_bg_color = ever_compare_generate_css('table_odd_color','ever_compare_style_tabs','background-color');
193
194 $event_heading_color = ever_compare_generate_css('table_heading_event_color','ever_compare_style_tabs','color');
195 $odd_heading_color = ever_compare_generate_css('table_heading_odd_color','ever_compare_style_tabs','color');
196
197 $event_content_color = ever_compare_generate_css('table_content_event_color','ever_compare_style_tabs','color');
198 $odd_content_color = ever_compare_generate_css('table_content_odd_color','ever_compare_style_tabs','color');
199
200 $link_color = ever_compare_generate_css('table_content_link_color','ever_compare_style_tabs','color');
201 $link_hover_color = ever_compare_generate_css('table_content_link_hover_color','ever_compare_style_tabs','color');
202
203 $inline_css .= "
204 .htcompare-col,.compare-data-primary .htcolumn-value{
205 {$border_color}
206 }
207 .htcompare-col{
208 {$column_padding}
209 }
210
211 .htcompare-row:nth-child(2n) .htcompare-col{
212 {$event_bg_color}
213 }
214 .htcompare-row:nth-child(2n+1) .htcompare-col{
215 {$odd_bg_color}
216 }
217
218 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-field-name{
219 {$event_heading_color}
220 }
221 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-field-name{
222 {$odd_heading_color}
223 }
224
225 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-value{
226 {$event_content_color}
227 }
228 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-value{
229 {$odd_content_color}
230 }
231
232 .htcompare-row .htcompare-col.htcolumn-value a{
233 {$link_color}
234 }
235 .htcompare-row .htcompare-col.htcolumn-value a:hover{
236 {$link_hover_color}
237 }
238
239 ";
240
241 }
242
243 return $inline_css;
244
245 }
246
247
248 }
249