-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"linked" hover for resizing handles dealing with the same variable
- Loading branch information
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters