Make WordPress Core

Changeset 26163


Ignore:
Timestamp:
11/14/2013 06:08:11 AM (13 years ago)
Author:
nacin
Message:

Fix JSHint errors in nav-menu.js.

props atimmer.
fixes #25953.

File:
1 edited

Legend:

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

    r25708 r26163  
    99 */
    1010
     11/* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl */
     12
    1113var wpNavMenu;
    1214
    1315(function($) {
    1416
    15         var api = wpNavMenu = {
     17        var api;
     18
     19        api = wpNavMenu = {
    1620
    1721                options : {
    … …  
    112116                                                // If it has children, move those too
    113117                                                if ( children ) {
    114                                                         children.each(function( index ) {
     118                                                        children.each(function() {
    115119                                                                var t = $(this),
    116120                                                                        thisDepth = t.menuItemDepth(),
    … …  
    131135                                                var item = $(this),
    132136                                                        input = item.find( '.menu-item-data-parent-id' ),
    133                                                         depth = parseInt( item.menuItemDepth() ),
     137                                                        depth = parseInt( item.menuItemDepth(), 10 ),
    134138                                                        parentDepth = depth - 1,
    135139                                                        parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first();
    136140
    137                                                 if ( 0 == depth ) { // Item is on the top level, has no parent
     141                                                if ( 0 === depth ) { // Item is on the top level, has no parent
    138142                                                        input.val(0);
    139143                                                } else { // Find the parent item, and retrieve its object id.
    … …  
    156160                                 */
    157161                                addSelectedToMenu : function(processMethod) {
    158                                         if ( 0 == $('#menu-to-edit').length ) {
     162                                        if ( 0 === $('#menu-to-edit').length ) {
    159163                                                return false;
    160164                                        }
    … …  
    162166                                        return this.each(function() {
    163167                                                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\[([^]\]*)/;
    166170
    167171                                                processMethod = processMethod || api.addMenuItemToBottom;
    … …  
    272276                moveMenuItem : function( $this, dir ) {
    273277
    274                         var menuItems = $('#menu-to-edit li');
     278                        var items, newItemPosition, newDepth,
     279                                menuItems = $( '#menu-to-edit li' ),
    275280                                menuItemsCount = menuItems.length,
    276281                                thisItem = $this.parents( 'li.menu-item' ),
    277282                                thisItemChildren = thisItem.childMenuItems(),
    278283                                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 ),
    281286                                nextItem = thisItem.next(),
    282287                                nextItemChildren = nextItem.childMenuItems(),
    283                                 nextItemDepth = parseInt( nextItem.menuItemDepth() ) + 1,
     288                                nextItemDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1,
    284289                                prevItem = thisItem.prev(),
    285                                 prevItemDepth = parseInt( prevItem.menuItemDepth() ),
     290                                prevItemDepth = parseInt( prevItem.menuItemDepth(), 10 ),
    286291                                prevItemId = prevItem.getItemData()['menu-item-db-id'];
    287292
    288293                        switch ( dir ) {
    289294                        case 'up':
    290                                 var newItemPosition = thisItemPosition - 1;
     295                                newItemPosition = thisItemPosition - 1;
    291296
    292297                                // Already at top
    … …  
    304309                                // Does this item have sub items?
    305310                                if ( thisItemChildren ) {
    306                                         var items = thisItem.add( thisItemChildren );
     311                                        items = thisItem.add( thisItemChildren );
    307312                                        // Move the entire block
    308313                                        items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
    … …  
    314319                                // Does this item have sub items?
    315320                                if ( thisItemChildren ) {
    316                                         var items = thisItem.add( thisItemChildren ),
     321                                        items = thisItem.add( thisItemChildren ),
    317322                                                nextItem = menuItems.eq( items.length + thisItemPosition ),
    318323                                                nextItemChildren = 0 !== nextItem.childMenuItems().length;
    319324
    320325                                        if ( nextItemChildren ) {
    321                                                 var newDepth = parseInt( nextItem.menuItemDepth() ) + 1;
     326                                                newDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1;
    322327                                                thisItem.moveHorizontally( newDepth, thisItemDepth );
    323328                                        }
    … …  
    345350                                // Does this item have sub items?
    346351                                if ( thisItemChildren ) {
    347                                         var items = thisItem.add( thisItemChildren );
     352                                        items = thisItem.add( thisItemChildren );
    348353                                        // Move the entire block
    349354                                        items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
    … …  
    407412
    408413                        $( '.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),
    412417                                        menuItem = $this.closest( 'li.menu-item' ).first(),
    413418                                        depth = menuItem.menuItemDepth(),
    414419                                        isPrimaryMenuItem = ( 0 === depth ),
    415420                                        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 ),
    418423                                        prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(),
    419424                                        prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(),
    … …  
    423428                                // Where can they move this menu item?
    424429                                if ( 0 !== position ) {
    425                                         var thisLink = menuItem.find( '.menus-move-up' );
     430                                        thisLink = menuItem.find( '.menus-move-up' );
    426431                                        thisLink.prop( 'title', menus.moveUp ).css( 'display', 'inline' );
    427432                                }
    428433
    429434                                if ( 0 !== position && isPrimaryMenuItem ) {
    430                                         var thisLink = menuItem.find( '.menus-move-top' );
     435                                        thisLink = menuItem.find( '.menus-move-top' );
    431436                                        thisLink.prop( 'title', menus.moveToTop ).css( 'display', 'inline' );
    432437                                }
    433438
    434439                                if ( position + 1 !== totalMenuItems && 0 !== position ) {
    435                                         var thisLink = menuItem.find( '.menus-move-down' );
     440                                        thisLink = menuItem.find( '.menus-move-down' );
    436441                                        thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' );
    437442                                }
    438443
    439444                                if ( 0 === position && 0 !== hasSameDepthSibling ) {
    440                                         var thisLink = menuItem.find( '.menus-move-down' );
     445                                        thisLink = menuItem.find( '.menus-move-down' );
    441446                                        thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' );
    442447                                }
    443448
    444449                                if ( ! isPrimaryMenuItem ) {
    445                                         var thisLink = menuItem.find( '.menus-move-left' ),
    446                                                 thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft );
     450                                        thisLink = menuItem.find( '.menus-move-left' ),
     451                                        thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft );
    447452                                        thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).html( thisLinkText ).css( 'display', 'inline' );
    448453                                }
    … …  
    450455                                if ( 0 !== position ) {
    451456                                        if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) {
    452                                                 var thisLink = menuItem.find( '.menus-move-right' ),
    453                                                         thisLinkText = menus.under.replace( '%s', prevItemNameRight );
     457                                                thisLink = menuItem.find( '.menus-move-right' ),
     458                                                thisLinkText = menus.under.replace( '%s', prevItemNameRight );
    454459                                                thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ).html( thisLinkText ).css( 'display', 'inline' );
    455460                                        }
    … …  
    457462
    458463                                if ( isPrimaryMenuItem ) {
    459                                         var primaryItems = $( '.menu-item-depth-0' ),
    460                                                 itemPosition = primaryItems.index( menuItem ) + 1,
    461                                                 totalMenuItems = primaryItems.length,
    462 
    463                                                 // String together help text for primary menu items
    464                                                 title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems );
     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 );
    465470                                } else {
    466                                         var parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1 ) ).first(),
    467                                                 parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
    468                                                 parentItemName = parentItem.find( '.menu-item-title' ).text(),
    469                                                 subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
    470                                                 itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
    471 
    472                                                 // String together help text for sub menu items
    473                                                 title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$s', parentItemName );
     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 );
    474479                                }
    475480
    … …  
    482487                                $(this).off( 'keydown' ).on( 'keydown', function(e){
    483488
    484                                         var $this = $(this);
     489                                        var arrows,
     490                                                $this = $( this ),
     491                                                thisItem = $this.parents( 'li.menu-item' ),
     492                                                thisItemData = thisItem.getItemData();
    485493
    486494                                        // Bail if it's not an arrow key
    … …  
    496504
    497505                                        // 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' };
    499507                                        if ( $('body').hasClass('rtl') )
    500508                                                arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' };
    … …  
    529537                        columns.checked = function(field) {
    530538                                $('.field-' + field).removeClass('hidden-field');
    531                         }
     539                        };
    532540                        columns.unchecked = function(field) {
    533541                                $('.field-' + field).addClass('hidden-field');
    534                         }
     542                        };
    535543                        // hide fields
    536544                        api.menuList.hideAdvancedMenuItemFields();
    … …  
    554562                                menuMaxDepth = initialMenuMaxDepth();
    555563
    556                         if( 0 != $( '#menu-to-edit li' ).length )
     564                        if( 0 !== $( '#menu-to-edit li' ).length )
    557565                                $( '.drag-instructions' ).show();
    558566
    … …  
    606614                                        tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder
    607615                                        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.
    609617                                        ui.item.after( ui.placeholder ); // reattach the placeholder.
    610618                                        tempHolder.css('margin-top', 0); // reset the margin
    … …  
    614622                                },
    615623                                stop: function(e, ui) {
    616                                         var children, depthChange = currentDepth - originalDepth;
     624                                        var children, subMenuTitle,
     625                                                depthChange = currentDepth - originalDepth;
    617626
    618627                                        // Return child elements to the list
    … …  
    620629
    621630                                        // Add "sub menu" description
    622                                         var subMenuTitle = ui.item.find( '.item-title .is-submenu' );
     631                                        subMenuTitle = ui.item.find( '.item-title .is-submenu' );
    623632                                        if ( 0 < currentDepth )
    624633                                                subMenuTitle.show();
    … …  
    627636
    628637                                        // Update depth classes
    629                                         if( depthChange != 0 ) {
     638                                        if ( 0 !== depthChange ) {
    630639                                                ui.item.updateDepthClass( currentDepth );
    631640                                                children.shiftDepthClass( depthChange );
    … …  
    674683                                                next.after( ui.placeholder );
    675684                                                updateSharedVars( ui );
    676                                                 $(this).sortable( "refreshPositions" );
     685                                                $( this ).sortable( 'refreshPositions' );
    677686                                        }
    678687                                }
    … …  
    707716                                if( ! body[0].className ) return 0;
    708717                                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;
    710719                        }
    711720
    … …  
    761770                                if ( e.keyCode === 13 ) {
    762771                                        e.preventDefault();
    763                                         $("#submit-customlinkdiv").click();
     772                                        $( '#submit-customlinkdiv' ).click();
    764773                                }
    765774                        });
    … …  
    780789                                $t.data( name, title );
    781790
    782                                 if( '' == val ) $t.val( title );
     791                                if( '' === val ) $t.val( title );
    783792                                else if ( title == val ) return;
    784793                                else $t.removeClass( name );
    … …  
    789798                        }).blur( function(){
    790799                                var $t = $(this);
    791                                 if( '' == $t.val() )
     800                                if( '' === $t.val() )
    792801                                        $t.addClass( name ).val( $t.data(name) );
    793802                        });
    … …  
    798807                attachThemeLocationsListeners : function() {
    799808                        var loc = $('#nav-menu-theme-locations'), params = {};
    800                         params['action'] = 'menu-locations-save';
     809                        params.action = 'menu-locations-save';
    801810                        params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val();
    802811                        loc.find('input[type="submit"]').click(function() {
    … …  
    805814                                });
    806815                                loc.find('.spinner').show();
    807                                 $.post( ajaxurl, params, function(r) {
     816                                $.post( ajaxurl, params, function() {
    808817                                        loc.find('.spinner').hide();
    809818                                });
    … …  
    861870                        processMethod = processMethod || api.addMenuItemToBottom;
    862871
    863                         if ( '' == url || 'http://' == url )
     872                        if ( '' === url || 'http://' == url )
    864873                                return false;
    865874
    … …  
    890899                addItemToMenu : function(menuItem, processMethod, callback) {
    891900                        var menu = $('#menu').val(),
    892                                 nonce = $('#menu-settings-column-nonce').val();
     901                                nonce = $('#menu-settings-column-nonce').val(),
     902                                params;
    893903
    894904                        processMethod = processMethod || function(){};
    … …  
    924934                 * @param object req The request arguments.
    925935                 */
    926                 addMenuItemToBottom : function( menuMarkup, req ) {
     936                addMenuItemToBottom : function( menuMarkup ) {
    927937                        $(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList );
    928938                        api.refreshKeyboardAccessibility();
    … …  
    930940                },
    931941
    932                 addMenuItemToTop : function( menuMarkup, req ) {
     942                addMenuItemToTop : function( menuMarkup ) {
    933943                        $(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
    934944                        api.refreshKeyboardAccessibility();
    … …  
    941951                        });
    942952
    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 ) {
    944954                                window.onbeforeunload = function(){
    945955                                        if ( api.menusChanged )
    … …  
    10091019                                                        wrap = document.createElement('div');
    10101020
    1011                                                         if ( ! metaBoxData['markup'] || ! toReplace )
     1021                                                        if ( ! metaBoxData.markup || ! toReplace )
    10121022                                                                return;
    10131023
    1014                                                         wrap.innerHTML = metaBoxData['markup'] ? metaBoxData['markup'] : '';
     1024                                                        wrap.innerHTML = metaBoxData.markup ? metaBoxData.markup : '';
    10151025
    10161026                                                        toReplace.parentNode.insertBefore( placeholder, toReplace );
    … …  
    10351045                                settings = $('#'+matchedSection[1]);
    10361046                                item = settings.parent();
    1037                                 if( 0 != item.length ) {
     1047                                if( 0 !== item.length ) {
    10381048                                        if( item.hasClass('menu-item-edit-inactive') ) {
    10391049                                                if( ! settings.data('menu-item-data') ) {
    … …  
    10611071                },
    10621072
    1063                 eventOnClickMenuSave : function(clickedEl) {
     1073                eventOnClickMenuSave : function() {
    10641074                        var locs = '',
    10651075                        menuName = $('#menu-name'),
    … …  
    10821092                },
    10831093
    1084                 eventOnClickMenuDelete : function(clickedEl) {
     1094                eventOnClickMenuDelete : function() {
    10851095                        // Delete warning AYS
    1086                         if ( confirm( navMenuL10n.warnDeleteMenu ) ) {
     1096                        if ( window.confirm( navMenuL10n.warnDeleteMenu ) ) {
    10871097                                window.onbeforeunload = null;
    10881098                                return true;
    … …  
    11091119                        takenIDs = {},
    11101120                        form = document.getElementById('nav-menu-meta'),
    1111                         pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'),
     1121                        pattern = /menu-item[(\[^]\]*/,
    11121122                        $items = $('<div>').html(resp).find('li'),
    11131123                        $item;
    … …  
    11551165                                        el.remove();
    11561166                                        children.shiftDepthClass( -1 ).updateParentMenuItemDBId();
    1157                                         if( 0 == $( '#menu-to-edit li' ).length ) {
     1167                                        if ( 0 === $( '#menu-to-edit li' ).length ) {
    11581168                                                $( '.drag-instructions' ).hide();
    11591169                                                ins.removeClass( 'menu-instructions-inactive' );
Note: See TracChangeset for help on using the changeset viewer.