示例#1
0
 /**
  * enqueue necessary scripts and styles
  */
 function admin_enqueue_scripts()
 {
     global $pagenow;
     if (in_array($pagenow, array('post-new.php', 'post.php')) && in_array(get_post_type(), $this->page)) {
         // js
         $deps = array('jquery');
         if (meta_box_find_field_type('date', $this->fields)) {
             $deps[] = 'jquery-ui-datepicker';
         }
         if (meta_box_find_field_type('slider', $this->fields)) {
             $deps[] = 'jquery-ui-slider';
         }
         if (meta_box_find_field_type('color', $this->fields)) {
             $deps[] = 'farbtastic';
         }
         if (in_array(true, array(meta_box_find_field_type('chosen', $this->fields), meta_box_find_field_type('post_chosen', $this->fields)))) {
             wp_register_script('chosen', CUSTOM_METABOXES_DIR . '/js/chosen.js', array('jquery'));
             $deps[] = 'chosen';
             wp_enqueue_style('chosen', CUSTOM_METABOXES_DIR . '/css/chosen.css');
         }
         if (in_array(true, array(meta_box_find_field_type('date', $this->fields), meta_box_find_field_type('slider', $this->fields), meta_box_find_field_type('color', $this->fields), meta_box_find_field_type('chosen', $this->fields), meta_box_find_field_type('post_chosen', $this->fields), meta_box_find_repeatable('repeatable', $this->fields), meta_box_find_field_type('image', $this->fields), meta_box_find_field_type('file', $this->fields)))) {
             wp_enqueue_script('meta_box', CUSTOM_METABOXES_DIR . '/js/scripts.js', $deps);
         }
         // css
         $deps = array();
         wp_register_style('jqueryui', CUSTOM_METABOXES_DIR . '/css/jqueryui.css');
         if (meta_box_find_field_type('date', $this->fields) || meta_box_find_field_type('slider', $this->fields)) {
             $deps[] = 'jqueryui';
         }
         if (meta_box_find_field_type('color', $this->fields)) {
             $deps[] = 'farbtastic';
         }
         wp_enqueue_style('meta_box', CUSTOM_METABOXES_DIR . '/css/meta_box.css', $deps);
     }
 }
 /**
  * enqueue necessary scripts and styles
  */
 function admin_enqueue_scripts()
 {
     global $pagenow;
     if (in_array($pagenow, array('post-new.php', 'post.php')) && in_array(get_post_type(), $this->page)) {
         // js
         $deps = array('jquery');
         if (meta_box_find_field_type('date', $this->fields)) {
             $deps[] = 'jquery-ui-datepicker';
         }
         if (meta_box_find_field_type('slider', $this->fields)) {
             $deps[] = 'jquery-ui-slider';
         }
         if (meta_box_find_field_type('color', $this->fields)) {
             // wp-color-picker
             // http://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/
             $deps[] = 'wp-color-picker';
         }
         wp_enqueue_style('wp-color-picker');
         wp_enqueue_script('my-script-handle', CUSTOM_METABOXES_DIR . '/js/wp-color-picker.js', array('wp-color-picker'), false, true);
         // wp_register_script( 'chosen', CUSTOM_METABOXES_DIR . '/js/chosen.js', array( 'jquery' ) );
         if (in_array(true, array(meta_box_find_field_type('chosen', $this->fields), meta_box_find_field_type('post_chosen', $this->fields)))) {
             wp_enqueue_script('chosen', CUSTOM_METABOXES_DIR . '/js/chosen.js', array('jquery'));
             $deps[] = 'chosen';
             wp_enqueue_style('chosen', CUSTOM_METABOXES_DIR . '/css/chosen.css');
         }
         if (in_array(true, array(meta_box_find_field_type('date', $this->fields), meta_box_find_field_type('slider', $this->fields), meta_box_find_field_type('color', $this->fields), meta_box_find_field_type('chosen', $this->fields), meta_box_find_field_type('post_chosen', $this->fields), meta_box_find_repeatable('repeatable', $this->fields), meta_box_find_field_type('image', $this->fields), meta_box_find_field_type('file', $this->fields)))) {
             wp_enqueue_script('meta_box', CUSTOM_METABOXES_DIR . '/js/scripts.js', $deps);
         }
         // css
         $deps = array();
         wp_register_style('jqueryui', CUSTOM_METABOXES_DIR . '/css/jqueryui.css');
         if (meta_box_find_field_type('date', $this->fields) || meta_box_find_field_type('slider', $this->fields)) {
             $deps[] = 'jqueryui';
         }
         if (meta_box_find_field_type('color', $this->fields)) {
             $deps[] = 'wp-color-picker';
         }
         wp_enqueue_style('meta_box', CUSTOM_METABOXES_DIR . '/css/meta_box.css', $deps);
     }
 }