PluginProbe
Orderable – Restaurant & Food Ordering System / 1.17.1
Orderable – Restaurant & Food Ordering System v1.17.1
0.1.4 0.1.5 0.2.0 1.0.0 1.1.0 1.1.1 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.19.1 1.19.2 1.2.0 1.20.0 1.20.1 All 44 releases
orderable / inc / class-assets.php

class-assets.php in Orderable – Restaurant & Food Ordering System 1.17.1, at inc/class-assets.php

167 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Script and style assets.
4 *
5 * @package Orderable/Classes
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Assets class.
12 */
13 class Orderable_Assets {
14 /**
15 * Run.
16 */
17 public static function run() {
18 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'frontend_assets' ) );
19 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_assets' ) );
20 add_filter( 'body_class', array( __CLASS__, 'body_class' ) );
21 }
22
23 /**
24 * Frontend assets.
25 */
26 public static function frontend_assets() {
27 if ( is_admin() ) {
28 return;
29 }
30
31 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
32 $suffix_css = ( is_rtl() ? '-rtl' : '' ) . $suffix;
33
34 wp_enqueue_style( 'orderable', ORDERABLE_ASSETS_URL . 'frontend/css/main' . $suffix_css . '.css', array(), ORDERABLE_VERSION );
35 wp_enqueue_script( 'orderable', ORDERABLE_ASSETS_URL . 'frontend/js/main' . $suffix . '.js', array( 'jquery', 'wc-add-to-cart' ), ORDERABLE_VERSION, true );
36
37 wp_add_inline_style( 'orderable', self::get_styles() );
38
39 wp_localize_script(
40 'orderable',
41 'orderable_vars',
42 array(
43 'i18n' => array(
44 'out_of_stock' => __( 'Sorry, that product is out of stock.', 'orderable' ),
45 'unavailable' => __( 'Sorry, that product is unavailable.', 'orderable' ),
46 'no_exist' => __( 'Sorry, that combination does not exist.', 'orderable' ),
47 ),
48 'ajax_url' => WC()->ajax_url(),
49 /**
50 * If the option "Enable AJAX add to cart buttons on archives" is not enabled,
51 * we need to turn off the click event for .add_to_cart_button elements on drawer.js
52 * to keep the AJAX behaviour only on Mini cart.
53 */
54 'woocommerce_enable_ajax_add_to_cart' => 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ),
55 )
56 );
57
58 do_action( 'orderable_after_frontend_assets' );
59 }
60
61 /**
62 * Get styles from settings.
63 *
64 * @return string
65 */
66 public static function get_styles() {
67 $brand_color = Orderable_Settings::get_setting( 'style_style_color' );
68 $product_title_font_size = Orderable_Settings::get_setting( 'style_products_title_size' );
69 $product_title_line_height = $product_title_font_size * 1.2;
70 $product_price_font_size = Orderable_Settings::get_setting( 'style_products_price_size' );
71 $product_price_line_height = $product_price_font_size * 1.2;
72
73 $styles = array(
74 '.orderable-button { color: %1$s; border-color: %1$s; }',
75 '.orderable-button--hover, .orderable-button:hover, .orderable-button:active, .orderable-button--active, .orderable-button:focus { border-color: %1$s; background: %1$s !important; color: #fff; }',
76 '.orderable-tabs__item--active a.orderable-tabs__link { background: %1$s !important; }',
77 '.orderable-button--filled, .orderable-drawer__cart .orderable-mini-cart__buttons .button.checkout { border-color: %1$s; background: %1$s !important; color: #fff; }',
78 '.orderable-button--filled.orderable-button--hover, .orderable-button--filled:hover, .orderable-button--filled:active, .orderable-button--filled:focus, .orderable-drawer__cart .orderable-mini-cart__buttons .button.checkout:hover, .orderable-drawer__cart .orderable-mini-cart__buttons .button.checkout:active, .orderable-drawer__cart .orderable-mini-cart__buttons .button.checkout:focus { border-color: %1$s; background: %1$s !important; }',
79 '.orderable-button--loading:after { border-top-color: %1$s; border-left-color: %1$s; }',
80 '.orderable-product-option--checked .orderable-product-option__label-state { border-color: %1$s !important; }',
81 ".orderable-products-list .orderable-product__title { font-size: {$product_title_font_size}px; line-height: {$product_title_line_height}px; }",
82 ".orderable-product__actions-price .amount { font-size: {$product_price_font_size}px; line-height: {$product_price_line_height}px; }",
83 );
84
85 return apply_filters( 'orderable_styles', sprintf( implode( '', $styles ), $brand_color ) );
86 }
87
88 /**
89 * Admin assets.
90 */
91 public static function admin_assets() {
92 if ( ! is_admin() || ! Orderable_Settings::is_settings_page() ) {
93 return;
94 }
95
96 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
97 $style_deps = apply_filters( 'orderable_admin_style_deps', array( 'wc-admin-layout' ) );
98 $script_deps = apply_filters( 'orderable_admin_script_deps', array( 'jquery' ) );
99
100 wp_enqueue_style( 'orderable', ORDERABLE_ASSETS_URL . 'admin/css/main' . $suffix . '.css', $style_deps, ORDERABLE_VERSION );
101 wp_enqueue_style( 'select2', ORDERABLE_ASSETS_URL . 'vendor/select2/select2' . $suffix . '.css', array(), ORDERABLE_VERSION );
102
103 wp_enqueue_media();
104 wp_enqueue_script( 'orderable-select2', ORDERABLE_ASSETS_URL . 'vendor/select2/select2' . $suffix . '.js', $script_deps, ORDERABLE_VERSION );
105 wp_enqueue_script( 'orderable-jquery-multi-select', ORDERABLE_ASSETS_URL . 'vendor/jquery-multi-select/jquery.multi-select' . $suffix . '.js', array( 'jquery' ), ORDERABLE_VERSION );
106 wp_enqueue_script( 'orderable', ORDERABLE_ASSETS_URL . 'admin/js/main' . $suffix . '.js', array( 'jquery' ), ORDERABLE_VERSION );
107
108 wp_localize_script(
109 'orderable',
110 'orderable_vars',
111 array(
112 'i18n' => array(
113 'confirm_remove_service_hours' => __( 'Are you sure you want to remove these service hours?', 'orderable' ),
114 ),
115 )
116 );
117
118 do_action( 'orderable_admin_assets_enqueued' );
119 }
120
121 /**
122 * Add body classes.
123 *
124 * @param array $classes
125 *
126 * @return array
127 */
128 public static function body_class( $classes = array() ) {
129 if ( $button_style = Orderable_Settings::get_setting( 'style_style_buttons' ) ) {
130 $classes[] = sprintf( 'orderable--button-style-%s', $button_style );
131 }
132
133 return $classes;
134 }
135
136 /**
137 * Adjust brightness of hex.
138 *
139 * @param string $hex
140 * @param int $steps
141 *
142 * @return string
143 */
144 public static function adjust_hex( $hex, $steps ) {
145 // Steps should be between -255 and 255. Negative = darker, positive = lighter
146 $steps = max( - 255, min( 255, $steps ) );
147
148 // Normalize into a six character long hex string
149 $hex = str_replace( '#', '', $hex );
150 if ( strlen( $hex ) == 3 ) {
151 $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
152 }
153
154 // Split into three parts: R, G and B
155 $color_parts = str_split( $hex, 2 );
156 $return = '#';
157
158 foreach ( $color_parts as $color ) {
159 $color = hexdec( $color ); // Convert to decimal
160 $color = max( 0, min( 255, $color + $steps ) ); // Adjust color
161 $return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
162 }
163
164 return $return;
165 }
166 }
167