| 1 |
<?php |
| 2 |
/** |
| 3 |
* Redux Framework is free software: you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License as published by |
| 5 |
* the Free Software Foundation, either version 2 of the License, or |
| 6 |
* any later version. |
| 7 |
* Redux Framework is distributed in the hope that it will be useful, |
| 8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
* GNU General Public License for more details. |
| 11 |
* You should have received a copy of the GNU General Public License |
| 12 |
* along with Redux Framework. If not, see <http://www.gnu.org/licenses/>. |
| 13 |
* |
| 14 |
* @package ReduxFramework |
| 15 |
* @subpackage Field_Section |
| 16 |
* @author Tobias Karnetze (athoss.de) |
| 17 |
* @version 1.0.0 |
| 18 |
*/ |
| 19 |
|
| 20 |
// Exit if accessed directly |
| 21 |
if ( ! defined( 'ABSPATH' ) ) { |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
// Don't duplicate me! |
| 26 |
if ( ! class_exists( 'ReduxFramework_section' ) ) { |
| 27 |
|
| 28 |
/** |
| 29 |
* Main ReduxFramework_heading class |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
*/ |
| 33 |
class ReduxFramework_section { |
| 34 |
|
| 35 |
/** |
| 36 |
* Field Constructor. |
| 37 |
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* @access public |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
public function __construct( $field = array(), $value = '', $parent ) { |
| 44 |
$this->parent = $parent; |
| 45 |
$this->field = $field; |
| 46 |
$this->value = $value; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Field Render Function. |
| 51 |
* Takes the vars and outputs the HTML for the field in the settings |
| 52 |
* |
| 53 |
* @since 1.0.0 |
| 54 |
* @access public |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function render() { |
| 58 |
|
| 59 |
// No errors please |
| 60 |
$defaults = array( |
| 61 |
'indent' => '', |
| 62 |
'style' => '', |
| 63 |
'class' => '', |
| 64 |
'title' => '', |
| 65 |
'subtitle' => '', |
| 66 |
); |
| 67 |
$this->field = wp_parse_args( $this->field, $defaults ); |
| 68 |
|
| 69 |
$guid = uniqid(); |
| 70 |
|
| 71 |
$add_class = ''; |
| 72 |
if ( isset( $this->field['indent'] ) && true === $this->field['indent'] ) { |
| 73 |
$add_class = ' form-table-section-indented'; |
| 74 |
} elseif( !isset( $this->field['indent'] ) || ( isset( $this->field['indent'] ) && false !== $this->field['indent'] ) ) { |
| 75 |
$add_class = " hide"; |
| 76 |
} |
| 77 |
|
| 78 |
echo '<input type="hidden" id="' . esc_attr($this->field['id']) . '-marker"></td></tr></table>'; |
| 79 |
|
| 80 |
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']) . ' ">'; |
| 81 |
|
| 82 |
if ( ! empty( $this->field['title'] ) ) { |
| 83 |
echo '<h3>' . esc_html($this->field['title']) . '</h3>'; |
| 84 |
} |
| 85 |
|
| 86 |
if ( ! empty( $this->field['subtitle'] ) ) { |
| 87 |
echo '<div class="redux-section-desc">' . esc_html($this->field['subtitle']) . '</div>'; |
| 88 |
} |
| 89 |
|
| 90 |
echo '</div><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) . '">'; |
| 91 |
|
| 92 |
// delete the tr afterwards |
| 93 |
?> |
| 94 |
<script type="text/javascript"> |
| 95 |
jQuery( document ).ready( |
| 96 |
function() { |
| 97 |
jQuery( '#<?php echo $this->field['id']; ?>-marker' ).parents( 'tr:first' ).css( {display: 'none'} ).prev('tr' ).css('border-bottom','none');; |
| 98 |
var group = jQuery( '#<?php echo $this->field['id']; ?>-marker' ).parents( '.redux-group-tab:first' ); |
| 99 |
if ( !group.hasClass( 'sectionsChecked' ) ) { |
| 100 |
group.addClass( 'sectionsChecked' ); |
| 101 |
var test = group.find( '.redux-section-indent-start h3' ); |
| 102 |
jQuery.each( |
| 103 |
test, function( key, value ) { |
| 104 |
jQuery( value ).css( 'margin-top', '20px' ) |
| 105 |
} |
| 106 |
); |
| 107 |
if ( group.find( 'h3:first' ).css( 'margin-top' ) == "20px" ) { |
| 108 |
group.find( 'h3:first' ).css( 'margin-top', '0' ); |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
); |
| 113 |
</script> |
| 114 |
<?php |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
public function enqueue() { |
| 119 |
if ( $this->parent->args['dev_mode'] ) { |
| 120 |
wp_enqueue_style( |
| 121 |
'redux-field-section-css', |
| 122 |
ReduxFramework::$_url . 'inc/fields/section/field_section.css', |
| 123 |
array(), |
| 124 |
time(), |
| 125 |
'all' |
| 126 |
); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |