Created
July 31, 2015 08:05
-
-
Save mlippens/2898383e50b3cc0bca8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* iCheck integration bindingHandler | |
* | |
* This handler will initialise checkboxes and update them accordingly in both ways | |
* | |
*/ | |
ko.bindingHandlers.iCheck = { | |
/** | |
* We set an event listener: if a checkbox is changed, we update the observable accordingly. | |
* @param el | |
* @param valueAccessor | |
*/ | |
init: (el, valueAccessor: Function) => { | |
var observable = valueAccessor(); | |
$(el).on("ifChanged", function() { | |
observable(this.checked); | |
}); | |
}, | |
/** | |
* If the observable is changed, we update the checkbox UI accordingly. | |
* @param el | |
* @param valueAccessor | |
*/ | |
update: (el, valueAccessor) => { | |
var val : boolean = ko.utils.unwrapObservable(valueAccessor()); | |
if (val) { | |
$(el).iCheck('check'); | |
} else { | |
$(el).iCheck('uncheck'); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment