balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-redux-section.php (3676B)


      1 <?php
      2 /**
      3  * Section Field
      4  *
      5  * @package     ReduxFramework/Fields
      6  * @author      Kevin Provance (kprovance) & Tobias Karnetze (athoss.de)
      7  * @version     4.0.0
      8  */
      9 
     10 defined( 'ABSPATH' ) || exit;
     11 
     12 // Don't duplicate me!
     13 if ( ! class_exists( 'Redux_Section', false ) ) {
     14 
     15 	/**
     16 	 * Main Redux_heading class
     17 	 *
     18 	 * @since       1.0.0
     19 	 */
     20 	class Redux_Section extends Redux_Field {
     21 
     22 		/**
     23 		 * Set field and value defaults.
     24 		 */
     25 		public function set_defaults() {
     26 			// No errors please.
     27 			$defaults = array(
     28 				'indent'   => true,
     29 				'style'    => '',
     30 				'class'    => '',
     31 				'title'    => '',
     32 				'subtitle' => '',
     33 			);
     34 
     35 			$this->field = wp_parse_args( $this->field, $defaults );
     36 		}
     37 
     38 		/**
     39 		 * Field Render Function.
     40 		 * Takes the vars and outputs the HTML for the field in the settings
     41 		 *
     42 		 * @since         1.0.0
     43 		 * @access        public
     44 		 * @return        void
     45 		 */
     46 		public function render() {
     47 			$guid = uniqid();
     48 
     49 			if ( true === $this->field['indent'] ) {
     50 				$this->field['class'] .= ' redux-section-indent-start';
     51 			}
     52 
     53 			$add_class = '';
     54 			if ( isset( $this->field['indent'] ) && true === $this->field['indent'] ) {
     55 				$add_class = ' form-table-section-indented';
     56 			} elseif ( ! isset( $this->field['indent'] ) || ( isset( $this->field['indent'] ) && false !== $this->field['indent'] ) ) {
     57 				$add_class = ' hide';
     58 			}
     59 
     60 			echo '<input type="hidden" id="' . esc_attr( $this->field['id'] ) . '-marker"></td></tr></table>';
     61 
     62 			if ( isset( $this->field['indent'] ) && true === $this->field['indent'] ) {
     63 				echo '<div class="indent-section-container">';
     64 			}
     65 
     66 			echo '<div id="section-' . esc_attr( $this->field['id'] ) . '" class="redux-section-field redux-field ' . esc_attr( $this->field['style'] ) . ' ' . esc_attr( $this->field['class'] ) . ' ">';
     67 
     68 			if ( ! empty( $this->field['title'] ) ) {
     69 				echo '<h3>' . wp_kses_post( $this->field['title'] ) . '</h3>';
     70 			}
     71 
     72 			if ( ! empty( $this->field['subtitle'] ) ) {
     73 				echo '<div class="redux-section-desc">' . wp_kses_post( $this->field['subtitle'] ) . '</div>';
     74 			}
     75 
     76 			echo '</div>';
     77 
     78 			if ( isset( $this->field['indent'] ) && true === $this->field['indent'] ) {
     79 				echo '</div>';
     80 			}
     81 
     82 			echo '<table id="section-table-' . esc_attr( $this->field['id'] ) . '" data-id="' . esc_attr( $this->field['id'] ) . '" class="form-table form-table-section no-border' . esc_attr( $add_class ) . '"><tbody><tr><th></th><td id="' . esc_attr( $guid ) . '">';
     83 
     84 			?>
     85 			<script type="text/javascript">
     86 				jQuery( document ).ready(
     87 					function() {
     88 						jQuery( '#<?php echo esc_attr( $this->field['id'] ); ?>-marker' ).parents( 'tr:first' )
     89 						.css( {display: 'none'} )
     90 						.prev( 'tr' )
     91 						.css( 'border-bottom', 'none' );
     92 
     93 						var group = jQuery( '#<?php echo esc_attr( $this->field['id'] ); ?>-marker' ).parents( '.redux-group-tab:first' );
     94 						if ( !group.hasClass( 'sectionsChecked' ) ) {
     95 							group.addClass( 'sectionsChecked' );
     96 							var test = group.find( '.redux-section-indent-start h3' );
     97 							jQuery.each(
     98 								test, function( key, value ) {
     99 									jQuery( value ).css( 'margin-top', '20px' )
    100 								}
    101 							);
    102 							if ( group.find( 'h3:first' ).css( 'margin-top' ) === "20px" ) {
    103 								group.find( 'h3:first' ).css( 'margin-top', '0' );
    104 							}
    105 						}
    106 					}
    107 				);
    108 			</script>
    109 			<?php
    110 		}
    111 
    112 		/**
    113 		 * Enqueue Script and styles.
    114 		 */
    115 		public function enqueue() {
    116 			if ( $this->parent->args['dev_mode'] ) {
    117 				wp_enqueue_style(
    118 					'redux-field-section-css',
    119 					Redux_Core::$url . 'inc/fields/section/redux-section.css',
    120 					array(),
    121 					$this->timestamp
    122 				);
    123 			}
    124 		}
    125 	}
    126 }
    127 
    128 class_alias( 'Redux_Section', 'ReduxFramework_Section' );