Changeset 26163
- Timestamp:
- 11/14/2013 06:08:11 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/nav-menu.js
r25708 r26163 9 9 */ 10 10 11 /* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl */ 12 11 13 var wpNavMenu; 12 14 13 15 (function($) { 14 16 15 var api = wpNavMenu = { 17 var api; 18 19 api = wpNavMenu = { 16 20 17 21 options : { … … 112 116 // If it has children, move those too 113 117 if ( children ) { 114 children.each(function( index) {118 children.each(function() { 115 119 var t = $(this), 116 120 thisDepth = t.menuItemDepth(), … … 131 135 var item = $(this), 132 136 input = item.find( '.menu-item-data-parent-id' ), 133 depth = parseInt( item.menuItemDepth() ),137 depth = parseInt( item.menuItemDepth(), 10 ), 134 138 parentDepth = depth - 1, 135 139 parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first(); 136 140 137 if ( 0 == depth ) { // Item is on the top level, has no parent141 if ( 0 === depth ) { // Item is on the top level, has no parent 138 142 input.val(0); 139 143 } else { // Find the parent item, and retrieve its object id. … … 156 160 */ 157 161 addSelectedToMenu : function(processMethod) { 158 if ( 0 == $('#menu-to-edit').length ) {162 if ( 0 === $('#menu-to-edit').length ) { 159 163 return false; 160 164 } … … 162 166 return this.each(function() { 163 167 var t = $(this), menuItems = {}, 164 checkboxes = ( menus.oneThemeLocationNoMenus && 0 == t.find('.tabs-panel-active .categorychecklist li input:checked').length ) ? t.find('#page-all li input[type="checkbox"]') : t.find('.tabs-panel-active .categorychecklist li input:checked'),165 re = new RegExp('menu-item\\[(\[^\\]\]*)');168 checkboxes = ( menus.oneThemeLocationNoMenus && 0 === t.find( '.tabs-panel-active .categorychecklist li input:checked' ).length ) ? t.find( '#page-all li input[type="checkbox"]' ) : t.find( '.tabs-panel-active .categorychecklist li input:checked' ), 169 re = /menu-item\[([^]\]*)/; 166 170 167 171 processMethod = processMethod || api.addMenuItemToBottom; … … 272 276 moveMenuItem : function( $this, dir ) { 273 277 274 var menuItems = $('#menu-to-edit li'); 278 var items, newItemPosition, newDepth, 279 menuItems = $( '#menu-to-edit li' ), 275 280 menuItemsCount = menuItems.length, 276 281 thisItem = $this.parents( 'li.menu-item' ), 277 282 thisItemChildren = thisItem.childMenuItems(), 278 283 thisItemData = thisItem.getItemData(), 279 thisItemDepth = parseInt( thisItem.menuItemDepth() ),280 thisItemPosition = parseInt( thisItem.index() ),284 thisItemDepth = parseInt( thisItem.menuItemDepth(), 10 ), 285 thisItemPosition = parseInt( thisItem.index(), 10 ), 281 286 nextItem = thisItem.next(), 282 287 nextItemChildren = nextItem.childMenuItems(), 283 nextItemDepth = parseInt( nextItem.menuItemDepth() ) + 1,288 nextItemDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1, 284 289 prevItem = thisItem.prev(), 285 prevItemDepth = parseInt( prevItem.menuItemDepth() ),290 prevItemDepth = parseInt( prevItem.menuItemDepth(), 10 ), 286 291 prevItemId = prevItem.getItemData()['menu-item-db-id']; 287 292 288 293 switch ( dir ) { 289 294 case 'up': 290 varnewItemPosition = thisItemPosition - 1;295 newItemPosition = thisItemPosition - 1; 291 296 292 297 // Already at top … … 304 309 // Does this item have sub items? 305 310 if ( thisItemChildren ) { 306 varitems = thisItem.add( thisItemChildren );311 items = thisItem.add( thisItemChildren ); 307 312 // Move the entire block 308 313 items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId(); … … 314 319 // Does this item have sub items? 315 320 if ( thisItemChildren ) { 316 varitems = thisItem.add( thisItemChildren ),321 items = thisItem.add( thisItemChildren ), 317 322 nextItem = menuItems.eq( items.length + thisItemPosition ), 318 323 nextItemChildren = 0 !== nextItem.childMenuItems().length; 319 324 320 325 if ( nextItemChildren ) { 321 var newDepth = parseInt( nextItem.menuItemDepth()) + 1;326 newDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1; 322 327 thisItem.moveHorizontally( newDepth, thisItemDepth ); 323 328 } … … 345 350 // Does this item have sub items? 346 351 if ( thisItemChildren ) { 347 varitems = thisItem.add( thisItemChildren );352 items = thisItem.add( thisItemChildren ); 348 353 // Move the entire block 349 354 items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId(); … … 407 412 408 413 $( '.item-edit' ).each( function() { 409 var $this = $(this),410 movement = [],411 availableMovement = '',414 var thisLink, thisLinkText, primaryItems, itemPosition, title, 415 parentItem, parentItemId, parentItemName, subItems, 416 $this = $(this), 412 417 menuItem = $this.closest( 'li.menu-item' ).first(), 413 418 depth = menuItem.menuItemDepth(), 414 419 isPrimaryMenuItem = ( 0 === depth ), 415 420 itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(), 416 position = parseInt( menuItem.index() ),417 prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1 ),421 position = parseInt( menuItem.index(), 10 ), 422 prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ), 418 423 prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(), 419 424 prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(), … … 423 428 // Where can they move this menu item? 424 429 if ( 0 !== position ) { 425 varthisLink = menuItem.find( '.menus-move-up' );430 thisLink = menuItem.find( '.menus-move-up' ); 426 431 thisLink.prop( 'title', menus.moveUp ).css( 'display', 'inline' ); 427 432 } 428 433 429 434 if ( 0 !== position && isPrimaryMenuItem ) { 430 varthisLink = menuItem.find( '.menus-move-top' );435 thisLink = menuItem.find( '.menus-move-top' ); 431 436 thisLink.prop( 'title', menus.moveToTop ).css( 'display', 'inline' ); 432 437 } 433 438 434 439 if ( position + 1 !== totalMenuItems && 0 !== position ) { 435 varthisLink = menuItem.find( '.menus-move-down' );440 thisLink = menuItem.find( '.menus-move-down' ); 436 441 thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' ); 437 442 } 438 443 439 444 if ( 0 === position && 0 !== hasSameDepthSibling ) { 440 varthisLink = menuItem.find( '.menus-move-down' );445 thisLink = menuItem.find( '.menus-move-down' ); 441 446 thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' ); 442 447 } 443 448 444 449 if ( ! isPrimaryMenuItem ) { 445 varthisLink = menuItem.find( '.menus-move-left' ),446 450 thisLink = menuItem.find( '.menus-move-left' ), 451 thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft ); 447 452 thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).html( thisLinkText ).css( 'display', 'inline' ); 448 453 } … … 450 455 if ( 0 !== position ) { 451 456 if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) { 452 varthisLink = menuItem.find( '.menus-move-right' ),453 457 thisLink = menuItem.find( '.menus-move-right' ), 458 thisLinkText = menus.under.replace( '%s', prevItemNameRight ); 454 459 thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ).html( thisLinkText ).css( 'display', 'inline' ); 455 460 } … … 457 462 458 463 if ( isPrimaryMenuItem ) { 459 varprimaryItems = $( '.menu-item-depth-0' ),460 461 462 463 464 464 primaryItems = $( '.menu-item-depth-0' ), 465 itemPosition = primaryItems.index( menuItem ) + 1, 466 totalMenuItems = primaryItems.length, 467 468 // String together help text for primary menu items 469 title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems ); 465 470 } else { 466 var parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1) ).first(),467 468 469 470 471 472 473 471 parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(), 472 parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(), 473 parentItemName = parentItem.find( '.menu-item-title' ).text(), 474 subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ), 475 itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1; 476 477 // String together help text for sub menu items 478 title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$s', parentItemName ); 474 479 } 475 480 … … 482 487 $(this).off( 'keydown' ).on( 'keydown', function(e){ 483 488 484 var $this = $(this); 489 var arrows, 490 $this = $( this ), 491 thisItem = $this.parents( 'li.menu-item' ), 492 thisItemData = thisItem.getItemData(); 485 493 486 494 // Bail if it's not an arrow key … … 496 504 497 505 // If RTL, swap left/right arrows 498 var arrows = { '38' : 'up', '40' : 'down', '37' : 'left', '39': 'right' };506 arrows = { '38': 'up', '40': 'down', '37': 'left', '39': 'right' }; 499 507 if ( $('body').hasClass('rtl') ) 500 508 arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' }; … … 529 537 columns.checked = function(field) { 530 538 $('.field-' + field).removeClass('hidden-field'); 531 } 539 }; 532 540 columns.unchecked = function(field) { 533 541 $('.field-' + field).addClass('hidden-field'); 534 } 542 }; 535 543 // hide fields 536 544 api.menuList.hideAdvancedMenuItemFields(); … … 554 562 menuMaxDepth = initialMenuMaxDepth(); 555 563 556 if( 0 != $( '#menu-to-edit li' ).length )564 if( 0 !== $( '#menu-to-edit li' ).length ) 557 565 $( '.drag-instructions' ).show(); 558 566 … … 606 614 tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder 607 615 ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item 608 $(this).sortable( "refresh"); // The children aren't sortable. We should let jQ UI know.616 $(this).sortable( 'refresh' ); // The children aren't sortable. We should let jQ UI know. 609 617 ui.item.after( ui.placeholder ); // reattach the placeholder. 610 618 tempHolder.css('margin-top', 0); // reset the margin … … 614 622 }, 615 623 stop: function(e, ui) { 616 var children, depthChange = currentDepth - originalDepth; 624 var children, subMenuTitle, 625 depthChange = currentDepth - originalDepth; 617 626 618 627 // Return child elements to the list … … 620 629 621 630 // Add "sub menu" description 622 varsubMenuTitle = ui.item.find( '.item-title .is-submenu' );631 subMenuTitle = ui.item.find( '.item-title .is-submenu' ); 623 632 if ( 0 < currentDepth ) 624 633 subMenuTitle.show(); … … 627 636 628 637 // Update depth classes 629 if ( depthChange != 0) {638 if ( 0 !== depthChange ) { 630 639 ui.item.updateDepthClass( currentDepth ); 631 640 children.shiftDepthClass( depthChange ); … … 674 683 next.after( ui.placeholder ); 675 684 updateSharedVars( ui ); 676 $( this).sortable( "refreshPositions");685 $( this ).sortable( 'refreshPositions' ); 677 686 } 678 687 } … … 707 716 if( ! body[0].className ) return 0; 708 717 var match = body[0].className.match(/menu-max-depth-(\d+)/); 709 return match && match[1] ? parseInt( match[1]) : 0;718 return match && match[1] ? parseInt( match[1], 10 ) : 0; 710 719 } 711 720 … … 761 770 if ( e.keyCode === 13 ) { 762 771 e.preventDefault(); 763 $( "#submit-customlinkdiv").click();772 $( '#submit-customlinkdiv' ).click(); 764 773 } 765 774 }); … … 780 789 $t.data( name, title ); 781 790 782 if( '' == val ) $t.val( title );791 if( '' === val ) $t.val( title ); 783 792 else if ( title == val ) return; 784 793 else $t.removeClass( name ); … … 789 798 }).blur( function(){ 790 799 var $t = $(this); 791 if( '' == $t.val() )800 if( '' === $t.val() ) 792 801 $t.addClass( name ).val( $t.data(name) ); 793 802 }); … … 798 807 attachThemeLocationsListeners : function() { 799 808 var loc = $('#nav-menu-theme-locations'), params = {}; 800 params ['action']= 'menu-locations-save';809 params.action = 'menu-locations-save'; 801 810 params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val(); 802 811 loc.find('input[type="submit"]').click(function() { … … 805 814 }); 806 815 loc.find('.spinner').show(); 807 $.post( ajaxurl, params, function( r) {816 $.post( ajaxurl, params, function() { 808 817 loc.find('.spinner').hide(); 809 818 }); … … 861 870 processMethod = processMethod || api.addMenuItemToBottom; 862 871 863 if ( '' == url || 'http://' == url )872 if ( '' === url || 'http://' == url ) 864 873 return false; 865 874 … … 890 899 addItemToMenu : function(menuItem, processMethod, callback) { 891 900 var menu = $('#menu').val(), 892 nonce = $('#menu-settings-column-nonce').val(); 901 nonce = $('#menu-settings-column-nonce').val(), 902 params; 893 903 894 904 processMethod = processMethod || function(){}; … … 924 934 * @param object req The request arguments. 925 935 */ 926 addMenuItemToBottom : function( menuMarkup , req) {936 addMenuItemToBottom : function( menuMarkup ) { 927 937 $(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList ); 928 938 api.refreshKeyboardAccessibility(); … … 930 940 }, 931 941 932 addMenuItemToTop : function( menuMarkup , req) {942 addMenuItemToTop : function( menuMarkup ) { 933 943 $(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList ); 934 944 api.refreshKeyboardAccessibility(); … … 941 951 }); 942 952 943 if ( 0 != $('#menu-to-edit').length || 0 != $('.menu-location-menus select').length ) {953 if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) { 944 954 window.onbeforeunload = function(){ 945 955 if ( api.menusChanged ) … … 1009 1019 wrap = document.createElement('div'); 1010 1020 1011 if ( ! metaBoxData ['markup']|| ! toReplace )1021 if ( ! metaBoxData.markup || ! toReplace ) 1012 1022 return; 1013 1023 1014 wrap.innerHTML = metaBoxData ['markup'] ? metaBoxData['markup']: '';1024 wrap.innerHTML = metaBoxData.markup ? metaBoxData.markup : ''; 1015 1025 1016 1026 toReplace.parentNode.insertBefore( placeholder, toReplace ); … … 1035 1045 settings = $('#'+matchedSection[1]); 1036 1046 item = settings.parent(); 1037 if( 0 != item.length ) {1047 if( 0 !== item.length ) { 1038 1048 if( item.hasClass('menu-item-edit-inactive') ) { 1039 1049 if( ! settings.data('menu-item-data') ) { … … 1061 1071 }, 1062 1072 1063 eventOnClickMenuSave : function( clickedEl) {1073 eventOnClickMenuSave : function() { 1064 1074 var locs = '', 1065 1075 menuName = $('#menu-name'), … … 1082 1092 }, 1083 1093 1084 eventOnClickMenuDelete : function( clickedEl) {1094 eventOnClickMenuDelete : function() { 1085 1095 // Delete warning AYS 1086 if ( confirm( navMenuL10n.warnDeleteMenu ) ) {1096 if ( window.confirm( navMenuL10n.warnDeleteMenu ) ) { 1087 1097 window.onbeforeunload = null; 1088 1098 return true; … … 1109 1119 takenIDs = {}, 1110 1120 form = document.getElementById('nav-menu-meta'), 1111 pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'),1121 pattern = /menu-item[(\[^]\]*/, 1112 1122 $items = $('<div>').html(resp).find('li'), 1113 1123 $item; … … 1155 1165 el.remove(); 1156 1166 children.shiftDepthClass( -1 ).updateParentMenuItemDBId(); 1157 if ( 0== $( '#menu-to-edit li' ).length ) {1167 if ( 0 === $( '#menu-to-edit li' ).length ) { 1158 1168 $( '.drag-instructions' ).hide(); 1159 1169 ins.removeClass( 'menu-instructions-inactive' );
Note: See TracChangeset
for help on using the changeset viewer.