Custom Menu Wizard Widget - Version 2.0.4

Version Description

  • bugfix : clearing the container field failed to remove the container from the output

  • addition : in the "assist", added automatic selection of the shortcode text when it is clicked

  • addition : remove WordPress's menu-item-has-children class (introduced in v3.7) when the filtered item no longer has children

  • change : tweaked styles and javascript in admin for WordPress v3.8

Download this release

Release Info

Developer wizzud
Plugin Icon 128x128 Custom Menu Wizard Widget
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.4

custom-menu-wizard.css CHANGED
@@ -1,17 +1,20 @@
1
  /**
2
  * custom-menu-wizard.css
3
- * Version: 2.0.3
4
  */
5
  /*widget admin style...*/
6
  /*NB .widget-content class is not present in accessibility mode*/
7
  .js .widget-content .widget-custom-menu-wizard-onchange .cmw-start-fieldset-collapsed {display:none;}
 
8
  .widget-custom-menu-wizard-onchange .cmw-colour-grey {color:#999999;}
9
  .widget-custom-menu-wizard-onchange .cmw-pad-left-1 {padding-left:1em;}
10
  .widget-custom-menu-wizard-onchange .cmw-off-the-page {display:none; position:absolute; left:-5000px; top:-5000px;}
11
  .widget-custom-menu-wizard-onchange .cmw-toggle-assist {float:right; line-height:1; margin-left:1em;}
12
- .widget-custom-menu-wizard-collapsible-fieldset {margin:0 0 0.5em; cursor:pointer;}
 
13
  .widget-custom-menu-wizard-collapsible-fieldset h3 {font-size:1em; margin:0; padding:2px 0.5em;}
14
- .widget-custom-menu-wizard-collapsible-fieldset div {background-color:#transparent; background-repeat:no-repeat; background-position:0 -36px; height:16px; width:16px; float:right; outline:0 none;}
 
15
  .js .widget-content .widget-custom-menu-wizard-collapsible-fieldset div.cmw-collapsed-fieldset {background-position:0 0;}
16
  .widget-custom-menu-wizard-disableifnot-rp, .widget-custom-menu-wizard-disableifnot-ci {line-height:1.3333;}
17
  .widget-custom-menu-wizard-childrenof optgroup option {padding-left:0.75em;}
1
  /**
2
  * custom-menu-wizard.css
3
+ * Version: 2.0.4
4
  */
5
  /*widget admin style...*/
6
  /*NB .widget-content class is not present in accessibility mode*/
7
  .js .widget-content .widget-custom-menu-wizard-onchange .cmw-start-fieldset-collapsed {display:none;}
8
+ .widget-custom-menu-wizard-onchange {margin:0 0 0.5em;}
9
  .widget-custom-menu-wizard-onchange .cmw-colour-grey {color:#999999;}
10
  .widget-custom-menu-wizard-onchange .cmw-pad-left-1 {padding-left:1em;}
11
  .widget-custom-menu-wizard-onchange .cmw-off-the-page {display:none; position:absolute; left:-5000px; top:-5000px;}
12
  .widget-custom-menu-wizard-onchange .cmw-toggle-assist {float:right; line-height:1; margin-left:1em;}
13
+ .widget-custom-menu-wizard-collapsible-fieldset .hidden-field {display:none;}
14
+ .widget-custom-menu-wizard-collapsible-fieldset {margin:0.5em 0 0; cursor:pointer; border-left-width:0; border-right-width:0; border-radius:0; text-align:center; background-color:#ffffff;}
15
  .widget-custom-menu-wizard-collapsible-fieldset h3 {font-size:1em; margin:0; padding:2px 0.5em;}
16
+ .widget-custom-menu-wizard-collapsible-fieldset h4 {font-size:1em; margin:0.75em 0;}
17
+ .widget-custom-menu-wizard-collapsible-fieldset div {background-color:transparent; background-repeat:no-repeat; background-position:0 -36px; height:16px; width:16px; float:right; margin-top:0.75em; outline:0 none;}
18
  .js .widget-content .widget-custom-menu-wizard-collapsible-fieldset div.cmw-collapsed-fieldset {background-position:0 0;}
19
  .widget-custom-menu-wizard-disableifnot-rp, .widget-custom-menu-wizard-disableifnot-ci {line-height:1.3333;}
20
  .widget-custom-menu-wizard-childrenof optgroup option {padding-left:0.75em;}
custom-menu-wizard.js CHANGED
@@ -1,5 +1,5 @@
1
  /* Plugin Name: Custom Menu Wizard
2
- * Version: 2.0.3
3
  * Author: Roger Barrett
4
  *
5
  * Script for controlling this widget's options (in Admin -> Widgets)
@@ -119,6 +119,26 @@ jQuery(function($){
119
  this.blur();
120
  return false;
121
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  /**
123
  * creates a new list of menu items and inserts it into the dialog content in place of any previous one
124
  * @param {Object} dialog jQuery object of the dialog
@@ -167,6 +187,7 @@ jQuery(function($){
167
  .append( $('<div/>').addClass('cmw-demo-theshortcode').html('<code class="ui-corner-all">[custom_menu_wizard]</code>') );
168
  dialog.find('.cmw-demo-themenu').on('click', 'a', assist.clickMenu);
169
  dialog.find('.cmw-demo-themenu').on('change', 'input', assist.changeMenu);
 
170
  dialog.find('.cmw-demo-theoutput').on('click', 'a', assist.clickOutput);
171
  dialog.dialog({autoOpen:false, width:Math.min($(window).width() * 0.8, 600), modal:false});
172
  }
@@ -564,46 +585,16 @@ jQuery(function($){
564
  dialog.dialog('close');
565
  }
566
  });
 
 
 
 
 
 
 
 
 
 
567
  });
568
 
569
- //1. when a widget is opened or saved, trigger change on the filter_item select
570
- //2. when a widget is deleted, destroy its dialog
571
- //To achieve this I've elected to modify WP's window.wpWidgets object and intercept some of its methods
572
- // - for (1), the fixLabels() method, which handily gets called whenever a widget is opened or saved
573
- // - for (2), the save() method
574
- if(window.wpWidgets){
575
- if(window.wpWidgets.fixLabels && !window.wpWidgets._cmw_fixLabels){
576
- //save the original...
577
- window.wpWidgets._cmw_fixLabels = window.wpWidgets.fixLabels;
578
- //replace the original...
579
- window.wpWidgets.fixLabels = function(widget){
580
- //trigger change on selectmenu...
581
- widget.find('.widget-custom-menu-wizard-selectmenu').trigger('change');
582
- //run the original...
583
- window.wpWidgets._cmw_fixLabels(widget);
584
- };
585
- }
586
- if(window.wpWidgets.save && !window.wpWidgets._cmw_save){
587
- //save the original...
588
- window.wpWidgets._cmw_save = window.wpWidgets.save;
589
- //replace the original...
590
- window.wpWidgets.save = function(widget, del, animate, order){
591
- //destroy dialog if deleting the widget...
592
- if(del){
593
- widget.find('.widget-custom-menu-wizard-onchange').each(function(){
594
- var dialog = $('#' + $(this).data().cmwDialogId);
595
- if(dialog.length){
596
- dialog.dialog('destroy');
597
- dialog.remove();
598
- }
599
- });
600
- }
601
- //run the original...
602
- window.wpWidgets._cmw_save(widget, del, animate, order);
603
- };
604
- }
605
- }else{
606
- //one-off fallback...
607
- $(dotPrefix + '-selectmenu').trigger('change');
608
- }
609
  });
1
  /* Plugin Name: Custom Menu Wizard
2
+ * Version: 2.0.4
3
  * Author: Roger Barrett
4
  *
5
  * Script for controlling this widget's options (in Admin -> Widgets)
119
  this.blur();
120
  return false;
121
  },
122
+ /**
123
+ * click handler for the shortcode : selects the text contained in the shortcode's CODE element
124
+ * @this {Element} The CODE element
125
+ * @param {Object} e Event object
126
+ */
127
+ clickShortcode : function(e){
128
+ var doc = document,
129
+ range, selection;
130
+ if (doc.body.createTextRange){ //ms
131
+ range = doc.body.createTextRange();
132
+ range.moveToElementText(this);
133
+ range.select();
134
+ }else if(window.getSelection){ //all others
135
+ selection = window.getSelection();
136
+ range = doc.createRange();
137
+ range.selectNodeContents(this);
138
+ selection.removeAllRanges();
139
+ selection.addRange(range);
140
+ }
141
+ },
142
  /**
143
  * creates a new list of menu items and inserts it into the dialog content in place of any previous one
144
  * @param {Object} dialog jQuery object of the dialog
187
  .append( $('<div/>').addClass('cmw-demo-theshortcode').html('<code class="ui-corner-all">[custom_menu_wizard]</code>') );
188
  dialog.find('.cmw-demo-themenu').on('click', 'a', assist.clickMenu);
189
  dialog.find('.cmw-demo-themenu').on('change', 'input', assist.changeMenu);
190
+ dialog.find('.cmw-demo-theshortcode').on('click', 'code', assist.clickShortcode);
191
  dialog.find('.cmw-demo-theoutput').on('click', 'a', assist.clickOutput);
192
  dialog.dialog({autoOpen:false, width:Math.min($(window).width() * 0.8, 600), modal:false});
193
  }
585
  dialog.dialog('close');
586
  }
587
  });
588
+ })
589
+ //when a widget is deleted, remove its dialog...
590
+ .on('click', '.widget-control-remove', function(e){
591
+ $(this).closest('div.widget').find('.widget-custom-menu-wizard-onchange').each(function(){
592
+ var dialog = $('#' + $(this).data().cmwDialogId);
593
+ if(dialog.length){
594
+ dialog.dialog('destroy');
595
+ dialog.remove();
596
+ }
597
+ });
598
  });
599
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600
  });
custom-menu-wizard.min.js CHANGED
@@ -1,28 +1,28 @@
1
  /* Plugin Name: Custom Menu Wizard
2
- * Version: 2.0.3
3
  * Author: Roger Barrett
4
  *
5
  * Script for controlling this widget's options (in Admin -> Widgets)
6
  */
7
- jQuery(function(f){var n={getDialog:function(c){return f("#"+c.find(".widget-custom-menu-wizard-onchange").data().cmwDialogId)},getSettings:function(c){var a={};f.each(c.serializeArray(),function(d,c){var b=c.name.replace(/.*\[([^\]]+)\]$/,"$1"),e="items"!==b&&/^-?\d+$/.test(c.value)?parseInt(c.value,10):c.value;a[b]=e;"items"===b&&(a._items_sep=!e||/(^\d+$|,)/.test(f.trim(e))?",":" ",e=f.map(e.split(/[,\s]+/),function(a){a=a?parseInt(a,10):0;return isNaN(a)||1>a?null:a}),a._items=e.join(a._items_sep))});
8
- return a},buildRecurse:function(c,a,d){var f="",b,e;a=(a||0)+1;d=d||"";for(b in c)e=b.split("|")[0],f+='<li class="level-'+a+'" data-itemid="'+e+'" data-level="'+a+'" data-trace="'+d+'">',f+='<a class="ui-corner-all" href="#"><span class="ui-corner-all" title="#'+e+'">'+b.replace(/^\d+\|/,""),f+='</span></a><input type="checkbox" value="'+e+'" />',c[b]&&(f+="<ul>"+n.buildRecurse(c[b],a,e+(d?",":"")+d)+"</ul>"),f+="</li>";return f},changeMenu:function(c){c=f(this);var a=f(c.closest(".ui-dialog-content").data().cmwTriggerChange).closest("form").find(".widget-custom-menu-wizard-setitems"),
9
- d=f.trim(a.val()),d=!d||/(^\d+$|,)/.test(d)?",":" ";a.val(c.closest(".cmw-demo-themenu").find("input").map(function(){return this.checked?this.value:null}).get().join(d)).trigger("change")},clickMenu:function(c){var a=f(this);c=["current-menu-item","current-menu-parent","current-menu-ancestor"];var d=a.closest(".ui-dialog-content"),h=d.find(".cmw-demo-themenu"),a=a.find("span").not("."+c[0]).parentsUntil(h,"li"),b,e=function(){this.title=this.title+" "+b.replace(" "," & ").replace(/-/g," ")};h.find("."+
10
- c.join(",.")).removeClass(c.join(" ")).each(function(){this.title=this.title.replace(/\s.*$/,"")});for(h=0;h<a.length;h++)b=1===h?c.join(" "):c[0],a.eq(h).children("a").find("span").addClass(b).each(e),1<c.length&&c.shift();f(d.data().cmwTriggerChange).trigger("change");return!1},clickOutput:function(c){c=this.href.split("#")[1];f(this).closest(".ui-dialog-content").find(".cmw-demo-themenu a").eq(c).not(":has(.current-menu-item)").trigger("click");this.blur();return!1},createMenu:function(c,a){var d=
11
- c.data(),h=c.find(".cmw-demo-themenu"),b=a.find(".widget-custom-menu-wizard-selectmenu"),e=parseInt(b.val(),10),m=h.find("ul").eq(0),k=h.data(),g;m.length&&m.data("menuid")===e||(g=f("<ul>"+n.buildRecurse(a.find(".widget-custom-menu-wizard-childrenof optgroup").data().cmwItems||{})+"</ul>"),m.remove(),c.dialog("option","title",d.cmwTitlePrefix+b.find("option:selected").text()),k.maxLevel=0,h.append(g.data("menuid",e)).find("a").each(function(a){var b=f(this).parent("li").data().level;f(this).data("indx",
12
- a);b&&b>k.maxLevel&&(k.maxLevel=b)}))},init:function(c){var a=f(this);c=a.closest(".widget-custom-menu-wizard-onchange").data();var d=f("#"+c.cmwDialogId),a=a.closest("form");d.length||(d=f("<div/>",{id:c.cmwDialogId}).addClass("widget-custom-menu-wizard-dialog").data({cmwTriggerChange:c.cmwDialogTrigger,cmwTitlePrefix:c.cmwDialogTitle}).append(f("<div/>").addClass("cmw-demo-theoutput").html("<strong>"+c.cmwDialogOutput+'</strong> &hellip;<div class="cmw-demo-theoutput-wrap ui-corner-all"></div><div class="cmw-demo-fallback"><small>'+
13
- c.cmwDialogFallback+"</small></div>")).append(f("<div/>").addClass("cmw-demo-themenu").html("<small><em>"+c.cmwDialogPrompt+"</em></small>")).append(f("<div/>").addClass("cmw-demo-theshortcode").html('<code class="ui-corner-all">[custom_menu_wizard]</code>')),d.find(".cmw-demo-themenu").on("click","a",n.clickMenu),d.find(".cmw-demo-themenu").on("change","input",n.changeMenu),d.find(".cmw-demo-theoutput").on("click","a",n.clickOutput),d.dialog({autoOpen:!1,width:Math.min(0.8*f(window).width(),600),
14
- modal:!1}));d.dialog("isOpen")?d.dialog("close"):(n.createMenu(d,a),d.dialog("open"),f(c.cmwDialogTrigger).trigger("change"));this.blur();return!1},shortcode:function(c,a){var d={menu:[a.menu]},h,b,e;a.title&&(d.title=a.title);if(0<a.filter)switch(a.filter_item){case 0:d.children_of="current";break;case -1:d.children_of="parent";break;case -2:d.children_of="root";break;default:d.children_of=[a.filter_item]}0>a.filter&&(d.items=a._items);0<a.filter&&0>a.filter_item&&a.fallback_no_ancestor&&(d.fallback_parent=
15
- a.fallback_include_parent_siblings?"siblings":a.fallback_include_parent?"parent":[1]);0<a.filter&&!a.filter_item&&a.fallback_no_children&&(d.fallback_current=a.fallback_nc_include_parent_siblings?"siblings":a.fallback_nc_include_parent?"parent":[1]);1<a.start_level&&(d.start_level=[a.start_level]);0<a.depth&&(d.depth=[a.depth]);a.depth_rel_current&&0<a.depth&&(d.depth_rel_current=[1]);e=[];0<a.filter&&(a.include_parent_siblings?e.push("siblings"):a.include_parent&&e.push("parent"),a.include_ancestors&&
16
- e.push("ancestors"),e.length&&(d.include=e.join(" ")));e=[];0<a.filter&&a.title_from_parent&&e.push("parent");a.title_from_current&&e.push("current");e.length&&(d.title_from=e.join(" "));for(e in{flat_output:1,contains_current:1,ol_root:1,ol_sub:1})a[e]&&(d[e]=[1]);h={container:"div",container_id:"",container_class:"",menu_class:"menu-widget",widget_class:""};for(e in h)a[e]!==h[e]&&(d[e]=a[e]);h={wrap_link:"before",wrap_link_text:"link_before"};for(e in h)(b=a[h[e]].toString().match(/^<(\w+)/))&&
17
- b[1]&&(d[e]=b[1]);h=[];for(e in d)h.push(f.isArray(d[e])?e+"="+d[e][0]:e+'="'+d[e]+'"');n.getDialog(c).find("code").text("[custom_menu_wizard "+h.join(" ")+"]")},show:function(c,a,d){a=a||f(this).closest("form");d=d||n.getSettings(a);c=n.getDialog(a);var h=c.find(".cmw-demo-themenu"),b=h.find(".picked"),e="",m="",k=0,g=c.find(".cmw-demo-theoutput-wrap").empty(),p=["menu-widget"],q={};if(b.length&&g.length){0<d.filter&&d.title_from_parent&&(m=h.find(".the-parent").children("a").text()||"");!m&&d.title_from_current&&
18
- (m=h.find(".current-menu-item").text()||"");m||d.hide_title||(m=d.title||"");for(b.each(function(a){var b=f(this),c=b.data(),h=c.trace?c.trace.toString().split(","):[];a=c.itemid.toString();var g=1,b=b.children("a");if(!d.flat_output)for(q[a]=1,a=0;a<h.length;a++)q[h[a]]&&g++;if(k)if(g>k)e+=d.ol_sub?"<ol>":"<ul>";else{for(;k>g;)--k,e+="</li>"+(d.ol_sub?"</ol>":"</ul>");e+="</li>"}e+='<li class="cmw-level-'+g+(c.included||"")+'"><a href="#'+b.data("indx")+'">'+b.text()+"</a>";k=g});1<k;)--k,e+="</li>"+
19
- (d.ol_sub?"</ol>":"</ul>");e+="</li>";p.push(c.find(".cmw-demo-fallback").data("fellback"));e=(d.ol_root?"<ol":"<ul")+' class="'+f.trim(p.join(" "))+'">'+e+(d.ol_root?"</ol>":"</ul>");g.html(e);m&&g.prepend("<h3>"+m+"</h3>");g.find("li").filter(function(){return!!f(this).children("ul, ol").length}).addClass("cmw-has-submenu")}n.shortcode(a,d)},update:function(c){var a=f(this).closest("form"),d=n.getDialog(a),h,b,e,m,k,g,p,q,r,l,s;if(d.length&&d.dialog("isOpen")){f(c.target).hasClass("widget-custom-menu-wizard-selectmenu")&&
20
- n.createMenu(d,a);b=n.getSettings(a);e=b.include_parent;m=b.include_parent_siblings;k=d.find(".cmw-demo-themenu");h=k.data().maxLevel;p=k.find(".current-menu-item").closest("li");q=p.length?p.data().level:-1;g=k.find("li").removeData("included").removeClass("the-parent");0>b.filter&&(g=g.filter(function(){var a=f(this).children("input"),c=-1<(b._items_sep+b._items+b._items_sep).indexOf(b._items_sep+a[0].value+b._items_sep);a.prop("checked",c);return c}),b._items||(g=f([])));g.length&&!p.length&&(b.contains_current||
21
- 0<b.filter&&1>b.filter_item)&&(g=f([]));g.length&&0<b.filter&&(0<b.filter_item?l=g.filter("[data-itemid="+b.filter_item+"]"):b.filter_item?1===q&&b.fallback_no_ancestor?(l=p,e=e||b.fallback_include_parent,m=m||b.fallback_include_parent_siblings,r="cmw-fellback-to-current"):l=1===q?k:-1>b.filter_item?k.find(".current-menu-ancestor").eq(0).closest("li"):k.find(".current-menu-parent").closest("li"):p.find("li").length?l=p:b.fallback_no_children&&(l=k.find(".current-menu-parent").closest("li"),l.length||
22
- (l=k),e=e||b.fallback_nc_include_parent,m=m||b.fallback_nc_include_parent_siblings,r="cmw-fellback-to-parent"));if(g.length)if(b.filter)l&&l.length?(s=b.depth_rel_current&&b.depth&&p.length&&l.has(p[0]).length?q-1+b.depth:b.depth?Math.max((l.data().level||0)+b.depth,b.start_level+b.depth-1):9999,g=l.find("li").filter(function(){var a=f(this).data().level;return a>=b.start_level&&a<=s})):0<b.filter&&(g=f([]));else for(s=b.depth_rel_current&&b.depth&&p.length&&q>=b.start_level?q+b.depth-1:b.depth?b.start_level+
23
- b.depth-1:9999,q=1;q<=h;q++)if(q<b.start_level||q>s)g=g.not(".level-"+q);g.length&&0<b.filter&&l&&l.is("li")&&(m&&(g=g.add(l.siblings("li").data("included"," cmw-an-included-parent-sibling")),e=!0),b.include_ancestors&&(g=g.add(l.parentsUntil(k,"li").data("included"," cmw-an-included-ancestor")),e=!0),e&&(g=g.add(l.data("included"," cmw-the-included-parent"))));!g.length||!b.contains_current||p.length&&g.filter(p).length||(g=f([]));g.length&&l&&l.is("li")&&l.addClass("the-parent");r=g.length?r:"";
24
- d.find(".cmw-demo-fallback").data("fellback",r).toggleClass("cmw-demo-fellback",!!r);k.toggleClass("cmw-demo-filteritems",0>b.filter).find(".picked").not(g.addClass("picked")).removeClass("picked");n.show.call(this,c,a,b)}}};f(document).on("click",".widget-custom-menu-wizard-collapsible-fieldset",function(){var c=f(this),a=c.find("input").eq(0),d=!a.prop("checked");a.length&&(a.prop("checked",d),c.find("div").toggleClass("cmw-collapsed-fieldset",d),c.next("div")[d?"slideUp":"slideDown"]());this.blur();
25
- return!1}).on("change",".widget-custom-menu-wizard-listen",function(){var c=f(this.form),a=c.find(".widget-custom-menu-wizard-selectmenu"),d=c.find(".widget-custom-menu-wizard-showall").prop("checked"),h=c.find(".widget-custom-menu-wizard-showspecific").prop("checked"),c=c.find(".widget-custom-menu-wizard-childrenof"),b=parseInt(c.val(),10),e;a.is(this)&&(a=this.selectedIndex,c.find("optgroup").filter(function(){var b=f(this).data("cmwOptgroupIndex")===a;b||f(this).remove();return b}).length||(e=
26
- f("#"+c.attr("id")+"_ignore").find("optgroup").eq(a).clone(),e.length&&(0<b&&(b=0,c.val(b)),e.find("option[selected]").removeAttr("selected").prop("selected",!1),c.append(e))));f.each({"":d||h,"-ss":h,"not-rp":d||h||0<=b,"not-ci":d||h||!!b},function(a,b){f(".widget-custom-menu-wizard-disableif"+a,this.form).toggleClass("cmw-colour-grey",b).find("input,select").prop("disabled",b)})}).on("change",".widget-custom-menu-wizard-onchange",n.update).on("click",".widget-custom-menu-wizard-toggle-assist",n.init).on("click",
27
- ".widget-action, .widget-control-close",function(){f(this).closest("div.widget").find(".widget-custom-menu-wizard-onchange").each(function(){var c=f("#"+f(this).data().cmwDialogId);c.length&&c.dialog("isOpen")&&c.dialog("close")})});window.wpWidgets?(window.wpWidgets.fixLabels&&!window.wpWidgets._cmw_fixLabels&&(window.wpWidgets._cmw_fixLabels=window.wpWidgets.fixLabels,window.wpWidgets.fixLabels=function(c){c.find(".widget-custom-menu-wizard-selectmenu").trigger("change");window.wpWidgets._cmw_fixLabels(c)}),
28
- window.wpWidgets.save&&!window.wpWidgets._cmw_save&&(window.wpWidgets._cmw_save=window.wpWidgets.save,window.wpWidgets.save=function(c,a,d,h){a&&c.find(".widget-custom-menu-wizard-onchange").each(function(){var a=f("#"+f(this).data().cmwDialogId);a.length&&(a.dialog("destroy"),a.remove())});window.wpWidgets._cmw_save(c,a,d,h)})):f(".widget-custom-menu-wizard-selectmenu").trigger("change")});
1
  /* Plugin Name: Custom Menu Wizard
2
+ * Version: 2.0.4
3
  * Author: Roger Barrett
4
  *
5
  * Script for controlling this widget's options (in Admin -> Widgets)
6
  */
7
+ jQuery(function(f){var n={getDialog:function(d){return f("#"+d.find(".widget-custom-menu-wizard-onchange").data().cmwDialogId)},getSettings:function(d){var a={};f.each(d.serializeArray(),function(b,d){var c=d.name.replace(/.*\[([^\]]+)\]$/,"$1"),e="items"!==c&&/^-?\d+$/.test(d.value)?parseInt(d.value,10):d.value;a[c]=e;"items"===c&&(a._items_sep=!e||/(^\d+$|,)/.test(f.trim(e))?",":" ",e=f.map(e.split(/[,\s]+/),function(a){a=a?parseInt(a,10):0;return isNaN(a)||1>a?null:a}),a._items=e.join(a._items_sep))});
8
+ return a},buildRecurse:function(d,a,b){var f="",c,e;a=(a||0)+1;b=b||"";for(c in d)e=c.split("|")[0],f+='<li class="level-'+a+'" data-itemid="'+e+'" data-level="'+a+'" data-trace="'+b+'">',f+='<a class="ui-corner-all" href="#"><span class="ui-corner-all" title="#'+e+'">'+c.replace(/^\d+\|/,""),f+='</span></a><input type="checkbox" value="'+e+'" />',d[c]&&(f+="<ul>"+n.buildRecurse(d[c],a,e+(b?",":"")+b)+"</ul>"),f+="</li>";return f},changeMenu:function(d){d=f(this);var a=f(d.closest(".ui-dialog-content").data().cmwTriggerChange).closest("form").find(".widget-custom-menu-wizard-setitems"),
9
+ b=f.trim(a.val()),b=!b||/(^\d+$|,)/.test(b)?",":" ";a.val(d.closest(".cmw-demo-themenu").find("input").map(function(){return this.checked?this.value:null}).get().join(b)).trigger("change")},clickMenu:function(d){var a=f(this);d=["current-menu-item","current-menu-parent","current-menu-ancestor"];var b=a.closest(".ui-dialog-content"),g=b.find(".cmw-demo-themenu"),a=a.find("span").not("."+d[0]).parentsUntil(g,"li"),c,e=function(){this.title=this.title+" "+c.replace(" "," & ").replace(/-/g," ")};g.find("."+
10
+ d.join(",.")).removeClass(d.join(" ")).each(function(){this.title=this.title.replace(/\s.*$/,"")});for(g=0;g<a.length;g++)c=1===g?d.join(" "):d[0],a.eq(g).children("a").find("span").addClass(c).each(e),1<d.length&&d.shift();f(b.data().cmwTriggerChange).trigger("change");return!1},clickOutput:function(d){d=this.href.split("#")[1];f(this).closest(".ui-dialog-content").find(".cmw-demo-themenu a").eq(d).not(":has(.current-menu-item)").trigger("click");this.blur();return!1},clickShortcode:function(d){var a=
11
+ document;a.body.createTextRange?(a=a.body.createTextRange(),a.moveToElementText(this),a.select()):window.getSelection&&(d=window.getSelection(),a=a.createRange(),a.selectNodeContents(this),d.removeAllRanges(),d.addRange(a))},createMenu:function(d,a){var b=d.data(),g=d.find(".cmw-demo-themenu"),c=a.find(".widget-custom-menu-wizard-selectmenu"),e=parseInt(c.val(),10),m=g.find("ul").eq(0),k=g.data(),h;m.length&&m.data("menuid")===e||(h=f("<ul>"+n.buildRecurse(a.find(".widget-custom-menu-wizard-childrenof optgroup").data().cmwItems||
12
+ {})+"</ul>"),m.remove(),d.dialog("option","title",b.cmwTitlePrefix+c.find("option:selected").text()),k.maxLevel=0,g.append(h.data("menuid",e)).find("a").each(function(a){var b=f(this).parent("li").data().level;f(this).data("indx",a);b&&b>k.maxLevel&&(k.maxLevel=b)}))},init:function(d){var a=f(this);d=a.closest(".widget-custom-menu-wizard-onchange").data();var b=f("#"+d.cmwDialogId),a=a.closest("form");b.length||(b=f("<div/>",{id:d.cmwDialogId}).addClass("widget-custom-menu-wizard-dialog").data({cmwTriggerChange:d.cmwDialogTrigger,
13
+ cmwTitlePrefix:d.cmwDialogTitle}).append(f("<div/>").addClass("cmw-demo-theoutput").html("<strong>"+d.cmwDialogOutput+'</strong> &hellip;<div class="cmw-demo-theoutput-wrap ui-corner-all"></div><div class="cmw-demo-fallback"><small>'+d.cmwDialogFallback+"</small></div>")).append(f("<div/>").addClass("cmw-demo-themenu").html("<small><em>"+d.cmwDialogPrompt+"</em></small>")).append(f("<div/>").addClass("cmw-demo-theshortcode").html('<code class="ui-corner-all">[custom_menu_wizard]</code>')),b.find(".cmw-demo-themenu").on("click",
14
+ "a",n.clickMenu),b.find(".cmw-demo-themenu").on("change","input",n.changeMenu),b.find(".cmw-demo-theshortcode").on("click","code",n.clickShortcode),b.find(".cmw-demo-theoutput").on("click","a",n.clickOutput),b.dialog({autoOpen:!1,width:Math.min(0.8*f(window).width(),600),modal:!1}));b.dialog("isOpen")?b.dialog("close"):(n.createMenu(b,a),b.dialog("open"),f(d.cmwDialogTrigger).trigger("change"));this.blur();return!1},shortcode:function(d,a){var b={menu:[a.menu]},g,c,e;a.title&&(b.title=a.title);if(0<
15
+ a.filter)switch(a.filter_item){case 0:b.children_of="current";break;case -1:b.children_of="parent";break;case -2:b.children_of="root";break;default:b.children_of=[a.filter_item]}0>a.filter&&(b.items=a._items);0<a.filter&&0>a.filter_item&&a.fallback_no_ancestor&&(b.fallback_parent=a.fallback_include_parent_siblings?"siblings":a.fallback_include_parent?"parent":[1]);0<a.filter&&!a.filter_item&&a.fallback_no_children&&(b.fallback_current=a.fallback_nc_include_parent_siblings?"siblings":a.fallback_nc_include_parent?
16
+ "parent":[1]);1<a.start_level&&(b.start_level=[a.start_level]);0<a.depth&&(b.depth=[a.depth]);a.depth_rel_current&&0<a.depth&&(b.depth_rel_current=[1]);e=[];0<a.filter&&(a.include_parent_siblings?e.push("siblings"):a.include_parent&&e.push("parent"),a.include_ancestors&&e.push("ancestors"),e.length&&(b.include=e.join(" ")));e=[];0<a.filter&&a.title_from_parent&&e.push("parent");a.title_from_current&&e.push("current");e.length&&(b.title_from=e.join(" "));for(e in{flat_output:1,contains_current:1,ol_root:1,
17
+ ol_sub:1})a[e]&&(b[e]=[1]);g={container:"div",container_id:"",container_class:"",menu_class:"menu-widget",widget_class:""};for(e in g)a[e]!==g[e]&&(b[e]=a[e]);g={wrap_link:"before",wrap_link_text:"link_before"};for(e in g)(c=a[g[e]].toString().match(/^<(\w+)/))&&c[1]&&(b[e]=c[1]);g=[];for(e in b)g.push(f.isArray(b[e])?e+"="+b[e][0]:e+'="'+b[e]+'"');n.getDialog(d).find("code").text("[custom_menu_wizard "+g.join(" ")+"]")},show:function(d,a,b){a=a||f(this).closest("form");b=b||n.getSettings(a);d=n.getDialog(a);
18
+ var g=d.find(".cmw-demo-themenu"),c=g.find(".picked"),e="",m="",k=0,h=d.find(".cmw-demo-theoutput-wrap").empty(),p=["menu-widget"],q={};if(c.length&&h.length){0<b.filter&&b.title_from_parent&&(m=g.find(".the-parent").children("a").text()||"");!m&&b.title_from_current&&(m=g.find(".current-menu-item").text()||"");m||b.hide_title||(m=b.title||"");for(c.each(function(a){var c=f(this),d=c.data(),h=d.trace?d.trace.toString().split(","):[];a=d.itemid.toString();var g=1,c=c.children("a");if(!b.flat_output)for(q[a]=
19
+ 1,a=0;a<h.length;a++)q[h[a]]&&g++;if(k)if(g>k)e+=b.ol_sub?"<ol>":"<ul>";else{for(;k>g;)--k,e+="</li>"+(b.ol_sub?"</ol>":"</ul>");e+="</li>"}e+='<li class="cmw-level-'+g+(d.included||"")+'"><a href="#'+c.data("indx")+'">'+c.text()+"</a>";k=g});1<k;)--k,e+="</li>"+(b.ol_sub?"</ol>":"</ul>");e+="</li>";p.push(d.find(".cmw-demo-fallback").data("fellback"));e=(b.ol_root?"<ol":"<ul")+' class="'+f.trim(p.join(" "))+'">'+e+(b.ol_root?"</ol>":"</ul>");h.html(e);m&&h.prepend("<h3>"+m+"</h3>");h.find("li").filter(function(){return!!f(this).children("ul, ol").length}).addClass("cmw-has-submenu")}n.shortcode(a,
20
+ b)},update:function(d){var a=f(this).closest("form"),b=n.getDialog(a),g,c,e,m,k,h,p,q,r,l,s;if(b.length&&b.dialog("isOpen")){f(d.target).hasClass("widget-custom-menu-wizard-selectmenu")&&n.createMenu(b,a);c=n.getSettings(a);e=c.include_parent;m=c.include_parent_siblings;k=b.find(".cmw-demo-themenu");g=k.data().maxLevel;p=k.find(".current-menu-item").closest("li");q=p.length?p.data().level:-1;h=k.find("li").removeData("included").removeClass("the-parent");0>c.filter&&(h=h.filter(function(){var a=f(this).children("input"),
21
+ b=-1<(c._items_sep+c._items+c._items_sep).indexOf(c._items_sep+a[0].value+c._items_sep);a.prop("checked",b);return b}),c._items||(h=f([])));h.length&&!p.length&&(c.contains_current||0<c.filter&&1>c.filter_item)&&(h=f([]));h.length&&0<c.filter&&(0<c.filter_item?l=h.filter("[data-itemid="+c.filter_item+"]"):c.filter_item?1===q&&c.fallback_no_ancestor?(l=p,e=e||c.fallback_include_parent,m=m||c.fallback_include_parent_siblings,r="cmw-fellback-to-current"):l=1===q?k:-1>c.filter_item?k.find(".current-menu-ancestor").eq(0).closest("li"):
22
+ k.find(".current-menu-parent").closest("li"):p.find("li").length?l=p:c.fallback_no_children&&(l=k.find(".current-menu-parent").closest("li"),l.length||(l=k),e=e||c.fallback_nc_include_parent,m=m||c.fallback_nc_include_parent_siblings,r="cmw-fellback-to-parent"));if(h.length)if(c.filter)l&&l.length?(s=c.depth_rel_current&&c.depth&&p.length&&l.has(p[0]).length?q-1+c.depth:c.depth?Math.max((l.data().level||0)+c.depth,c.start_level+c.depth-1):9999,h=l.find("li").filter(function(){var a=f(this).data().level;
23
+ return a>=c.start_level&&a<=s})):0<c.filter&&(h=f([]));else for(s=c.depth_rel_current&&c.depth&&p.length&&q>=c.start_level?q+c.depth-1:c.depth?c.start_level+c.depth-1:9999,q=1;q<=g;q++)if(q<c.start_level||q>s)h=h.not(".level-"+q);h.length&&0<c.filter&&l&&l.is("li")&&(m&&(h=h.add(l.siblings("li").data("included"," cmw-an-included-parent-sibling")),e=!0),c.include_ancestors&&(h=h.add(l.parentsUntil(k,"li").data("included"," cmw-an-included-ancestor")),e=!0),e&&(h=h.add(l.data("included"," cmw-the-included-parent"))));
24
+ !h.length||!c.contains_current||p.length&&h.filter(p).length||(h=f([]));h.length&&l&&l.is("li")&&l.addClass("the-parent");r=h.length?r:"";b.find(".cmw-demo-fallback").data("fellback",r).toggleClass("cmw-demo-fellback",!!r);k.toggleClass("cmw-demo-filteritems",0>c.filter).find(".picked").not(h.addClass("picked")).removeClass("picked");n.show.call(this,d,a,c)}}};f(document).on("click",".widget-custom-menu-wizard-collapsible-fieldset",function(){var d=f(this),a=d.find("input").eq(0),b=!a.prop("checked");
25
+ a.length&&(a.prop("checked",b),d.find("div").toggleClass("cmw-collapsed-fieldset",b),d.next("div")[b?"slideUp":"slideDown"]());this.blur();return!1}).on("change",".widget-custom-menu-wizard-listen",function(){var d=f(this.form),a=d.find(".widget-custom-menu-wizard-selectmenu"),b=d.find(".widget-custom-menu-wizard-showall").prop("checked"),g=d.find(".widget-custom-menu-wizard-showspecific").prop("checked"),d=d.find(".widget-custom-menu-wizard-childrenof"),c=parseInt(d.val(),10),e;a.is(this)&&(a=this.selectedIndex,
26
+ d.find("optgroup").filter(function(){var b=f(this).data("cmwOptgroupIndex")===a;b||f(this).remove();return b}).length||(e=f("#"+d.attr("id")+"_ignore").find("optgroup").eq(a).clone(),e.length&&(0<c&&(c=0,d.val(c)),e.find("option[selected]").removeAttr("selected").prop("selected",!1),d.append(e))));f.each({"":b||g,"-ss":g,"not-rp":b||g||0<=c,"not-ci":b||g||!!c},function(a,b){f(".widget-custom-menu-wizard-disableif"+a,this.form).toggleClass("cmw-colour-grey",b).find("input,select").prop("disabled",
27
+ b)})}).on("change",".widget-custom-menu-wizard-onchange",n.update).on("click",".widget-custom-menu-wizard-toggle-assist",n.init).on("click",".widget-action, .widget-control-close",function(){f(this).closest("div.widget").find(".widget-custom-menu-wizard-onchange").each(function(){var d=f("#"+f(this).data().cmwDialogId);d.length&&d.dialog("isOpen")&&d.dialog("close")})}).on("click",".widget-control-remove",function(d){f(this).closest("div.widget").find(".widget-custom-menu-wizard-onchange").each(function(){var a=
28
+ f("#"+f(this).data().cmwDialogId);a.length&&(a.dialog("destroy"),a.remove())})})});
custom-menu-wizard.php CHANGED
@@ -3,13 +3,19 @@
3
  * Plugin Name: Custom Menu Wizard
4
  * Plugin URI: http://wordpress.org/plugins/custom-menu-wizard/
5
  * Description: Show any part of a custom menu in a Widget, or in content using a Shortcode. Customise the output with extra classes or html; filter by current menu item or a specific item; set a depth, show the parent(s), change the list style, etc. Use the included emulator to assist with the filter settings.
6
- * Version: 2.0.3
7
  * Author: Roger Barrett
8
  * Author URI: http://www.wizzud.com/
9
  * License: GPL2+
10
  */
11
 
12
  /*
 
 
 
 
 
 
13
  * v2.0.3 change log:
14
  * - fixed bug with missing global when enqueuing scripts and styles for admin page
15
  *
@@ -59,7 +65,7 @@
59
  * - moved the setting of 'disabled' attributes on INPUTs/SELECTs from PHP into javascript
60
  */
61
 
62
- $Custom_Menu_Wizard_Widget_Version = '2.0.3';
63
 
64
  /**
65
  * registers the widget and adds the shortcode
@@ -144,7 +150,7 @@ function custom_menu_wizard_update_message($plugin_data, $r){
144
  //show if not empty...
145
  if(!empty($readme)){
146
  ?>
147
- <div style="font-weight:normal;background-color:#fff0c0;border:1px solid #ff9933;border-radius:0.5em;margin:0.5em;">
148
  <div style="margin:0.5em 0.5em 0.5em 1em;max-height:12em;overflow:auto;">
149
  <?php echo $readme; ?>
150
  </div>
@@ -515,6 +521,9 @@ class Custom_Menu_Wizard_Walker extends Walker_Nav_Menu {
515
  //add the submenu class?...
516
  if( $v['kids'] > 0 ){
517
  $elements[ $i ]->classes[] = 'cmw-has-submenu';
 
 
 
518
  }
519
  //add the level class...
520
  $elements[ $i ]->classes[] = 'cmw-level-' . $v['level'];
@@ -700,7 +709,7 @@ class Custom_Menu_Wizard_Walker extends Walker_Nav_Menu {
700
  }
701
  //strings...
702
  foreach( $this->_cmw_strings as $k=>$v ){
703
- $instance[ $k ] = empty( $instance[ $k ] ) ? $v : trim( $instance[ $k ] );
704
  }
705
  //html strings...
706
  foreach( $this->_cmw_html as $k=>$v ){
@@ -1310,6 +1319,8 @@ class Custom_Menu_Wizard_Walker extends Walker_Nav_Menu {
1310
  </p>
1311
  <?php $this->_close_a_field_section(); ?>
1312
 
 
 
1313
  </div>
1314
 
1315
  <?php
@@ -1328,7 +1339,7 @@ class Custom_Menu_Wizard_Walker extends Walker_Nav_Menu {
1328
  <input id="<?php echo $this->get_field_id($fname); ?>" class="hidden-field" name="<?php echo $this->get_field_name($fname); ?>"
1329
  type="checkbox" value="1" <?php checked( $instance[$fname] ); ?> />
1330
  <div style="background-image:url(images/arrows.png);" class="<?php echo $instance[$fname] ? 'cmw-collapsed-fieldset' : ''; ?>"></div>
1331
- <h3><?php _e( $text ); ?></h3>
1332
  </div>
1333
  <div class="<?php echo $instance[$fname] ? 'cmw-start-fieldset-collapsed' : ''; ?>">
1334
  <?php
3
  * Plugin Name: Custom Menu Wizard
4
  * Plugin URI: http://wordpress.org/plugins/custom-menu-wizard/
5
  * Description: Show any part of a custom menu in a Widget, or in content using a Shortcode. Customise the output with extra classes or html; filter by current menu item or a specific item; set a depth, show the parent(s), change the list style, etc. Use the included emulator to assist with the filter settings.
6
+ * Version: 2.0.4
7
  * Author: Roger Barrett
8
  * Author URI: http://www.wizzud.com/
9
  * License: GPL2+
10
  */
11
 
12
  /*
13
+ * v2.0.4 change log:
14
+ * - fixed bug where clearing the container field failed to remove the container from the output
15
+ * - remove WordPress's menu-item-has-children class (WP v3.7+) when the filtered item no longer has children
16
+ * - added automatic selection of the shortcode text when it is clicked
17
+ * - tweaked admin styling and javascript for WordPress v3.8
18
+ *
19
  * v2.0.3 change log:
20
  * - fixed bug with missing global when enqueuing scripts and styles for admin page
21
  *
65
  * - moved the setting of 'disabled' attributes on INPUTs/SELECTs from PHP into javascript
66
  */
67
 
68
+ $Custom_Menu_Wizard_Widget_Version = '2.0.4';
69
 
70
  /**
71
  * registers the widget and adds the shortcode
150
  //show if not empty...
151
  if(!empty($readme)){
152
  ?>
153
+ <div style="font-weight:normal;background-color:#fff0c0;border:1px solid #d54e21;border-radius:0.5em;margin:0.1em 0;">
154
  <div style="margin:0.5em 0.5em 0.5em 1em;max-height:12em;overflow:auto;">
155
  <?php echo $readme; ?>
156
  </div>
521
  //add the submenu class?...
522
  if( $v['kids'] > 0 ){
523
  $elements[ $i ]->classes[] = 'cmw-has-submenu';
524
+ }else{
525
+ //3.7 adds a menu-item-has-children class to (original) menu items that have kids : remove it as the item is now childless...
526
+ $elements[ $i ]->classes = array_diff( $elements[ $i ]->classes, array('menu-item-has-children') );
527
  }
528
  //add the level class...
529
  $elements[ $i ]->classes[] = 'cmw-level-' . $v['level'];
709
  }
710
  //strings...
711
  foreach( $this->_cmw_strings as $k=>$v ){
712
+ $instance[ $k ] = isset( $instance[ $k ] ) ? trim( $instance[ $k ] ) : $v; //bug in 2.0.2 fixed!
713
  }
714
  //html strings...
715
  foreach( $this->_cmw_html as $k=>$v ){
1319
  </p>
1320
  <?php $this->_close_a_field_section(); ?>
1321
 
1322
+ <script type="text/javascript">jQuery(function($){$('#<?php echo $this->get_field_id('menu'); ?>').trigger('change');})</script>
1323
+
1324
  </div>
1325
 
1326
  <?php
1339
  <input id="<?php echo $this->get_field_id($fname); ?>" class="hidden-field" name="<?php echo $this->get_field_name($fname); ?>"
1340
  type="checkbox" value="1" <?php checked( $instance[$fname] ); ?> />
1341
  <div style="background-image:url(images/arrows.png);" class="<?php echo $instance[$fname] ? 'cmw-collapsed-fieldset' : ''; ?>"></div>
1342
+ <h4><?php _e( $text ); ?></h4>
1343
  </div>
1344
  <div class="<?php echo $instance[$fname] ? 'cmw-start-fieldset-collapsed' : ''; ?>">
1345
  <?php
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: wizzud
3
  Tags: menu,widget,widgets,navigation,nav,custom menus,custom menu,partial menu,menu level,menu branch
4
  Requires at least: 3.0.1
5
- Tested up to: 3.7.1
6
- Stable tag: 2.0.3
7
  License: GPLv2 or Later
8
 
9
  Show branches or levels of your menu in a widget, or in content using a shortcode, with full customisation.
@@ -489,6 +489,16 @@ It was a close call, but since the Output options can extend the final list - an
489
 
490
  == Changelog ==
491
 
 
 
 
 
 
 
 
 
 
 
492
  = 2.0.3 =
493
 
494
  * bugfix : missing global when enqueuing scripts and styles for admin
@@ -579,6 +589,11 @@ Initial release
579
 
580
  == Upgrade Notice ==
581
 
 
 
 
 
 
582
  = 2.0.3 =
583
 
584
  Fixed a minor bug with a missing global when enqueuing script and style for the admin.
2
  Contributors: wizzud
3
  Tags: menu,widget,widgets,navigation,nav,custom menus,custom menu,partial menu,menu level,menu branch
4
  Requires at least: 3.0.1
5
+ Tested up to: 3.8
6
+ Stable tag: 2.0.4
7
  License: GPLv2 or Later
8
 
9
  Show branches or levels of your menu in a widget, or in content using a shortcode, with full customisation.
489
 
490
  == Changelog ==
491
 
492
+ = 2.0.4 =
493
+
494
+ * bugfix : clearing the container field failed to remove the container from the output
495
+
496
+ * addition : in the "assist", added automatic selection of the shortcode text when it is clicked
497
+
498
+ * addition : remove WordPress's menu-item-has-children class (introduced in v3.7) when the filtered item no longer has children
499
+
500
+ * change : tweaked styles and javascript in admin for WordPress v3.8
501
+
502
  = 2.0.3 =
503
 
504
  * bugfix : missing global when enqueuing scripts and styles for admin
589
 
590
  == Upgrade Notice ==
591
 
592
+ = 2.0.4 =
593
+
594
+ Fixed a bug that prevented the container field being removed, and added removal of the menu-item-has-children class when the filtered item no longer has children.
595
+ The admin widget styling and javascript have been tweaked to accommodate WordPress 3.8.
596
+
597
  = 2.0.3 =
598
 
599
  Fixed a minor bug with a missing global when enqueuing script and style for the admin.