UNPKG

hellojs-xiaotian

Version:

A clientside Javascript library for standardizing requests to OAuth2 web services (and OAuth1 - with a shim)

20 lines (19 loc) 894 B
ko.bindingHandlers['submit'] = { 'init': function (element, valueAccessor, allBindings, viewModel, bindingContext) { if (typeof valueAccessor() != "function") throw new Error("The value for a submit binding must be a function"); ko.utils.registerEventHandler(element, "submit", function (event) { var handlerReturnValue; var value = valueAccessor(); try { handlerReturnValue = value.call(bindingContext['$data'], element); } finally { if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true. if (event.preventDefault) event.preventDefault(); else event.returnValue = false; } } }); } };