|
3 | 3 | *
|
4 | 4 | * @link https://github.com/nonplus/angular-ui-router-uib-modal
|
5 | 5 | *
|
6 |
| - * @license angular-ui-router-uib-modal v0.0.10 |
| 6 | + * @license angular-ui-router-uib-modal v0.0.11 |
7 | 7 | * (c) Copyright Stepan Riha <[email protected]>
|
8 | 8 | * License MIT
|
9 | 9 | */
|
10 | 10 |
|
11 | 11 | (function(angular) {
|
12 | 12 |
|
13 |
| -/* global angular */ |
14 | 13 | "use strict";
|
15 | 14 | angular.module("ui.router.modal", ["ui.router"])
|
16 |
| - .config(["$stateProvider", function($stateProvider) { |
17 |
| - |
18 |
| - var stateProviderState = $stateProvider.state; |
19 |
| - |
20 |
| - $stateProvider.state = function(stateName, options) { |
21 |
| - |
22 |
| - // check for $stateProvider.state({name: "state", ...}) usage |
23 |
| - if (angular.isObject(stateName)) { |
24 |
| - options = stateName; |
25 |
| - stateName = options.name; |
26 |
| - } |
27 |
| - |
28 |
| - if (options.modal) { |
29 |
| - |
30 |
| - if (options.onEnter) { |
31 |
| - throw new Error("Invalid modal state definition: The onEnter setting may not be specified."); |
32 |
| - } |
33 |
| - |
34 |
| - if (options.onExit) { |
35 |
| - throw new Error("Invalid modal state definition: The onExit setting may not be specified."); |
36 |
| - } |
37 |
| - |
38 |
| - var openModal; |
39 |
| - |
40 |
| - // Get modal.resolve keys from state.modal or state.resolve |
41 |
| - var resolve = (Array.isArray(options.modal) ? options.modal : []).concat(Object.keys(options.resolve || {})); |
42 |
| - |
43 |
| - var inject = ["$uibModal", "$state"]; |
44 |
| - options.onEnter = function($uibModal, $state) { |
45 |
| - |
46 |
| - // Add resolved values to modal options |
47 |
| - if (resolve.length) { |
48 |
| - options.resolve = {}; |
49 |
| - for(var i = 0; i < resolve.length; i++) { |
50 |
| - options.resolve[resolve[i]] = injectedConstant(arguments[inject.length + i]); |
51 |
| - } |
52 |
| - } |
53 |
| - |
54 |
| - var thisModal = openModal = $uibModal.open(options); |
55 |
| - |
56 |
| - openModal.result['finally'](function() { |
57 |
| - if (thisModal === openModal) { |
58 |
| - // Dialog was closed via $uibModalInstance.close/dismiss, go to our parent state |
59 |
| - $state.go($state.get("^", stateName).name); |
60 |
| - } |
61 |
| - }); |
62 |
| - }; |
63 |
| - |
64 |
| - // Make sure that onEnter receives state.resolve configuration |
65 |
| - options.onEnter.$inject = inject.concat(resolve); |
66 |
| - |
67 |
| - options.onExit = function() { |
68 |
| - if (openModal) { |
69 |
| - // State has changed while dialog was open |
70 |
| - openModal.close(); |
71 |
| - openModal = null; |
72 |
| - } |
73 |
| - }; |
74 |
| - |
75 |
| - } |
76 |
| - |
77 |
| - return stateProviderState.call($stateProvider, stateName, options); |
78 |
| - }; |
79 |
| - }]); |
80 |
| - |
| 15 | + .config(["$stateProvider", function ($stateProvider) { |
| 16 | + var stateProviderState = $stateProvider.state; |
| 17 | + $stateProvider["state"] = state; |
| 18 | + function state(name, config) { |
| 19 | + var stateName; |
| 20 | + var options; |
| 21 | + // check for $stateProvider.state({name: "state", ...}) usage |
| 22 | + if (angular.isObject(name)) { |
| 23 | + options = name; |
| 24 | + stateName = options.name; |
| 25 | + } |
| 26 | + else { |
| 27 | + options = config; |
| 28 | + stateName = name; |
| 29 | + } |
| 30 | + if (options.modal) { |
| 31 | + if (options.onEnter) { |
| 32 | + throw new Error("Invalid modal state definition: The onEnter setting may not be specified."); |
| 33 | + } |
| 34 | + if (options.onExit) { |
| 35 | + throw new Error("Invalid modal state definition: The onExit setting may not be specified."); |
| 36 | + } |
| 37 | + var openModal_1; |
| 38 | + // Get modal.resolve keys from state.modal or state.resolve |
| 39 | + var resolve_1 = (Array.isArray(options.modal) ? options.modal : []).concat(Object.keys(options.resolve || {})); |
| 40 | + var inject_1 = ["$uibModal", "$state"]; |
| 41 | + options.onEnter = function ($uibModal, $state) { |
| 42 | + // Add resolved values to modal options |
| 43 | + if (resolve_1.length) { |
| 44 | + options.resolve = {}; |
| 45 | + for (var i = 0; i < resolve_1.length; i++) { |
| 46 | + options.resolve[resolve_1[i]] = injectedConstant(arguments[inject_1.length + i]); |
| 47 | + } |
| 48 | + } |
| 49 | + var thisModal = openModal_1 = $uibModal.open(options); |
| 50 | + openModal_1.result['finally'](function () { |
| 51 | + if (thisModal === openModal_1) { |
| 52 | + // Dialog was closed via $uibModalInstance.close/dismiss, go to our parent state |
| 53 | + $state.go($state.get("^", stateName).name); |
| 54 | + } |
| 55 | + }); |
| 56 | + }; |
| 57 | + // Make sure that onEnter receives state.resolve configuration |
| 58 | + options.onEnter["$inject"] = inject_1.concat(resolve_1); |
| 59 | + options.onExit = function () { |
| 60 | + if (openModal_1) { |
| 61 | + // State has changed while dialog was open |
| 62 | + openModal_1.close(); |
| 63 | + openModal_1 = null; |
| 64 | + } |
| 65 | + }; |
| 66 | + } |
| 67 | + return stateProviderState.call($stateProvider, stateName, options); |
| 68 | + } |
| 69 | + }]); |
81 | 70 | function injectedConstant(val) {
|
82 |
| - return [function() { return val; }]; |
| 71 | + return [function () { return val; }]; |
83 | 72 | }
|
84 | 73 |
|
85 | 74 |
|
|
0 commit comments