diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index 2d7f3ba..5f9fbe6 100644
|
|
|
165 | 165 | * @param {Object} options |
166 | 166 | */ |
167 | 167 | initialize: function ( id, options ) { |
168 | | var container = this; |
| 168 | var container = this, defaultParams; |
169 | 169 | container.id = id; |
170 | | container.params = {}; |
171 | | $.extend( container, options || {} ); |
| 170 | options = options || {}; |
| 171 | defaultParams = { |
| 172 | title: '', |
| 173 | description: '', |
| 174 | priority: 100, |
| 175 | type: 'default', |
| 176 | content: null, |
| 177 | active: true, |
| 178 | instanceNumber: null |
| 179 | }; |
| 180 | if ( 'section' === container.containerType ) { |
| 181 | $.extend( defaultParams, { |
| 182 | panel: null, |
| 183 | customizeAction: '' |
| 184 | }); |
| 185 | } |
| 186 | options.params = $.extend( |
| 187 | defaultParams, |
| 188 | options.params || {} |
| 189 | ); |
| 190 | $.extend( container, options ); |
172 | 191 | container.templateSelector = 'customize-' + container.containerType + '-' + container.params.type; |
173 | 192 | container.container = $( container.params.content ); |
174 | 193 | if ( 0 === container.container.length ) { |
… |
… |
|
202 | 221 | |
203 | 222 | api.utils.bubbleChildValueChanges( container, [ 'priority', 'active' ] ); |
204 | 223 | |
205 | | container.priority.set( isNaN( container.params.priority ) ? 100 : container.params.priority ); |
| 224 | container.priority.set( container.params.priority ); |
206 | 225 | container.active.set( container.params.active ); |
207 | 226 | container.expanded.set( false ); |
208 | 227 | }, |
… |
… |
|
386 | 405 | |
387 | 406 | if ( 0 !== $( '#tmpl-' + container.templateSelector ).length ) { |
388 | 407 | template = wp.template( container.templateSelector ); |
389 | | if ( template && container.container ) { |
390 | | return $.trim( template( container.params ) ); |
391 | | } |
| 408 | } else { |
| 409 | template = wp.template( 'customize-' + container.containerType + '-default' ); |
| 410 | } |
| 411 | if ( template && container.container ) { |
| 412 | return $.trim( template( container.params ) ); |
392 | 413 | } |
393 | 414 | |
394 | 415 | return '<li></li>'; |
… |
… |
|
407 | 428 | /** |
408 | 429 | * @since 4.1.0 |
409 | 430 | * |
410 | | * @param {String} id |
411 | | * @param {Array} options |
| 431 | * @param {string} id - The ID for the section. |
| 432 | * @param {object} options - Object containing one property: params. |
| 433 | * @param {object} options.params - Object containing the following properties. |
| 434 | * @param {string} options.params.title - Title shown when section is collapsed and expanded. |
| 435 | * @param {string=} [options.params.description] - Description shown at the top of the section. |
| 436 | * @param {number=100} [options.params.priority] - The sort priority for the section. |
| 437 | * @param {string=default} [options.params.type] - The type of the section. See wp.customize.sectionConstructor. |
| 438 | * @param {string=} [options.params.content] - The markup to be used for the section container. If empty, a JS template is used. |
| 439 | * @param {boolean=true} [options.params.active] - Whether the section is active or not. |
| 440 | * @param {string} options.params.panel - The ID for the panel this section is associated with. |
| 441 | * @param {string=} [options.params.customizeAction] - Additional context information shown before the section title when expanded. |
412 | 442 | */ |
413 | 443 | initialize: function ( id, options ) { |
414 | 444 | var section = this; |
… |
… |
|
1009 | 1039 | /** |
1010 | 1040 | * @since 4.1.0 |
1011 | 1041 | * |
1012 | | * @param {String} id |
1013 | | * @param {Object} options |
| 1042 | * @param {string} id - The ID for the panel. |
| 1043 | * @param {object} options - Object containing one property: params. |
| 1044 | * @param {object} options.params - Object containing the following properties. |
| 1045 | * @param {string} options.params.title - Title shown when panel is collapsed and expanded. |
| 1046 | * @param {string=} [options.params.description] - Description shown at the top of the panel. |
| 1047 | * @param {number=100} [options.params.priority] - The sort priority for the panel. |
| 1048 | * @param {string=default} [options.params.type] - The type of the panel. See wp.customize.panelConstructor. |
| 1049 | * @param {string=} [options.params.content] - The markup to be used for the panel container. If empty, a JS template is used. |
| 1050 | * @param {boolean=true} [options.params.active] - Whether the panel is active or not. |
1014 | 1051 | */ |
1015 | 1052 | initialize: function ( id, options ) { |
1016 | 1053 | var panel = this; |
… |
… |
|
1216 | 1253 | // Add the content to the container. |
1217 | 1254 | if ( 0 !== $( '#tmpl-' + panel.templateSelector + '-content' ).length ) { |
1218 | 1255 | template = wp.template( panel.templateSelector + '-content' ); |
1219 | | if ( template && panel.container ) { |
1220 | | panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) ); |
1221 | | } |
| 1256 | } else { |
| 1257 | template = wp.template( 'customize-panel-default-content' ); |
| 1258 | } |
| 1259 | if ( template && panel.container ) { |
| 1260 | panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) ); |
1222 | 1261 | } |
1223 | 1262 | } |
1224 | 1263 | }); |
diff --git tests/qunit/fixtures/customize-settings.js tests/qunit/fixtures/customize-settings.js
index 5ef44a1..bc92c4c 100644
|
|
window._wpCustomizeSettings = { |
57 | 57 | 'priority': 110, |
58 | 58 | 'title': 'Fixture titleless panel using template', |
59 | 59 | 'type': 'titleless' |
60 | | } |
| 60 | }, |
| 61 | 'fixture-panel-reusing-default-template': { |
| 62 | 'active': true, |
| 63 | 'description': 'Lorem ipsum', |
| 64 | 'instanceNumber': 3, |
| 65 | 'priority': 110, |
| 66 | 'title': 'Fixture panel of custom type re-using default template', |
| 67 | 'type': 'reusing-default-template' |
| 68 | }, |
| 69 | 'fixture-panel-without-params': {} |
61 | 70 | }, |
62 | 71 | 'sections': { |
63 | 72 | 'fixture-section': { |
… |
… |
window._wpCustomizeSettings = { |
87 | 96 | 'priority': 20, |
88 | 97 | 'title': 'Fixture titleless section using template', |
89 | 98 | 'type': 'titleless' |
90 | | } |
| 99 | }, |
| 100 | 'fixture-section-reusing-default-template': { |
| 101 | 'active': true, |
| 102 | 'description': '', |
| 103 | 'instanceNumber': 4, |
| 104 | 'panel': 'fixture-panel', |
| 105 | 'priority': 20, |
| 106 | 'title': 'Fixture section of custom type re-using default template', |
| 107 | 'type': 'reusing-default-template' |
| 108 | }, |
| 109 | 'fixture-section-without-params': {} |
91 | 110 | }, |
92 | 111 | 'settings': { |
93 | 112 | 'fixture-setting': { |
diff --git tests/qunit/wp-admin/js/customize-controls.js tests/qunit/wp-admin/js/customize-controls.js
index 215d468..6ca4908 100644
|
|
jQuery( window ).load( function (){ |
136 | 136 | ok( 0 === section.container.find( '> .accordion-section-title' ).length ); |
137 | 137 | ok( 1 === section.container.find( '> .accordion-section-content' ).length ); |
138 | 138 | } ); |
| 139 | module( 'Customizer Custom Type Section Lacking Specific Template' ); |
| 140 | test( 'Fixture section has expected content', function () { |
| 141 | var id = 'fixture-section-reusing-default-template', section; |
| 142 | section = wp.customize.section( id ); |
| 143 | ok( ! section.params.content ); |
| 144 | ok( !! section.container ); |
| 145 | ok( section.container.is( '.control-section.control-section-' + section.params.type ) ); |
| 146 | ok( 1 === section.container.find( '> .accordion-section-title' ).length ); |
| 147 | ok( 1 === section.container.find( '> .accordion-section-content' ).length ); |
| 148 | } ); |
| 149 | module( 'Customizer Section lacking any params' ); |
| 150 | test( 'Fixture section has default params supplied', function () { |
| 151 | var id = 'fixture-section-without-params', section, defaultParams; |
| 152 | section = wp.customize.section( id ); |
| 153 | defaultParams = { |
| 154 | title: '', |
| 155 | description: '', |
| 156 | priority: 100, |
| 157 | panel: null, |
| 158 | type: 'default', |
| 159 | content: null, |
| 160 | active: true, |
| 161 | instanceNumber: null, |
| 162 | customizeAction: '' |
| 163 | }; |
| 164 | jQuery.each( defaultParams, function ( key, value ) { |
| 165 | ok( 'undefined' !== typeof section.params[ key ] ); |
| 166 | equal( value, section.params[ key ] ); |
| 167 | } ); |
| 168 | } ); |
| 169 | |
139 | 170 | |
140 | 171 | // Begin panels. |
141 | 172 | module( 'Customizer Panel in Fixture' ); |
… |
… |
jQuery( window ).load( function (){ |
199 | 230 | ok( 1 === panel.container.find( '> .control-panel-content' ).length ); |
200 | 231 | } ); |
201 | 232 | |
| 233 | module( 'Customizer Custom Type Panel Lacking Specific Template' ); |
| 234 | test( 'Fixture panel has expected content', function () { |
| 235 | var id = 'fixture-panel-reusing-default-template', panel; |
| 236 | panel = wp.customize.panel( id ); |
| 237 | ok( ! panel.params.content ); |
| 238 | ok( !! panel.container ); |
| 239 | ok( panel.container.is( '.control-panel.control-panel-' + panel.params.type ) ); |
| 240 | ok( 1 === panel.container.find( '> .accordion-section-title' ).length ); |
| 241 | ok( 1 === panel.container.find( '> .control-panel-content' ).length ); |
| 242 | } ); |
| 243 | module( 'Customizer Panel lacking any params' ); |
| 244 | test( 'Fixture panel has default params supplied', function () { |
| 245 | var id = 'fixture-panel-without-params', panel, defaultParams; |
| 246 | panel = wp.customize.panel( id ); |
| 247 | defaultParams = { |
| 248 | title: '', |
| 249 | description: '', |
| 250 | priority: 100, |
| 251 | type: 'default', |
| 252 | content: null, |
| 253 | active: true, |
| 254 | instanceNumber: null |
| 255 | }; |
| 256 | jQuery.each( defaultParams, function ( key, value ) { |
| 257 | ok( 'undefined' !== typeof panel.params[ key ] ); |
| 258 | equal( value, panel.params[ key ] ); |
| 259 | } ); |
| 260 | } ); |
202 | 261 | |
203 | 262 | module( 'Dynamically-created Customizer Setting Model' ); |
204 | 263 | settingId = 'new_blogname'; |