PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.2.6
Ever Compare – Products Compare Plugin for WooCommerce v1.2.6
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.6, at includes/classes/Assets.php

283 lines 11.6 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 'remove_on_click' => ever_compare_get_option( 'remove_on_click','ever_compare_settings_tabs', 'off' ),
113 'enable_success_notification' => ever_compare_get_option( 'enable_success_notification', 'ever_compare_settings_general', 'off' ),
114 'success_added_notification_text' => ever_compare_get_option( 'success_added_notification_text', 'ever_compare_settings_general', __( '{product_name} added to wishlist.', 'ever-compare') ),
115 'success_removed_notification_text' => ever_compare_get_option( 'success_removed_notification_text', 'ever_compare_settings_general', __( '{product_name} removed from wishlist.', 'ever-compare') ),
116 'removed_notification_after' => ever_compare_get_option( 'removed_notification_after', 'ever_compare_settings_general', -1 ),
117 );
118 $localize_data = array(
119 'ajaxurl' => admin_url( 'admin-ajax.php' ),
120 'popup' => ( ever_compare_get_option( 'open_popup', 'ever_compare_settings_tabs', 'on' ) === 'on' ) ? 'yes' : 'no',
121 'option_data' => $option_data,
122 );
123
124 // Admin Localize data
125 $setting_page = 0;
126 if( isset( $_GET['page'] ) && $_GET['page'] == 'evercompare' ){
127 $setting_page = 1;
128 }
129 $admin_option_data = array(
130 'enable_success_notification' => ever_compare_get_option( 'enable_success_notification','ever_compare_settings_general','off' ),
131 'shop_btn_position' => ever_compare_get_option( 'shop_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
132 'product_btn_position' => ever_compare_get_option( 'product_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
133 'remove_on_click' => ever_compare_get_option( 'remove_on_click','ever_compare_settings_tabs', 'off' ),
134 'button_icon_type' => ever_compare_get_option( 'button_icon_type','ever_compare_settings_tabs','none' ),
135 'added_button_icon_type' => ever_compare_get_option( 'added_button_icon_type','ever_compare_settings_tabs','none' ),
136 'enable_shareable_link' => ever_compare_get_option( 'enable_shareable_link','ever_compare_table_settings_tabs','off' ),
137 'button_style' => ever_compare_get_option( 'button_style','ever_compare_style_tabs','theme' ),
138 'table_style' => ever_compare_get_option( 'table_style','ever_compare_style_tabs','default' ),
139 'notification_style' => ever_compare_get_option( 'notification_style','ever_compare_style_tabs','default' ),
140 );
141 $admin_localize_data = array(
142 'is_settings'=> $setting_page,
143 'option_data'=> $admin_option_data,
144 );
145 wp_localize_script( 'evercompare-frontend', 'evercompare', $localize_data );
146 wp_localize_script( 'evercompare-admin', 'evercompare', $admin_localize_data );
147
148 }
149
150 /**
151 * [inline_style]
152 * @return [CSS String]
153 */
154 public function inline_style(){
155
156 $inline_css = '';
157
158 // Button Custom Style
159 if( 'custom' === ever_compare_get_option( 'button_style', 'ever_compare_style_tabs', 'theme' ) ){
160
161 $btn_padding = ever_compare_dimensions( 'button_custom_padding','ever_compare_style_tabs','padding' );
162 $btn_margin = ever_compare_dimensions( 'button_custom_margin','ever_compare_style_tabs','margin' );
163 $btn_border_radius = ever_compare_dimensions( 'button_custom_border_radius','ever_compare_style_tabs','border-radius' );
164 $btn_border_width = ever_compare_dimensions( 'button_custom_border','ever_compare_style_tabs','border-width' );
165 $btn_border_style = !empty( $btn_border_width ) ? 'border-style:solid;' : '';
166
167 $btn_border_color = ever_compare_generate_css('button_custom_border_color','ever_compare_style_tabs','border-color');
168 $btn_color = ever_compare_generate_css('button_color','ever_compare_style_tabs','color');
169 $btn_bg_color = ever_compare_generate_css('background_color','ever_compare_style_tabs','background-color');
170
171 // Hover
172 $btn_hover_color = ever_compare_generate_css('button_hover_color','ever_compare_style_tabs','color');
173 $btn_hover_bg_color = ever_compare_generate_css('hover_background_color','ever_compare_style_tabs','background-color');
174
175 $inline_css .= "
176 .htcompare-btn{
177 {$btn_padding}
178 {$btn_margin}
179 {$btn_color}
180 {$btn_bg_color}
181 {$btn_border_width}
182 {$btn_border_style}
183 {$btn_border_color}
184 {$btn_border_radius}
185 }
186 .htcompare-btn:hover{
187 {$btn_hover_color}
188 {$btn_hover_bg_color}
189 }
190 ";
191
192 }
193
194 // Table style
195 if( 'custom' === ever_compare_get_option( 'table_style', 'ever_compare_style_tabs', 'default' ) ){
196
197 $border_color = ever_compare_generate_css('table_border_color','ever_compare_style_tabs','border-color');
198 $column_padding = ever_compare_dimensions( 'table_column_padding','ever_compare_style_tabs','padding' );
199
200 $event_bg_color = ever_compare_generate_css('table_event_color','ever_compare_style_tabs','background-color');
201 $odd_bg_color = ever_compare_generate_css('table_odd_color','ever_compare_style_tabs','background-color');
202
203 $event_heading_color = ever_compare_generate_css('table_heading_event_color','ever_compare_style_tabs','color');
204 $odd_heading_color = ever_compare_generate_css('table_heading_odd_color','ever_compare_style_tabs','color');
205
206 $event_content_color = ever_compare_generate_css('table_content_event_color','ever_compare_style_tabs','color');
207 $odd_content_color = ever_compare_generate_css('table_content_odd_color','ever_compare_style_tabs','color');
208
209 $link_color = ever_compare_generate_css('table_content_link_color','ever_compare_style_tabs','color');
210 $link_hover_color = ever_compare_generate_css('table_content_link_hover_color','ever_compare_style_tabs','color');
211
212 $inline_css .= "
213 .htcompare-col,.compare-data-primary .htcolumn-value{
214 {$border_color}
215 }
216 .htcompare-col{
217 {$column_padding}
218 }
219
220 .htcompare-row:nth-child(2n) .htcompare-col{
221 {$event_bg_color}
222 }
223 .htcompare-row:nth-child(2n+1) .htcompare-col{
224 {$odd_bg_color}
225 }
226
227 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-field-name{
228 {$event_heading_color}
229 }
230 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-field-name{
231 {$odd_heading_color}
232 }
233
234 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-value{
235 {$event_content_color}
236 }
237 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-value{
238 {$odd_content_color}
239 }
240
241 .htcompare-row .htcompare-col.htcolumn-value a{
242 {$link_color}
243 }
244 .htcompare-row .htcompare-col.htcolumn-value a:hover{
245 {$link_hover_color}
246 }
247
248 ";
249
250 }
251
252 // Notification Custom Style
253 if( 'custom' === ever_compare_get_option( 'notification_style', 'ever_compare_style_tabs', 'default' ) ){
254 $notification_color = ever_compare_generate_css('notification_text_color','ever_compare_style_tabs','color');
255 $notification_bg_color = ever_compare_generate_css('notification_bg_color','ever_compare_style_tabs','background-color');
256 $notification_border_color = ever_compare_generate_css('notification_border_color','ever_compare_style_tabs','border-color');
257 $notification_btn_color = ever_compare_generate_css('notification_btn_color','ever_compare_style_tabs','color');
258 $notification_btn_color_hover = ever_compare_generate_css('notification_btn_color_hover','ever_compare_style_tabs','color');
259
260 $inline_css .= "
261 .htcompare-notification{
262 {$notification_bg_color}
263 {$notification_border_color}
264 }
265 .htcompare-notification-text{
266 {$notification_color}
267 }
268 .htcompare-notification-close{
269 {$notification_btn_color}
270 }
271 .htcompare-notification-close:hover{
272 {$notification_btn_color_hover}
273 }
274 ";
275 }
276
277 return $inline_css;
278
279 }
280
281
282 }
283