<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[32681] trunk: Customizer: Improve JS templates for Panels and Sections added in [32658].</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/32681">32681</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/32681","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-06-01 22:46:56 +0000 (Mon, 01 Jun 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Customizer: Improve JS templates for Panels and Sections added in <a href="https://core.trac.wordpress.org/changeset/32658">[32658]</a>.

* Always fall back to using the default template if no custom template exists.
* Provide a set of default params when constructing new `Section` and `Panel` objects.

Includes QUnit tests.

Props celloexpressions, westonruter, ocean90.
Fixes <a href="https://core.trac.wordpress.org/ticket/30737">#30737</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjscustomizecontrolsjs">trunk/src/wp-admin/js/customize-controls.js</a></li>
<li><a href="#trunktestsqunitfixturescustomizesettingsjs">trunk/tests/qunit/fixtures/customize-settings.js</a></li>
<li><a href="#trunktestsqunitwpadminjscustomizecontrolsjs">trunk/tests/qunit/wp-admin/js/customize-controls.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjscustomizecontrolsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/customize-controls.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-controls.js       2015-06-01 19:01:53 UTC (rev 32680)
+++ trunk/src/wp-admin/js/customize-controls.js 2015-06-01 22:46:56 UTC (rev 32681)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -157,18 +157,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">                defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
</span><span class="cx" style="display: block; padding: 0 10px">                defaultExpandedArguments: { duration: 'fast', completeCallback: $.noop },
</span><span class="cx" style="display: block; padding: 0 10px">                containerType: 'container',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                defaults: {
+                       title: '',
+                       description: '',
+                       priority: 100,
+                       type: 'default',
+                       content: null,
+                       active: true,
+                       instanceNumber: null
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 4.1.0
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param {String} id
-                * @param {Object} options
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {string}         id - The ID for the container.
+                * @param {object}         options - Object containing one property: params.
+                * @param {object}         options.params - Object containing the following properties.
+                * @param {string}         options.params.title - Title shown when panel is collapsed and expanded.
+                * @param {string=}        [options.params.description] - Description shown at the top of the panel.
+                * @param {number=100}     [options.params.priority] - The sort priority for the panel.
+                * @param {string=default} [options.params.type] - The type of the panel. See wp.customize.panelConstructor.
+                * @param {string=}        [options.params.content] - The markup to be used for the panel container. If empty, a JS template is used.
+                * @param {boolean=true}   [options.params.active] - Whether the panel is active or not.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                initialize: function ( id, options ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        var container = this;
</span><span class="cx" style="display: block; padding: 0 10px">                        container.id = id;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        container.params = {};
-                       $.extend( container, options || {} );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 options = options || {};
+
+                       options.params = _.defaults(
+                               options.params || {},
+                               container.defaults
+                       );
+
+                       $.extend( container, options );
</ins><span class="cx" style="display: block; padding: 0 10px">                         container.templateSelector = 'customize-' + container.containerType + '-' + container.params.type;
</span><span class="cx" style="display: block; padding: 0 10px">                        container.container = $( container.params.content );
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( 0 === container.container.length ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -202,7 +224,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        api.utils.bubbleChildValueChanges( container, [ 'priority', 'active' ] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        container.priority.set( isNaN( container.params.priority ) ? 100 : container.params.priority );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 container.priority.set( container.params.priority );
</ins><span class="cx" style="display: block; padding: 0 10px">                         container.active.set( container.params.active );
</span><span class="cx" style="display: block; padding: 0 10px">                        container.expanded.set( false );
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -386,10 +408,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( 0 !== $( '#tmpl-' + container.templateSelector ).length ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                template = wp.template( container.templateSelector );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( template && container.container ) {
-                                       return $.trim( template( container.params ) );
-                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } else {
+                               template = wp.template( 'customize-' + container.containerType + '-default' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( template && container.container ) {
+                               return $.trim( template( container.params ) );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        return '<li></li>';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -403,12 +427,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        api.Section = Container.extend({
</span><span class="cx" style="display: block; padding: 0 10px">                containerType: 'section',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                defaults: {
+                       title: '',
+                       description: '',
+                       priority: 100,
+                       type: 'default',
+                       content: null,
+                       active: true,
+                       instanceNumber: null,
+                       panel: null,
+                       customizeAction: ''
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 4.1.0
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param {String} id
-                * @param {Array}  options
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {string}         id - The ID for the section.
+                * @param {object}         options - Object containing one property: params.
+                * @param {object}         options.params - Object containing the following properties.
+                * @param {string}         options.params.title - Title shown when section is collapsed and expanded.
+                * @param {string=}        [options.params.description] - Description shown at the top of the section.
+                * @param {number=100}     [options.params.priority] - The sort priority for the section.
+                * @param {string=default} [options.params.type] - The type of the section. See wp.customize.sectionConstructor.
+                * @param {string=}        [options.params.content] - The markup to be used for the section container. If empty, a JS template is used.
+                * @param {boolean=true}   [options.params.active] - Whether the section is active or not.
+                * @param {string}         options.params.panel - The ID for the panel this section is associated with.
+                * @param {string=}        [options.params.customizeAction] - Additional context information shown before the section title when expanded.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                initialize: function ( id, options ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        var section = this;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1009,8 +1053,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 4.1.0
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param  {String} id
-                * @param  {Object} options
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {string}         id - The ID for the panel.
+                * @param {object}         options - Object containing one property: params.
+                * @param {object}         options.params - Object containing the following properties.
+                * @param {string}         options.params.title - Title shown when panel is collapsed and expanded.
+                * @param {string=}        [options.params.description] - Description shown at the top of the panel.
+                * @param {number=100}     [options.params.priority] - The sort priority for the panel.
+                * @param {string=default} [options.params.type] - The type of the panel. See wp.customize.panelConstructor.
+                * @param {string=}        [options.params.content] - The markup to be used for the panel container. If empty, a JS template is used.
+                * @param {boolean=true}   [options.params.active] - Whether the panel is active or not.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                initialize: function ( id, options ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        var panel = this;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1216,10 +1267,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        // Add the content to the container.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( 0 !== $( '#tmpl-' + panel.templateSelector + '-content' ).length ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                template = wp.template( panel.templateSelector + '-content' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( template && panel.container ) {
-                                       panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) );
-                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } else {
+                               template = wp.template( 'customize-panel-default-content' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( template && panel.container ) {
+                               panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        });
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsqunitfixturescustomizesettingsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/fixtures/customize-settings.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/fixtures/customize-settings.js  2015-06-01 19:01:53 UTC (rev 32680)
+++ trunk/tests/qunit/fixtures/customize-settings.js    2015-06-01 22:46:56 UTC (rev 32681)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -57,7 +57,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'priority': 110,
</span><span class="cx" style="display: block; padding: 0 10px">                        'title': 'Fixture titleless panel using template',
</span><span class="cx" style="display: block; padding: 0 10px">                        'type': 'titleless'
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         },
+               'fixture-panel-reusing-default-template': {
+                       'active': true,
+                       'description': 'Lorem ipsum',
+                       'instanceNumber': 3,
+                       'priority': 110,
+                       'title': 'Fixture panel of custom type re-using default template',
+                       'type': 'reusing-default-template'
+               },
+               'fixture-panel-without-params': {}
</ins><span class="cx" style="display: block; padding: 0 10px">         },
</span><span class="cx" style="display: block; padding: 0 10px">        'sections': {
</span><span class="cx" style="display: block; padding: 0 10px">                'fixture-section': {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -87,7 +96,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'priority': 20,
</span><span class="cx" style="display: block; padding: 0 10px">                        'title': 'Fixture titleless section using template',
</span><span class="cx" style="display: block; padding: 0 10px">                        'type': 'titleless'
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         },
+               'fixture-section-reusing-default-template': {
+                       'active': true,
+                       'description': '',
+                       'instanceNumber': 4,
+                       'panel': 'fixture-panel',
+                       'priority': 20,
+                       'title': 'Fixture section of custom type re-using default template',
+                       'type': 'reusing-default-template'
+               },
+               'fixture-section-without-params': {}
</ins><span class="cx" style="display: block; padding: 0 10px">         },
</span><span class="cx" style="display: block; padding: 0 10px">        'settings': {
</span><span class="cx" style="display: block; padding: 0 10px">                'fixture-setting': {
</span></span></pre></div>
<a id="trunktestsqunitwpadminjscustomizecontrolsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/wp-admin/js/customize-controls.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/wp-admin/js/customize-controls.js       2015-06-01 19:01:53 UTC (rev 32680)
+++ trunk/tests/qunit/wp-admin/js/customize-controls.js 2015-06-01 22:46:56 UTC (rev 32681)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -136,7 +136,38 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ok( 0 === section.container.find( '> .accordion-section-title' ).length );
</span><span class="cx" style="display: block; padding: 0 10px">                ok( 1 === section.container.find( '> .accordion-section-content' ).length );
</span><span class="cx" style="display: block; padding: 0 10px">        } );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        module( 'Customizer Custom Type Section Lacking Specific Template' );
+       test( 'Fixture section has expected content', function () {
+               var id = 'fixture-section-reusing-default-template', section;
+               section = wp.customize.section( id );
+               ok( ! section.params.content );
+               ok( !! section.container );
+               ok( section.container.is( '.control-section.control-section-' + section.params.type ) );
+               ok( 1 === section.container.find( '> .accordion-section-title' ).length );
+               ok( 1 === section.container.find( '> .accordion-section-content' ).length );
+       } );
+       module( 'Customizer Section lacking any params' );
+       test( 'Fixture section has default params supplied', function () {
+               var id = 'fixture-section-without-params', section, defaultParams;
+               section = wp.customize.section( id );
+               defaultParams = {
+                       title: '',
+                       description: '',
+                       priority: 100,
+                       panel: null,
+                       type: 'default',
+                       content: null,
+                       active: true,
+                       instanceNumber: null,
+                       customizeAction: ''
+               };
+               jQuery.each( defaultParams, function ( key, value ) {
+                       ok( 'undefined' !== typeof section.params[ key ] );
+                       equal( value, section.params[ key ] );
+               } );
+       } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">         // Begin panels.
</span><span class="cx" style="display: block; padding: 0 10px">        module( 'Customizer Panel in Fixture' );
</span><span class="cx" style="display: block; padding: 0 10px">        test( 'Fixture panel exists', function () {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -199,6 +230,34 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ok( 1 === panel.container.find( '> .control-panel-content' ).length );
</span><span class="cx" style="display: block; padding: 0 10px">        } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        module( 'Customizer Custom Type Panel Lacking Specific Template' );
+       test( 'Fixture panel has expected content', function () {
+               var id = 'fixture-panel-reusing-default-template', panel;
+               panel = wp.customize.panel( id );
+               ok( ! panel.params.content );
+               ok( !! panel.container );
+               ok( panel.container.is( '.control-panel.control-panel-' + panel.params.type ) );
+               ok( 1 === panel.container.find( '> .accordion-section-title' ).length );
+               ok( 1 === panel.container.find( '> .control-panel-content' ).length );
+       } );
+       module( 'Customizer Panel lacking any params' );
+       test( 'Fixture panel has default params supplied', function () {
+               var id = 'fixture-panel-without-params', panel, defaultParams;
+               panel = wp.customize.panel( id );
+               defaultParams = {
+                       title: '',
+                       description: '',
+                       priority: 100,
+                       type: 'default',
+                       content: null,
+                       active: true,
+                       instanceNumber: null
+               };
+               jQuery.each( defaultParams, function ( key, value ) {
+                       ok( 'undefined' !== typeof panel.params[ key ] );
+                       equal( value, panel.params[ key ] );
+               } );
+       } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        module( 'Dynamically-created Customizer Setting Model' );
</span><span class="cx" style="display: block; padding: 0 10px">        settingId = 'new_blogname';
</span></span></pre>
</div>
</div>

</body>
</html>