343 | | $(formEL).bind('submit', function(e) { |
344 | | return that.eventSubmitMetaForm.call(that, this, e); |
| 343 | // If a "Add to Menu" button was clicked, submit that metabox ajax style. |
| 344 | $(formEL).click(function(e) { |
| 345 | // based on the input, call that function |
| 346 | var divcontainer = $(e.target).parent().parent().parent(); |
| 347 | |
| 348 | if ( $(e.target).is('input') && $(e.target).hasClass('button-secondary') && !$(e.target).hasClass('quick-search-submit') ) { |
| 349 | if ( $(divcontainer).hasClass('customlinkdiv') ) { |
| 350 | that.addCustomLink(); |
| 351 | } else if ( $(divcontainer).hasClass('posttypediv') || $(divcontainer).hasClass('taxonomydiv') ) { |
| 352 | that.addItemsToMenu( $(divcontainer).attr('id') ); |
| 353 | }; |
| 354 | return false; |
| 355 | } else if ( $(e.target).is('input') && $(e.target).hasClass('quick-search-submit') ) { |
| 356 | that.quickSearch( $(divcontainer).attr('id') ); |
| 357 | return false; |
| 358 | }; |
346 | | $(formEL).find('input:submit').click(function() { |
347 | | $(this).siblings('img.waiting').show(); |
| 360 | }, |
| 361 | |
| 362 | quickSearch : function(id) { |
| 363 | var type = $('#' + id + ' .quick-search').attr('name'), |
| 364 | q = $('#' + id + ' .quick-search').val(), |
| 365 | menu = $('#menu').val(), |
| 366 | nonce = $('#menu-settings-column-nonce').val(), |
| 367 | params = {}, |
| 368 | that = this, |
| 369 | processMethod = function(){}; |
| 370 | |
| 371 | processMethod = that.processQuickSearchQueryResponse; |
| 372 | |
| 373 | params = { |
| 374 | 'action': 'menu-quick-search', |
| 375 | 'response-format': 'markup', |
| 376 | 'menu': menu, |
| 377 | 'menu-settings-column-nonce': nonce, |
| 378 | 'q': q, |
| 379 | 'type': type |
| 380 | }; |
| 381 | |
| 382 | $.post( ajaxurl, params, function(menuMarkup) { |
| 383 | processMethod.call(that, menuMarkup, params); |
| 386 | |
| 387 | addCustomLink : function() { |
| 388 | var url = $('#custom-menu-item-url').val(), |
| 389 | label = $('#custom-menu-item-name').val(), |
| 390 | menu = $('#menu').val(), |
| 391 | nonce = $('#menu-settings-column-nonce').val(), |
| 392 | params = {}, |
| 393 | that = this, |
| 394 | processMethod = function(){}; |
| 395 | |
| 396 | if ( '' == url || 'http://' == url ) |
| 397 | return false; |
| 398 | |
| 399 | // Show the ajax spinner |
| 400 | $('.customlinkdiv img.waiting').show(); |
| 401 | |
| 402 | params = { |
| 403 | 'action': 'add-menu-item', |
| 404 | 'menu': menu, |
| 405 | 'menu-settings-column-nonce': nonce, |
| 406 | 'menu-item': { |
| 407 | '-1': { |
| 408 | 'menu-item-type': 'custom', |
| 409 | 'menu-item-url': url, |
| 410 | 'menu-item-title': label |
| 411 | } |
| 412 | } |
| 413 | }; |
| 414 | |
| 415 | processMethod = that.eventAddMenuItem; |
| 416 | |
| 417 | $.post( ajaxurl, params, function(menuMarkup) { |
| 418 | processMethod.call(that, menuMarkup, params); |
| 419 | |
| 420 | // Remove the ajax spinner |
| 421 | $('.customlinkdiv img.waiting').hide(); |
| 422 | }); |
| 423 | }, |
| 738 | |
| 739 | /** |
| 740 | * Adds menu items to the menu. |
| 741 | * |
| 742 | * @param string id The id of the metabox |
| 743 | */ |
| 744 | addItemsToMenu : function(id) { |
| 745 | var items = $( '.tabs-panel-active .categorychecklist li input:checked', '#' + id), |
| 746 | menu = $('#menu').val(), |
| 747 | nonce = $('#menu-settings-column-nonce').val(), |
| 748 | params = {}, |
| 749 | that = this, |
| 750 | processMethod = function(){}, |
| 751 | re = new RegExp('menu-item\\[(\[^\\]\]*)'); |
| 752 | |
| 753 | processMethod = that.eventAddMenuItem; |
| 754 | |
| 755 | // If no items are checked, bail. |
| 756 | if ( !items.length ) |
| 757 | return false; |
| 758 | |
| 759 | // Show the ajax spinner |
| 760 | $('#' + id + ' img.waiting').show(); |
| 762 | // do stuff |
| 763 | $(items).each(function(){ |
| 764 | listItemDBIDMatch = re.exec( $(this).attr('name') ); |
| 765 | listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); |
| 766 | listItemData = getListDataFromID(listItemDBID); |
| 767 | |
| 768 | params = { |
| 769 | 'action': 'add-menu-item', |
| 770 | 'menu': menu, |
| 771 | 'menu-settings-column-nonce': nonce, |
| 772 | 'menu-item': {} |
| 773 | }; |
| 774 | |
| 775 | params['menu-item'][listItemDBID] = listItemData; |
| 776 | |
| 777 | $.post( ajaxurl, params, function(menuMarkup) { |
| 778 | processMethod.call(that, menuMarkup, params); |
| 779 | }); |
| 780 | |
| 781 | // Uncheck the item |
| 782 | $(this).attr('checked', false); |
| 783 | }); |
| 784 | |
| 785 | // Remove the ajax spinner |
| 786 | $('#' + id + ' img.waiting').hide(); |
| 787 | }, |
| 788 | |