Skip to content

Commit

Permalink
update meta box lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Bearded Avenger committed Jan 31, 2014
1 parent 99c3615 commit a363c60
Show file tree
Hide file tree
Showing 16 changed files with 399 additions and 327 deletions.
21 changes: 11 additions & 10 deletions admin/includes/custom-meta-boxes/class.cmb-meta-box.php
Expand Up @@ -119,7 +119,7 @@ function enqueue_styles() {

$suffix = CMB_DEV ? '' : '.min';

if ( version_compare( get_bloginfo( 'version' ), '3.7', '>' ) )
if ( version_compare( get_bloginfo( 'version' ), '3.8', '>=' ) )
wp_enqueue_style( 'cmb-styles', trailingslashit( CMB_URL ) . "css/dist/cmb$suffix.css" );
else
wp_enqueue_style( 'cmb-styles', trailingslashit( CMB_URL ) . 'css/legacy.css' );
Expand Down Expand Up @@ -240,27 +240,28 @@ static function layout_fields( array $fields ) { ?>

$current_colspan += $field->args['cols'];

$classes = array('field');
$classes = array( 'field', get_class($field) );

if ( ! empty( $field->args['repeatable'] ) )
$classes[] = 'repeatable';

$classes[] = get_class($field);
if ( ! empty( $field->args['sortable'] ) )
$classes[] = 'cmb-sortable';

$classes = 'class="' . esc_attr( implode(' ', array_map( 'sanitize_html_class', $classes ) ) ) . '"';

$attrs = array();
$attrs = array(
sprintf( 'id="%s"', sanitize_html_class( $field->id ) ),
sprintf( 'class="%s"', esc_attr( implode(' ', array_map( 'sanitize_html_class', $classes ) ) ) )
);

// Field Repeatable Max.
if ( isset( $field->args['repeatable_max'] ) )
$attrs[] = 'data-rep-max="' . intval( $field->args['repeatable_max'] ) . '"';

$attrs = implode( ' ', $attrs );
$attrs[] = sprintf( 'data-rep-max="%s"', intval( $field->args['repeatable_max'] ) );

?>

<div class="cmb-cell-<?php echo intval( $field->args['cols'] ); ?>">

<div <?php echo $classes; ?> <?php echo $attrs; ?>>
<div <?php echo implode( ' ', $attrs ); ?>>
<?php $field->display(); ?>
</div>

Expand Down
30 changes: 14 additions & 16 deletions admin/includes/custom-meta-boxes/classes.fields.php
Expand Up @@ -67,6 +67,10 @@ public function __construct( $name, $title, array $values, $args = array() ) {
* @uses wp_enqueue_script()
*/
public function enqueue_scripts() {

if ( isset( $this->args['sortable'] ) && $this->args['sortable'] )
wp_enqueue_script( 'jquery-ui-sortable' );

}

/**
Expand Down Expand Up @@ -539,7 +543,7 @@ private function parse_image_size( $size ) {

// Handle default WP size format.
if ( is_array( $size ) && isset( $size[0] ) && isset( $size[1] ) )
$size = array( 'width' => $size[0], 'height' => $size[0] );
$size = array( 'width' => $size[0], 'height' => $size[1] );

return wp_parse_args( $size, array(
'width' => get_option( 'thumbnail_size_w' ),
Expand Down Expand Up @@ -641,7 +645,7 @@ public function enqueue_scripts() {

parent::enqueue_scripts();

wp_enqueue_style( 'cmb-jquery-ui', trailingslashit( CMB_URL ) . 'css/jquery-ui.css', '1.10.3' );
wp_enqueue_style( 'cmb-jquery-ui', trailingslashit( CMB_URL ) . 'css/vendor/jquery-ui/jquery-ui.css', '1.10.3' );

wp_enqueue_script( 'cmb-timepicker', trailingslashit( CMB_URL ) . 'js/jquery.timePicker.min.js', array( 'jquery', 'cmb-scripts' ) );
wp_enqueue_script( 'cmb-datetime', trailingslashit( CMB_URL ) . 'js/field.datetime.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'cmb-scripts' ) );
Expand Down Expand Up @@ -1323,8 +1327,14 @@ public function display() {
$this->title();
$this->description();

// if there are no values and it's not repeateble, we want to do one with empty string
if ( ! $this->get_values() && ! $this->args['repeatable'] )
$values = array( '' );
else
$values = $this->get_values();

$i = 0;
foreach ( $this->get_values() as $value ) {
foreach ( $values as $value ) {

$this->field_index = $i;
$this->value = $value;
Expand Down Expand Up @@ -1352,7 +1362,7 @@ public function display() {

</div>

<button class="button repeat-field"><?php esc_html_e( 'Add New', 'cmb' ); ?></button>
<button class="button repeat-field"><?php esc_html_e( 'Add New Group', 'cmb' ); ?></button>

<?php }

Expand Down Expand Up @@ -1437,15 +1447,3 @@ public function set_values( array $values ) {
}

}

class Email_Field extends CMB_Field {

public function html() {
?>
<p>
<input type="email" name="<?php echo $this->name ?>" value="<?php echo esc_attr( $this->get_value() ) ?>" />
</p>
<?php
}

}
1 change: 1 addition & 0 deletions admin/includes/custom-meta-boxes/css/dist/cmb.css
Expand Up @@ -10,6 +10,7 @@

/** Features **/
@import '../src/repeatable.css';
@import '../src/sortable.css';

/** Fields **/
@import '../src/group.css';
Expand Down
4 changes: 2 additions & 2 deletions admin/includes/custom-meta-boxes/css/dist/cmb.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a363c60

Please sign in to comment.