Browse files

Merge pull request #260 from funkedgeek/master

Autosave bug fix, updated color field, select standardizing
  • Loading branch information...
2 parents a7e8416 + 304c5b4 commit 462ba5acb4d3ebe4f97e43b4ad23679aa7770ef3 @rilwis committed Mar 27, 2013
View
2 demo/demo.php
@@ -93,7 +93,7 @@
),
// Select multiple values, optional. Default is false.
'multiple' => false,
- 'default' =>'Select an Item'
+ 'std' =>'Select an Item'
),
// HIDDEN
array(
View
8 inc/classes/meta-box.php
@@ -170,7 +170,10 @@ public function show()
$saved = self::has_been_saved( $post->ID, $this->fields );
// Container
- echo '<div class="rwmb-meta-box">';
+ echo sprintf(
+ '<div class="rwmb-meta-box" data-autosave="%s">',
+ $this->meta_box['autosave'] ? 'true' : 'false'
+ );
wp_nonce_field( "rwmb-save-{$this->meta_box['id']}", "nonce_{$this->meta_box['id']}" );
@@ -420,12 +423,9 @@ function save_post( $post_id )
{
// Check whether:
// - form is submitted properly
- // - the post is autosaved
- $autosave = defined('DOING_AUTOSAVE') && DOING_AUTOSAVE;
if (
empty( $_POST["nonce_{$this->meta_box['id']}"] )
|| !wp_verify_nonce( $_POST["nonce_{$this->meta_box['id']}"], "rwmb-save-{$this->meta_box['id']}" )
- || $this->meta_box['autosave'] != $autosave
)
{
return;
View
4 inc/fields/color.php
@@ -13,8 +13,8 @@ class RWMB_Color_Field
*/
static function admin_enqueue_scripts()
{
- wp_enqueue_style( 'rwmb-color', RWMB_CSS_URL . 'color.css', array( 'farbtastic' ), RWMB_VER );
- wp_enqueue_script( 'rwmb-color', RWMB_JS_URL . 'color.js', array( 'farbtastic' ), RWMB_VER, true );
+ wp_enqueue_style( 'rwmb-color', RWMB_CSS_URL . 'color.css', array( 'farbtastic', 'wp-color-picker' ), RWMB_VER );
+ wp_enqueue_script( 'rwmb-color', RWMB_JS_URL . 'color.js', array( 'farbtastic', 'wp-color-picker' ), RWMB_VER, true );
}
/**
View
14 inc/fields/posts.php
@@ -61,10 +61,12 @@ static function normalize_field( $field )
$field = wp_parse_args( $field, array(
'post_type' => 'post',
'field_type' => 'select_advanced',
- 'default' => sprintf( __( 'Select a %s', 'rwmb' ), $default_post_type ),
'parent' => false,
'query_args' => array()
) );
+
+ $field['std'] = empty( $field['std'] ) ? sprintf( __( 'Select a %s', 'rwmb' ), $default_post_type ) : $field['std'];
+
if ( $field['parent'] )
{
@@ -78,7 +80,15 @@ static function normalize_field( $field )
'posts_per_page' => '-1'
) );
- return RWMB_Select_Advanced_Field::normalize_field( $field );
+ switch ( $field['field_type'] )
+ {
+ case 'select':
+ return RWMB_Select_Field::normalize_field( $field );
+ break;
+ case 'select_advanced':
+ default:
+ return RWMB_Select_Advanced_Field::normalize_field( $field );
+ }
}
/**
View
9 inc/fields/select-advanced.php
@@ -59,18 +59,19 @@ static function html( $html, $meta, $field )
*/
static function normalize_field( $field )
{
+ $field = parent::normalize_field( $field );
+
$field = wp_parse_args( $field, array(
'js_options' => array(),
) );
$field['js_options'] = wp_parse_args( $field['js_options'], array(
'allowClear' => true,
'width' => 'resolve',
- 'placeholder' => __( 'Select a value', 'rwmb' )
+ 'placeholder' => empty( $field['std'] ) ? __( 'Select a value', 'rwmb' ) : $field['std']
) );
- $field['default'] = isset( $field['default']) ? $field['default'] : $field['js_options']['placeholder'];
-
- $field = parent::normalize_field( $field );
+
+ $field['std'] = '';
return $field;
}
View
4 inc/fields/select.php
@@ -107,7 +107,6 @@ static function normalize_field( $field )
$field = wp_parse_args( $field, array(
'desc'=> '',
'name' => $field['id'],
- 'default' => $field['desc'],
'size' => $field['multiple'] ? 5 : 0,
) );
if ( !$field['clone'] && $field['multiple'] )
@@ -124,7 +123,8 @@ static function normalize_field( $field )
*/
static function options_html( $field, $meta )
{
- $html = !empty($field['default'])? "<option value=''>{$field['default']}</option>" : '';
+ $html = "<option value=''>{$field['std']}</option>";
+
$option = '<option value="%s" %s>%s</option>';
foreach ( $field['options'] as $value => $label )
View
5 inc/fields/taxonomy.php
@@ -37,10 +37,7 @@ static function normalize_field( $field )
$field['options']['args'] = ( ! isset( $field['options']['args'] ) ) ? $default_args : wp_parse_args( $field['options']['args'], $default_args );
$tax = get_taxonomy( $field['options']['taxonomy'] );
- $field = wp_parse_args( $field, array(
- 'required' => false,
- 'default' => sprintf( __( 'Select a %s' , 'rwmb' ), $tax->labels->singular_name ),
- ) );
+ $field['std'] = empty( $field['std'] ) ? sprintf( __( 'Select a %s' , 'rwmb' ), $tax->labels->singular_name ) : $field['std'];
$field['field_name'] = "{$field['id']}[]";
View
9 js/autosave.js
@@ -4,9 +4,12 @@ jQuery( function( $ )
{
if ( -1 != s.data.indexOf( 'action=autosave' ) )
{
- $( '.rwmb-meta-box :input' ).each( function()
- {
- s.data += '&' + $( this ).serialize();
+ $( '.rwmb-meta-box').each(function(){
+ var $meta_box = $( this );
+ if( $meta_box.data( 'autosave' ) == true )
+ {
+ s.data += '&' + $( ':input', $meta_box ).serialize();
+ }
} );
}
} );
View
21 js/color.js
@@ -3,8 +3,7 @@
* Used for static & dynamic added elements (when clone)
*/
jQuery( document ).ready( function( $ )
-{
-
+{
$( ':input.rwmb-color' ).each( rwmb_update_color_picker );
$( '.rwmb-input' ).on( 'clone', ':input.rwmb-color', rwmb_update_color_picker )
.on( 'focus', '.rwmb-color', function()
@@ -20,14 +19,24 @@ jQuery( document ).ready( function( $ )
function rwmb_update_color_picker()
{
var $this = $( this ),
+ $clone_container = $this.closest('.rwmb-clone'),
$color_picker = $this.siblings( '.rwmb-color-picker' );
-
+
// Make sure the value is displayed
if ( !$this.val() )
$this.val( '#' );
-
- $color_picker.farbtastic( $this );
-
+
+ if( typeof jQuery.wp === 'object' && typeof jQuery.wp.wpColorPicker === 'function' ){
+ if( $clone_container.length > 0 )
+ {
+ $this.appendTo( $clone_container ).siblings( 'div.wp-picker-container' ).remove();
+ }
+ $this.wpColorPicker();
+ }
+ else {
+ //We use farbtastic if the WordPress color picker widget doesn't exist
+ $color_picker.farbtastic( $this );
+ }
}
} );

0 comments on commit 462ba5a

Please sign in to comment.