]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/postbox.js
Wordpress 4.6-scripts
[autoinstalls/wordpress.git] / wp-admin / js / postbox.js
index c75e423dfd0fbb29459db0f9b11df719361f94d1..a8222ee296fc2dbf80fea8f1faba0aaa4cb6632d 100644 (file)
@@ -1,4 +1,4 @@
-/* global ajaxurl */
+/* global ajaxurl, postBoxL10n */
 
 var postboxes;
 
@@ -109,7 +109,20 @@ var postboxes;
                                distance: 2,
                                tolerance: 'pointer',
                                forcePlaceholderSize: true,
-                               helper: 'clone',
+                               helper: function( event, element ) {
+                                       // `helper: 'clone'` is equivalent to `return element.clone();`
+                                       // Cloning a checked radio and then inserting that clone next to the original
+                                       // radio unchecks the original radio (since only one of the two can be checked).
+                                       // We get around this by renaming the helper's inputs' name attributes so that,
+                                       // when the helper is inserted into the DOM for the sortable, no radios are
+                                       // duplicated, and no original radio gets unchecked.
+                                       return element.clone()
+                                               .find( ':input' )
+                                                       .attr( 'name', function( i, currentName ) {
+                                                               return 'sort_' + parseInt( Math.random() * 100000, 10 ).toString() + '_' + currentName;
+                                                       } )
+                                               .end();
+                               },
                                opacity: 0.65,
                                stop: function() {
                                        var $el = $( this );
@@ -126,6 +139,7 @@ var postboxes;
                                                $(ui.sender).sortable('cancel');
 
                                        postboxes._mark_area();
+                                       $document.trigger( 'postbox-moved', ui.item );
                                }
                        });
 
@@ -184,10 +198,13 @@ var postboxes;
                        $( '#dashboard-widgets .meta-box-sortables:visible' ).each( function() {
                                var t = $(this);
 
-                               if ( visible == 1 || t.children('.postbox:visible').length )
+                               if ( visible == 1 || t.children('.postbox:visible').length ) {
                                        t.removeClass('empty-container');
-                               else
+                               }
+                               else {
                                        t.addClass('empty-container');
+                                       t.attr('data-emptyString', postBoxL10n.postBoxEmptyString);
+                               }
                        });
 
                        if ( side.length ) {