Make WordPress Core

Changeset 33014


Ignore:
Timestamp:
07/01/2015 12:57:03 AM (9 years ago)
Author:
obenland
Message:

Open closed widget areas when dragging onto them.

Allows dropping Widgets into the correct spot of a given sidebar, no matter
whether that sidebar is open or closed. Removes a step from the setup process
for closed sidebars.

Props polevaultweb.
Fixes #13524.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/widgets.js

    r32689 r33014  
    55
    66wpWidgets = {
     7    /**
     8     * A closed Sidebar that gets a Widget dragged over it.
     9     *
     10     * @var element|null
     11     */
     12    hoveredSidebar: null,
    713
    814    init : function() {
     
    95101            zIndex: 100,
    96102            containment: '#wpwrap',
     103            refreshPositions: true,
    97104            start: function( event, ui ) {
    98105                var chooser = $(this).find('.widgets-chooser');
     
    117124            }
    118125        });
     126
     127        /**
     128         * Opens and closes previously closed Sidebars when Widgets are dragged over/out of them.
     129         */
     130        sidebars.droppable( {
     131            tolerance: 'pointer',
     132
     133            /**
     134             * Open Sidebar when a Widget gets dragged over it.
     135             *
     136             * @param event
     137             */
     138            over: function( event ) {
     139                var $wrap = $( event.target ).parent();
     140
     141                if ( wpWidgets.hoveredSidebar && ! $wrap.is( wpWidgets.hoveredSidebar ) ) {
     142                    // Close the previous Sidebar as the Widget has been dragged onto another Sidebar.
     143                    wpWidgets.closeSidebar( event );
     144                }
     145
     146                if ( $wrap.hasClass( 'closed' ) ) {
     147                    wpWidgets.hoveredSidebar = $wrap;
     148                    $wrap.removeClass( 'closed' );
     149                }
     150            },
     151
     152            /**
     153             * Close Sidebar when the Widget gets dragged out of it.
     154             *
     155             * @param event
     156             */
     157            out: function( event ) {
     158                if ( wpWidgets.hoveredSidebar ) {
     159                    wpWidgets.closeSidebar( event );
     160                }
     161            }
     162        } );
    119163
    120164        sidebars.sortable({
     
    149193                    id = the_id;
    150194
     195                // Reset the var to hold a previously closed sidebar.
     196                wpWidgets.hoveredSidebar = null;
     197
    151198                if ( $widget.hasClass('deleting') ) {
    152199                    wpWidgets.save( $widget, 1, 0, 1 ); // delete widget
     
    492539        $( '#widgets-left' ).removeClass( 'chooser' );
    493540        $( '.widget-in-question' ).removeClass( 'widget-in-question' );
     541    },
     542
     543    /**
     544     * Closes a Sidebar that was previously closed, but opened by dragging a Widget over it.
     545     *
     546     * Used when a Widget gets dragged in/out of the Sidebar and never dropped.
     547     *
     548     * @param sidebar
     549     */
     550    closeSidebar: function( sidebar ) {
     551        this.hoveredSidebar.addClass( 'closed' );
     552        $( sidebar.target ).css( 'min-height', '' );
     553        this.hoveredSidebar = null;
    494554    }
    495555};
Note: See TracChangeset for help on using the changeset viewer.