From c4350810506d1a4e8b6b413025ba1ae7329855a1 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 31 Oct 2016 10:36:18 -0400 Subject: [PATCH] Add JS events for supporting pw-button-dropdown enabled and disabled states per processwire/processwire-issues#62 --- wire/modules/Inputfield/InputfieldSubmit/dropdown.js | 12 +++++++++++- .../Inputfield/InputfieldSubmit/dropdown.min.js | 2 +- .../Process/ProcessPageEdit/ProcessPageEdit.js | 10 ++++++++++ .../Process/ProcessPageEdit/ProcessPageEdit.min.js | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldSubmit/dropdown.js b/wire/modules/Inputfield/InputfieldSubmit/dropdown.js index 450cf82a..e7a7877a 100644 --- a/wire/modules/Inputfield/InputfieldSubmit/dropdown.js +++ b/wire/modules/Inputfield/InputfieldSubmit/dropdown.js @@ -107,7 +107,7 @@ var InputfieldSubmitDropdown = { } $a.click(InputfieldSubmitDropdown.click); }); - + /* // add first item to be same as default button action var $li = $('
  • '); @@ -133,6 +133,16 @@ var InputfieldSubmitDropdown = { $toggleButton.click(function() { return false; + }).on('pw-button-dropdown-off', function() { + $(this).siblings('.pw-button-dropdown-main') + .removeClass('pw-button-dropdown-main') + .addClass('pw-button-dropdown-disabled'); + $(this).hide(); + }).on('pw-button-dropdown-on', function() { + $(this).siblings('.pw-button-dropdown-disabled') + .addClass('pw-button-dropdown-main') + .removeClass('pw-button-dropdown-disabled') + $(this).show(); }); }, diff --git a/wire/modules/Inputfield/InputfieldSubmit/dropdown.min.js b/wire/modules/Inputfield/InputfieldSubmit/dropdown.min.js index f9fa9ca6..8db6143d 100644 --- a/wire/modules/Inputfield/InputfieldSubmit/dropdown.min.js +++ b/wire/modules/Inputfield/InputfieldSubmit/dropdown.min.js @@ -1 +1 @@ -var InputfieldSubmitDropdown={click:function(){var e=$(this);var b=e.attr("href");var f=e.closest(".pw-button-dropdown");var d;if(!f.length){return true}d=f.data("button");if(e.hasClass("pw-button-dropdown-default")){}else{var c=e.attr("data-dropdown-value");var a=f.attr("data-dropdown-input");if(!c){return true}if(a){var g=$(a);if(!g.length){return true}g.val(c)}else{if(b.length>1){return true}}if(d){d.attr("value",c)}}if(!d){return true}$(":input:focus").blur();d.click();return false},dropdownCnt:0,initDropdown:function(e,d){var c=$("").attr("id","pw-dropdown-toggle-"+d.attr("id"));d.after(c);c.button();var h=null;if(e.hasClass("pw-button-dropdown-template")){h=e;e=h.clone();h.hide()}InputfieldSubmitDropdown.dropdownCnt++;var g="pw-button-dropdown-"+InputfieldSubmitDropdown.dropdownCnt;e.addClass("dropdown-menu pw-dropdown-menu shortcuts pw-button-dropdown-init "+g);e.data("button",d);var a=d.find(".ui-button-text");var b=$.trim(a.text());var f=a.html();e.find("a").each(function(){var j=$(this);if(h){var i=j.html();if(i.indexOf("%s")>-1){j.html(i.replace("%s",b))}}j.click(InputfieldSubmitDropdown.click)});d.addClass("pw-button-dropdown-main");c.after(e).addClass("dropdown-toggle dropdown-toggle-click pw-dropdown-toggle pw-button-dropdown-toggle").attr("data-dropdown","."+g);if(d.hasClass("ui-priority-secondary")){c.addClass("ui-priority-secondary")}if(d.hasClass("head_button_clone")){c.addClass("head_button_clone")}c.click(function(){return false})},init:function(b,c){if($("body").hasClass("touch-device")||$("body").hasClass("modal")){$("ul.pw-button-dropdown").hide();return false}var a=(typeof b=="string")?$(b):b;a.each(function(){var d=$(this);if(typeof c!="undefined"){c.addClass("pw-button-dropdown-template");InputfieldSubmitDropdown.initDropdown(c,d)}else{var e=$("#"+$(this).prop("id")+"_dropdown");if(e.length){InputfieldSubmitDropdown.initDropdown(e,d)}}});return true}}; \ No newline at end of file +var InputfieldSubmitDropdown={click:function(){var e=$(this);var b=e.attr("href");var f=e.closest(".pw-button-dropdown");var d;if(!f.length){return true}d=f.data("button");if(e.hasClass("pw-button-dropdown-default")){}else{var c=e.attr("data-dropdown-value");var a=f.attr("data-dropdown-input");if(!c){return true}if(a){var g=$(a);if(!g.length){return true}g.val(c)}else{if(b.length>1){return true}}if(d){d.attr("value",c)}}if(!d){return true}$(":input:focus").blur();d.click();return false},dropdownCnt:0,initDropdown:function(e,d){var c=$("").attr("id","pw-dropdown-toggle-"+d.attr("id"));d.after(c);c.button();var h=null;if(e.hasClass("pw-button-dropdown-template")){h=e;e=h.clone();h.hide()}InputfieldSubmitDropdown.dropdownCnt++;var g="pw-button-dropdown-"+InputfieldSubmitDropdown.dropdownCnt;e.addClass("dropdown-menu pw-dropdown-menu shortcuts pw-button-dropdown-init "+g);e.data("button",d);var a=d.find(".ui-button-text");var b=$.trim(a.text());var f=a.html();e.find("a").each(function(){var j=$(this);if(h){var i=j.html();if(i.indexOf("%s")>-1){j.html(i.replace("%s",b))}}j.click(InputfieldSubmitDropdown.click)});d.addClass("pw-button-dropdown-main");c.after(e).addClass("dropdown-toggle dropdown-toggle-click pw-dropdown-toggle pw-button-dropdown-toggle").attr("data-dropdown","."+g);if(d.hasClass("ui-priority-secondary")){c.addClass("ui-priority-secondary")}if(d.hasClass("head_button_clone")){c.addClass("head_button_clone")}c.click(function(){return false}).on("pw-button-dropdown-off",function(){$(this).siblings(".pw-button-dropdown-main").removeClass("pw-button-dropdown-main").addClass("pw-button-dropdown-disabled");$(this).hide()}).on("pw-button-dropdown-on",function(){$(this).siblings(".pw-button-dropdown-disabled").addClass("pw-button-dropdown-main").removeClass("pw-button-dropdown-disabled");$(this).show()})},init:function(b,c){if($("body").hasClass("touch-device")||$("body").hasClass("modal")){$("ul.pw-button-dropdown").hide();return false}var a=(typeof b=="string")?$(b):b;a.each(function(){var d=$(this);if(typeof c!="undefined"){c.addClass("pw-button-dropdown-template");InputfieldSubmitDropdown.initDropdown(c,d)}else{var e=$("#"+$(this).prop("id")+"_dropdown");if(e.length){InputfieldSubmitDropdown.initDropdown(e,d)}}});return true}}; \ No newline at end of file diff --git a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.js b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.js index 1e04725f..0ce752e8 100644 --- a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.js +++ b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.js @@ -55,4 +55,14 @@ function initPageEditForm() { $viewMenu.find(".page-view-action-" + action + " > a").click(); return false; }); + + var $template = $('#template'); + var templateID = $template.val(); + $template.on('change', function() { + if($(this).val() == templateID) { + $('.pw-button-dropdown-toggle').trigger('pw-button-dropdown-on'); + } else { + $('.pw-button-dropdown-toggle').trigger('pw-button-dropdown-off'); + } + }); } diff --git a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.min.js b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.min.js index af2ce3cb..007bfdeb 100644 --- a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.min.js +++ b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.min.js @@ -1 +1 @@ -function initPageEditForm(){$("#ProcessPageEdit:not(.ProcessPageEditSingleField)").WireTabs({items:$("#ProcessPageEdit > .Inputfields > .InputfieldWrapper"),id:"PageEditTabs",skipRememberTabIDs:["ProcessPageEditDelete"]});$("#submit_delete").click(function(){if(!$("#delete_page").is(":checked")){$("#wrap_delete_page label").effect("highlight",{},500);return}$(this).before("");$("#ProcessPageEdit").submit()});$(document).on("click","#AddPageBtn",function(){return false}).on("click","button[type=submit]",function(f){if($("body").hasClass("pw-uploading")){return confirm($("#ProcessPageEdit").attr("data-uploading"))}});if(typeof InputfieldSubmitDropdown!="undefined"){var d=$("ul.pw-button-dropdown:not(.pw-button-dropdown-init)");$("button[type=submit]").each(function(){var f=$(this);var e=f.attr("name");if(e.indexOf("submit")==-1){return}if(e.indexOf("_save")==-1&&e.indexOf("_publish")==-1){return}InputfieldSubmitDropdown.init(f,d)})}var c=$("#_ProcessPageEditView");var b=$("#_ProcessPageEditViewDropdown");var a=c.css("color");$("#_ProcessPageEditViewDropdownToggle").css("color",a);c.click(function(){var e=c.attr("data-action");if(e=="this"||e=="new"||!e.length){return true}b.find(".page-view-action-"+e+" > a").click();return false})}; \ No newline at end of file +function initPageEditForm(){$("#ProcessPageEdit:not(.ProcessPageEditSingleField)").WireTabs({items:$("#ProcessPageEdit > .Inputfields > .InputfieldWrapper"),id:"PageEditTabs",skipRememberTabIDs:["ProcessPageEditDelete"]});$("#submit_delete").click(function(){if(!$("#delete_page").is(":checked")){$("#wrap_delete_page label").effect("highlight",{},500);return}$(this).before("");$("#ProcessPageEdit").submit()});$(document).on("click","#AddPageBtn",function(){return false}).on("click","button[type=submit]",function(g){if($("body").hasClass("pw-uploading")){return confirm($("#ProcessPageEdit").attr("data-uploading"))}});if(typeof InputfieldSubmitDropdown!="undefined"){var f=$("ul.pw-button-dropdown:not(.pw-button-dropdown-init)");$("button[type=submit]").each(function(){var h=$(this);var g=h.attr("name");if(g.indexOf("submit")==-1){return}if(g.indexOf("_save")==-1&&g.indexOf("_publish")==-1){return}InputfieldSubmitDropdown.init(h,f)})}var e=$("#_ProcessPageEditView");var b=$("#_ProcessPageEditViewDropdown");var a=e.css("color");$("#_ProcessPageEditViewDropdownToggle").css("color",a);e.click(function(){var g=e.attr("data-action");if(g=="this"||g=="new"||!g.length){return true}b.find(".page-view-action-"+g+" > a").click();return false});var d=$("#template");var c=d.val();d.on("change",function(){if($(this).val()==c){$(".pw-button-dropdown-toggle").trigger("pw-button-dropdown-on")}else{$(".pw-button-dropdown-toggle").trigger("pw-button-dropdown-off")}})}; \ No newline at end of file