Created
January 3, 2013 19:15
-
-
Save WagnerMatos/4446152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// Load scripts and styles for Meta box */ | |
// enqueue scripts and styles, but only if is_admin | |
if(is_admin()) { | |
wp_enqueue_script('jquery-ui-datepicker'); | |
wp_enqueue_script('jquery-ui-slider'); | |
wp_enqueue_script('custom-js', get_template_directory_uri().'/library/metaboxes/js/custom-js.js'); | |
wp_enqueue_style('jquery-ui-custom', get_template_directory_uri().'/library/metaboxes/css/jquery-ui-custom.css'); | |
} | |
// add some custom js to the head of the page | |
add_action('admin_head','add_custom_scripts'); | |
function add_custom_scripts() { | |
global $home_custom_meta_fields, $post; | |
$output = '<script type="text/javascript"> | |
jQuery(function() {'; | |
foreach ($home_custom_meta_fields as $field) { // loop through the fields looking for certain types | |
// date | |
if($field['type'] == 'date') | |
$output .= 'jQuery(".datepicker").datepicker();'; | |
// slider | |
if ($field['type'] == 'slider') { | |
$value = get_post_meta($post->ID, $field['id'], true); | |
if ($value == '') $value = $field['min']; | |
$output .= ' | |
jQuery( "#'.$field['id'].'-slider" ).slider({ | |
value: '.$value.', | |
min: '.$field['min'].', | |
max: '.$field['max'].', | |
step: '.$field['step'].', | |
slide: function( event, ui ) { | |
jQuery( "#'.$field['id'].'" ).val( ui.value ); | |
} | |
});'; | |
} | |
} | |
$output .= '}); | |
</script>'; | |
echo $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment