Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
70a5b4d
Sortable
mattheu Apr 24, 2013
15b7065
file field fixes
mattheu Apr 24, 2013
a21b2b0
group field fixes
mattheu Apr 24, 2013
d432535
only do sortable for direct children - avoid issues with sortable groups
mattheu Apr 27, 2013
3cd91d7
Merge branch 'refs/heads/master' into sortable-2013
mattheu Apr 27, 2013
d02693a
Merge branch 'refs/heads/master' into sortable-2013
mattheu Apr 27, 2013
ede4f59
bug fix. not unsetting var correctly
mattheu Apr 28, 2013
fd1e3da
button with href???
mattheu Apr 28, 2013
f798597
Comprehensive example file
mattheu Apr 28, 2013
cf42e29
Merge branch 'sortable-2013' of github.com:humanmade/Custom-Meta-Boxe…
mattheu Apr 28, 2013
7e5ada3
Merge branch 'refs/heads/master' into sortable-2013
mattheu Apr 28, 2013
3bc3afe
on load, set value for ajax post select
mattheu Apr 28, 2013
cdf45e0
example editor height
mattheu Apr 28, 2013
9932664
don't reinitialise tinyMCE after sorting if the editor is not set to …
mattheu Apr 30, 2013
24d4a4e
Merge branch 'refs/heads/master' into sortable-2013
mattheu May 3, 2013
7d93719
Merge branch 'refs/heads/master' into sortable-2013
mattheu Jun 5, 2013
001442f
Merge branch 'refs/heads/master' into sortable-2013
mattheu Oct 22, 2013
5517d55
prefix sortable classes
mattheu Oct 24, 2013
a24401f
add sortable placeholder
mattheu Oct 24, 2013
8fecd9d
missed some classes
mattheu Oct 24, 2013
ec85e5a
only trigger sortable on repeat for sortable fields
mattheu Oct 24, 2013
cf2ad6e
Image fields don't really need drag handles
mattheu Oct 24, 2013
c66052c
make all the buttons accessible
mattheu Oct 24, 2013
123207e
update sortable styles
mattheu Oct 28, 2013
3e0d7db
Merge branch 'refs/heads/master' into sortable-2013
mattheu Nov 1, 2013
90615a3
lost in the merge
mattheu Nov 1, 2013
1db4c82
more examples
mattheu Nov 1, 2013
f8dfc66
Merge branch 'refs/heads/master' into sortable-2013
mattheu Nov 8, 2013
6f14c87
style optimisations
mattheu Nov 8, 2013
e731cf7
more specific labelling
mattheu Nov 8, 2013
62e2261
Merge branch 'refs/heads/master' into sortable-2013
mattheu Nov 8, 2013
686ccbf
move to css directory and create 3.8 stylesheet
mattheu Nov 10, 2013
521c157
Merge branch 'refs/heads/jquery-ui' into MP6
mattheu Nov 10, 2013
d6e7dc0
css class namespacing
mattheu Nov 10, 2013
96f0660
cmv present field should be contained within td
mattheu Nov 10, 2013
d27b2b0
indenting
mattheu Nov 10, 2013
3510fbd
date time js for all
mattheu Nov 10, 2013
e905bb0
new CMB.css
mattheu Nov 10, 2013
3eba32b
button styles
mattheu Nov 10, 2013
ddabd3b
padding
mattheu Nov 10, 2013
122de75
style should be specific for group.
mattheu Nov 11, 2013
f9e12e2
Display bugs for select fields (in IE mainly)
mattheu Nov 14, 2013
cba835f
tighten up the layout
mattheu Nov 14, 2013
1a7ebd0
Use divs and CSS to style grid layout instead of tables.
mattheu Nov 14, 2013
bbfac4d
Merge pull request #119 from humanmade/MP6-responsive
mattheu Nov 14, 2013
e25292b
grid wrapper el uneccessary
mattheu Nov 18, 2013
d1fdc10
Merge branch 'MP6' of github.com:humanmade/Custom-Meta-Boxes into MP6
mattheu Nov 18, 2013
bd11400
Merge branch 'refs/heads/master' into sortable-2013
mattheu Nov 19, 2013
0f81ece
Merge branch 'refs/heads/master' into MP6
mattheu Nov 19, 2013
192428c
Merge branch 'refs/heads/master' into sortable-2013
mattheu Nov 21, 2013
3dd61b7
Merge branch 'refs/heads/master' into MP6
mattheu Nov 21, 2013
9c8f1f9
improve the use of version compare
mattheu Nov 24, 2013
9e40938
fix css bug in wysiwyg
mattheu Nov 24, 2013
c94fbd6
Fix added to core http://core.trac.wordpress.org/changeset/26364
mattheu Nov 25, 2013
4b49b24
Use grunt to concatenate CSS files
mattheu Nov 26, 2013
b925c32
Move CSS to externals/dist dir
mattheu Nov 26, 2013
44df870
Merge branch 'refs/heads/master' into MP6
mattheu Nov 26, 2013
0bdc4e3
fix jquery-ui images + cleanup old ones
mattheu Nov 26, 2013
5aa0276
Merge branch 'refs/heads/master' into MP6
mattheu Dec 1, 2013
1bcf505
Rename
mattheu Dec 1, 2013
9769f9e
fix tests for this branch
mattheu Dec 1, 2013
a34de5c
update for rename
mattheu Dec 1, 2013
74ecd07
fix unit test
mattheu Dec 1, 2013
a02d0fb
consistent height of field title & description
mattheu Dec 1, 2013
e74e689
no need to pass object by reference
mattheu Dec 2, 2013
9180d2e
Merge pull request #116 from humanmade/MP6
mattheu Dec 2, 2013
bc6bd2e
Merge branch 'refs/heads/master' into sortable-2013
mattheu Dec 2, 2013
1244fcf
fix version compare
mattheu Dec 3, 2013
8c2f853
Sortable MP6 styles
mattheu Dec 3, 2013
99a6b77
Recompile
mattheu Dec 3, 2013
b092701
don't store non-rep grouped field data as an array
mattheu Dec 4, 2013
e82c2a0
update unit tests
mattheu Dec 5, 2013
0d4df7a
Merge pull request #135 from humanmade/fix-135
mattheu Dec 5, 2013
e676af7
Merge branch 'refs/heads/master' into sortable-2013
mattheu Dec 5, 2013
5c74482
should still display group fields if values are empty
mattheu Dec 11, 2013
58be270
Merge pull request #140 from humanmade/fix-groups-not-displayed
mattheu Dec 14, 2013
93ae22f
Neater way to add element attributes
mattheu Jan 3, 2014
c5deae4
add field ID as continuer element ID attribute
mattheu Jan 3, 2014
67a0f66
Merge pull request #55 from humanmade/sortable-2013
mattheu Jan 3, 2014
874cd3d
Merge branch 'refs/heads/master' into field-id-as-id
mattheu Jan 3, 2014
38d25ae
fix version comparrison
mattheu Jan 3, 2014
8b561ac
Merge pull request #148 from humanmade/field-id-as-id
mattheu Jan 3, 2014
d226bcf
hot fix bad array key
mattheu Jan 7, 2014
073e8af
Fixed wrong css path
Jan 8, 2014
44b35d6
Merge pull request #153 from tormjens/patch-1
mattheu Jan 8, 2014
066d0f4
Fix: File and Image fields over-flowing the wrapper box.
banago Feb 20, 2014
f55685e
Combiled Fix #144
banago Feb 20, 2014
f064c7c
Merge branch 'fix-label-height'
banago Feb 22, 2014
9d842bb
Merged master and compiled.
banago Feb 22, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
39 changes: 39 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*global module:false*/
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/**\n' +
' * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;' + ' License: <%= pkg.license %>\n' +
' */',
cssmin: {
combine: {
options: {
banner: '<%= banner %>'
},
files: {
'css/dist/cmb.min.css': [
'css/src/layout.css',
'css/src/generic.css',
'css/src/repeatable.css',
'css/src/sortable.css',
'css/src/group.css',
'css/src/file.css',
'css/src/misc-fields.css'
]
}
}
}
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-cssmin');

// Default task.
grunt.registerTask('default', [ 'cssmin' ] );

};
52 changes: 30 additions & 22 deletions class.cmb-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ function enqueue_scripts() {

function enqueue_styles() {

wp_enqueue_style( 'cmb-styles', trailingslashit( CMB_URL ) . 'style.css' );
$suffix = CMB_DEV ? '' : '.min';

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' );

foreach ( $this->fields as $field )
$field->enqueue_styles();
Expand Down Expand Up @@ -221,57 +226,60 @@ function show() { ?>
*/
static function layout_fields( array $fields ) { ?>

<table class="form-table cmb_metabox">
<div class="cmb_metabox">

<?php $current_colspan = 0;

foreach ( $fields as $field ) :

if ( $current_colspan == 0 ) : ?>

<tr>
<div class="cmb-row">

<?php endif;

$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);

$classes = 'class="' . esc_attr( implode(' ', array_map( 'sanitize_html_class', $classes ) ) ) . '"';
if ( ! empty( $field->args['sortable'] ) )
$classes[] = 'cmb-sortable';

$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'] ) );

?>

<td style="width: <?php esc_attr_e( $field->args['cols'] / 12 * 100 ); ?>%" colspan="<?php esc_attr_e( $field->args['cols'] ); ?>">
<div <?php echo $classes; ?> <?php echo $attrs; ?>>
<?php $field->display(); ?>
</div>
</td>
<div class="cmb-cell-<?php echo intval( $field->args['cols'] ); ?>">

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

<input type="hidden" name="_cmb_present_<?php esc_attr_e( $field->id ); ?>" value="1" />

<?php if ( $current_colspan == 12 ) :
</div>

<?php if ( $current_colspan == 12 || $field === end( $fields ) ) :

$current_colspan = 0; ?>

</tr>
</div><!-- .cmb-row -->

<?php endif; ?>

<input type="hidden" name="_cmb_present_<?php esc_attr_e( $field->id ); ?>" value="1" />

<?php endforeach; ?>

</table>
</div>

<?php }

Expand Down
84 changes: 45 additions & 39 deletions classes.fields.php
Original file line number Diff line number Diff line change
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 @@ -325,7 +329,7 @@ public function display() {
<div class="field-item" data-class="<?php echo esc_attr( get_class($this) ) ?>" style="position: relative; <?php echo esc_attr( $this->args['style'] ); ?>">

<?php if ( $this->args['repeatable'] ) : ?>
<button class="cmb-delete-field" title="Remove field"><span class="cmb-delete-field-icon">&times;</span> Remove Group</button>
<button class="cmb-delete-field" title="Remove field"><span class="cmb-delete-field-icon">&times;</span></button>
<?php endif; ?>

<?php $this->html(); ?>
Expand All @@ -344,7 +348,7 @@ public function display() {
$this->field_index = 'x'; // x used to distinguish hidden fields.
$this->value = ''; ?>

<div class="field-item hidden" data-class="<?php echo esc_attr( get_class($this) ) ?>" style="position: relative">
<div class="field-item hidden" data-class="<?php echo esc_attr( get_class($this) ) ?>" style="position: relative; <?php echo esc_attr( $this->args['style'] ); ?>">

<?php if ( $this->args['repeatable'] ) : ?>
<button class="cmb-delete-field" title="Remove field"><span class="cmb-delete-field-icon">&times;</span> Remove Group</button>
Expand All @@ -369,9 +373,7 @@ public function display() {
*/
class CMB_Text_Field extends CMB_Field {

public function html() {

?>
public function html() { ?>

<input type="text" <?php $this->id_attr(); ?> <?php $this->boolean_attr(); ?> <?php $this->class_attr(); ?> <?php $this->name_attr(); ?> value="<?php echo esc_attr( $this->get_value() ); ?>" />

Expand Down Expand Up @@ -541,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 @@ -598,10 +600,10 @@ public function html() { ?>
class CMB_Date_Field extends CMB_Field {

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-datetime', trailingslashit( CMB_URL ) . 'js/field.datetime.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'cmb-scripts' ) );
}
Expand All @@ -619,7 +621,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 All @@ -643,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 @@ -1268,7 +1270,7 @@ function cmb_ajax_post_select() {
class CMB_Group_Field extends CMB_Field {

static $added_js;
public $fields = array();
private $fields = array();

function __construct() {

Expand Down Expand Up @@ -1309,11 +1311,11 @@ public function enqueue_styles() {
parent::enqueue_styles();

foreach ( $this->args['fields'] as $f ) {

$class = _cmb_field_class_for_type( $f['type'] );
$field = new $class( '', '', array(), $f );
$field->enqueue_styles();
}

}

public function display() {
Expand All @@ -1325,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 @@ -1354,27 +1362,16 @@ 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 }

}

public function add_field( CMB_Field $field ) {

$field->parent = &$this;
$this->fields[$field->id] = $field;

}

public function &get_fields() {
return $this->fields;
}

public function html() {

$fields = &$this->get_fields();
$value = $this->value;
$value = $this->value;

if ( ! empty( $value ) ) {
foreach ( $value as $field_id => $field_value ) {
Expand All @@ -1391,40 +1388,49 @@ public function html() {

?>

<div class="group <?php echo ! empty( $this->args['repeatable'] ) ? 'cloneable' : '' ?>" style="position: relative">

<?php if ( $this->args['repeatable'] ) : ?>
<button class="cmb-delete-field" title="Remove field"><span class="cmb-delete-field-icon">&times;</span> Remove Group</button>
<?php endif; ?>

<?php CMB_Meta_Box::layout_fields( $fields ); ?>
<?php if ( $this->args['repeatable'] ) : ?>
<button class="cmb-delete-field" title="Remove field"><span class="cmb-delete-field-icon">&times;</span> Remove Group</button>
<?php endif; ?>

</div>
<?php CMB_Meta_Box::layout_fields( $fields ); ?>

<?php }

public function parse_save_values() {

$fields = &$this->get_fields();
$values = &$this->get_values();

foreach ( $values as &$group_value ) {
foreach ( $group_value as $field_id => &$field_value ) {

if ( ! isset( $fields[$field_id] ) ) {
$field_value = array();
continue;
}

$field = $fields[$field_id];
$field->values = $field_value;
$field->parse_save_values();

$field_value = $field->get_values();

// if the field is a repeatable field, store the whole array of them, if it's not repeatble,
// just store the first (and only) one directly
if ( ! $field->args['repeatable'] )
$field_value = reset( $field_value );
}
}


}

public function add_field( CMB_Field $field ) {
$field->parent = $this;
$this->fields[$field->id] = $field;
}

public function &get_fields() {
return $this->fields;
}

public function set_values( array $values ) {
Expand All @@ -1440,4 +1446,4 @@ public function set_values( array $values ) {

}

}
}
18 changes: 18 additions & 0 deletions css/dist/cmb.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* CMB Styles
*
* This file is used for development only and is loaded when CMB_DEV is defined as true.
* cmb.min.css is generated by the Grunt build process.
*/

@import '../src/layout.css';
@import '../src/generic.css';

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

/** Fields **/
@import '../src/group.css';
@import '../src/file.css';
@import '../src/misc-fields.css';
Loading