mirror of
https://github.com/Febbweiss/filebrowser-durandal-widget.git
synced 2026-03-05 14:45:43 +00:00
init
This commit is contained in:
19
lib/knockout/src/binding/defaultBindings/submit.js
Normal file
19
lib/knockout/src/binding/defaultBindings/submit.js
Normal file
@@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user