/*
amm_plugin Name: Advance Menu Manager
Plugin URI : wwww.multidots.com
Author : Multidots Solutions Pvt. Ltd.
*/
;(function($) {
$.amm_menu_manager = function(el, options) {
var amm_plugin = this;
var amm_event = function() {
amm_plugin.el = el;
amm_plugin.$menu = $(el);
amm_plugin.$menuItems = amm_plugin.$menu.find('li.menu-item');
amm_plugin.$menuItems.each(function(){
amm_menu_item(jQuery(this));
});
//Drag
amm_plugin.$menu.on('mousedown', 'li.menu-item', function(e){
});
//Drop
amm_plugin.$menu.on( 'mouseup', 'li.menu-item', function(e){
//alert("abc");
var $dropped_item = jQuery( this );
var $startParents = amm_parents_item( $dropped_item );
//console.log($startParents);
setTimeout( function(){
amm_fresh_item( 'parents' , $dropped_item , $startParents );
//alert(jQuery( this ).find(".menu-item-title").text());
$depth_drag_item = amm_menu_item_depth($dropped_item);
//console.log($dropped_item);
//alert($depth_drag_item);
if($depth_drag_item > 0){jQuery( $dropped_item ).find(".is-submenu").text("sub item");}
if($depth_drag_item > 5){jQuery( $dropped_item ).addClass("menu_depth_more_5");}
}, 400);
//menu object change status
menu_object_change_status = 'yes';
});
amm_plugin.itemcount = 0;
//ADM menu jQuery event's
jQuery('.submit-add-to-menu').click(function(){
//admin click the 'Add Item' button
amm_plugin.itemcount = amm_plugin.$menuItems.size();
checking_for_new_menu_item();
});
jQuery(document).on('click', '.item-controls .delete_node', function() {
var del_item_obj = jQuery(this).closest('li');
//var del_result = confirm("You are sure to permanently delete this menu item. \n 'Cancel' to stop 'OK' to delete");
confirm_md("Are You sure you want to permanently delete this menu item? \n'Cancel' to stop 'OK' to delete",'Delete Confirmation', function(del_result_con){
if (del_result_con) {
//change menu depth
var del_item_depth = amm_menu_item_depth(del_item_obj);
var del_item_prent_id = del_item_obj.find('.menu-item-data-parent-id').val();
var del_item_id = del_item_obj.find('.menu-item-data-db-id').val();
var loop_flag = 1; //looping only chile item
//menu-item-depth
del_item_obj.nextUntil(function(){
if( !jQuery(this).hasClass('menu-item-depth-0') && loop_flag == 1 && !jQuery(this).hasClass('menu-item-depth-'+del_item_depth)){
var item_get_depth = amm_menu_item_depth(jQuery(this));
var item_parent_id = jQuery(this).find('.menu-item-settings .menu-item-data-parent-id').val();
//change menu depth related to deleted parent menu`
jQuery(this).removeClass('menu-item-depth-'+item_get_depth);
jQuery(this).addClass('menu-item-depth-'+(item_get_depth - 1));
if(del_item_id == item_parent_id){
//check delete menu id to chile menu parent id if it's same than replace with delete menu parent id
jQuery(this).find('.menu-item-settings .menu-item-data-parent-id').val(del_item_prent_id);
}
//if parent menu item delete then all chiled menu desplayd
jQuery(this).removeClass('item-hide');
}else{
loop_flag =2;
}
});
//end change menu depth logic
var old_del_nodes = '';
var del_node_add = del_item_id;
old_del_nodes = jQuery( '#delete_menu_items' ).val();
//del_node_add = del_item_obj.attr( 'data-attr-menu-item' );
jQuery( '#delete_menu_items' ).val( del_node_add + ',' + old_del_nodes );
//jQuery(this).closest('li').slideUp(500);
del_item_obj.closest('li').remove();
var $deleted_item = del_item_obj.parents( 'li.menu-item' );
var $startParents = amm_parents_item( $deleted_item );
amm_fresh_item();
setTimeout(function(){ amm_fresh_item( 'delete' , $deleted_item , $startParents ); }, 500);
//if ( jQuery('ul#menu-to-edit li').length < 1 ) {
//jQuery('ul#menu-to-edit').before('
');
$amm_parent_highlighter.css({
'top' : '-7px',
'height': height+'px'
});
$amm_parent_highlighter.hide();
$item.append($amm_parent_highlighter);
/*
$item.find('.amm_highlighter').hover(function(){
$amm_parent_highlighter.fadeIn('fast');
}, function(){
$amm_parent_highlighter.fadeOut('fast');
});*/
}
};
var amm_fresh_item = function( set , $item , $items ){
switch( set ){
case 'parents':
$items = $items.add( amm_parents_item( $item ) );
break;
case 'delete':
break;
default:
$items = amm_plugin.$menuItems;
}
$items.each( function(){
amm_menu_item( jQuery(this) );
});
};
function checking_for_new_menu_item(){
var $itemGroup = $('#menu-to-edit li.menu-item');
$itemGroup.each(function(){
amm_menu_item(jQuery(this));
});
setTimeout(function(){
checking_for_new_menu_item();
}, 500);
}
amm_event();
}
$.fn.amm_menu_manager = function(options) {
return this.each(function() {
if (undefined == jQuery(this).data('amm_menu_manager')) {
var amm_menu_manager = new $.amm_menu_manager(this, options);
jQuery(this).data('amm_menu_manager', amm_menu_manager);
}
});
}
})(jQuery);
if(typeof menus === 'undefined'){
var menus = jQuery('#menu-to-edit');
}
var curent_menu_add_obj = 'none';
var append_menu_item_same_level = '';
//** Get current chiled/depth
function get_depth_of_menu_item ( $menu_item ) {
var depth_menu_item = 0;
if($menu_item.hasClass('menu-item-depth-0')) depth_menu_item = 0;
else if($menu_item.hasClass('menu-item-depth-1')) depth_menu_item = 1;
else if($menu_item.hasClass('menu-item-depth-2')) depth_menu_item = 2;
else if($menu_item.hasClass('menu-item-depth-3')) depth_menu_item = 3;
else if($menu_item.hasClass('menu-item-depth-4')) depth_menu_item = 4;
else if($menu_item.hasClass('menu-item-depth-5')) depth_menu_item = 5;
else if($menu_item.hasClass('menu-item-depth-6')) depth_menu_item = 6;
else if($menu_item.hasClass('menu-item-depth-7')) depth_menu_item = 7;
else if($menu_item.hasClass('menu-item-depth-8')) depth_menu_item = 8;
return depth_menu_item;
}
var menu_object_change_status = 'none';
jQuery(document).ready( function($) {
//jQuery(document).click(function(event) { window.onbeforeunload = null; });
jQuery('#md_amm_menu_form input[type=text], #md_amm_menu_form ul#menu-to-edit li input[type=checkbox]').change(function(){
menu_object_change_status = 'yes';
});
jQuery('#md_amm_menu_form').submit(function(){
window.onbeforeunload = null;
});
var $menu = jQuery('#menu-to-edit');
if($menu.size() == 0) return;
$menu.amm_menu_manager();
var amm_obj = $menu.data('amm_menu_manager');
//console.log(amm_obj);
jQuery('.add-new-menu-action_custom').click(function(){
jQuery('#custom-new-menu-name').val('');
jQuery('#manage-menus_add_new_menu').slideToggle();
});
jQuery(document).on("keypress",'#custom-new-menu-name',function(e){
//jQuery('#custom-new-menu-name').live("keypress", function(e) {
if (e.keyCode == 13) {
jQuery('#save_menu_custom').trigger( "click" );
}
});
jQuery('#save_menu_custom').on('click',function(){
var new_menu_name = jQuery('#custom-new-menu-name').val();
if ( new_menu_name == "" ) {
jQuery('#custom-new-menu-name').css('box-shadow','0px 0px 2px rgba(255, 0, 0, 0.8)');
jQuery('#custom-new-menu-name').css('border-color','#F00');
} else {
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.ajax({
url: ajaxurl,
type:'POST',
data: {
'action': 'my_action_create_menu_ajax',
'new_menu_name': new_menu_name
},
success:function(response) {
if(response == 1 ) {
window.location.reload();
}else if(response == 2 ){
alert_md('"'+new_menu_name +'"' + ' menu is already registered');
}
}
});
}
});
/* =============================================================== */
jQuery('#page_on_front').on('change', function(){
var menu_id = jQuery('#page_on_front').val();
if( 0 == menu_id ) {
jQuery('#menu_list_id').slideUp().hide();
}
});
jQuery('#amm_menu_delete').on('click', function(){
var menu_id = jQuery('#page_on_front').val();
confirm_md("You are about to permanently delete this menu? \n'Cancel' to stop 'OK' to delete",'Delete Confirmation',
function(result) {
if (result) {
jQuery('#munu_manager_plus_full_loading_wrapper').css('height',jQuery( document ).height());
jQuery('#munu_manager_plus_full_loading_wrapper').fadeIn();
//Logic to delete the item
var data = {
'action': 'my_action_delete_menu',
'delete_menu_id': menu_id
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
if(response == true ) {
//alert_md(' Menu deleted successfully ');
window.location.reload();
}else{
jQuery('#munu_manager_plus_full_loading_wrapper').fadeOut();
alert_md("Please try again later");
}
});
}
});
});
/* Count total menu items are present in current menu navigation */
var $total_elements = jQuery('#menu-to-edit').find('li.menu-item');
var menu_item="";
var count=0;
/**
* toggle_plus_action method
* This function is used to hide all child elements of the parent menu items
* @Version 1.0.0
* @Author Multiodots
*/
jQuery( '#toggle_plus_action' ).click( function() {
var all_child_elements = jQuery('#menu-to-edit').find('.menu-item:not(.menu-item-depth-0)');
all_child_elements.removeClass('item-hide');
jQuery( "#menu-to-edit li" ).each(function( index ) {
jQuery(this).find('span.click.block_hide_show').addClass('chiled-hide');
//menu setting section closed
jQuery(this).find('.menu-item-settings.menu-manager-plus-setting').removeClass('item-show');
});
//jQuery(this).hide();
jQuery(this).css('font-weight','bold');
//jQuery('#toggle_minus_action').css("display", "block")
jQuery('#toggle_minus_action').css('font-weight', 'normal');
});
/**
* toggle_minus_action method
* This function is used to show all child elements of the parent menu items
* @Version 1.0.0
* @Author Multiodots
*/
jQuery( '#toggle_minus_action' ).click( function() {
var all_child_elements = jQuery('#menu-to-edit').find('.menu-item:not(.menu-item-depth-0)');
all_child_elements.addClass('item-hide');
jQuery('#menu-to-edit li').find('span.click.block_hide_show').removeClass('chiled-hide');
//jQuery(this).hide();
//jQuery('#toggle_plus_action').css("display", "block");
jQuery(this).css('font-weight', 'bold');
jQuery('#toggle_plus_action').css('font-weight', 'normal');
jQuery( "#menu-to-edit li" ).each(function( index ) {
jQuery(this).find('span.click.block_hide_show').removeClass('chiled-hide');
//menu setting section closed
jQuery(this).find('.menu-item-settings.menu-manager-plus-setting').removeClass('item-show');
});
});
/*
* Add + and - controls to block for expand and collapse the menu items start
*/
jQuery(document).on('click', 'span.click.block_hide_show', function(e) {
var parent_li_id = jQuery(this).closest("li").attr("id");
var hide_controlls = "";
//only same level menu item hided
var same_level_depth_obj = jQuery(this).closest("li").next();
same_level_depth_obj = get_depth_of_menu_item(same_level_depth_obj);
same_level_depth_obj = "menu-item-depth-"+same_level_depth_obj;
//var element_depth = parseInt(jQuery('#'+parent_li_id).attr('data-depth'));
var element_depth = parseInt(get_depth_of_menu_item(jQuery(this).closest("li")));
while(element_depth >= 0){
hide_controlls += ".menu-item-depth-"+element_depth;
if(element_depth > 0) hide_controlls += ", ";
element_depth--;
}
$array = jQuery('#'+parent_li_id).nextUntil(hide_controlls);
jQuery( this ).toggleClass('chiled-hide');
jQuery.each( $array, function( i, item_obj ) {
jQuery(this).find('.menu-item-settings.menu-manager-plus-setting').removeClass('item-show');
});
if(jQuery( this ).hasClass('chiled-hide')){
//$array.removeClass('item-hide');
//same level item will hide
jQuery.each( $array, function( i, item_obj ) {
if(jQuery(this).hasClass(same_level_depth_obj)) {
jQuery(this).removeClass('item-hide');
jQuery(this).find('.my-menu-controls-groups span.click.block_hide_show').removeClass('chiled-hide');
}
});
}else{
jQuery.each( $array, function( i, item_obj ) {
jQuery(this).addClass('item-hide');
jQuery(this).find('.my-menu-controls-groups span.click.block_hide_show').addClass('chiled-hide');
});
}
});
jQuery(document).on('click', '.add_first_menu_item', function(e) {
//open popup
curent_menu_add_obj = 'none';
jQuery('#menu_manager_popup').css('height',jQuery( document ).height());
jQuery('#menu_manager_popup').css('padding-top',jQuery(window).scrollTop() - 90);
jQuery('#menu_manager_popup').fadeIn();
menu_object_change_status = 'yes';
/**amm**/
jQuery('.nav-menu-meta ul li .menu-item-checkbox').removeAttr('checked');
jQuery('.nav-menu-meta ul li .button-controls .add-to-menu .spinner').removeAttr("style");
});
jQuery(document).on('click', '.add_menu_item_in_nav_menu', function() {
//open popup
/**amm**/
jQuery('.nav-menu-meta ul li .menu-item-checkbox').removeAttr('checked');
jQuery('.nav-menu-meta ul li .button-controls .add-to-menu .spinner').removeAttr("style");
jQuery('#menu_manager_popup').css('height',jQuery( document ).height());
jQuery('#menu_manager_popup').css('padding-top',jQuery(window).scrollTop() - 90);
jQuery('#menu_manager_popup').fadeIn();
jQuery('#menu_manager_popup_main-wrapper').fadeIn();
jQuery('#menu_manager_popup_container #amm_wp_post_edit.wp-post-edit').remove();
curent_menu_add_obj = jQuery(this).parents('li.menu-item');
// if admin can added menu item as same level of menu( added new menu item after chiled menu)
// first of all clear sub menu obj than check admin added menu as same level with chiled menu ot not
append_menu_item_same_level ='';
var loop_flag = 1;
var c_item_get_depth = get_depth_of_menu_item(curent_menu_add_obj);
curent_menu_add_obj.nextUntil(function(){
var currrent_item_depth = get_depth_of_menu_item(jQuery(this));
if( !jQuery(this).hasClass('menu-item-depth-0') && loop_flag == 1 && !jQuery(this).hasClass('menu-item-depth-'+c_item_get_depth) && currrent_item_depth > c_item_get_depth ){
append_menu_item_same_level = jQuery(this);
}else{
loop_flag = 2;
}
});
});
// menu setting inner delete menu item click event
jQuery(document).on('click', 'li .menu-item-settings a.menu_manager-plus-setting-delete', function(e) {
jQuery(this).closest( "li" ).find('.delete_node').trigger( "click" );
return false;
});
jQuery(document).on('click', 'li .menu-item-settings a.menu_manager-plus-setting-cancel', function(e) {
//jQuery(this).closest( "li" ).find('.menu-item-settings.menu-manager-plus-setting').fadeToggle('show');
jQuery(this).closest( "li" ).find('.item-controls span.menu_sub_details').trigger( "click" );
return false;
});
// heightlighted feature
jQuery('ul.menu-manager-plus-menu-wrapper li .menu-item-bar').hover(function(){
var $c_item = jQuery(this).closest( "li" );
if(!$c_item.find('.my-menu-controls-groups span.click.block_hide_show').hasClass('chiled-hide')){
return false;
}
var item_buffer = 9;
var Item_height = $c_item.outerHeight() + item_buffer;
var loop_flag = 1;
var item_get_depth = get_depth_of_menu_item($c_item);
var counter = 1;
$c_item.nextUntil(function(){
var currrent_item_depth = get_depth_of_menu_item(jQuery(this));
if( !jQuery(this).hasClass('menu-item-depth-0') && loop_flag == 1 && !jQuery(this).hasClass('menu-item-depth-'+item_get_depth) && currrent_item_depth > item_get_depth ){
if(!jQuery( this ).hasClass('item-hide')){
counter++;
Item_height += jQuery( this ).outerHeight();
Item_height += item_buffer;
}
}else{
loop_flag = 2;
}
});
$c_item.find('.amm_block_highlight').css('height',Item_height);
//jQuery(this).closest( "li" ).find('.amm_block_highlight').fadeIn();
}, function(){
jQuery(this).closest( "li" ).find('.amm_block_highlight').fadeOut();
});
// add new page popup open
jQuery(document).on('click', '#menu_manager_popup_container div#mm_cancel', function(e) {
jQuery('#menu_manager_popup').fadeOut();
});
//esc key press then add new page popup will closed
jQuery(document).keyup(function(e) {
if (e.keyCode == 27) { jQuery('#menu_manager_popup').fadeOut(); }
});
jQuery(document).on('click','#amm_wp_post_edit .amm_menu_cancel_btn',function(){
jQuery('#menu_manager_popup').fadeOut();
});
// Menu Id hideshow on click
jQuery('#amm_menu_item_id').click(function(){
jQuery(this).toggleClass('active');
jQuery('.view_menu_id').toggleClass('item-show');
if ( jQuery(this ).is( ".active" ) ) {
jQuery(this).text("Hide Menu Id");
}else{
jQuery(this).text("Show Menu Id");
}
});
/*************************** Back to top event ****************************************/
jQuery("div#amm_back_to_content span.back-to-top").click(function() { jQuery('html, body').animate({ scrollTop: jQuery("#wpbody-content").offset().top }, 1000);});
jQuery(window).scroll( function(){
if( jQuery(window).scrollTop() > 150 ){
jQuery("div#amm_back_to_content").fadeIn(1000);
}else{
jQuery("div#amm_back_to_content").fadeOut(500);
}
});
/********************************* Edit menu item ******************************************/
jQuery(document).on({
mouseenter: function () {
jQuery(this).find('span.amm_main_menu_item_edit').css('display','inline-block');
},
mouseleave: function () {
jQuery(this).find('span.amm_main_menu_item_edit').removeAttr("style");
}
},'ul.menu-manager-plus-menu-wrapper li .menu-item-handle .item-title');
jQuery(document).on('click', 'ul.menu-manager-plus-menu-wrapper li .menu-item-handle .item-title .menu-item-title', function() {
//open popup
jQuery('#menu_manager_popup').css('height',jQuery( document ).height());
jQuery('#menu_manager_popup').css('padding-top',jQuery(window).scrollTop() - 90);
jQuery('#menu_manager_popup').fadeIn();
jQuery('#menu_manager_popup_main-wrapper').fadeOut();
jQuery('#menu_manager_popup_container #amm_wp_post_edit.wp-post-edit').remove();
var html_content = '
Want to edit this item? Buy the Pro Version to access all the features. Buy Pro Version ';
jQuery('#menu_manager_popup_container').append(html_content);
});
//edit fornt end menu save event
jQuery(document).on('click','#menu_manager_popup #menu_manager_popup_container #Amp_amp_update_wrapper.amp_update_mew_item_wrapper .amp_update_item_inner_main .amp_update_item_submit_row_wrapper .amp_menu_amp_update_cancel', function(){
jQuery('#menu_manager_popup_container #amp_wp_post_edit.wp-post-edit').remove();
jQuery('#menu_manager_popup').fadeOut();
});
}); //end of document ready