Skip to content

Commit

Permalink
"linked" hover for resizing handles dealing with the same variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bago committed May 25, 2022
1 parent b555634 commit 6d0bb60
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/css/style_mosaico_content.less
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
.ui-resizable-handle {
display: none !important;
}
&:hover .ui-resizable-handle {
&:hover .ui-resizable-handle,
.resizing-hover .ui-resizable-handle, {
display: block !important;
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/js/bindings/syncedhoverclass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
/* globals global:false */

var ko = require("knockout");

/**
* wants a "ref" observable, that will be instrumented with an additional observable shared by other bindings pointing to the same observable
* wants also a "class" that will be set when the element is hovered (that will also be set when any of the other element with the same ref will be hovered)
*/
ko.bindingHandlers['syncedhoverclass'] = {
init: function(element, valueAccessor) {
if (typeof valueAccessor().ref.syncedHoverObservable == 'undefined') valueAccessor().ref.syncedHoverObservable = ko.observable(false);

var syncedHoverObservable = valueAccessor().ref.syncedHoverObservable;
var className = valueAccessor().class;

ko.applyBindingsToNode(element, {
event: {
mouseenter: function () { syncedHoverObservable(true); },
mouseleave: function () { syncedHoverObservable(false); }
}
});

var subscriber = syncedHoverObservable.subscribe(function(hover) {
ko.utils.toggleDomNodeCssClass(element, className, hover);
});

ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
subscriber.dispose();
});

},
};
2 changes: 1 addition & 1 deletion src/js/converter/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var processBlock = function(element, defs, themeUpdater, blockPusher, templateUr
if (typeof defs[bindingValue] !== 'undefined' && typeof defs[bindingValue]._min !== 'undefined') resizableOptions += ', minHeight: '+defs[bindingValue]._min;
if (typeof defs[bindingValue] !== 'undefined' && typeof defs[bindingValue]._max !== 'undefined') resizableOptions += ', maxHeight: '+defs[bindingValue]._max;

var resizingBinding = "extresizable: { data: " + bindingValue + ", options: { handles: 's'" + resizableOptions + ", resizing: $root.resizing } }, attr: { 'data-size': ko.utils.unwrapObservable(" + bindingValue + ")+'px' } ";
var resizingBinding = "syncedhoverclass: { ref: " + bindingValue + ", class: 'resizing-hover' }, extresizable: { data: " + bindingValue + ", options: { handles: 's'" + resizableOptions + ", resizing: $root.resizing } }, attr: { 'data-size': ko.utils.unwrapObservable(" + bindingValue + ")+'px' } ";

var resizingDiv = $('<div class="ui-resizing-div" data-ko-wrap="false" style="width: 100%; height: 100%"></div>')[0];
domutils.setAttribute(resizingDiv, 'data-bind', resizingBinding);
Expand Down
3 changes: 2 additions & 1 deletion src/js/ko-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ require("./bindings/eventable.js");
require("./bindings/tooltips.js");
require("./bindings/extender-pagination.js");
require("./bindings/validated-value.js");
require("./bindings/scrollintoview.js");
require("./bindings/scrollintoview.js");
require("./bindings/syncedhoverclass.js");

0 comments on commit 6d0bb60

Please sign in to comment.