Demonstrates that, even with v3.x, it appears that multiple bindings on an element will cause all of those bindings's update method to fire whenever any of the bound values gets updated.
///<summary>Similar to slideVisible, but delays the slideUp() after the value turns to false to
/// allow the user to see something before the item disapears. Useful for things like a status
/// message which turns to "process complete" and then delays the slideUp() for a second or two so that
/// the user sees the "process complete" message.</summary>
ko.bindingHandlers.slideVisibleDelayedHide = {
init: function (element, valueAccessor) {
},
update: function (element, valueAccessor, allBindingsAccessor) {
// First get the latest data that we're bound to
var newValue = ko.utils.unwrapObservable(valueAccessor()), allBindings = allBindingsAccessor();
console.log("slideVisibleDelayedHide 'update' called, with new value: " + newValue);
// Grab some more data from other binding properties
var duration = allBindings.slideDuration || 400; // 400ms is default duration unless otherwise specified
var hideDelay = allBindings.slideHideDelay || 2000;
// Workaround for Knockout 2.x issue of firing ALL binding on the same element when ANY of their
// bound values change: Only do these actions if the bound value is actually different than it
// was last time (in other words, only act when it logically makes sense that the bindings 'update'
// should be called).
var valueHasChanged = element.ko_slideVisibleDelayedHide_currentValue != newValue;
if (valueHasChanged) {
// Now manipulate the DOM element
if (newValue == true) {
// Cancel a scheduled hide action since the value has been toggled to true again
// (the scheduled hide would negate this show action after a short delay)
if (typeof element.ko_slideVisibleDelayedHide_timeoutId !== 'undefined')
clearTimeout(element.ko_slideVisibleDelayedHide_timeoutId);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.