Ticket #29211: 29211.2.diff
File 29211.2.diff, 13.9 KB (added by , 10 years ago) |
---|
-
src/wp-admin/js/customize-controls.js
1840 1840 * @augments wp.customize.Control 1841 1841 * @augments wp.customize.Class 1842 1842 */ 1843 api. HeaderControl = api.Control.extend({1843 api.CropControl = api.Control.extend({ 1844 1844 ready: function() { 1845 this.btnRemove = $('#customize-control-header_image .actions .remove'); 1846 this.btnNew = $('#customize-control-header_image .actions .new'); 1845 var control = this 1847 1846 1847 this.btnRemove = control.container.find('.actions .remove'); 1848 this.btnNew = control.container.find('.actions .new'); 1849 1848 1850 _.bindAll(this, 'openMedia', 'removeImage'); 1849 1851 1850 1852 this.btnNew.on( 'click', this.openMedia ); … … 1854 1856 1855 1857 new api.HeaderTool.CurrentView({ 1856 1858 model: api.HeaderTool.currentHeader, 1857 el: '#customize-control-header_image .current .container'1859 el: control.container.find('.current .container') 1858 1860 }); 1859 1861 1860 1862 new api.HeaderTool.ChoiceListView({ 1861 1863 collection: api.HeaderTool.UploadsList = new api.HeaderTool.ChoiceList(), 1862 el: '#customize-control-header_image .choices .uploaded .list'1864 el: control.container.find('.choices .uploaded .list') 1863 1865 }); 1864 1866 1865 1867 new api.HeaderTool.ChoiceListView({ 1866 1868 collection: api.HeaderTool.DefaultsList = new api.HeaderTool.DefaultsList(), 1867 el: '#customize-control-header_image .choices .default .list'1869 el: control.container.find('.choices .default .list') 1868 1870 }); 1869 1871 1870 1872 api.HeaderTool.combinedList = api.HeaderTool.CombinedList = new api.HeaderTool.CombinedList([ … … 2096 2098 api.HeaderTool.currentHeader.trigger('hide'); 2097 2099 api.HeaderTool.CombinedList.trigger('control:removeImage'); 2098 2100 } 2101 }); 2099 2102 2103 /** 2104 * @class 2105 * @augments wp.customize.Control 2106 * @augments wp.customize.Class 2107 */ 2108 api.HeaderControl = api.CropControl.extend({ 2109 2100 2110 }); 2101 2111 2102 2112 /** … … 2699 2709 media: api.MediaControl, 2700 2710 upload: api.UploadControl, 2701 2711 image: api.ImageControl, 2712 cropimage: api.CropControl, 2702 2713 header: api.HeaderControl, 2703 2714 background: api.BackgroundControl, 2704 2715 theme: api.ThemeControl -
src/wp-includes/class-wp-customize-control.php
997 997 } 998 998 999 999 /** 1000 * Customize HeaderImage Control class.1000 * Customize Cropped Image Control class. 1001 1001 * 1002 * @since 3.4.01002 * @since 4.3.0 1003 1003 * 1004 1004 * @see WP_Customize_Image_Control 1005 1005 */ 1006 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { 1007 public $type = 'header'; 1008 public $uploaded_headers; 1009 public $default_headers; 1006 abstract class WP_Customize_Cropped_Image_Control extends WP_Customize_Image_Control { 1007 public $type = 'cropimage'; 1010 1008 1009 protected $width = 150; 1010 protected $height = 150; 1011 protected $flex_width = false; 1012 protected $flex_height = false; 1013 protected $localized_name; 1014 protected $current_title = ''; 1015 1016 protected $uploaded_images = array(); 1017 protected $default_images = array(); 1018 1011 1019 /** 1020 * Constructor. 1021 * 1022 * @since 3.4.0 1023 * @uses WP_Customize_Image_Control::__construct() 1024 * 1012 1025 * @param WP_Customize_Manager $manager 1013 1026 */ 1014 public function __construct( $manager ) { 1015 parent::__construct( $manager, 'header_image', array( 1016 'label' => __( 'Header Image' ), 1017 'settings' => array( 1018 'default' => 'header_image', 1019 'data' => 'header_image_data', 1020 ), 1021 'section' => 'header_image', 1022 'removed' => 'remove-header', 1023 'get_url' => 'get_header_image', 1024 ) ); 1027 public function __construct( $manager, $id, $args ) { 1028 $defaults = array( 1029 'localized_name' => '_cropped_image_' . $id 1030 ); 1025 1031 1032 $args = wp_parse_args( $args, $defaults ); 1033 1034 parent::__construct( $manager, $id, $args ); 1026 1035 } 1027 1036 1028 1037 /** … … 1034 1043 1035 1044 $this->prepare_control(); 1036 1045 1037 wp_localize_script( 'customize-views', '_wpCustomizeHeader', array(1046 wp_localize_script( 'customize-views', $this->localized_name, array( 1038 1047 'data' => array( 1039 'width' => absint( get_theme_support( 'custom-header', 'width' ) ), 1040 'height' => absint( get_theme_support( 'custom-header', 'height' ) ), 1041 'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ), 1042 'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ), 1043 'currentImgSrc' => $this->get_current_image_src(), 1048 'width' => absint( $this->width ), 1049 'height' => absint( $this->height ), 1050 'flex-width' => absint( $this->flex_width ), 1051 'flex-height' => absint( $this->flex_height ), 1044 1052 ), 1045 1053 'nonces' => array( 1046 1054 'add' => wp_create_nonce( 'header-add' ), 1047 1055 'remove' => wp_create_nonce( 'header-remove' ), 1048 1056 ), 1049 'uploads' => $this->uploaded_headers,1050 'defaults' => $this->default_ headers1057 'uploads' => $this->uploaded_images, 1058 'defaults' => $this->default_images 1051 1059 ) ); 1052 1060 1053 1061 parent::enqueue(); … … 1054 1062 } 1055 1063 1056 1064 /** 1057 *1058 * @global Custom_Image_Header $custom_image_header1059 */1060 public function prepare_control() {1061 global $custom_image_header;1062 if ( empty( $custom_image_header ) ) {1063 return;1064 }1065 1066 // Process default headers and uploaded headers.1067 $custom_image_header->process_default_headers();1068 $this->default_headers = $custom_image_header->get_default_header_images();1069 $this->uploaded_headers = $custom_image_header->get_uploaded_header_images();1070 }1071 1072 /**1073 1065 * @access public 1074 1066 */ 1075 public function print_ header_image_template() {1067 public function print_crop_image_template() { 1076 1068 ?> 1077 <script type="text/template" id="tmpl-header-choice"> 1078 <# if (data.random) { #> 1079 <button type="button" class="button display-options random"> 1080 <span class="dashicons dashicons-randomize dice"></span> 1081 <# if ( data.type === 'uploaded' ) { #> 1082 <?php _e( 'Randomize uploaded headers' ); ?> 1083 <# } else if ( data.type === 'default' ) { #> 1084 <?php _e( 'Randomize suggested headers' ); ?> 1085 <# } #> 1086 </button> 1087 1088 <# } else { #> 1089 1090 <# if (data.type === 'uploaded') { #> 1091 <button type="button" class="dashicons dashicons-no close"><span class="screen-reader-text"><?php _e( 'Remove image' ); ?></span></button> 1092 <# } #> 1093 1094 <button type="button" class="choice thumbnail" 1095 data-customize-image-value="{{{data.header.url}}}" 1096 data-customize-header-image-data="{{JSON.stringify(data.header)}}"> 1097 <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span> 1098 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}"> 1099 </button> 1100 1101 <# } #> 1102 </script> 1103 1104 <script type="text/template" id="tmpl-header-current"> 1069 <script type="text/template" id="tmpl-cropped-current"> 1105 1070 <# if (data.choice) { #> 1106 1071 <# if (data.random) { #> 1107 1072 … … 1138 1103 } 1139 1104 1140 1105 /** 1141 * @return string|void1142 */1143 public function get_current_image_src() {1144 $src = $this->value();1145 if ( isset( $this->get_url ) ) {1146 $src = call_user_func( $this->get_url, $src );1147 return $src;1148 }1149 }1150 1151 /**1152 1106 * @access public 1153 1107 */ 1154 1108 public function render_content() { 1155 $this->print_ header_image_template();1156 $visibility = $this->get_current_image_src() ? '' : ' style="display:none" '; 1157 $width = absint( get_theme_support( 'custom-header', 'width' ));1158 $height = absint( get_theme_support( 'custom-header', 'height' ));1109 $this->print_crop_image_template(); 1110 1111 $width = absint( $this->width ); 1112 $height = absint( $this->height ); 1159 1113 ?> 1160 1114 1161 1162 1115 <div class="customize-control-content"> 1163 1116 <p class="customizer-section-intro"> 1164 1117 <?php 1165 1118 if ( $width && $height ) { 1166 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a headersize of <strong>%s × %s</strong> pixels.' ), $width, $height );1119 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a size of <strong>%s × %s</strong> pixels.' ), $width, $height ); 1167 1120 } elseif ( $width ) { 1168 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a headerwidth of <strong>%s</strong> pixels.' ), $width );1121 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a width of <strong>%s</strong> pixels.' ), $width ); 1169 1122 } else { 1170 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a he ader height of <strong>%s</strong> pixels.' ), $height );1123 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a height of <strong>%s</strong> pixels.' ), $height ); 1171 1124 } 1172 1125 ?> 1173 1126 </p> 1174 1127 <div class="current"> 1175 1128 <span class="customize-control-title"> 1176 <?php _e( 'Current header' ); ?>1129 <?php echo $this->current_title ? $this->current_title : _x( 'Current', 'cropped image' ); ?> 1177 1130 </span> 1178 1131 <div class="container"> 1179 1132 </div> 1180 1133 </div> 1181 1134 <div class="actions"> 1182 <?php /* translators: Hide as in hide headerimage via the Customizer */ ?>1183 <button type="button" <?php echo $visibility ?> class="button remove"><?php _ex( 'Hide image', 'custom header' ); ?></button>1184 <?php /* translators: New as in add new headerimage via the Customizer */ ?>1185 <button type="button" class="button new"><?php _ex( 'Add new image', ' headerimage' ); ?></button>1135 <?php /* translators: Hide as in hide cropped image via the Customizer */ ?> 1136 <button type="button" class="button remove"><?php _ex( 'Hide image', 'crop image' ); ?></button> 1137 <?php /* translators: New as in add new cropped image via the Customizer */ ?> 1138 <button type="button" class="button new"><?php _ex( 'Add new image', 'cropped image' ); ?></button> 1186 1139 <div style="clear:both"></div> 1187 1140 </div> 1188 1141 <div class="choices"> 1189 <span class="customize-control-title header-previously-uploaded">1190 <?php _ex( 'Previously uploaded', 'c ustom headers' ); ?>1142 <span class="customize-control-title cropped-image-previously-uploaded"> 1143 <?php _ex( 'Previously uploaded', 'cropped images' ); ?> 1191 1144 </span> 1192 1145 <div class="uploaded"> 1193 1146 <div class="list"> 1194 1147 </div> 1195 1148 </div> 1196 <span class="customize-control-title header-default">1197 <?php _ex( 'Suggested', 'c ustom headers' ); ?>1149 <span class="customize-control-title cropped-image-default"> 1150 <?php _ex( 'Suggested', 'cropped images' ); ?> 1198 1151 </span> 1199 1152 <div class="default"> 1200 1153 <div class="list"> … … 1207 1160 } 1208 1161 1209 1162 /** 1163 * Customize Header Image Control class. 1164 * 1165 * @since 3.4.0 1166 * 1167 * @see WP_Customize_Cropped_Image_Control 1168 */ 1169 class WP_Customize_Header_Image_Control extends WP_Customize_Cropped_Image_Control { 1170 public $type = 'header'; 1171 1172 /** 1173 * @param WP_Customize_Manager $manager 1174 */ 1175 public function __construct( $manager ) { 1176 parent::__construct( $manager, 'header_image', array( 1177 'label' => __( 'Header Image' ), 1178 'current_title' => __( 'Current header' ), 1179 'settings' => array( 1180 'default' => 'header_image', 1181 'data' => 'header_image_data', 1182 ), 1183 'section' => 'header_image', 1184 'removed' => 'remove-header', 1185 ) ); 1186 1187 $this->width = get_theme_support( 'custom-header', 'width' ); 1188 $this->height = get_theme_support( 'custom-header', 'height' ); 1189 $this->flex_width = get_theme_support( 'custom-header', 'flex-width' ); 1190 $this->flex_height = get_theme_support( 'custom-header', 'flex-height' ); 1191 $this->localized_name = '_wpCustomizeHeader'; 1192 } 1193 1194 /** 1195 * 1196 * @global Custom_Image_Header $custom_image_header 1197 */ 1198 public function prepare_control() { 1199 global $custom_image_header; 1200 1201 if ( empty( $custom_image_header ) ) { 1202 return; 1203 } 1204 1205 // Process default headers and uploaded headers. 1206 $custom_image_header->process_default_headers(); 1207 $this->default_images = $custom_image_header->get_default_header_images(); 1208 $this->uploaded_images = $custom_image_header->get_uploaded_header_images(); 1209 } 1210 1211 /** 1212 * @access public 1213 */ 1214 public function print_header_image_template() { 1215 ?> 1216 <script type="text/template" id="tmpl-header-choice"> 1217 <# if (data.random) { #> 1218 <button type="button" class="button display-options random"> 1219 <span class="dashicons dashicons-randomize dice"></span> 1220 <# if ( data.type === 'uploaded' ) { #> 1221 <?php _e( 'Randomize uploaded headers' ); ?> 1222 <# } else if ( data.type === 'default' ) { #> 1223 <?php _e( 'Randomize suggested headers' ); ?> 1224 <# } #> 1225 </button> 1226 1227 <# } else { #> 1228 1229 <# if (data.type === 'uploaded') { #> 1230 <button type="button" class="dashicons dashicons-no close"><span class="screen-reader-text"><?php _e( 'Remove image' ); ?></span></button> 1231 <# } #> 1232 1233 <button type="button" class="choice thumbnail" 1234 data-customize-image-value="{{{data.header.url}}}" 1235 data-customize-header-image-data="{{JSON.stringify(data.header)}}"> 1236 <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span> 1237 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}"> 1238 </button> 1239 1240 <# } #> 1241 </script> 1242 <?php 1243 } 1244 1245 /** 1246 * @access public 1247 */ 1248 public function render_content() { 1249 $this->print_header_image_template(); 1250 1251 parent::render_content(); 1252 } 1253 } 1254 1255 /** 1210 1256 * Customize Theme Control class. 1211 1257 * 1212 1258 * @since 4.2.0 -
src/wp-includes/js/customize-views.js
16 16 * @augments wp.Backbone.View 17 17 */ 18 18 api.HeaderTool.CurrentView = wp.Backbone.View.extend({ 19 template: wp.template(' header-current'),19 template: wp.template('cropped-current'), 20 20 21 21 initialize: function() { 22 22 this.listenTo(this.model, 'change', this.render);