Skip to content

Commit 7a4f084

Browse files
author
andreilupu
committed
a shot at #22
1 parent b5e1009 commit 7a4f084

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

features/metaboxes/init.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ function show() {
364364
// Use nonce for verification
365365
echo '<input type="hidden" name="wp_meta_box_nonce" value="', wp_create_nonce( basename( __FILE__ ) ), '" />';
366366

367+
// load assets only when we have a metabox on page
368+
cmb_enqueue_scripts();
369+
367370
echo '<ul class="form-table cmb_metabox">';
368371

369372
// we use the variable to check if we need a default or not
@@ -1032,7 +1035,7 @@ function save( $post_id ) {
10321035
/**
10331036
* Adding scripts and styles
10341037
*/
1035-
function cmb_scripts( $hook ) {
1038+
function cmb_register_scripts( $hook ) {
10361039

10371040
global $pixtypes_plugin;
10381041
$plugin_version = 0;
@@ -1054,15 +1057,9 @@ function cmb_scripts( $hook ) {
10541057
);
10551058
// styles required for cmb
10561059
$cmb_style_array = array( 'thickbox', 'tooltipster' );
1057-
// if we're 3.5 or later, user wp-color-picker
1058-
if ( 3.5 <= $wp_version ) {
1059-
$cmb_script_array[] = 'wp-color-picker';
1060-
$cmb_style_array[] = 'wp-color-picker';
1061-
} else {
1062-
// otherwise use the older 'farbtastic'
1063-
$cmb_script_array[] = 'farbtastic';
1064-
$cmb_style_array[] = 'farbtastic';
1065-
}
1060+
1061+
$cmb_script_array[] = 'wp-color-picker';
1062+
$cmb_style_array[] = 'wp-color-picker';
10661063

10671064
wp_register_script( 'cmb-tooltipster', CMB_META_BOX_URL . 'js/jquery.tooltipster.min.js' );
10681065
wp_register_script( 'cmb-timepicker', CMB_META_BOX_URL . 'js/jquery.timePicker.min.js' );
@@ -1081,30 +1078,29 @@ function cmb_scripts( $hook ) {
10811078
'post_id' => get_the_ID(),
10821079
'post_type' => get_post_type()
10831080
) );
1084-
wp_enqueue_script( 'cmb-timepicker' );
1085-
wp_enqueue_script( 'cmb-scripts' );
10861081

10871082
wp_register_style( 'gridster', CMB_META_BOX_URL . 'css/jquery.gridster.css' );
10881083

10891084
wp_register_style( 'pix_builder', CMB_META_BOX_URL . 'css/pix_builder.css', array( 'gridster' ), $plugin_version );
10901085
wp_register_style( 'tooltipster', CMB_META_BOX_URL . 'css/tooltipster.css' );
10911086
wp_register_style( 'cmb-styles', CMB_META_BOX_URL . 'css/style.css', $cmb_style_array, $plugin_version );
1092-
1093-
wp_enqueue_style( 'cmb-styles' );
10941087
}
10951088
}
10961089

1097-
add_action( 'admin_enqueue_scripts', 'cmb_scripts', 10 );
1090+
add_action( 'admin_enqueue_scripts', 'cmb_register_scripts', 10 );
1091+
1092+
function cmb_enqueue_scripts(){
1093+
wp_enqueue_script( 'cmb-timepicker' );
1094+
wp_enqueue_script( 'cmb-scripts' );
1095+
wp_enqueue_style( 'cmb-styles' );
1096+
}
10981097

10991098
function cmb_editor_footer_scripts() {
1100-
?>
1101-
<?php
11021099
if ( isset( $_GET['cmb_force_send'] ) && 'true' == $_GET['cmb_force_send'] ) {
11031100
$label = $_GET['cmb_send_label'];
11041101
if ( empty( $label ) ) {
11051102
$label = "Select File";
1106-
}
1107-
?>
1103+
} ?>
11081104
<script type="text/javascript">
11091105
jQuery(function ($) {
11101106
$('td.savesend input').val('<?php echo $label; ?>');

0 commit comments

Comments
 (0)