Skip to content

Commit

Permalink
Added support of custom event names for modal binding (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
faulknercs committed Jul 11, 2017
1 parent 2265a78 commit f8d6c14
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/bindings/modalBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
role: 'dialog'
},

events: {
shown: 'shown.bs.modal',
hidden: 'hidden.bs.modal'
},

headerTemplate: {
name: 'modalHeader',
templateEngine: ko.stringTemplateEngine.instance
Expand All @@ -30,7 +35,8 @@
var $element = $(element),
value = valueAccessor(),
defaults = ko.bindingHandlers.modal.defaults,
options = ko.utils.extend({ show: $element.data().show || false }, ko.utils.unwrapProperties(value.options)),
events = $.extend({}, defaults.events, ko.toJS(value.events)),
options = ko.utils.extend({ show: $element.data().show || false }, ko.toJS(value.options)),
extendDefaults = function (defs, val) {
var extended = {
name: defs.name,
Expand Down Expand Up @@ -67,7 +73,7 @@
$element.addClass(defaults.css).attr(defaults.attributes);
$element.modal(options);

$element.on('shown.bs.modal', function () {
$element.on(events.shown, function () {
if (typeof value.visible !== 'undefined' && typeof value.visible === 'function' && !ko.isComputed(value.visible)) {
value.visible(true);
}
Expand All @@ -76,7 +82,7 @@
});

if (typeof value.visible !== 'undefined' && typeof value.visible === 'function' && !ko.isComputed(value.visible)) {
$element.on('hidden.bs.modal', function() {
$element.on(events.hidden, function() {
value.visible(false);
});

Expand Down

1 comment on commit f8d6c14

@Usaga
Copy link

@Usaga Usaga commented on f8d6c14 Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.