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
ko.extenders.cache1 = function (target) { | |
target.cached = ko.observable(target.peek()); | |
target.cache = function () { | |
target.cached(target()); | |
}; | |
return target; | |
}; | |
var x = ko.observable(1).extend({ cache1: {} }); | |
x(2); |
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
ko.extenders.coalesce = function (target, defaultValue) { | |
var result = ko.computed({ | |
read: function () { | |
return target() === undefined ? ko.unwrap(defaultValue) : target(); | |
}, | |
write: function (value) { | |
target(value); | |
} | |
}); | |
result.defaultValue = ko.computed(function () { |
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
ko.extenders.filter = function (target, pattern) { | |
var result = ko.computed({ | |
read: target, | |
write: function (value) { | |
if (typeof value !== "string") { | |
target(value); | |
return; | |
} | |
var current = target(); | |
var filtered = value.replace(pattern, ""); |
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
function log(value) { | |
console.log(typeof value + ": " + value); | |
} | |
ko.extenders.numeric1 = function (target) { | |
return ko.computed({ | |
read: target, | |
write: function (value) { | |
var number = parseFloat(value); | |
target(isNaN(number) ? value : number); |
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
ko.extenders.observe = function (target, source) { | |
target(source); | |
var result = ko.computed({ | |
read: function () { | |
return target()(); | |
}, | |
write: function (value) { | |
target()(value); | |
} | |
}); |
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
<script type="text/javascript"> | |
ko.bindingHandlers.slide = { | |
enabled: true, | |
queue: "ko.bindingHandlers.slide", | |
init: function (element, valueAccessor) { | |
var visible = Boolean(ko.unwrap(valueAccessor())); | |
$(element).toggle(visible); | |
}, | |
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
<script type="text/javascript"> | |
ko.bindingHandlers.sortable = { | |
normalize: function (valueAccessor) { | |
var value = ko.unwrap(valueAccessor()); | |
if (typeof value === "object" && "data" in value) { | |
return value; | |
} else { | |
return { data: valueAccessor() }; | |
} | |
}, |
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
<script type="text/javascript"> | |
ko.bindingHandlers.tooltip = { | |
normalize: function (valueAccessor) { | |
var value = ko.unwrap(valueAccessor()); | |
if (typeof value === "object" && "data" in value) { | |
return value; | |
} else { | |
return { data: value }; | |
} | |
}, |
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
<script type="text/javascript"> | |
ko.bindingHandlers.validationPopover = { | |
init: function (element, valueAccessor, allBindings) { | |
if (!allBindings.has("value")) { | |
return; | |
} | |
var $element = $(element); | |
var value = allBindings.get("value"); | |
$element.popover($.extend({}, ko.unwrap(valueAccessor()), { | |
content: function () { |
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
$.widget("scw.toggler", { | |
options: { | |
active: true, | |
animated: true, | |
duration: "_default", | |
cssClass: "toggler-active" | |
}, | |
_finish: function () { | |
while (this.element.queue().length > 0) { |