1368
1367
* @param {Object} args merged on top of this.defaultActiveArguments
1370
1369
onChangeExpanded: function ( expanded, args ) {
1371
var self = this, $widget, $inside, complete, prevComplete, expandControl;
1370
var self = this, $widget, $inside, complete, prevComplete, expandControl, $toggleBtn;
1373
1372
self.embedWidgetControl(); // Make sure the outer form is embedded so that the expanded state can be set in the UI.
1374
1373
if ( expanded ) {
1577
1578
api.Panel.prototype.ready.call( panel );
1579
1580
panel.deferred.embedded.done(function() {
1580
var panelMetaContainer, noRenderedAreasNotice, shouldShowNotice;
1581
var panelMetaContainer, noticeContainer, updateNotice, getActiveSectionCount, shouldShowNotice;
1581
1582
panelMetaContainer = panel.container.find( '.panel-meta' );
1582
noRenderedAreasNotice = $( '<div></div>', {
1584
// @todo This should use the Notifications API introduced to panels. See <https://core.trac.wordpress.org/ticket/38794>.
1585
noticeContainer = $( '<div></div>', {
1583
1586
'class': 'no-widget-areas-rendered-notice'
1585
noRenderedAreasNotice.append( $( '<em></em>', {
1586
text: l10n.noAreasRendered
1588
panelMetaContainer.append( noRenderedAreasNotice );
1588
panelMetaContainer.append( noticeContainer );
1591
* Get the number of active sections in the panel.
1593
* @return {number} Number of active sidebar sections.
1595
getActiveSectionCount = function() {
1596
return _.filter( panel.sections(), function( section ) {
1597
return section.active();
1602
* Determine whether or not the notice should be displayed.
1590
1606
shouldShowNotice = function() {
1591
return ( 0 === _.filter( panel.sections(), function( section ) {
1592
return section.active();
1607
var activeSectionCount = getActiveSectionCount();
1608
if ( 0 === activeSectionCount ) {
1611
return activeSectionCount !== api.Widgets.data.registeredSidebars.length;
1616
* Update the notice.
1620
updateNotice = function() {
1621
var activeSectionCount = getActiveSectionCount(), someRenderedMessage, nonRenderedAreaCount, registeredAreaCount;
1622
noticeContainer.empty();
1624
registeredAreaCount = api.Widgets.data.registeredSidebars.length;
1625
if ( activeSectionCount !== registeredAreaCount ) {
1627
if ( 0 !== activeSectionCount ) {
1628
nonRenderedAreaCount = registeredAreaCount - activeSectionCount;
1629
someRenderedMessage = l10n.someAreasShown[ nonRenderedAreaCount ];
1631
someRenderedMessage = l10n.noAreasShown;
1633
if ( someRenderedMessage ) {
1634
noticeContainer.append( $( '<p></p>', {
1635
text: someRenderedMessage
1639
noticeContainer.append( $( '<p></p>', {
1640
text: l10n.navigatePreview
1597
1647
* Set the initial visibility state for rendered notice.
1598
1648
* Update the visibility of the notice whenever a reflow happens.
1600
noRenderedAreasNotice.toggle( shouldShowNotice() );
1650
noticeContainer.toggle( shouldShowNotice() );
1601
1651
api.previewer.deferred.active.done( function () {
1602
noRenderedAreasNotice.toggle( shouldShowNotice() );
1652
noticeContainer.toggle( shouldShowNotice() );
1604
1654
api.bind( 'pane-contents-reflowed', function() {
1605
1655
var duration = ( 'resolved' === api.previewer.deferred.active.state() ) ? 'fast' : 0;
1606
1657
if ( shouldShowNotice() ) {
1607
noRenderedAreasNotice.slideDown( duration );
1658
noticeContainer.slideDown( duration );
1609
noRenderedAreasNotice.slideUp( duration );
1660
noticeContainer.slideUp( duration );