Ticket #13220: sortable.groups.improvements.2.patch
File sortable.groups.improvements.2.patch, 4.1 KB (added by , 14 years ago) |
---|
-
wp-admin/js/nav-menu.dev.js
163 163 }, 164 164 165 165 initSortables : function() { 166 var currentDepth = 0, originalDepth, minDepth, maxDepth, prevBottom,167 menuLeft = api.menuList.offset().left,168 newItem, transport;166 var currentDepth = 0, originalDepth, minDepth, maxDepth, 167 prev, next, prevBottom, nextThreshold, helperHeight, transport, 168 menuLeft = api.menuList.offset().left; 169 169 170 170 api.menuList.sortable({ 171 171 handle: '.menu-item-handle', 172 172 placeholder: 'sortable-placeholder', 173 173 start: function(e, ui) { 174 var height, width, parent, children, maxChildDepth ;174 var height, width, parent, children, maxChildDepth, tempHolder; 175 175 176 176 transport = ui.item.children('.menu-item-transport'); 177 177 178 178 // Set depths. currentDepth must be set before children are located. 179 originalDepth = ( newItem ) ? 0 :ui.item.menuItemDepth();179 originalDepth = ui.item.menuItemDepth(); 180 180 updateCurrentDepth(ui, originalDepth); 181 181 182 182 // Attach child elements to parent … … 185 185 children = parent.childMenuItems(); 186 186 transport.append( children ); 187 187 188 // Now that the element is complete, we can update...189 updateDepthRange(ui);190 191 188 // Update the height of the placeholder to match the moving item. 192 189 height = transport.outerHeight(); 193 190 // If there are children, account for distance between top of children and parent 194 191 height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0; 195 192 height += ui.helper.outerHeight(); 193 helperHeight = height; 196 194 height -= 2; // Subtract 2 for borders 197 195 ui.placeholder.height(height); 198 196 … … 206 204 width += api.depthToPx(maxChildDepth - originalDepth); // Account for children 207 205 width -= 2; // Subtract 2 for borders 208 206 ui.placeholder.width(width); 207 208 // Update the list of menu items. 209 tempHolder = ui.placeholder.next(); 210 tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder 211 ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item 212 $(this).sortable( "refresh" ); // The children aren't sortable. We should let jQ UI know. 213 ui.item.after( ui.placeholder ); // reattach the placeholder. 214 tempHolder.css('margin-top', 0); // reset the margin 215 216 // Now that the element is complete, we can update... 217 updateSharedVars(ui); 209 218 }, 210 219 stop: function(e, ui) { 211 220 var children, depthChange = currentDepth - originalDepth; … … 227 236 // Make sure the placeholder is inside the menu. 228 237 // Otherwise fix it, or we're in trouble. 229 238 if( ! ui.placeholder.parent().hasClass('menu') ) 230 ui.placeholder.appendTo(api.menuList);239 (prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder ); 231 240 232 update DepthRange(ui);241 updateSharedVars(ui); 233 242 }, 234 243 sort: function(e, ui) { 235 244 var offset = ui.helper.offset(), … … 242 251 243 252 if( depth != currentDepth ) 244 253 updateCurrentDepth(ui, depth); 254 255 // If we overlap the next element, manually shift downwards 256 if( nextThreshold && offset.top + helperHeight > nextThreshold ) { 257 next.after( ui.placeholder ); 258 updateSharedVars( ui ); 259 $(this).sortable( "refreshPositions" ); 260 } 245 261 } 246 262 }); 247 263 248 function updateDepthRange(ui) { 249 var prev = ui.placeholder.prev(), 250 next = ui.placeholder.next(), depth; 264 function updateSharedVars(ui) { 265 var depth; 266 267 prev = ui.placeholder.prev(); 268 next = ui.placeholder.next(); 251 269 252 270 // Make sure we don't select the moving item. 253 271 if( prev[0] == ui.item[0] ) prev = prev.prev(); 254 272 if( next[0] == ui.item[0] ) next = next.next(); 255 273 256 274 prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0; 275 nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0; 257 276 minDepth = (next.length) ? next.menuItemDepth() : 0; 258 277 259 278 if( prev.length )