PluginProbe
Orderable – Restaurant & Food Ordering System / 0.2.0
Orderable – Restaurant & Food Ordering System v0.2.0
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 0.2.0, at inc/class-assets.php

139 lines 5.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
33 wp_enqueue_style( 'orderable', ORDERABLE_ASSETS_URL . 'frontend/css/main' . $suffix . '.css', array(), ORDERABLE_VERSION );
34 wp_enqueue_script( 'orderable', ORDERABLE_ASSETS_URL . 'frontend/js/main' . $suffix . '.js', array( 'jquery' ), ORDERABLE_VERSION, true );
35
36 wp_add_inline_style( 'orderable', self::get_styles() );
37
38 wp_localize_script( 'orderable', 'orderable_vars', array(
39 'i18n' => array(
40 'out_of_stock' => __( 'Sorry, that product is out of stock.', 'orderable' ),
41 'unavailable' => __( 'Sorry, that product is unavailable.', 'orderable' ),
42 'no_exist' => __( 'Sorry, that combination does not exist.', 'orderable' ),
43 ),
44 ) );
45
46 do_action( 'orderable_after_frontend_assets' );
47 }
48
49 /**
50 * Get styles from settings.
51 *
52 * @return string
53 */
54 public static function get_styles() {
55 $brand_color = Orderable_Settings::get_setting( 'style_style_color' );
56 $product_title_font_size = Orderable_Settings::get_setting( 'style_products_title_size' );
57 $product_title_line_height = $product_title_font_size * 1.2;
58 $product_price_font_size = Orderable_Settings::get_setting( 'style_products_price_size' );
59 $product_price_line_height = $product_price_font_size * 1.2;
60
61 $styles = array(
62 '.orderable-button { color: %1$s; border-color: %1$s; }',
63 '.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; }',
64 '.orderable-tabs__item--active a.orderable-tabs__link { background: %1$s !important; }',
65 '.orderable-button--filled, .orderable-drawer__cart .orderable-mini-cart__buttons .button.checkout { border-color: %1$s; background: %1$s !important; color: #fff; }',
66 '.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; }',
67 '.orderable-button--loading:after { border-top-color: %1$s; border-left-color: %1$s; }',
68 '.orderable-product-option--checked .orderable-product-option__label-state { border-color: %1$s !important; }',
69 ".orderable-product__title { font-size: {$product_title_font_size}px; line-height: {$product_title_line_height}px; }",
70 ".orderable-product__actions-price .amount { font-size: {$product_price_font_size}px; line-height: {$product_price_line_height}px; }",
71 );
72
73 return apply_filters( 'orderable_styles', sprintf( implode( '', $styles ), $brand_color ) );
74 }
75
76 /**
77 * Admin assets.
78 */
79 public static function admin_assets() {
80 if ( ! is_admin() || ! Orderable_Settings::is_settings_page() ) {
81 return;
82 }
83
84 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
85
86 wp_enqueue_style( 'orderable', ORDERABLE_ASSETS_URL . 'admin/css/main' . $suffix . '.css', array(), ORDERABLE_VERSION );
87 wp_enqueue_style( 'select2', ORDERABLE_ASSETS_URL . 'vendor/select2/select2' . $suffix . '.css', array(), ORDERABLE_VERSION );
88
89 wp_enqueue_script( 'orderable-select2', ORDERABLE_ASSETS_URL . 'vendor/select2/select2' . $suffix . '.js', array( 'jquery' ), ORDERABLE_VERSION );
90 wp_enqueue_script( 'orderable-jquery-multi-select', ORDERABLE_ASSETS_URL . 'vendor/jquery-multi-select/jquery.multi-select' . $suffix . '.js', array( 'jquery' ), ORDERABLE_VERSION );
91 wp_enqueue_script( 'orderable', ORDERABLE_ASSETS_URL . 'admin/js/main' . $suffix . '.js', array( 'jquery' ), ORDERABLE_VERSION );
92 }
93
94 /**
95 * Add body classes.
96 *
97 * @param array $classes
98 *
99 * @return array
100 */
101 public static function body_class( $classes = array() ) {
102 if ( $button_style = Orderable_Settings::get_setting( 'style_style_buttons' ) ) {
103 $classes[] = sprintf( 'orderable--button-style-%s', $button_style );
104 }
105
106 return $classes;
107 }
108
109 /**
110 * Adjust brightness of hex.
111 *
112 * @param string $hex
113 * @param int $steps
114 *
115 * @return string
116 */
117 public static function adjust_hex( $hex, $steps ) {
118 // Steps should be between -255 and 255. Negative = darker, positive = lighter
119 $steps = max( - 255, min( 255, $steps ) );
120
121 // Normalize into a six character long hex string
122 $hex = str_replace( '#', '', $hex );
123 if ( strlen( $hex ) == 3 ) {
124 $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
125 }
126
127 // Split into three parts: R, G and B
128 $color_parts = str_split( $hex, 2 );
129 $return = '#';
130
131 foreach ( $color_parts as $color ) {
132 $color = hexdec( $color ); // Convert to decimal
133 $color = max( 0, min( 255, $color + $steps ) ); // Adjust color
134 $return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
135 }
136
137 return $return;
138 }
139 }