Changeset 13473 for trunk/wp-admin/js/nav-menu-default-items.dev.js
- Timestamp:
- 02/27/2010 11:06:56 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/nav-menu-default-items.dev.js
r13449 r13473 1 1 /** 2 2 * WordPress Administration Custom Navigation 3 * Interface JQueryfunctions3 * Interface $ functions 4 4 * 5 * @version 1.1.05 * @version 2.0.0 6 6 * 7 7 * @package WordPress … … 9 9 */ 10 10 11 /* 11 /** 12 12 * Init Functions 13 */ 14 jQuery(function($) 15 { 16 //Makes dialog box 17 $("#dialog-confirm").dialog({ 18 autoOpen: false, 19 resizable: false, 20 height: 210, 21 width: 400, 22 modal: true, 23 buttons: { 24 'Save': function() { 13 */ 14 jQuery(document).ready(function($){ 15 16 // Handle Save Button Clicks 17 $('#save_menu').click(function(){ 18 wp_update_post_data(); 19 }); 20 21 // Clear the quick search textbox 22 $('.quick-search').click(function(){ 23 $(this).attr( 'value', '' ); 24 }); 25 26 // Quick Search submit 27 $('.quick-search-submit').click(function(){ 28 $(this).siblings('.quick-search').search(); 29 }); 30 31 // Edit menu item 32 $('#menu-container .item-edit').click(function(){ 33 wp_edit_menu_item( $(this).attr('value') ); 34 }); 35 36 // Delete menu item 37 $('#menu-container .item-delete').live( 'click', function(){ 38 wp_remove_menu_item( $(this).attr('value') ); 39 }); 40 41 // Update menu item settings (thickbox) 42 $('#update-menu-item').click(function(){ 43 wp_update_menu_item(); 44 tb_remove(); 45 46 // Give feedback to the user 47 var id = $('#edit-item-id').val(); 48 $('#menu-' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 49 }); 50 51 // Close thickbox 52 $('#cancel-save').click(function(){ 53 tb_remove(); 54 }); 55 56 // Show All Button 57 $('.show-all').click(function(){ 58 $(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 10px;' ); 59 $(this).offsetParent().find('.list-wrap').css( 'display','block' ); 60 $(this).siblings('.quick-search').attr( 'value', '' ); 61 $(this).offsetParent().find('.list-wrap dt').css( 'display', 'block' ); 62 $(this).hide(); 63 $(this).siblings('.hide-all').show(); 64 }); 65 66 // Hide All Button 67 $('.hide-all').click(function(){ 68 $(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 0px;' ); 69 $(this).offsetParent().find('.list-wrap').css( 'display','none' ); 70 $(this).siblings('.quick-search').attr( 'value', 'Search' ); 71 $(this).offsetParent().find('.list-wrap dt').css( 'display', 'none' ); 72 $(this).hide(); 73 $(this).siblings('.show-all').show(); 74 }); 75 76 // Add queued menu items into the menu 77 $('.enqueue a').click(function(){ 78 wp_add_queued_items_to_menu(this); 79 }); 80 81 // Create the link, add it to the menu + available links section 82 $('#add-custom-link .add-to-menu a').click(function(){ 83 var link_url = $(this).offsetParent().find('#menu-item-url').val(); 84 var link_name = $(this).offsetParent().find('#menu-item-name').val(); 85 var links = $(this).offsetParent().find('#available-links input:checked'); 86 87 // If links are checked in the available links section, add them to the menu 88 if ( links ) { 89 for (var i = 0; i < links.length; i++) { 90 wp_add_item_to_menu( 'Custom', links[i].name, links[i].value, links[i].id.substring( 5, links[i].id.length ), 0, '' ); 91 }; 92 93 // Reset the checkboxes; 94 $(links).attr('checked', false); 95 }; 96 97 // Don't save the link if it was left with it's default settings 98 if ( 'http://' == link_url || 'Menu Item' == link_name ) 99 return; 100 101 // Parameters to send off 102 params = { 103 action: 'add-menu-link', 104 link_url: link_url, 105 link_name: link_name, 106 }; 107 108 // save the link 109 $.post( ajaxurl, params, function(response) { 110 if ( null == response || '-1' == response ) 111 return false; 112 113 params.link_id = response; 114 115 // add it to the available links section 116 // wp_update_links_list( params ); 117 118 // and update the Menu with the new link 119 wp_add_item_to_menu( 'Custom', params.link_name, params.link_url, params.link_id, 0, '' ); 120 }, 'json'); 121 }); 122 123 // Add dropzones 124 $('#menu li').prepend('<div class="dropzone"></div>'); 25 125 26 titletosave = $('#edittitle').attr('value'); 27 linktosave = $('#editlink').attr('value'); 28 anchortitletosave = $('#editanchortitle').attr('value'); 29 newwindowtosave = $('#editnewwindow').attr('value'); 30 desctosave = $('#editdescription').attr('value'); 31 32 $('#title' + $(this).dialog('option', 'itemID')).attr('value',titletosave); 33 $('#linkurl' + $(this).dialog('option', 'itemID')).attr('value',linktosave); 34 $('#anchortitle' + $(this).dialog('option', 'itemID')).attr('value',anchortitletosave); 35 $('#newwindow' + $(this).dialog('option', 'itemID')).attr('value',newwindowtosave); 36 $('#description' + $(this).dialog('option', 'itemID')).attr('value',desctosave); 37 38 $('#menu-' + $(this).dialog('option', 'itemID') + ' > dl > dt > span.title').text(titletosave); 39 40 $('#view' + + $(this).dialog('option', 'itemID')).attr('href', linktosave); 41 42 $(this).dialog('close'); 43 44 }, 45 Cancel: function() { 46 $(this).dialog('close'); 47 } 48 } 49 }); 50 51 // $('#message').animate({ opacity: 1.0 },2000).fadeOut(300, function(){ $(this).remove();}); 52 53 //Add dropzone 54 $('#custom-nav li').prepend('<div class="dropzone"></div>'); 55 56 //Make li items draggable 57 $('#custom-nav li').draggable({ 58 handle: ' > dl', 59 opacity: .8, 60 addClasses: false, 61 helper: 'clone', 62 zIndex: 100 63 }); 64 65 //Make items droppable 66 $('#custom-nav dl, #custom-nav .dropzone').droppable( 67 { 68 accept: '#custom-nav li', 69 tolerance: 'pointer', 70 drop: function(e, ui) 71 { 72 var li = $(this).parent(); 73 var child = !$(this).hasClass('dropzone'); 74 //Add UL to first child 75 if (child && li.children('ul').length == 0) 76 { 77 li.append('<ul id="sub-menu" />'); 78 } 79 //Make it draggable 80 if (child) 81 { 82 li.children('ul').append(ui.draggable); 83 } 84 else 85 { 86 li.before(ui.draggable); 87 } 88 89 li.find('dl,.dropzone').css({ backgroundColor: '', borderColor: '' }); 90 91 var draggablevalue = ui.draggable.attr('value'); 92 var droppablevalue = li.attr('value'); 93 li.find('#menu-' + draggablevalue).find('#parent' + draggablevalue).val(droppablevalue); 94 $(this).parent().find("dt").removeAttr('style'); 95 $(this).parent().find("div:first").removeAttr('style'); 96 97 98 }, 99 over: function() 100 { 101 //Add child 102 if ($(this).attr('class') == 'dropzone ui-droppable') 103 { 104 $(this).parent().find("div:first").css('background', 'none').css('height', '50px'); 105 } 106 //Add above 107 else if ($(this).attr('class') == 'ui-droppable') 108 { 109 $(this).parent().find("dt:first").css('background', '#d8d8d8'); 110 } 111 //do nothing 112 else { 113 114 } 115 var parentid = $(this).parent().attr('id'); 116 117 }, 118 out: function() 119 { 120 $(this).parent().find("dt").removeAttr('style'); 121 $(this).parent().find("div:first").removeAttr('style'); 122 $(this).filter('.dropzone').css({ borderColor: '' }); 123 }, 124 deactivate: function() 125 { 126 127 128 } 129 130 131 }); 132 133 //Handle Save Button Clicks 134 $('#save_top').click(function() 135 { 136 updatepostdata(); 137 }); 138 $('#save_bottom').click(function() 139 { 140 updatepostdata(); 141 }); 142 143 126 // Make menu items draggable 127 $('#menu li').draggable({ 128 handle: ' > dl', 129 opacity: .8, 130 addClasses: false, 131 helper: 'clone', 132 zIndex: 100 144 133 }); 145 134 135 // Make items droppable 136 $('#menu dl, #menu .dropzone').droppable({ 137 accept: '#menu li', 138 tolerance: 'pointer', 139 140 drop: function(e, ui) { 141 var li = $(this).parent(); 142 var child = !$(this).hasClass('dropzone'); 143 144 // Add UL to first child 145 if ( child && li.children('ul').length == 0 ) { 146 li.append('<ul id="sub-menu" />'); 147 } 148 // Make it draggable 149 if ( child ) { 150 li.children('ul').append( ui.draggable ); 151 } else { 152 li.before( ui.draggable ); 153 } 146 154 155 li.find('dl,.dropzone').css({ backgroundColor: '', borderColor: '' }); 156 157 var draggablevalue = ui.draggable.attr('value'); 158 var droppablevalue = li.attr('value'); 159 160 li.find('#menu-' + draggablevalue).find('#parent' + draggablevalue).val(droppablevalue); 161 $(this).parent().find('dt').removeAttr('style'); 162 163 $(this).parent().find('div:first').removeAttr('style'); 164 }, 165 166 over: function() { 167 168 if ( 'dropzone ui-droppable' == $(this).attr('class') ) { 169 // Add child 170 $(this).parent().find('dt:first').css('background', 'none').css('height', '50px'); 171 172 } else if ($(this).attr('class') == 'ui-droppable') { 173 // Add above 174 $(this).parent().find('dt:first').css('background', '#d8d8d8'); 175 176 } else { 177 // do nothing 178 } 179 var parentid = $(this).parent().attr('id'); 180 }, 181 out: function() { 182 $(this).parent().find('dt').removeAttr('style'); 183 $(this).parent().find('div:first').removeAttr('style'); 184 $(this).filter('.dropzone').css({ borderColor: '' }); 185 }, 186 deactivate: function() { 187 // 188 } 189 }); 190 });
Note: See TracChangeset
for help on using the changeset viewer.