equal
deleted
inserted
replaced
4 * |
4 * |
5 * @version 2.0.0 |
5 * @version 2.0.0 |
6 * |
6 * |
7 * @package WordPress |
7 * @package WordPress |
8 * @subpackage Administration |
8 * @subpackage Administration |
|
9 * @output wp-admin/js/nav-menu.js |
9 */ |
10 */ |
10 |
11 |
11 /* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl */ |
12 /* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl, wpNavMenu */ |
12 |
|
13 var wpNavMenu; |
|
14 |
13 |
15 (function($) { |
14 (function($) { |
16 |
15 |
17 var api; |
16 var api; |
18 |
17 |
19 api = wpNavMenu = { |
18 /** |
|
19 * Contains all the functions to handle WordPress navigation menus administration. |
|
20 * |
|
21 * @namespace wpNavMenu |
|
22 */ |
|
23 api = window.wpNavMenu = { |
20 |
24 |
21 options : { |
25 options : { |
22 menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead. |
26 menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead. |
23 globalMaxDepth: 11, |
27 globalMaxDepth: 11, |
24 sortableItems: '> *', |
28 sortableItems: '> *', |
165 }); |
169 }); |
166 }, |
170 }, |
167 /** |
171 /** |
168 * Adds selected menu items to the menu. |
172 * Adds selected menu items to the menu. |
169 * |
173 * |
|
174 * @ignore |
|
175 * |
170 * @param jQuery metabox The metabox jQuery object. |
176 * @param jQuery metabox The metabox jQuery object. |
171 */ |
177 */ |
172 addSelectedToMenu : function(processMethod) { |
178 addSelectedToMenu : function(processMethod) { |
173 if ( 0 === $('#menu-to-edit').length ) { |
179 if ( 0 === $('#menu-to-edit').length ) { |
174 return false; |
180 return false; |
827 } else if ( -1 != e.target.className.indexOf('item-cancel') ) { |
833 } else if ( -1 != e.target.className.indexOf('item-cancel') ) { |
828 return that.eventOnClickCancelLink(e.target); |
834 return that.eventOnClickCancelLink(e.target); |
829 } |
835 } |
830 } |
836 } |
831 }); |
837 }); |
|
838 |
|
839 $( '#menu-name' ).on( 'input', _.debounce( function () { |
|
840 var menuName = $( document.getElementById( 'menu-name' ) ), |
|
841 menuNameVal = menuName.val(); |
|
842 |
|
843 if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) { |
|
844 // Add warning for invalid menu name. |
|
845 menuName.parent().addClass( 'form-invalid' ); |
|
846 } else { |
|
847 // Remove warning for valid menu name. |
|
848 menuName.parent().removeClass( 'form-invalid' ); |
|
849 } |
|
850 }, 500 ) ); |
|
851 |
832 $('#add-custom-links input[type="text"]').keypress(function(e){ |
852 $('#add-custom-links input[type="text"]').keypress(function(e){ |
833 $('#customlinkdiv').removeClass('form-invalid'); |
853 $('#customlinkdiv').removeClass('form-invalid'); |
834 |
854 |
835 if ( e.keyCode === 13 ) { |
855 if ( e.keyCode === 13 ) { |
836 e.preventDefault(); |
856 e.preventDefault(); |
865 return false; |
885 return false; |
866 }); |
886 }); |
867 }, |
887 }, |
868 |
888 |
869 attachQuickSearchListeners : function() { |
889 attachQuickSearchListeners : function() { |
870 var searchTimer, |
890 var searchTimer; |
871 inputEvent; |
|
872 |
891 |
873 // Prevent form submission. |
892 // Prevent form submission. |
874 $( '#nav-menu-meta' ).on( 'submit', function( event ) { |
893 $( '#nav-menu-meta' ).on( 'submit', function( event ) { |
875 event.preventDefault(); |
894 event.preventDefault(); |
876 }); |
895 }); |
877 |
896 |
878 /* |
897 $( '#nav-menu-meta' ).on( 'input', '.quick-search', function() { |
879 * Use feature detection to determine whether inputs should use |
|
880 * the `keyup` or `input` event. Input is preferred but lacks support |
|
881 * in legacy browsers. See changeset 34078, see also ticket #26600#comment:59 |
|
882 */ |
|
883 if ( 'oninput' in document.createElement( 'input' ) ) { |
|
884 inputEvent = 'input'; |
|
885 } else { |
|
886 inputEvent = 'keyup'; |
|
887 } |
|
888 |
|
889 $( '#nav-menu-meta' ).on( inputEvent, '.quick-search', function() { |
|
890 var $this = $( this ); |
898 var $this = $( this ); |
891 |
899 |
892 $this.attr( 'autocomplete', 'off' ); |
900 $this.attr( 'autocomplete', 'off' ); |
893 |
901 |
894 if ( searchTimer ) { |
902 if ( searchTimer ) { |
934 api.processQuickSearchQueryResponse(menuMarkup, params, panel); |
942 api.processQuickSearchQueryResponse(menuMarkup, params, panel); |
935 }); |
943 }); |
936 }, |
944 }, |
937 |
945 |
938 addCustomLink : function( processMethod ) { |
946 addCustomLink : function( processMethod ) { |
939 var url = $('#custom-menu-item-url').val(), |
947 var url = $('#custom-menu-item-url').val().trim(), |
940 label = $('#custom-menu-item-name').val(); |
948 label = $('#custom-menu-item-name').val(); |
941 |
949 |
942 processMethod = processMethod || api.addMenuItemToBottom; |
950 processMethod = processMethod || api.addMenuItemToBottom; |
943 |
951 |
944 if ( '' === url || 'http://' == url ) { |
952 if ( '' === url || 'http://' == url ) { |
1170 eventOnClickMenuSave : function() { |
1178 eventOnClickMenuSave : function() { |
1171 var locs = '', |
1179 var locs = '', |
1172 menuName = $('#menu-name'), |
1180 menuName = $('#menu-name'), |
1173 menuNameVal = menuName.val(); |
1181 menuNameVal = menuName.val(); |
1174 // Cancel and warn if invalid menu name |
1182 // Cancel and warn if invalid menu name |
1175 if( !menuNameVal || menuNameVal == menuName.attr('title') || !menuNameVal.replace(/\s+/, '') ) { |
1183 if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) { |
1176 menuName.parent().addClass('form-invalid'); |
1184 menuName.parent().addClass( 'form-invalid' ); |
1177 return false; |
1185 return false; |
1178 } |
1186 } |
1179 // Copy menu theme locations |
1187 // Copy menu theme locations |
1180 $('#nav-menu-theme-locations select').each(function() { |
1188 $('#nav-menu-theme-locations select').each(function() { |
1181 locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />'; |
1189 locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />'; |