From 434e1cdd4cbb4d8b65415cdd01d07e53320ef15e Mon Sep 17 00:00:00 2001 From: Gwen Date: Sun, 9 Aug 2015 03:19:31 +0200 Subject: [PATCH] added modal hooks --- components/ionModal/ionModal.js | 41 ++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/components/ionModal/ionModal.js b/components/ionModal/ionModal.js index c903494..ba21a7a 100644 --- a/components/ionModal/ionModal.js +++ b/components/ionModal/ionModal.js @@ -7,6 +7,9 @@ IonModal = { leaveActiveClass: 'ng-leave-active', view: {}, views: [], + hooksOpen: {}, + hooksClose: {}, + hooksAllId: '__all__', open: function (templateName, data) { Meteor.setTimeout(function () { @@ -30,6 +33,16 @@ IonModal = { $modal.addClass(this.enterActiveClass); }.bind(this), 50); + var hooksAll = this.hooksOpen[this.hooksAllId] || []; + _.each(hooksAll, function(hook) { + hook.apply(this, [templateName]); + }); + + var hooks = this.hooksOpen[templateName] || []; + _.each(hooks, function(hook) { + hook.apply(this, [templateName]); + }); + }.bind(this), 0); }, @@ -56,8 +69,34 @@ IonModal = { $('body').removeClass('modal-open'); }); + var hooksAll = this.hooksClose[this.hooksAllId] || []; + _.each(hooksAll, function(hook) { + hook.apply(this, [templateName]); + }); + + var hooks = this.hooksClose[templateName] || []; + _.each(hooks, function(hook) { + hook.apply(this, [templateName]); + }); + }.bind(this), 0); + }, + onOpen: function(templateName, callback) { + if (!callback) { + callback = templateName; + templateName = this.hooksAllId; + } + this.hooksOpen[templateName] = this.hooksOpen[templateName] || []; + this.hooksOpen[templateName].push(callback); + }, + onClose: function(templateName, callback) { + if (!callback) { + callback = templateName; + templateName = this.hooksAllId; + } + this.hooksClose[templateName] = this.hooksClose[templateName] || []; + this.hooksClose[templateName].push(callback); } }; @@ -174,4 +213,4 @@ var getElementModalTemplateName = function(element) { var tplView = Meteor._get(modalView, 'parentView', 'parentView'); // Twice because the parent view is a #with block var tplName = tplView.name.slice('Template.'.length, tplView.name.length); return tplName; -} +};