Skip to content

Instantly share code, notes, and snippets.

@MacDada
Last active December 11, 2015 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MacDada/4635367 to your computer and use it in GitHub Desktop.
Save MacDada/4635367 to your computer and use it in GitHub Desktop.
ko.bindingHandlers.canvasContext = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
if ("undefined" === typeof viewModel.__canvasContexts__) {
viewModel.__canvasContexts__ = [];
}
// works now :)
if ("function" !== typeof element.getContext && FlashCanvas) {
FlashCanvas.initElement(element);
}
// sharing canvas context with VM – useful when debugging
viewModel.__canvasContexts__.push(element.getContext("2d"));
},
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
var callback = ko.utils.unwrapObservable(valueAccessor());
callback.call(viewModel, element.getContext("2d"));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment