| 441 | | $(formEL).bind('submit', function(e) { |
| 442 | | return that.eventSubmitMetaForm.call(that, this, e); |
| | 440 | // If a "Add to Menu" button was clicked, submit that metabox ajax style. |
| | 441 | $(formEL).click(function(e) { |
| | 442 | // based on the input, call that function |
| | 443 | var divcontainer = $(e.target).parent().parent().parent(); |
| | 444 | |
| | 445 | if ( $(e.target).is('input') && $(e.target).hasClass('button-secondary') && !$(e.target).hasClass('quick-search-submit') ) { |
| | 446 | if ( $(divcontainer).hasClass('customlinkdiv') ) { |
| | 447 | that.addCustomLink(); |
| | 448 | } else if ( $(divcontainer).hasClass('posttypediv') || $(divcontainer).hasClass('taxonomydiv') ) { |
| | 449 | that.addItemsToMenu( $(divcontainer).attr('id') ); |
| | 450 | }; |
| | 451 | return false; |
| | 452 | } else if ( $(e.target).is('input') && $(e.target).hasClass('quick-search-submit') ) { |
| | 453 | that.quickSearch( $(divcontainer).attr('id') ); |
| | 454 | return false; |
| | 455 | }; |
| 444 | | $(formEL).find('input:submit').click(function() { |
| 445 | | $(this).siblings('img.waiting').show(); |
| | 457 | }, |
| | 458 | |
| | 459 | quickSearch : function(id) { |
| | 460 | var type = $('#' + id + ' .quick-search').attr('name'), |
| | 461 | q = $('#' + id + ' .quick-search').val(), |
| | 462 | menu = $('#menu').val(), |
| | 463 | nonce = $('#menu-settings-column-nonce').val(), |
| | 464 | params = {}, |
| | 465 | that = this, |
| | 466 | processMethod = function(){}; |
| | 467 | |
| | 468 | processMethod = that.processQuickSearchQueryResponse; |
| | 469 | |
| | 470 | params = { |
| | 471 | 'action': 'menu-quick-search', |
| | 472 | 'response-format': 'markup', |
| | 473 | 'menu': menu, |
| | 474 | 'menu-settings-column-nonce': nonce, |
| | 475 | 'q': q, |
| | 476 | 'type': type |
| | 477 | }; |
| | 478 | |
| | 479 | $.post( ajaxurl, params, function(menuMarkup) { |
| | 480 | processMethod.call(that, menuMarkup, params); |
| | 483 | |
| | 484 | addCustomLink : function() { |
| | 485 | var url = $('#custom-menu-item-url').val(), |
| | 486 | label = $('#custom-menu-item-name').val(), |
| | 487 | menu = $('#menu').val(), |
| | 488 | nonce = $('#menu-settings-column-nonce').val(), |
| | 489 | params = {}, |
| | 490 | that = this, |
| | 491 | processMethod = function(){}; |
| | 492 | |
| | 493 | if ( '' == url || 'http://' == url ) |
| | 494 | return false; |
| | 495 | |
| | 496 | // Show the ajax spinner |
| | 497 | $('.customlinkdiv img.waiting').show(); |
| | 498 | |
| | 499 | params = { |
| | 500 | 'action': 'add-menu-item', |
| | 501 | 'menu': menu, |
| | 502 | 'menu-settings-column-nonce': nonce, |
| | 503 | 'menu-item': { |
| | 504 | '-1': { |
| | 505 | 'menu-item-type': 'custom', |
| | 506 | 'menu-item-url': url, |
| | 507 | 'menu-item-title': label |
| | 508 | } |
| | 509 | } |
| | 510 | }; |
| | 511 | |
| | 512 | processMethod = that.eventAddMenuItem; |
| | 513 | |
| | 514 | $.post( ajaxurl, params, function(menuMarkup) { |
| | 515 | processMethod.call(that, menuMarkup, params); |
| | 516 | |
| | 517 | // Remove the ajax spinner |
| | 518 | $('.customlinkdiv img.waiting').hide(); |
| | 519 | }); |
| | 520 | }, |
| 712 | | for ( i = 0; i < len; i++ ) { |
| 713 | | if ( // we're submitting a checked item |
| 714 | | inputs[i].name && |
| 715 | | -1 != inputs[i].name.indexOf('menu-item-object-id') && |
| 716 | | inputs[i].checked || |
| 717 | | ( // or we're dealing with a custom link |
| 718 | | 'undefined' != typeof inputs[i].id && |
| 719 | | 'custom-menu-item-url' == inputs[i].id && |
| 720 | | '' != inputs[i].value && |
| 721 | | 'http://' != inputs[i].value |
| 722 | | ) |
| 723 | | ) { |
| 724 | | params['action'] = 'add-menu-item'; |
| 725 | | processMethod = that.processAddMenuItemResponse; |
| | 794 | params = { |
| | 795 | 'action': 'add-menu-item', |
| | 796 | 'menu': menu, |
| | 797 | 'menu-settings-column-nonce': nonce, |
| | 798 | 'menu-item': {} |
| | 799 | }; |
| 735 | | inputs[i].checked = false; |
| 736 | | |
| 737 | | // we're submitting a search term |
| 738 | | } else if ( |
| 739 | | '' == params['action'] && // give precedence to adding items |
| 740 | | '' != inputs[i].value && |
| 741 | | inputs[i].className && |
| 742 | | -1 != inputs[i].className.search(/quick-search\b[^-]/) |
| 743 | | ) { |
| 744 | | params['action'] = 'menu-quick-search'; |
| 745 | | params['q'] = inputs[i].value; |
| 746 | | params['response-format'] = 'markup'; |
| 747 | | params['type'] = inputs[i].name; |
| 748 | | processMethod = that.processQuickSearchQueryResponse; |
| 749 | | } |
| 750 | | } |
| 751 | | params['menu'] = thisForm.elements['menu'].value; |
| 752 | | params['menu-settings-column-nonce'] = thisForm.elements['menu-settings-column-nonce'].value; |
| 753 | | |
| 754 | | $.post( ajaxurl, params, function(menuMarkup) { |
| 755 | | processMethod.call(that, menuMarkup, params); |
| 756 | | $(thisForm).find('img.waiting').hide(); |
| | 807 | // Uncheck the item |
| | 808 | $(this).attr('checked', false); |