Skip to content

Commit

Permalink
Adding support for the (as of WP2.5) new colorpicker.
Browse files Browse the repository at this point in the history
  • Loading branch information
zamoose committed Mar 6, 2013
1 parent 6a5d1af commit f4459a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
15 changes: 13 additions & 2 deletions init.php
Expand Up @@ -487,12 +487,23 @@ function save( $post_id) {
* Adding scripts and styles
*/
function cmb_scripts( $hook ) {
global $wp_version;
if ( $hook == 'post.php' || $hook == 'post-new.php' || $hook == 'page-new.php' || $hook == 'page.php' ) {
$cmb_script_array = array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'media-upload', 'thickbox' );
$cmb_style_array = array( 'thickbox' );
if( 3.5 <= $wp_version ){
$cmb_script_array[] = 'wp-color-picker';
$cmb_style_array[] = 'wp-color-picker';
}else{
$cmb_script_array[] = 'farbtastic';
$cmb_style_array[] = 'farbtastic';
}
wp_register_script( 'cmb-timepicker', CMB_META_BOX_URL . 'js/jquery.timePicker.min.js' );
wp_register_script( 'cmb-scripts', CMB_META_BOX_URL . 'js/cmb.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'media-upload', 'thickbox', 'farbtastic' ) );
wp_register_script( 'cmb-scripts', CMB_META_BOX_URL . 'js/cmb.js', $cmb_script_array, '0.9.1' );
wp_localize_script( 'cmb-scripts', 'cmb_ajax_data', array( 'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ), 'post_id' => get_the_ID() ) );
wp_enqueue_script( 'cmb-timepicker' );
wp_enqueue_script( 'cmb-scripts' );
wp_register_style( 'cmb-styles', CMB_META_BOX_URL . 'style.css', array( 'thickbox', 'farbtastic' ) );
wp_register_style( 'cmb-styles', CMB_META_BOX_URL . 'style.css', $cmb_style_array );
wp_enqueue_style( 'cmb-styles' );
}
}
Expand Down
24 changes: 14 additions & 10 deletions js/cmb.js
Expand Up @@ -45,16 +45,20 @@ jQuery(document).ready(function ($) {
/**
* Initialize color picker
*/
$('input:text.cmb_colorpicker').each(function (i) {
$(this).after('<div id="picker-' + i + '" style="z-index: 1000; background: #EEE; border: 1px solid #CCC; position: absolute; display: block;"></div>');
$('#picker-' + i).hide().farbtastic($(this));
})
.focus(function() {
$(this).next().show();
})
.blur(function() {
$(this).next().hide();
});
if( typeof jQuery.wp === 'object' && typeof jQuery.wp.wpColorPicker === 'function' ){
$('input:text.cmb_colorpicker').wpColorPicker();
}else{
$('input:text.cmb_colorpicker').each(function (i) {
$(this).after('<div id="picker-' + i + '" style="z-index: 1000; background: #EEE; border: 1px solid #CCC; position: absolute; display: block;"></div>');
$('#picker-' + i).hide().farbtastic($(this));
})
.focus(function() {
$(this).next().show();
})
.blur(function() {
$(this).next().hide();
});
}

/**
* File and image upload handling
Expand Down

3 comments on commit f4459a1

@zamoose
Copy link
Owner Author

@zamoose zamoose commented on f4459a1 Mar 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, as of WP 3.5, not 2.4. Fat-fingered.

@jtsternberg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice improvement. Did you test it on a pre-3.5 install?

@zamoose
Copy link
Owner Author

@zamoose zamoose commented on f4459a1 Mar 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, appears to fall back correctly to Farbtastic on a clean 3.4.2 install.

Please sign in to comment.