From 6a3974f923b530616ac457397178acb4c05008ae Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 27 Dec 2013 22:26:06 -0800 Subject: [PATCH] Auto-open sidebar section in customizer when accessed via notice on widgets admin Fixes #32 --- widget-customizer.js | 13 +++++++++++++ widget-customizer.php | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/widget-customizer.js b/widget-customizer.js index 3680c73..9f81bf6 100644 --- a/widget-customizer.js +++ b/widget-customizer.js @@ -89,7 +89,20 @@ var WidgetCustomizer = (function ($) { active_sidebar_sections.stop().slideDown( function () { $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow } ); + + // Open the first visible sidebar section automatically if widget customizer + // requested from the admin notice on the widgets page + if ( ! self._visibilitySetup && /widget-customizer=open/.test( location.search ) ) { + active_sidebar_sections.filter( ':first' ).each( function () { + if ( ! $( this ).hasClass( 'open' ) ) { + $( this ).find( '.accordion-section-title' ).trigger( 'click' ); + } + this.scrollIntoView(); + } ); + } + self._visibilitySetup = true; } ); + }; /** diff --git a/widget-customizer.php b/widget-customizer.php index d9231f2..11470ed 100644 --- a/widget-customizer.php +++ b/widget-customizer.php @@ -1166,8 +1166,9 @@ static function widget_customizer_link() { echo sprintf( __( 'The Widget Customizer plugin is activated. You can now edit and preview changes to widgets in the %1$s.', 'widget-customizer' ), sprintf( - '%2$s', - admin_url( 'customize.php' ), + '%3$s', + admin_url( 'customize.php?widget-customizer=open' ), + esc_attr__( 'Open the Customizer with the section for the template\'s first rendered sidebar pre-opened.', 'widget-customizer' ), esc_html__( 'Customizer', 'widget-customizer' ) ) ); // xss ok