From b7ebc0bdba83e75e98f4b2569eb918837fce6c13 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 26 Nov 2024 16:04:50 +0000 Subject: [PATCH 1/4] only show actionMenuBtn if there are items in it --- .../cp/src/js/SortableCheckboxSelect.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/web/assets/cp/src/js/SortableCheckboxSelect.js b/src/web/assets/cp/src/js/SortableCheckboxSelect.js index 9d051972803..f9db35d3cf6 100644 --- a/src/web/assets/cp/src/js/SortableCheckboxSelect.js +++ b/src/web/assets/cp/src/js/SortableCheckboxSelect.js @@ -123,10 +123,26 @@ Craft.SortableCheckboxSelect.Item = Garnish.Base.extend({ } }); + const allCheckedSiblings = this.getAllCheckedSiblings(); + // if there are no other checked siblings, hide current item's action menu btn + if (allCheckedSiblings.length == 0) { + this.$actionMenuBtn.hide(); + } else if (allCheckedSiblings.length == 1) { + // if there's only one other checked sibling, + // we need to show that sibling's action menu btn as it would have been hidden so far + $(allCheckedSiblings[0]).find('.btn.action-btn').show(); + } + this.$item.trigger('checked'); }, onUncheck: function () { + const allCheckedSiblings = this.getAllCheckedSiblings(); + // if there's only one other checked sibling, hide that sibling's action menu btn + if (allCheckedSiblings.length == 1) { + $(allCheckedSiblings[0]).find('.btn.action-btn').hide(); + } + this.$moveHandle?.addClass('disabled'); this.$actionMenuBtn?.remove(); this.$actionMenu?.remove(); @@ -149,6 +165,12 @@ Craft.SortableCheckboxSelect.Item = Garnish.Base.extend({ return $item.length ? $item : null; }, + getAllCheckedSiblings: function() { + return $item = this.$item.siblings( + '.checkbox-select-item:not(.all):has(input[type=checkbox]:checked)' + ); + }, + moveUp: function () { const $prev = this.getPrevCheckedItem(); if ($prev) { From 026d5fc955d21af194df527c3f78a0d7a39d58c4 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 26 Nov 2024 16:09:04 +0000 Subject: [PATCH 2/4] tweak --- src/web/assets/cp/src/js/SortableCheckboxSelect.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/web/assets/cp/src/js/SortableCheckboxSelect.js b/src/web/assets/cp/src/js/SortableCheckboxSelect.js index f9db35d3cf6..a3dd1a5c021 100644 --- a/src/web/assets/cp/src/js/SortableCheckboxSelect.js +++ b/src/web/assets/cp/src/js/SortableCheckboxSelect.js @@ -165,8 +165,8 @@ Craft.SortableCheckboxSelect.Item = Garnish.Base.extend({ return $item.length ? $item : null; }, - getAllCheckedSiblings: function() { - return $item = this.$item.siblings( + getAllCheckedSiblings: function () { + return this.$item.siblings( '.checkbox-select-item:not(.all):has(input[type=checkbox]:checked)' ); }, From 4fb91ca8f50e6f487d252727555fc124284e2b4a Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 26 Nov 2024 16:09:10 +0000 Subject: [PATCH 3/4] build --- src/web/assets/cp/dist/cp.js | 2 +- src/web/assets/cp/dist/cp.js.map | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/web/assets/cp/dist/cp.js b/src/web/assets/cp/dist/cp.js index dc68b77953f..a98b26dbe63 100644 --- a/src/web/assets/cp/dist/cp.js +++ b/src/web/assets/cp/dist/cp.js @@ -1,3 +1,3 @@ /*! For license information please see cp.js.LICENSE.txt */ -(function(){var __webpack_modules__={463:function(){Craft.Accordion=Garnish.Base.extend({$trigger:null,targetSelector:null,_$target:null,init:function(t){var e=this;this.$trigger=$(t),this.$trigger.data("accordion")&&(console.warn("Double-instantiating an accordion trigger on an element"),this.$trigger.data("accordion").destroy()),this.$trigger.data("accordion",this),this.targetSelector=this.$trigger.attr("aria-controls")?"#".concat(this.$trigger.attr("aria-controls")):null,this.targetSelector&&(this._$target=$(this.targetSelector)),this.addListener(this.$trigger,"click","onTriggerClick"),this.addListener(this.$trigger,"keypress",(function(t){var n=t.keyCode;n!==Garnish.SPACE_KEY&&n!==Garnish.RETURN_KEY||(t.preventDefault(),e.onTriggerClick())}))},onTriggerClick:function(){"true"===this.$trigger.attr("aria-expanded")?this.hideTarget(this._$target):this.showTarget(this._$target)},showTarget:function(t){var e=this;if(t&&t.length){this.showTarget._currentHeight=t.height(),t.removeClass("hidden"),this.$trigger.removeClass("collapsed").addClass("expanded").attr("aria-expanded","true");for(var n=0;n=this.settings.maxItems)){var e=$(t).appendTo(this.$tbody),n=e.find(".delete");this.settings.sortable&&this.sorter.addItems(e),this.$deleteBtns=this.$deleteBtns.add(n),this.addListener(n,"click","handleDeleteBtnClick"),this.totalItems++,this.updateUI()}},reorderItems:function(){var t=this;if(this.settings.sortable){for(var e=[],n=0;n=this.settings.maxItems?$(this.settings.newItemBtnSelector).addClass("hidden"):$(this.settings.newItemBtnSelector).removeClass("hidden"))}},{defaults:{tableSelector:null,noItemsSelector:null,newItemBtnSelector:null,idAttribute:"data-id",nameAttribute:"data-name",sortable:!1,allowDeleteAll:!0,minItems:0,maxItems:null,reorderAction:null,deleteAction:null,reorderSuccessMessage:Craft.t("app","New order saved."),reorderFailMessage:Craft.t("app","Couldn’t save new order."),confirmDeleteMessage:Craft.t("app","Are you sure you want to delete “{name}”?"),deleteSuccessMessage:Craft.t("app","“{name}” deleted."),deleteFailMessage:Craft.t("app","Couldn’t delete “{name}”."),onReorderItems:$.noop,onDeleteItem:$.noop}})},6872:function(){Craft.AssetImageEditor=Garnish.Modal.extend({$body:null,$footer:null,$imageTools:null,$buttons:null,$cancelBtn:null,$replaceBtn:null,$saveBtn:null,$focalPointBtn:null,$editorContainer:null,$straighten:null,$croppingCanvas:null,$spinner:null,$constraintContainer:null,$constraintRadioInputs:null,$customConstraints:null,canvas:null,image:null,viewport:null,focalPoint:null,focalPointInnerCircle:null,focalPointOuterCircle:null,focalPointPickedIndicator:null,grid:null,croppingCanvas:null,clipper:null,croppingRectangle:null,cropperHandles:null,cropperGrid:null,croppingShade:null,imageStraightenAngle:0,viewportRotation:0,originalWidth:0,originalHeight:0,imageVerticeCoords:null,zoomRatio:1,animationInProgress:!1,currentView:"",assetId:null,cacheBust:null,draggingCropper:!1,scalingCropper:!1,handleClicked:!1,draggingFocal:!1,focalPickedUp:!1,focalClicked:!1,cropperClicked:!1,previousMouseX:0,previousMouseY:0,shiftKeyHeld:!1,editorHeight:0,editorWidth:0,cropperState:!1,scaleFactor:1,flipData:{},focalPointState:!1,maxImageSize:null,lastLoadedDimensions:null,imageIsLoading:!1,mouseMoveEvent:null,croppingConstraint:!1,constraintOrientation:"landscape",showingCustomConstraint:!1,saving:!1,renderImage:null,renderCropper:null,_queue:null,init:function(t,e){var n=this;this._queue=new Craft.Queue,this.cacheBust=Date.now(),this.setSettings(e,Craft.AssetImageEditor.defaults),null===this.settings.allowDegreeFractions&&(this.settings.allowDegreeFractions=Craft.isImagick),Garnish.prefersReducedMotion()&&(this.settings.animationDuration=1),this.assetId=t,this.flipData={x:0,y:0},this.$container=$('').appendTo(Garnish.$bod),this.$body=$('
').appendTo(this.$container),this.$footer=$('