Add AYS notice on unsaved menu changes. see #12472

git-svn-id: http://svn.automattic.com/wordpress/trunk@14741 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2010-05-19 09:56:02 +00:00
parent 1c01f24307
commit 31dd323f01
3 changed files with 28 additions and 2 deletions

View File

@ -21,6 +21,7 @@ var wpNavMenu;
menuList : undefined, // Set in init. menuList : undefined, // Set in init.
targetList : undefined, // Set in init. targetList : undefined, // Set in init.
menusChanged : false,
// Functions that run on init. // Functions that run on init.
init : function() { init : function() {
@ -40,6 +41,8 @@ var wpNavMenu;
this.attachHomeLinkListener(); this.attachHomeLinkListener();
this.attachUnsavedChangesListener();
if( api.menuList.length ) // If no menu, we're in the + tab. if( api.menuList.length ) // If no menu, we're in the + tab.
this.initSortables(); this.initSortables();
@ -223,6 +226,7 @@ var wpNavMenu;
if( depthChange != 0 ) { if( depthChange != 0 ) {
ui.item.updateDepthClass( currentDepth ); ui.item.updateDepthClass( currentDepth );
children.shiftDepthClass( depthChange ); children.shiftDepthClass( depthChange );
api.registerChange();
} }
// Update the item data. // Update the item data.
ui.item.updateParentMenuItemDBId(); ui.item.updateParentMenuItemDBId();
@ -253,6 +257,9 @@ var wpNavMenu;
updateSharedVars( ui ); updateSharedVars( ui );
$(this).sortable( "refreshPositions" ); $(this).sortable( "refreshPositions" );
} }
},
update: function(e, ui) {
api.registerChange();
} }
}); });
@ -333,6 +340,7 @@ var wpNavMenu;
var form = $('#nav-menu-meta'); var form = $('#nav-menu-meta');
form.find('.add-to-menu input').click(function(){ form.find('.add-to-menu input').click(function(){
api.registerChange();
$(this).trigger('wp-add-menu-item', [api.addMenuItemToBottom]); $(this).trigger('wp-add-menu-item', [api.addMenuItemToBottom]);
return false; return false;
}); });
@ -477,6 +485,23 @@ var wpNavMenu;
}); });
}, },
attachUnsavedChangesListener : function() {
$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea').change(function(){
api.registerChange();
});
window.onbeforeunload = function(){
if ( api.menusChanged )
return navMenuL10n.saveAlert;
};
$('input.menu-save, input.save-menu-item').click(function(){
window.onbeforeunload = null;
});
},
registerChange : function() {
api.menusChanged = true;
},
attachTabsPanelListeners : function() { attachTabsPanelListeners : function() {
$('#menu-settings-column').bind('click', function(e) { $('#menu-settings-column').bind('click', function(e) {
var selectAreaMatch, activePanel, panelId, wrapper, items, var selectAreaMatch, activePanel, panelId, wrapper, items,

File diff suppressed because one or more lines are too long

View File

@ -384,7 +384,7 @@ function wp_default_scripts( &$scripts ) {
) ); ) );
// Custom Navigation // Custom Navigation
$scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100518' ); $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100519' );
$scripts->localize( 'nav-menu', 'navMenuL10n', array( $scripts->localize( 'nav-menu', 'navMenuL10n', array(
'home' => _x('Home', 'nav menu home label'), 'home' => _x('Home', 'nav menu home label'),
'homeurl' => home_url('/'), 'homeurl' => home_url('/'),
@ -394,6 +394,7 @@ function wp_default_scripts( &$scripts ) {
'noResultsFound' => _x('No results found.', 'search results'), 'noResultsFound' => _x('No results found.', 'search results'),
'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), 'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
'warnDeleteMenuItem' => __( "You are about to permanently delete this menu item. \n 'Cancel' to stop, 'OK' to delete." ), 'warnDeleteMenuItem' => __( "You are about to permanently delete this menu item. \n 'Cancel' to stop, 'OK' to delete." ),
'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'),
) ); ) );
$scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100516' ); $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100516' );