chap3 -> Custom bindings -> The toggle binding
parent
5f833290b6
commit
7c1c4ee8f1
|
@ -27,6 +27,7 @@
|
||||||
<script type="text/javascript" src="js/vendors/bootstrap.js"></script>
|
<script type="text/javascript" src="js/vendors/bootstrap.js"></script>
|
||||||
<script type="text/javascript" src="js/vendors/knockout-3.2.0.js"></script>
|
<script type="text/javascript" src="js/vendors/knockout-3.2.0.js"></script>
|
||||||
<script type="text/javascript" src="js/vendors/koExternalTemplateEngine_all.js"></script>
|
<script type="text/javascript" src="js/vendors/koExternalTemplateEngine_all.js"></script>
|
||||||
|
<script type="text/javascript" src="js/custom/koBindings.js"></script>
|
||||||
<!-- app -->
|
<!-- app -->
|
||||||
<script type="text/javascript" src="js/models/Product.js"></script>
|
<script type="text/javascript" src="js/models/Product.js"></script>
|
||||||
<script type="text/javascript" src="js/models/CartProduct.js"></script>
|
<script type="text/javascript" src="js/models/CartProduct.js"></script>
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
ko.bindingHandlers.toggle = {
|
||||||
|
init: function (element, valueAccessor) {
|
||||||
|
var value = valueAccessor();
|
||||||
|
ko.applyBindingsToNode(element, {
|
||||||
|
click: function() {
|
||||||
|
value(!value());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -9,7 +9,7 @@
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="btn btn-primary btn-sm"
|
class="btn btn-primary btn-sm"
|
||||||
data-bind="click: showCartDetails, css:{ disabled: cart().length < 1}"
|
data-bind="toggle:visibleCart, css:{ disabled: cart().length < 1}"
|
||||||
>
|
>
|
||||||
Show Cart Details
|
Show Cart Details
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in New Issue