Skip to content

Instantly share code, notes, and snippets.

@anthonyvscode
Last active November 18, 2015 05:07
Show Gist options
  • Save anthonyvscode/b92896fe1c3474ea6f6f to your computer and use it in GitHub Desktop.
Save anthonyvscode/b92896fe1c3474ea6f6f to your computer and use it in GitHub Desktop.
KnockoutJS autosize.js (http://www.jacklmoore.com/autosize/) custom binding handler
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(["knockout", "autosize"], factory);
} else {
// Browser globals
factory(ko, autosize);
}
}(this, function (ko, autosize) {
ko.bindingHandlers.autosize = {
init: function (element, valueAccessor) {
var enabled = ko.unwrap(valueAccessor());
if (enabled === true) {
autosize(element);
}
}
}
}));
@anthonyvscode
Copy link
Author

Usage:

<textarea data-bind="autosize: true"></textarea>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment