From 339635a62ec0d6cac9af44efd57fb14ff56948c1 Mon Sep 17 00:00:00 2001 From: Joe Prisk Date: Fri, 27 Oct 2017 14:31:10 +0100 Subject: [PATCH] call clean up close empty --- dst/angular-modal-service.js | 10 +++++++--- dst/angular-modal-service.js.map | 2 +- dst/angular-modal-service.min.js | 2 +- dst/angular-modal-service.min.js.map | 2 +- src/angular-modal-service.js | 6 +++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dst/angular-modal-service.js b/dst/angular-modal-service.js index 1f1ee55..92f6c0a 100644 --- a/dst/angular-modal-service.js +++ b/dst/angular-modal-service.js @@ -42,7 +42,7 @@ /************************************************************************/ /******/ ([ /* 0 */ -/***/ function(module, exports) { +/***/ (function(module, exports) { 'use strict'; @@ -118,7 +118,11 @@ // Create a new scope for the modal. var modalScope = (options.scope || $rootScope).$new(); - var rootScopeOnClose = $rootScope.$on('$locationChangeSuccess', cleanUpClose); + + // wrap cleanUpClose as otherwise unexptected parameters are passed in - https://docs.angularjs.org/api/ng/service/$location#event-$locationChangeSuccess + var rootScopeOnClose = $rootScope.$on('$locationChangeSuccess', function () { + cleanUpClose(); + }); // Create the inputs object to the controller - this will include // the scope, as well as all inputs provided. @@ -242,6 +246,6 @@ return new ModalService(); }]); -/***/ } +/***/ }) /******/ ]); //# sourceMappingURL=angular-modal-service.js.map \ No newline at end of file diff --git a/dst/angular-modal-service.js.map b/dst/angular-modal-service.js.map index 8834699..75e7fb7 100644 --- a/dst/angular-modal-service.js.map +++ b/dst/angular-modal-service.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap 71ad43885cd736a446cc","webpack:///./src/angular-modal-service.js"],"names":["module","angular","factory","$animate","$document","$compile","$controller","$http","$rootScope","$q","$templateRequest","$timeout","ModalService","self","openModals","getTemplate","template","templateUrl","deferred","defer","resolve","then","error","reject","promise","appendChild","parent","child","children","length","enter","closeModals","result","delay","close","splice","showModal","options","body","element","controllerName","controller","modal","modalScope","scope","$new","rootScopeOnClose","$on","cleanUpClose","closeDeferred","closedDeferred","inputs","$scope","preClose","undefined","extend","linkFn","modalElement","$element","controllerObjBefore","controllerAs","modalController","appendElement","bodyClass","classList","add","closed","document","activeElement","blur","push","remove","leave","$destroy","i"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;AAEA,KAAIA,UAASC,QAAQD,MAAR,CAAe,qBAAf,EAAsC,EAAtC,CAAb;;AAEAA,SAAOE,OAAP,CAAe,cAAf,EAA+B,CAAC,UAAD,EAAa,WAAb,EAA0B,UAA1B,EAAsC,aAAtC,EAAqD,OAArD,EAA8D,YAA9D,EAA4E,IAA5E,EAAkF,kBAAlF,EAAsG,UAAtG,EAC7B,UAASC,QAAT,EAAmBC,SAAnB,EAA8BC,QAA9B,EAAwCC,WAAxC,EAAqDC,KAArD,EAA4DC,UAA5D,EAAwEC,EAAxE,EAA4EC,gBAA5E,EAA8FC,QAA9F,EAAwG;;AAExG,YAASC,YAAT,GAAwB;;AAEtB,SAAIC,OAAO,IAAX;;AAEA;AACAA,UAAKC,UAAL,GAAkB,EAAlB;;AAEA;AACA;AACA;AACA,SAAIC,cAAc,SAAdA,WAAc,CAASC,QAAT,EAAmBC,WAAnB,EAAgC;AAChD,WAAIC,WAAWT,GAAGU,KAAH,EAAf;AACA,WAAIH,QAAJ,EAAc;AACZE,kBAASE,OAAT,CAAiBJ,QAAjB;AACD,QAFD,MAEO,IAAIC,WAAJ,EAAiB;AACtBP,0BAAiBO,WAAjB,EAA8B,IAA9B,EACGI,IADH,CACQ,UAASL,QAAT,EAAmB;AACvBE,oBAASE,OAAT,CAAiBJ,QAAjB;AACD,UAHH,EAGK,UAASM,KAAT,EAAgB;AACjBJ,oBAASK,MAAT,CAAgBD,KAAhB;AAC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,oBAAOjB,KAAP,GAAe,IAAf;AACAhB,wBAAW,IAAX;AACA+B,6BAAgB,IAAhB;AACAP,qBAAQ,IAAR;AACAS,sBAAS,IAAT;AACAM,4BAAe,IAAf;AACAd,0BAAa,IAAb;AACD,YA1BT;;AA4BA;AACAG,+BAAoBA,kBAApB;AACD;AAEF,QA3HH,EA4HGzB,IA5HH,CA4HQ,IA5HR,EA4Hc,UAASC,KAAT,EAAgB;AAAE;AAC5BJ,kBAASK,MAAT,CAAgBD,KAAhB;AACD,QA9HH;;AAgIA,cAAOJ,SAASM,OAAhB;AACD,MAjJD;AAmJD;;AAED,UAAO,IAAIZ,YAAJ,EAAP;AACD,EAvM8B,CAA/B,E","file":"angular-modal-service.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 71ad43885cd736a446cc","'use strict';\n\nvar module = angular.module('angularModalService', []);\n\nmodule.factory('ModalService', ['$animate', '$document', '$compile', '$controller', '$http', '$rootScope', '$q', '$templateRequest', '$timeout',\n function($animate, $document, $compile, $controller, $http, $rootScope, $q, $templateRequest, $timeout) {\n\n function ModalService() {\n\n var self = this;\n \n // Track open modals.\n self.openModals = [];\n\n // Returns a promise which gets the template, either\n // from the template parameter or via a request to the\n // template url parameter.\n var getTemplate = function(template, templateUrl) {\n var deferred = $q.defer();\n if (template) {\n deferred.resolve(template);\n } else if (templateUrl) {\n $templateRequest(templateUrl, true)\n .then(function(template) {\n deferred.resolve(template);\n }, function(error) {\n deferred.reject(error);\n });\n } else {\n deferred.reject(\"No template or templateUrl has been specified.\");\n }\n return deferred.promise;\n };\n\n // Adds an element to the DOM as the last child of its container\n // like append, but uses $animate to handle animations. Returns a\n // promise that is resolved once all animation is complete.\n var appendChild = function(parent, child) {\n var children = parent.children();\n if (children.length > 0) {\n return $animate.enter(child, parent, children[children.length - 1]);\n }\n return $animate.enter(child, parent);\n };\n\n // Close all modals, providing the given result to the close promise.\n self.closeModals = function(result, delay) {\n while (self.openModals.length) {\n self.openModals[0].close(result, delay);\n self.openModals.splice(0, 1);\n }\n };\n\n self.showModal = function(options) {\n\n // Get the body of the document, we'll add the modal to this.\n var body = angular.element($document[0].body);\n\n // Create a deferred we'll resolve when the modal is ready.\n var deferred = $q.defer();\n\n // Validate the input parameters.\n var controllerName = options.controller;\n if (!controllerName) {\n deferred.reject(\"No controller has been specified.\");\n return deferred.promise;\n }\n\n // Get the actual html of the template.\n getTemplate(options.template, options.templateUrl)\n .then(function(template) {\n\n // The main modal object we will build.\n var modal = {};\n\n // Create a new scope for the modal.\n var modalScope = (options.scope || $rootScope).$new();\n var rootScopeOnClose = $rootScope.$on('$locationChangeSuccess', cleanUpClose);\n\n // Create the inputs object to the controller - this will include\n // the scope, as well as all inputs provided.\n // We will also create a deferred that is resolved with a provided\n // close function. The controller can then call 'close(result)'.\n // The controller can also provide a delay for closing - this is\n // helpful if there are closing animations which must finish first.\n var closeDeferred = $q.defer();\n var closedDeferred = $q.defer();\n var inputs = {\n $scope: modalScope,\n close: function(result, delay) {\n // If we have a pre-close function, call it.\n if (typeof options.preClose === 'function') options.preClose(modal, result, delay);\n\n if (delay === undefined || delay === null) delay = 0;\n $timeout(function() {\n\n cleanUpClose(result);\n\n }, delay);\n }\n };\n\n // If we have provided any inputs, pass them to the controller.\n if (options.inputs) angular.extend(inputs, options.inputs);\n\n // Compile then link the template element, building the actual element.\n // Set the $element on the inputs so that it can be injected if required.\n var linkFn = $compile(template);\n var modalElement = linkFn(modalScope);\n inputs.$element = modalElement;\n\n // Create the controller, explicitly specifying the scope to use.\n var controllerObjBefore = modalScope[options.controllerAs];\n var modalController = $controller(options.controller, inputs, false, options.controllerAs);\n\n if (options.controllerAs && controllerObjBefore) {\n angular.extend(modalController, controllerObjBefore);\n }\n\n // Then, append the modal to the dom.\n if (options.appendElement) {\n // append to custom append element\n appendChild(options.appendElement, modalElement);\n } else {\n // append to body when no custom append element is specified\n appendChild(body, modalElement);\n }\n\t\t \n // Finally, append any custom classes to the body\n if(options.bodyClass) {\n body[0].classList.add(options.bodyClass);\n }\n\n // Populate the modal object...\n modal.controller = modalController;\n modal.scope = modalScope;\n modal.element = modalElement;\n modal.close = closeDeferred.promise;\n modal.closed = closedDeferred.promise;\n\n // ...which is passed to the caller via the promise.\n deferred.resolve(modal);\n\n // Clear previous input focus to avoid open multiple modals on enter\n document.activeElement.blur();\n\n // We can track this modal in our open modals.\n self.openModals.push({ modal: modal, close: inputs.close });\n\n function cleanUpClose(result) {\n\n // Resolve the 'close' promise.\n closeDeferred.resolve(result);\n\t\t\t\n // Remove the custom class from the body\n if(options.bodyClass) {\n body[0].classList.remove(options.bodyClass);\n }\n\n // Let angular remove the element and wait for animations to finish.\n $animate.leave(modalElement)\n .then(function () {\n // Resolve the 'closed' promise.\n closedDeferred.resolve(result);\n\n // We can now clean up the scope\n modalScope.$destroy();\n\n // Remove the modal from the set of open modals.\n for (var i=0; i 0) {\n return $animate.enter(child, parent, children[children.length - 1]);\n }\n return $animate.enter(child, parent);\n };\n\n // Close all modals, providing the given result to the close promise.\n self.closeModals = function(result, delay) {\n while (self.openModals.length) {\n self.openModals[0].close(result, delay);\n self.openModals.splice(0, 1);\n }\n };\n\n self.showModal = function(options) {\n\n // Get the body of the document, we'll add the modal to this.\n var body = angular.element($document[0].body);\n\n // Create a deferred we'll resolve when the modal is ready.\n var deferred = $q.defer();\n\n // Validate the input parameters.\n var controllerName = options.controller;\n if (!controllerName) {\n deferred.reject(\"No controller has been specified.\");\n return deferred.promise;\n }\n\n // Get the actual html of the template.\n getTemplate(options.template, options.templateUrl)\n .then(function(template) {\n\n // The main modal object we will build.\n var modal = {};\n\n // Create a new scope for the modal.\n var modalScope = (options.scope || $rootScope).$new();\n\n // wrap cleanUpClose as otherwise unexptected parameters are passed in - https://docs.angularjs.org/api/ng/service/$location#event-$locationChangeSuccess\n var rootScopeOnClose = $rootScope.$on('$locationChangeSuccess', function() {\n cleanUpClose()\n });\n\n // Create the inputs object to the controller - this will include\n // the scope, as well as all inputs provided.\n // We will also create a deferred that is resolved with a provided\n // close function. The controller can then call 'close(result)'.\n // The controller can also provide a delay for closing - this is\n // helpful if there are closing animations which must finish first.\n var closeDeferred = $q.defer();\n var closedDeferred = $q.defer();\n var inputs = {\n $scope: modalScope,\n close: function(result, delay) {\n // If we have a pre-close function, call it.\n if (typeof options.preClose === 'function') options.preClose(modal, result, delay);\n\n if (delay === undefined || delay === null) delay = 0;\n $timeout(function() {\n\n cleanUpClose(result);\n\n }, delay);\n }\n };\n\n // If we have provided any inputs, pass them to the controller.\n if (options.inputs) angular.extend(inputs, options.inputs);\n\n // Compile then link the template element, building the actual element.\n // Set the $element on the inputs so that it can be injected if required.\n var linkFn = $compile(template);\n var modalElement = linkFn(modalScope);\n inputs.$element = modalElement;\n\n // Create the controller, explicitly specifying the scope to use.\n var controllerObjBefore = modalScope[options.controllerAs];\n var modalController = $controller(options.controller, inputs, false, options.controllerAs);\n\n if (options.controllerAs && controllerObjBefore) {\n angular.extend(modalController, controllerObjBefore);\n }\n\n // Then, append the modal to the dom.\n if (options.appendElement) {\n // append to custom append element\n appendChild(options.appendElement, modalElement);\n } else {\n // append to body when no custom append element is specified\n appendChild(body, modalElement);\n }\n\t\t \n // Finally, append any custom classes to the body\n if(options.bodyClass) {\n body[0].classList.add(options.bodyClass);\n }\n\n // Populate the modal object...\n modal.controller = modalController;\n modal.scope = modalScope;\n modal.element = modalElement;\n modal.close = closeDeferred.promise;\n modal.closed = closedDeferred.promise;\n\n // ...which is passed to the caller via the promise.\n deferred.resolve(modal);\n\n // Clear previous input focus to avoid open multiple modals on enter\n document.activeElement.blur();\n\n // We can track this modal in our open modals.\n self.openModals.push({ modal: modal, close: inputs.close });\n\n function cleanUpClose(result) {\n\n // Resolve the 'close' promise.\n closeDeferred.resolve(result);\n\t\t\t\n // Remove the custom class from the body\n if(options.bodyClass) {\n body[0].classList.remove(options.bodyClass);\n }\n\n // Let angular remove the element and wait for animations to finish.\n $animate.leave(modalElement)\n .then(function () {\n // Resolve the 'closed' promise.\n closedDeferred.resolve(result);\n\n // We can now clean up the scope\n modalScope.$destroy();\n\n // Remove the modal from the set of open modals.\n for (var i=0; i0?e.enter(n,o,l[l.length-1]):e.enter(n,o)};t.closeModals=function(e,o){for(;t.openModals.length;)t.openModals[0].close(e,o),t.openModals.splice(0,1)},t.showModal=function(a){var p=angular.element(o[0].body),d=s.defer();return a.controller?(u(a.template,a.templateUrl).then(function(o){function u(o){h.resolve(o),a.bodyClass&&p[0].classList.remove(a.bodyClass),e.leave(b).then(function(){$.resolve(o),m.$destroy();for(var e=0;e0?e.enter(n,o,l[l.length-1]):e.enter(n,o)};t.closeModals=function(e,o){for(;t.openModals.length;)t.openModals[0].close(e,o),t.openModals.splice(0,1)},t.showModal=function(c){var p=angular.element(o[0].body),d=s.defer();return c.controller?(u(c.template,c.templateUrl).then(function(o){function u(o){h.resolve(o),c.bodyClass&&p[0].classList.remove(c.bodyClass),e.leave(b).then(function(){$.resolve(o),m.$destroy();for(var e=0;e