diff --git a/assets/js/ajax.js b/assets/js/ajax.js index 981449c..50a0306 100644 --- a/assets/js/ajax.js +++ b/assets/js/ajax.js @@ -1,14 +1,14 @@ /** * Admin Ajax Function */ -(function($){ +(function ($) { - $.fn.jc_edit_menu = function(){ + $.fn.jc_edit_menu = function () { var id = JC_Submenu.get_menu_id($(this).attr('id')); - var _menu_item = $('#menu-item-'+id); - - if(_menu_item.hasClass('menu-item-edit-inactive') && !_menu_item.hasClass('jc-submenu-populated')){ + var _menu_item = $('#menu-item-' + id); + + if (_menu_item.hasClass('menu-item-edit-inactive') && !_menu_item.hasClass('jc-submenu-populated')) { var id = JC_Submenu.get_menu_id(_menu_item.attr('id')); var data = { @@ -19,7 +19,7 @@ // show loading $("
").insertBefore(_menu_item.find('.menu-item-actions')); - jQuery.post(ajax_object.ajax_url, data, function(response) { + jQuery.post(ajax_object.ajax_url, data, function (response) { _menu_item.find("#jc-submenu-loading").remove(); @@ -29,50 +29,50 @@ * Display Active Menu Population Options * @since 0.6 */ - _menu_item.find('.jc-accord-heading').each(function(){ + _menu_item.find('.jc-accord-heading').each(function () { var accord_heading = $(this); var id = JC_Submenu.get_menu_id(accord_heading.attr('id')); var btn_handle = $('input', accord_heading); var btn_label = $('label', accord_heading); - btn_handle.live('change', function(){ + btn_handle.on('change', function () { - $('.jc-accord-heading', $('#menu-item-'+id)).removeClass('active'); - $('.item-edit-panel', $('#menu-item-'+id)).hide(); + $('.jc-accord-heading', $('#menu-item-' + id)).removeClass('active'); + $('.item-edit-panel', $('#menu-item-' + id)).hide(); - if($(this).attr('checked') == 'checked'){ - $( '.show-'+$(this).val() , $('#menu-item-'+id) ).show(); + if ($(this).is(':checked')) { + $('.show-' + $(this).val(), $('#menu-item-' + id)).show(); accord_heading.addClass('active'); } }); - btn_label.click(function(event){ - $('.jc-accord-heading input:checked', $('#menu-item-'+id)).attr('checked', false); - btn_handle.attr('checked', 'checked').trigger('change'); + btn_label.click(function (event) { + $('.jc-accord-heading input:checked', $('#menu-item-' + id)).prop('checked', false); + btn_handle.prop('checked', true).trigger('change'); event.preventDefault(); }); btn_handle.filter(":checked").trigger('change'); }); - + /** * Display JC Submenu Options * @since 0.6 */ - _menu_item.find('input.jc-submenu-autopopulate').each(function(index){ + _menu_item.find('input.jc-submenu-autopopulate').each(function (index) { var options_handle = $(this); var id = JC_Submenu.get_menu_id(options_handle.attr('id')); - options_handle.live('change', function(){ - if($(this).attr('checked') == 'checked'){ - $( '#jc-submenu-populate-block-'+id).show(); - $('.jc-submenu-active').show(); - }else{ - $( '#jc-submenu-populate-block-'+id).hide(); - $('.jc-submenu-active').hide(); - } + options_handle.on('change', function () { + if ($(this).is(':checked')) { + $('#jc-submenu-populate-block-' + id).show(); + $('.jc-submenu-active').show(); + } else { + $('#jc-submenu-populate-block-' + id).hide(); + $('.jc-submenu-active').hide(); + } }); options_handle.filter(':checked').trigger('change'); @@ -82,37 +82,37 @@ * Filter Taxonomy via selected Post Type * @since 0.6 */ - _menu_item.find('select[id^="edit-jc-submenu-populate-post"]').each(function(){ + _menu_item.find('select[id^="edit-jc-submenu-populate-post"]').each(function () { var post_select = $(this); var id = JC_Submenu.get_menu_id(post_select.attr('id')); - var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-'+id)); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-' + id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var taxs = tax_select.clone(); - post_select.live('change', function(){ + post_select.on('change', function () { var show_taxs = post_select.find(':selected').data('taxs').split(' '); var selected = tax_select.find(':selected').val(); // tax_select = taxs.clone(); tax_select.empty(); - $('option', taxs).each(function(index){ - + $('option', taxs).each(function (index) { + var val = $(this).val(); - if($.inArray(val, show_taxs) != -1 || val == 0){ + if ($.inArray(val, show_taxs) != -1 || val == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { tax_select.append(clone_option.attr('selected', 'selected')); - }else{ - tax_select.append(clone_option); + } else { + tax_select.append(clone_option); } - }else{ - tax_select.find('option[value='+val+']').remove(); + } else { + tax_select.find('option[value=' + val + ']').remove(); } }); @@ -129,37 +129,37 @@ post_select.trigger('change'); }); - + /** * Filter Terms depending on chosen taxonomy * @since 0.6 */ - _menu_item.find('select[id^="edit-jc-submenu-post-tax"]').each(function(){ + _menu_item.find('select[id^="edit-jc-submenu-post-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax')){ + if (tax == $(this).data('tax')) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -178,32 +178,32 @@ * Filter Taxonomy Terms depending on chosen taxonomy * @since 0.6 */ - _menu_item.find('select[id^="edit-jc-submenu-populate-tax"]').each(function(){ + _menu_item.find('select[id^="edit-jc-submenu-populate-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax') || $(this).data('tax') == 0){ + if (tax == $(this).data('tax') || $(this).data('tax') == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -228,13 +228,13 @@ * * add before .menu-item-actions */ - $(document).ready(function(){ + $(document).ready(function () { + + $('#menu-to-edit').on('click', 'a.item-edit', function () { + $(this).jc_edit_menu(); + }); - $('#menu-to-edit').on('click', 'a.item-edit', function(){ - $(this).jc_edit_menu(); - }); - - }); + }); })(jQuery); \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js index 9e43396..09d7253 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -4,65 +4,65 @@ var JC_Submenu = { - get_menu_id: function (id){ - id= id.split("-"); - id = id[id.length-1]; + get_menu_id: function (id) { + id = id.split("-"); + id = id[id.length - 1]; return id; } }; -(function($){ +(function ($) { /** * Display Active Menu Population Options * @since 0.2 */ - $('.jc-accord-heading').each(function(){ + $('.jc-accord-heading').each(function () { var accord_heading = $(this); var id = JC_Submenu.get_menu_id(accord_heading.attr('id')); var btn_handle = $('input', accord_heading); var btn_label = $('label', accord_heading); - btn_handle.live('change', function(){ + btn_handle.on('change', function () { - $('.jc-accord-heading', $('#menu-item-'+id)).removeClass('active'); - $('.item-edit-panel', $('#menu-item-'+id)).hide(); + $('.jc-accord-heading', $('#menu-item-' + id)).removeClass('active'); + $('.item-edit-panel', $('#menu-item-' + id)).hide(); - if($(this).attr('checked') == 'checked'){ - $( '.show-'+$(this).val() , $('#menu-item-'+id) ).show(); + if ($(this).is(':checked')) { + $('.show-' + $(this).val(), $('#menu-item-' + id)).show(); accord_heading.addClass('active'); } }); - btn_label.click(function(event){ - $('.jc-accord-heading input:checked', $('#menu-item-'+id)).attr('checked', false); - btn_handle.attr('checked', 'checked').trigger('change'); + btn_label.click(function (event) { + $('.jc-accord-heading input:checked', $('#menu-item-' + id)).prop('checked', false); + btn_handle.prop('checked', true).trigger('change'); event.preventDefault(); }); btn_handle.filter(":checked").trigger('change'); }); - + /** * Display JC Submenu Options * @since 0.2 */ - $('input.jc-submenu-autopopulate').each(function(index){ + $('input.jc-submenu-autopopulate').each(function (index) { var options_handle = $(this); var id = JC_Submenu.get_menu_id(options_handle.attr('id')); - options_handle.live('change', function(){ - if($(this).attr('checked') == 'checked'){ - $( '#jc-submenu-populate-block-'+id).show(); - $('.jc-submenu-active').show(); - }else{ - $( '#jc-submenu-populate-block-'+id).hide(); - $('.jc-submenu-active').hide(); - } + options_handle.on('change', function () { + if ($(this).is(':checked')) { + $('#jc-submenu-populate-block-' + id).show(); + $('.jc-submenu-active').show(); + } else { + $('#jc-submenu-populate-block-' + id).hide(); + $('.jc-submenu-active').hide(); + } }); options_handle.filter(':checked').trigger('change'); @@ -72,37 +72,37 @@ var JC_Submenu = { * Filter Taxonomy via selected Post Type * @since 0.2 */ - $('select[id^="edit-jc-submenu-populate-post"]').each(function(){ + $('select[id^="edit-jc-submenu-populate-post"]').each(function () { var post_select = $(this); var id = JC_Submenu.get_menu_id(post_select.attr('id')); - var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-'+id)); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-' + id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var taxs = tax_select.clone(); - post_select.live('change', function(){ + post_select.on('change', function () { var show_taxs = post_select.find(':selected').data('taxs').split(' '); var selected = tax_select.find(':selected').val(); // tax_select = taxs.clone(); tax_select.empty(); - $('option', taxs).each(function(index){ - + $('option', taxs).each(function (index) { + var val = $(this).val(); - if($.inArray(val, show_taxs) != -1 || val == 0){ + if ($.inArray(val, show_taxs) != -1 || val == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { tax_select.append(clone_option.attr('selected', 'selected')); - }else{ - tax_select.append(clone_option); + } else { + tax_select.append(clone_option); } - }else{ - tax_select.find('option[value='+val+']').remove(); + } else { + tax_select.find('option[value=' + val + ']').remove(); } }); @@ -119,37 +119,37 @@ var JC_Submenu = { post_select.trigger('change'); }); - + /** * Filter Terms depending on chosen taxonomy * @since 0.2 */ - $('select[id^="edit-jc-submenu-post-tax"]').each(function(){ + $('select[id^="edit-jc-submenu-post-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax')){ + if (tax == $(this).data('tax')) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -168,32 +168,32 @@ var JC_Submenu = { * Filter Taxonomy Terms depending on chosen taxonomy * @since 0.5.4 */ - $('select[id^="edit-jc-submenu-populate-tax"]').each(function(){ + $('select[id^="edit-jc-submenu-populate-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax') || $(this).data('tax') == 0){ + if (tax == $(this).data('tax') || $(this).data('tax') == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -212,7 +212,7 @@ var JC_Submenu = { /** * Document Ready */ - $(document).ready(function(){ + $(document).ready(function () { $('.item-edit-panel').hide(); }); diff --git a/readme.txt b/readme.txt index 7b88525..5df4e91 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: jcollings Donate link: Tags: submenu, menu, dynamic, custom post type, taxonomy, child pages Requires at least: 3.0.1 -Tested up to: 4 -Stable tag: 0.8.4 +Tested up to: 5.5 +Stable tag: 0.9.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -29,23 +29,232 @@ For further documentation on installing and using JC Submneu features can be fou = How do i use the split menu functionality = -The documentation for using the split menu functionality (widget, shortcode, action) can be found [here](http://jamescollings.co.uk/jc-submenu/resources/output-split-menu-section/) +** What is a WordPress Split Menu ** + +A WordPress Split Menu is the process of creating a multi level menu, and displaying a menu section relative to the currently viewed object/page. For Example if a site has the following menu and pages: + +``` +Page 1 + - Page 1.1 + - Page 1.2 +Page 2 + - Page 1.3 +``` + +Creating a split menu section for this example, you would set the start depth of 1, this means that when you are viewing any page or child page of Page 1 the split menu would output related items only: + +``` +Page 1 + - Page 1.1 + - Page 1.2 +``` + +and if you were viewing any page or child page of Page 2 the split menu section would be: + +``` +Page 2 + - Page 1.3 +``` + +** Wordpress Split Menu Widget ** + +JC Submenu plugin comes with a widget titled “Split Menu Widget” which allows you to output your split menu within a wordpress sidebar. + +It is located under Appearance > Widgets in your wordpress administration area. + +Widget Settings: + +* Choose Split Menu widget from the list of avaliable widgets +* Select Menu – Choose the menu you wish to split +* Start Level – Choose the starting depth to display +* Menu Depth – Choose how many levels you wish to display +* Show Parent – Choose to display the split menu’s parent item +* Show Hierarcy – Choose to display a flat or nested list +* Trigger Depth – Choose how many levels of children you would like to display in relation to the activate page, 0 = show all. (Added in v 0.62) + +** Split Menu Action ** + +JC Submenu plugin comes with a built in wordpress action to easily output a split menu anywhere within your theme. + +``` + +``` + +* hierarchy – Whether to display a flat list instead +* start – Menu depth you wish to split from +* depth – Amount of levels you wish to display +* show_parent – Whether to display the parent item +* trigger_depth – how many levels of children you would like to display in relation to the activate page, 0 = show all. (Added in v 0.62) +* menu_class – Set the class of the menu element +* menu_id – Set the id of the menu element +* container – what to wrap the ul in +* container_id – Set the id of the container element +* container_class – Set the class of the container element = How do i output a section of menu = -The documentation for displaying a section of menu (widget, shortcode, action) can be found [here](http://jamescollings.co.uk/jc-submenu/resources/how-to-output-a-section-of-a-wordpress-menu/) +** Menu Section Widget ** + +JC Submenu plugins comes with a widget titled "Section Menu Widget" which allows you to output a section of your wordpress menu within a sidebar. +It is located under Appearance > Widgets in your wordpress administration area. + +Widget Settings: + +* Choose Section Menu widget from the list of avaliable widgets +* Select Menu Part – Choose the menu section you wish display +* Menu Depth – Set how many levels of the menu you wish to display +* Show Parent – Choose whether to display the parent item + +** Menu Section Action ** + +JC Submenu plugin comes with a built in wordpress action to easily output a section of a menu anywhere within your theme. + +``` + +``` + +* hierarchy – Whether to display a flat list instead +* start – Menu item you wish to display from +* depth – Amount of levels you wish to display +* show_parent – Whether to display the parent item +* menu_class – Set the class of the menu element +* menu_id – Set the id of the menu element +* container – what to wrap the ul in +* container_id – Set the id of the container element +* container_class – Set the class of the container element + +** Menu Section Shortcode ** + +Display a section of your wordpress menu within your visual editor using wordpress shortcodes. + +``` +[jcs_menu_section menu="" hierarchy="1" start="1" depth="5" show_parent="0" /] + +``` + +* menu – Choose the menu you wish to display +* hierarchy – Whether to display a flat list instead +* start – ID Menu item you wish to display from (can be found by hovering over the menu item within the wordpress menu admin page) +* depth – Amount of levels you wish to display +* show_parent – Whether to display the parent item = How do i automatically populate menu items = -The documentation for automatically populating menu items can be found [here](http://jamescollings.co.uk/jc-submenu/resources/how-to-automatically-populate-wordpress-submenus/) +JC Submenu WordPress plugin takes the hassle out of creating menus, by removing the manual addition of items and allowing you to automatically populate menu items from posts, categories, tags, custom post types, and taxonomies. + +Each with many customisable options allowing you to refine your final menu. + +** Enabling Automatic Menu Population ** + +Once you have the JC Submenu installed, from the menus section + +* Add a menu item that you wish to have posts as a submenu and click on save menu. +* When the page reloads, click on the arrow on the right hand side of the menu item to display the advanced options.Tick the checkbox labelled JC Submenu – Automatically populate submenu to show an accordion of population options. + +** Populate WordPress Menus with Posts ** + +1. Click on the section labelled Populate from post type. +* Post Type – Make sure Post is selected from from the drop down labelled Post Type +* Taxonomy – If you wish to only show posts from a certain category/taxonomy choose the appropriate taxonomy from the drop down labelled Taxonomy (otherwise choose All), If you wish to filter it down further by choosing a term within that taxonomy choose the appropriate term from the drop down labelled Terms. +* Order – Choose which field you want to order and how you’d like it ordered Ascending or Descending. +* Post Limit – Setting the number of posts to display, Set to 0 if you wish not to have a limit. + +** Populate WordPress Menus with Taxonomies ** + +1. Click on the section labelled Populate from taxonomy. +* Taxonomies – Choose the taxonomy from the drop down you wish to populate from. +* Order – Choose which field you want to order and how you’d like it ordered Ascending or Descending. +* Hide Empty Terms – Hide terms that do not have any posts / custom posts. + +** Populate WordPress Menus with Child Pages ** + +1. Click on the section labelled Populate from pages. +* Parent Page – Choose the parent page to fetch the child pages. +* Order – Choose which field you want to order and how you’d like it ordered Ascending or Descending. + = What Actions and filters are avaliable in this plugin = -A list of all actions and filters can be found [here](http://jamescollings.co.uk/jc-submenu/sections/actions-filters/) +** jcs/menu_item_args ** + +jcs/menu_item_args filter is used to edit wp_nav_menu options on a per menu item basis allowing a truely customizeable menu output. + +Example – Display Menu Item Image + +This example shows how to add an image before a menu item depending on that items object type. + +``` +add_filter( 'jcs/menu_item_args', 'jcs_menu_item_args', 10, 2); +function jcs_menu_item_args($args, $item){ + + switch($item->object){ + case 'page': + // add blue 10 pixel image before the menu item name + $args->link_before = '