changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
17:34716fd837a4 | 18:be944660c56a |
---|---|
42 api.targetList = api.menuList; |
42 api.targetList = api.menuList; |
43 |
43 |
44 this.jQueryExtensions(); |
44 this.jQueryExtensions(); |
45 |
45 |
46 this.attachMenuEditListeners(); |
46 this.attachMenuEditListeners(); |
47 |
|
48 this.attachBulkSelectButtonListeners(); |
|
49 this.attachMenuCheckBoxListeners(); |
|
50 this.attachMenuItemDeleteButton(); |
|
51 this.attachPendingMenuItemsListForDeletion(); |
|
47 |
52 |
48 this.attachQuickSearchListeners(); |
53 this.attachQuickSearchListeners(); |
49 this.attachThemeLocationsListeners(); |
54 this.attachThemeLocationsListeners(); |
50 this.attachMenuSaveSubmitListeners(); |
55 this.attachMenuSaveSubmitListeners(); |
51 |
56 |
388 if ( thisItemData['menu-item-parent-id'] === prevItemId ) |
393 if ( thisItemData['menu-item-parent-id'] === prevItemId ) |
389 break; |
394 break; |
390 thisItem.shiftHorizontally( 1 ); |
395 thisItem.shiftHorizontally( 1 ); |
391 break; |
396 break; |
392 } |
397 } |
393 $this.focus(); |
398 $this.trigger( 'focus' ); |
394 api.registerChange(); |
399 api.registerChange(); |
395 api.refreshKeyboardAccessibility(); |
400 api.refreshKeyboardAccessibility(); |
396 api.refreshAdvancedAccessibility(); |
401 api.refreshAdvancedAccessibility(); |
397 }, |
402 }, |
398 |
403 |
570 case 'right': |
575 case 'right': |
571 api.moveMenuItem( $this, 'right' ); |
576 api.moveMenuItem( $this, 'right' ); |
572 break; |
577 break; |
573 } |
578 } |
574 // Put focus back on same menu item. |
579 // Put focus back on same menu item. |
575 $( '#edit-' + thisItemData['menu-item-db-id'] ).focus(); |
580 $( '#edit-' + thisItemData['menu-item-db-id'] ).trigger( 'focus' ); |
576 return false; |
581 return false; |
577 }); |
582 }); |
578 }); |
583 }); |
579 }, |
584 }, |
580 |
585 |
606 $('.field-' + field).addClass('hidden-field'); |
611 $('.field-' + field).addClass('hidden-field'); |
607 }; |
612 }; |
608 // Hide fields. |
613 // Hide fields. |
609 api.menuList.hideAdvancedMenuItemFields(); |
614 api.menuList.hideAdvancedMenuItemFields(); |
610 |
615 |
611 $('.hide-postbox-tog').click(function () { |
616 $('.hide-postbox-tog').on( 'click', function () { |
612 var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(','); |
617 var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(','); |
613 $.post(ajaxurl, { |
618 $.post(ajaxurl, { |
614 action: 'closed-postboxes', |
619 action: 'closed-postboxes', |
615 hidden: hidden, |
620 hidden: hidden, |
616 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), |
621 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), |
807 menuMaxDepth = newDepth; |
812 menuMaxDepth = newDepth; |
808 } |
813 } |
809 }, |
814 }, |
810 |
815 |
811 initManageLocations : function () { |
816 initManageLocations : function () { |
812 $('#menu-locations-wrap form').submit(function(){ |
817 $('#menu-locations-wrap form').on( 'submit', function(){ |
813 window.onbeforeunload = null; |
818 window.onbeforeunload = null; |
814 }); |
819 }); |
815 $('.menu-location-menus select').on('change', function () { |
820 $('.menu-location-menus select').on('change', function () { |
816 var editLink = $(this).closest('tr').find('.locations-edit-menu-link'); |
821 var editLink = $(this).closest('tr').find('.locations-edit-menu-link'); |
817 if ($(this).find('option:selected').data('orig')) |
822 if ($(this).find('option:selected').data('orig')) |
821 }); |
826 }); |
822 }, |
827 }, |
823 |
828 |
824 attachMenuEditListeners : function() { |
829 attachMenuEditListeners : function() { |
825 var that = this; |
830 var that = this; |
826 $('#update-nav-menu').bind('click', function(e) { |
831 $('#update-nav-menu').on('click', function(e) { |
827 if ( e.target && e.target.className ) { |
832 if ( e.target && e.target.className ) { |
828 if ( -1 != e.target.className.indexOf('item-edit') ) { |
833 if ( -1 != e.target.className.indexOf('item-edit') ) { |
829 return that.eventOnClickEditLink(e.target); |
834 return that.eventOnClickEditLink(e.target); |
830 } else if ( -1 != e.target.className.indexOf('menu-save') ) { |
835 } else if ( -1 != e.target.className.indexOf('menu-save') ) { |
831 return that.eventOnClickMenuSave(e.target); |
836 return that.eventOnClickMenuSave(e.target); |
850 // Remove warning for valid menu name. |
855 // Remove warning for valid menu name. |
851 menuName.parent().removeClass( 'form-invalid' ); |
856 menuName.parent().removeClass( 'form-invalid' ); |
852 } |
857 } |
853 }, 500 ) ); |
858 }, 500 ) ); |
854 |
859 |
855 $('#add-custom-links input[type="text"]').keypress(function(e){ |
860 $('#add-custom-links input[type="text"]').on( 'keypress', function(e){ |
856 $('#customlinkdiv').removeClass('form-invalid'); |
861 $('#customlinkdiv').removeClass('form-invalid'); |
857 |
862 |
858 if ( e.keyCode === 13 ) { |
863 if ( e.keyCode === 13 ) { |
859 e.preventDefault(); |
864 e.preventDefault(); |
860 $( '#submit-customlinkdiv' ).click(); |
865 $( '#submit-customlinkdiv' ).trigger( 'click' ); |
861 } |
866 } |
862 }); |
867 }); |
868 }, |
|
869 |
|
870 /** |
|
871 * Handle toggling bulk selection checkboxes for menu items. |
|
872 * |
|
873 * @since 5.8.0 |
|
874 */ |
|
875 attachBulkSelectButtonListeners : function() { |
|
876 var that = this; |
|
877 |
|
878 $( '.bulk-select-switcher' ).on( 'change', function() { |
|
879 if ( this.checked ) { |
|
880 $( '.bulk-select-switcher' ).prop( 'checked', true ); |
|
881 that.enableBulkSelection(); |
|
882 } else { |
|
883 $( '.bulk-select-switcher' ).prop( 'checked', false ); |
|
884 that.disableBulkSelection(); |
|
885 } |
|
886 }); |
|
887 }, |
|
888 |
|
889 /** |
|
890 * Enable bulk selection checkboxes for menu items. |
|
891 * |
|
892 * @since 5.8.0 |
|
893 */ |
|
894 enableBulkSelection : function() { |
|
895 var checkbox = $( '#menu-to-edit .menu-item-checkbox' ); |
|
896 |
|
897 $( '#menu-to-edit' ).addClass( 'bulk-selection' ); |
|
898 $( '#nav-menu-bulk-actions-top' ).addClass( 'bulk-selection' ); |
|
899 $( '#nav-menu-bulk-actions-bottom' ).addClass( 'bulk-selection' ); |
|
900 |
|
901 $.each( checkbox, function() { |
|
902 $(this).prop( 'disabled', false ); |
|
903 }); |
|
904 }, |
|
905 |
|
906 /** |
|
907 * Disable bulk selection checkboxes for menu items. |
|
908 * |
|
909 * @since 5.8.0 |
|
910 */ |
|
911 disableBulkSelection : function() { |
|
912 var checkbox = $( '#menu-to-edit .menu-item-checkbox' ); |
|
913 |
|
914 $( '#menu-to-edit' ).removeClass( 'bulk-selection' ); |
|
915 $( '#nav-menu-bulk-actions-top' ).removeClass( 'bulk-selection' ); |
|
916 $( '#nav-menu-bulk-actions-bottom' ).removeClass( 'bulk-selection' ); |
|
917 |
|
918 if ( $( '.menu-items-delete' ).is( '[aria-describedby="pending-menu-items-to-delete"]' ) ) { |
|
919 $( '.menu-items-delete' ).removeAttr( 'aria-describedby' ); |
|
920 } |
|
921 |
|
922 $.each( checkbox, function() { |
|
923 $(this).prop( 'disabled', true ).prop( 'checked', false ); |
|
924 }); |
|
925 |
|
926 $( '.menu-items-delete' ).addClass( 'disabled' ); |
|
927 $( '#pending-menu-items-to-delete ul' ).empty(); |
|
928 }, |
|
929 |
|
930 /** |
|
931 * Listen for state changes on bulk action checkboxes. |
|
932 * |
|
933 * @since 5.8.0 |
|
934 */ |
|
935 attachMenuCheckBoxListeners : function() { |
|
936 var that = this; |
|
937 |
|
938 $( '#menu-to-edit' ).on( 'change', '.menu-item-checkbox', function() { |
|
939 that.setRemoveSelectedButtonStatus(); |
|
940 }); |
|
941 }, |
|
942 |
|
943 /** |
|
944 * Create delete button to remove menu items from collection. |
|
945 * |
|
946 * @since 5.8.0 |
|
947 */ |
|
948 attachMenuItemDeleteButton : function() { |
|
949 var that = this; |
|
950 |
|
951 $( document ).on( 'click', '.menu-items-delete', function( e ) { |
|
952 var itemsPendingDeletion, itemsPendingDeletionList, deletionSpeech; |
|
953 |
|
954 e.preventDefault(); |
|
955 |
|
956 if ( ! $(this).hasClass( 'disabled' ) ) { |
|
957 $.each( $( '.menu-item-checkbox:checked' ), function( index, element ) { |
|
958 $( element ).parents( 'li' ).find( 'a.item-delete' ).trigger( 'click' ); |
|
959 }); |
|
960 |
|
961 $( '.menu-items-delete' ).addClass( 'disabled' ); |
|
962 $( '.bulk-select-switcher' ).prop( 'checked', false ); |
|
963 |
|
964 itemsPendingDeletion = ''; |
|
965 itemsPendingDeletionList = $( '#pending-menu-items-to-delete ul li' ); |
|
966 |
|
967 $.each( itemsPendingDeletionList, function( index, element ) { |
|
968 var itemName = $( element ).find( '.pending-menu-item-name' ).text(); |
|
969 var itemSpeech = menus.menuItemDeletion.replace( '%s', itemName ); |
|
970 |
|
971 itemsPendingDeletion += itemSpeech; |
|
972 if ( ( index + 1 ) < itemsPendingDeletionList.length ) { |
|
973 itemsPendingDeletion += ', '; |
|
974 } |
|
975 }); |
|
976 |
|
977 deletionSpeech = menus.itemsDeleted.replace( '%s', itemsPendingDeletion ); |
|
978 wp.a11y.speak( deletionSpeech, 'polite' ); |
|
979 that.disableBulkSelection(); |
|
980 } |
|
981 }); |
|
982 }, |
|
983 |
|
984 /** |
|
985 * List menu items awaiting deletion. |
|
986 * |
|
987 * @since 5.8.0 |
|
988 */ |
|
989 attachPendingMenuItemsListForDeletion : function() { |
|
990 $( '#post-body-content' ).on( 'change', '.menu-item-checkbox', function() { |
|
991 var menuItemName, menuItemType, menuItemID, listedMenuItem; |
|
992 |
|
993 if ( ! $( '.menu-items-delete' ).is( '[aria-describedby="pending-menu-items-to-delete"]' ) ) { |
|
994 $( '.menu-items-delete' ).attr( 'aria-describedby', 'pending-menu-items-to-delete' ); |
|
995 } |
|
996 |
|
997 menuItemName = $(this).next().text(); |
|
998 menuItemType = $(this).parent().next( '.item-controls' ).find( '.item-type' ).text(); |
|
999 menuItemID = $(this).attr( 'data-menu-item-id' ); |
|
1000 |
|
1001 listedMenuItem = $( '#pending-menu-items-to-delete ul' ).find( '[data-menu-item-id=' + menuItemID + ']' ); |
|
1002 if ( listedMenuItem.length > 0 ) { |
|
1003 listedMenuItem.remove(); |
|
1004 } |
|
1005 |
|
1006 if ( this.checked === true ) { |
|
1007 $( '#pending-menu-items-to-delete ul' ).append( |
|
1008 '<li data-menu-item-id="' + menuItemID + '">' + |
|
1009 '<span class="pending-menu-item-name">' + menuItemName + '</span> ' + |
|
1010 '<span class="pending-menu-item-type">(' + menuItemType + ')</span>' + |
|
1011 '<span class="separator"></span>' + |
|
1012 '</li>' |
|
1013 ); |
|
1014 } |
|
1015 |
|
1016 $( '#pending-menu-items-to-delete li .separator' ).html( ', ' ); |
|
1017 $( '#pending-menu-items-to-delete li .separator' ).last().html( '.' ); |
|
1018 }); |
|
1019 }, |
|
1020 |
|
1021 /** |
|
1022 * Set status of bulk delete checkbox. |
|
1023 * |
|
1024 * @since 5.8.0 |
|
1025 */ |
|
1026 setBulkDeleteCheckboxStatus : function() { |
|
1027 var that = this; |
|
1028 var checkbox = $( '#menu-to-edit .menu-item-checkbox' ); |
|
1029 |
|
1030 $.each( checkbox, function() { |
|
1031 if ( $(this).prop( 'disabled' ) ) { |
|
1032 $(this).prop( 'disabled', false ); |
|
1033 } else { |
|
1034 $(this).prop( 'disabled', true ); |
|
1035 } |
|
1036 |
|
1037 if ( $(this).is( ':checked' ) ) { |
|
1038 $(this).prop( 'checked', false ); |
|
1039 } |
|
1040 }); |
|
1041 |
|
1042 that.setRemoveSelectedButtonStatus(); |
|
1043 }, |
|
1044 |
|
1045 /** |
|
1046 * Set status of menu items removal button. |
|
1047 * |
|
1048 * @since 5.8.0 |
|
1049 */ |
|
1050 setRemoveSelectedButtonStatus : function() { |
|
1051 var button = $( '.menu-items-delete' ); |
|
1052 |
|
1053 if ( $( '.menu-item-checkbox:checked' ).length > 0 ) { |
|
1054 button.removeClass( 'disabled' ); |
|
1055 } else { |
|
1056 button.addClass( 'disabled' ); |
|
1057 } |
|
863 }, |
1058 }, |
864 |
1059 |
865 attachMenuSaveSubmitListeners : function() { |
1060 attachMenuSaveSubmitListeners : function() { |
866 /* |
1061 /* |
867 * When a navigation menu is saved, store a JSON representation of all form data |
1062 * When a navigation menu is saved, store a JSON representation of all form data |
868 * in a single input to avoid PHP `max_input_vars` limitations. See #14134. |
1063 * in a single input to avoid PHP `max_input_vars` limitations. See #14134. |
869 */ |
1064 */ |
870 $( '#update-nav-menu' ).submit( function() { |
1065 $( '#update-nav-menu' ).on( 'submit', function() { |
871 var navMenuData = $( '#update-nav-menu' ).serializeArray(); |
1066 var navMenuData = $( '#update-nav-menu' ).serializeArray(); |
872 $( '[name="nav-menu-data"]' ).val( JSON.stringify( navMenuData ) ); |
1067 $( '[name="nav-menu-data"]' ).val( JSON.stringify( navMenuData ) ); |
873 }); |
1068 }); |
874 }, |
1069 }, |
875 |
1070 |
876 attachThemeLocationsListeners : function() { |
1071 attachThemeLocationsListeners : function() { |
877 var loc = $('#nav-menu-theme-locations'), params = {}; |
1072 var loc = $('#nav-menu-theme-locations'), params = {}; |
878 params.action = 'menu-locations-save'; |
1073 params.action = 'menu-locations-save'; |
879 params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val(); |
1074 params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val(); |
880 loc.find('input[type="submit"]').click(function() { |
1075 loc.find('input[type="submit"]').on( 'click', function() { |
881 loc.find('select').each(function() { |
1076 loc.find('select').each(function() { |
882 params[this.name] = $(this).val(); |
1077 params[this.name] = $(this).val(); |
883 }); |
1078 }); |
884 loc.find( '.spinner' ).addClass( 'is-active' ); |
1079 loc.find( '.spinner' ).addClass( 'is-active' ); |
885 $.post( ajaxurl, params, function() { |
1080 $.post( ajaxurl, params, function() { |
906 clearTimeout( searchTimer ); |
1101 clearTimeout( searchTimer ); |
907 } |
1102 } |
908 |
1103 |
909 searchTimer = setTimeout( function() { |
1104 searchTimer = setTimeout( function() { |
910 api.updateQuickSearchResults( $this ); |
1105 api.updateQuickSearchResults( $this ); |
911 }, 500 ); |
1106 }, 500 ); |
912 }).on( 'blur', '.quick-search', function() { |
1107 }).on( 'blur', '.quick-search', function() { |
913 api.lastSearch = ''; |
1108 api.lastSearch = ''; |
914 }); |
1109 }); |
915 }, |
1110 }, |
916 |
1111 |
945 api.processQuickSearchQueryResponse(menuMarkup, params, panel); |
1140 api.processQuickSearchQueryResponse(menuMarkup, params, panel); |
946 }); |
1141 }); |
947 }, |
1142 }, |
948 |
1143 |
949 addCustomLink : function( processMethod ) { |
1144 addCustomLink : function( processMethod ) { |
950 var url = $('#custom-menu-item-url').val().trim(), |
1145 var url = $('#custom-menu-item-url').val().toString(), |
951 label = $('#custom-menu-item-name').val(); |
1146 label = $('#custom-menu-item-name').val(); |
1147 |
|
1148 if ( '' !== url ) { |
|
1149 url = url.trim(); |
|
1150 } |
|
952 |
1151 |
953 processMethod = processMethod || api.addMenuItemToBottom; |
1152 processMethod = processMethod || api.addMenuItemToBottom; |
954 |
1153 |
955 if ( '' === url || 'https://' == url || 'http://' == url ) { |
1154 if ( '' === url || 'https://' == url || 'http://' == url ) { |
956 $('#customlinkdiv').addClass('form-invalid'); |
1155 $('#customlinkdiv').addClass('form-invalid'); |
961 $( '.customlinkdiv .spinner' ).addClass( 'is-active' ); |
1160 $( '.customlinkdiv .spinner' ).addClass( 'is-active' ); |
962 this.addLinkToMenu( url, label, processMethod, function() { |
1161 this.addLinkToMenu( url, label, processMethod, function() { |
963 // Remove the Ajax spinner. |
1162 // Remove the Ajax spinner. |
964 $( '.customlinkdiv .spinner' ).removeClass( 'is-active' ); |
1163 $( '.customlinkdiv .spinner' ).removeClass( 'is-active' ); |
965 // Set custom link form back to defaults. |
1164 // Set custom link form back to defaults. |
966 $('#custom-menu-item-name').val('').blur(); |
1165 $('#custom-menu-item-name').val('').trigger( 'blur' ); |
967 $( '#custom-menu-item-url' ).val( '' ).attr( 'placeholder', 'https://' ); |
1166 $( '#custom-menu-item-url' ).val( '' ).attr( 'placeholder', 'https://' ); |
968 }); |
1167 }); |
969 }, |
1168 }, |
970 |
1169 |
971 addLinkToMenu : function(url, label, processMethod, callback) { |
1170 addLinkToMenu : function(url, label, processMethod, callback) { |
997 }; |
1196 }; |
998 |
1197 |
999 $.post( ajaxurl, params, function(menuMarkup) { |
1198 $.post( ajaxurl, params, function(menuMarkup) { |
1000 var ins = $('#menu-instructions'); |
1199 var ins = $('#menu-instructions'); |
1001 |
1200 |
1002 menuMarkup = $.trim( menuMarkup ); // Trim leading whitespaces. |
1201 menuMarkup = menuMarkup || ''; |
1202 menuMarkup = menuMarkup.toString().trim(); // Trim leading whitespaces. |
|
1003 processMethod(menuMarkup, params); |
1203 processMethod(menuMarkup, params); |
1004 |
1204 |
1005 // Make it stand out a bit more visually, by adding a fadeIn. |
1205 // Make it stand out a bit more visually, by adding a fadeIn. |
1006 $( 'li.pending' ).hide().fadeIn('slow'); |
1206 $( 'li.pending' ).hide().fadeIn('slow'); |
1007 $( '.drag-instructions' ).show(); |
1207 $( '.drag-instructions' ).show(); |
1041 api.refreshAdvancedAccessibility(); |
1241 api.refreshAdvancedAccessibility(); |
1042 $( document ).trigger( 'menu-item-added', [ $menuMarkup ] ); |
1242 $( document ).trigger( 'menu-item-added', [ $menuMarkup ] ); |
1043 }, |
1243 }, |
1044 |
1244 |
1045 attachUnsavedChangesListener : function() { |
1245 attachUnsavedChangesListener : function() { |
1046 $('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').change(function(){ |
1246 $('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').on( 'change', function(){ |
1047 api.registerChange(); |
1247 api.registerChange(); |
1048 }); |
1248 }); |
1049 |
1249 |
1050 if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) { |
1250 if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) { |
1051 window.onbeforeunload = function(){ |
1251 window.onbeforeunload = function(){ |
1052 if ( api.menusChanged ) |
1252 if ( api.menusChanged ) |
1053 return wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' ); |
1253 return wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' ); |
1054 }; |
1254 }; |
1055 } else { |
1255 } else { |
1056 // Make the post boxes read-only, as they can't be used yet. |
1256 // Make the post boxes read-only, as they can't be used yet. |
1057 $( '#menu-settings-column' ).find( 'input,select' ).end().find( 'a' ).attr( 'href', '#' ).unbind( 'click' ); |
1257 $( '#menu-settings-column' ).find( 'input,select' ).end().find( 'a' ).attr( 'href', '#' ).off( 'click' ); |
1058 } |
1258 } |
1059 }, |
1259 }, |
1060 |
1260 |
1061 registerChange : function() { |
1261 registerChange : function() { |
1062 api.menusChanged = true; |
1262 api.menusChanged = true; |
1063 }, |
1263 }, |
1064 |
1264 |
1065 attachTabsPanelListeners : function() { |
1265 attachTabsPanelListeners : function() { |
1066 $('#menu-settings-column').bind('click', function(e) { |
1266 $('#menu-settings-column').on('click', function(e) { |
1067 var selectAreaMatch, selectAll, panelId, wrapper, items, |
1267 var selectAreaMatch, selectAll, panelId, wrapper, items, |
1068 target = $(e.target); |
1268 target = $(e.target); |
1069 |
1269 |
1070 if ( target.hasClass('nav-tab-link') ) { |
1270 if ( target.hasClass('nav-tab-link') ) { |
1071 |
1271 |
1081 |
1281 |
1082 $('.tabs', wrapper).removeClass('tabs'); |
1282 $('.tabs', wrapper).removeClass('tabs'); |
1083 target.parent().addClass('tabs'); |
1283 target.parent().addClass('tabs'); |
1084 |
1284 |
1085 // Select the search bar. |
1285 // Select the search bar. |
1086 $('.quick-search', wrapper).focus(); |
1286 $('.quick-search', wrapper).trigger( 'focus' ); |
1087 |
1287 |
1088 // Hide controls in the search tab if no items found. |
1288 // Hide controls in the search tab if no items found. |
1089 if ( ! wrapper.find( '.tabs-panel-active .menu-item-title' ).length ) { |
1289 if ( ! wrapper.find( '.tabs-panel-active .menu-item-title' ).length ) { |
1090 wrapper.addClass( 'has-no-menu-item' ); |
1290 wrapper.addClass( 'has-no-menu-item' ); |
1091 } else { |
1291 } else { |
1134 $( '#nav-menu-meta' ).on( 'click', 'a.page-numbers', function() { |
1334 $( '#nav-menu-meta' ).on( 'click', 'a.page-numbers', function() { |
1135 var $container = $( this ).closest( '.inside' ); |
1335 var $container = $( this ).closest( '.inside' ); |
1136 |
1336 |
1137 $.post( ajaxurl, this.href.replace( /.*\?/, '' ).replace( /action=([^&]*)/, '' ) + '&action=menu-get-metabox', |
1337 $.post( ajaxurl, this.href.replace( /.*\?/, '' ).replace( /action=([^&]*)/, '' ) + '&action=menu-get-metabox', |
1138 function( resp ) { |
1338 function( resp ) { |
1139 var metaBoxData = $.parseJSON( resp ), |
1339 var metaBoxData = JSON.parse( resp ), |
1140 toReplace; |
1340 toReplace; |
1141 |
1341 |
1142 if ( -1 === resp.indexOf( 'replace-id' ) ) { |
1342 if ( -1 === resp.indexOf( 'replace-id' ) ) { |
1143 return; |
1343 return; |
1144 } |
1344 } |
1324 return Math.floor(px / api.options.menuItemDepthPerLevel); |
1524 return Math.floor(px / api.options.menuItemDepthPerLevel); |
1325 } |
1525 } |
1326 |
1526 |
1327 }; |
1527 }; |
1328 |
1528 |
1329 $(document).ready(function(){ wpNavMenu.init(); }); |
1529 $( function() { |
1530 |
|
1531 wpNavMenu.init(); |
|
1532 |
|
1533 // Prevent focused element from being hidden by the sticky footer. |
|
1534 $( '.menu-edit a, .menu-edit button, .menu-edit input, .menu-edit textarea, .menu-edit select' ).on('focus', function() { |
|
1535 if ( window.innerWidth >= 783 ) { |
|
1536 var navMenuHeight = $( '#nav-menu-footer' ).height() + 20; |
|
1537 var bottomOffset = $(this).offset().top - ( $(window).scrollTop() + $(window).height() - $(this).height() ); |
|
1538 |
|
1539 if ( bottomOffset > 0 ) { |
|
1540 bottomOffset = 0; |
|
1541 } |
|
1542 bottomOffset = bottomOffset * -1; |
|
1543 |
|
1544 if( bottomOffset < navMenuHeight ) { |
|
1545 var scrollTop = $(document).scrollTop(); |
|
1546 $(document).scrollTop( scrollTop + ( navMenuHeight - bottomOffset ) ); |
|
1547 } |
|
1548 } |
|
1549 }); |
|
1550 }); |
|
1330 |
1551 |
1331 })(jQuery); |
1552 })(jQuery); |