layers_inline_button_styles
The Layers layers inline button styles function.
Description
layers_inline_button_styles( (constant) $container_id = NULL, (string) $type = 'background', (array) $args = array() );
Parameters (3)
- 0. $container_id — Optional. (constant) =>
NULL
- The container id.
- 1. $type — Optional. (string) =>
'background'
- The type.
- 2. $args — Optional. (array) =>
array()
- The args.
Usage
if ( !function_exists( 'layers_inline_button_styles' ) ) { require_once '/core/helpers/template.php'; } // The container id. $container_id = NULL; // The type. $type = 'background'; // The args. $args = array(); // NOTICE! Understand what this does before running. $result = layers_inline_button_styles($container_id, $type, $args);
Defined (1)
The function is defined in the following location(s).
- /core/helpers/template.php
- function layers_inline_button_styles( $container_id = NULL, $type = 'background' , $args = array() ) {
- $styles = '';
- // Auto text color based on background color
- if( isset( $args[ 'button' ][ 'background-color' ] ) && NULL !== layers_is_light_or_dark( $args[ 'button' ][ 'background-color' ] ) ) {
- // temporarily darken the background color, so we only switch text color if very light
- $background_darker = layers_hex_darker( $args[ 'button' ][ 'background-color' ], 28 );
- if ( 'light' == layers_is_light_or_dark( $background_darker ) ) {
- $args['button']['color'] = 'rgba(0, 0, 0, .85)';
- }
- else if ( 'dark' == layers_is_light_or_dark( $background_darker ) ) {
- $args['button']['color'] = '#FFFFFF';
- }
- // Add styling for the standard colors
- $styles .= layers_inline_styles( $container_id, $type, $args );
- }
- // Add styling for the hover colors
- if( isset( $args['selectors'] ) ) {
- if ( ! is_array( $args['selectors'] ) ) {
- // Make sure selectors is array if comma seperated string is passed
- $args['selectors'] = explode( ', ', $args['selectors'] );
- $args['selectors'] = array_map( 'trim', $args['selectors'] );
- }
- $hover_args = $args;
- foreach( $args['selectors'] as $selector ) {
- $new_selectors[] = $selector . ':hover';
- }
- $hover_args['selectors'] = $new_selectors;
- }
- // Generate a lighter text background color
- if( isset( $args[ 'button' ][ 'background-color' ] ) ) {
- $hover_args[ 'button' ]['background-color'] = layers_hex_lighter( $args[ 'button' ][ 'background-color' ] );
- }
- // Apply hover colors
- if( isset( $hover_args ) ) {
- $styles .= layers_inline_styles( $container_id, $type, $hover_args );// Add styling for the standard colors
- }
- return $styles;
- }