-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
98 lines (98 loc) · 3.41 KB
/
index.js
File metadata and controls
98 lines (98 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(function() {
angular.module('tjsail33.ionicModals', ['ionic']).factory('$modalService', [
'$ionicModal', '$rootScope', '$q', '$injector', '$controller', function($ionicModal, $rootScope, $q, $injector, $controller) {
var _cleanup, _evalController, show;
show = function(templeteUrl, controller, parameters, options, parentScope) {
var ctrlInstance, defaultOptions, deferred, modalScope, thisScopeId;
deferred = $q.defer();
ctrlInstance = void 0;
if(parentScope) {
modalScope = parentScope.$new();
}else{
modalScope = $rootScope.$new();
}
thisScopeId = modalScope.$id;
defaultOptions = {
animation: 'slide-in-up',
focusFirstInput: false,
backdropClickToClose: true,
hardwareBackButtonClose: true,
modalCallback: null
};
options = angular.extend({}, defaultOptions, options);
$ionicModal.fromTemplateUrl(templeteUrl, {
scope: modalScope,
animation: options.animation,
focusFirstInput: options.focusFirstInput,
backdropClickToClose: options.backdropClickToClose,
hardwareBackButtonClose: options.hardwareBackButtonClose
}).then((function(modal) {
var ctrlEval, locals;
modalScope.modal = modal;
modalScope.openModal = function() {
modalScope.modal.show();
};
modalScope.closeModal = function(result) {
deferred.resolve(result);
modalScope.modal.hide();
};
modalScope.$on('modal.hidden', function(thisModal) {
var modalScopeId;
if (thisModal.currentScope) {
modalScopeId = thisModal.currentScope.$id;
if (thisScopeId === modalScopeId) {
deferred.resolve(null);
_cleanup(thisModal.currentScope);
}
}
});
locals = {
'$scope': modalScope,
'parameters': parameters
};
ctrlEval = _evalController(controller);
ctrlInstance = $controller(controller, locals);
if (ctrlEval.isControllerAs) {
ctrlInstance.openModal = modalScope.openModal;
ctrlInstance.closeModal = modalScope.closeModal;
}
modalScope.modal.show().then(function() {
modalScope.$broadcast('modal.afterShow', modalScope.modal);
});
if (angular.isFunction(options.modalCallback)) {
options.modalCallback(modal);
}
}), function(err) {
deferred.reject(err);
});
return deferred.promise;
};
_cleanup = function(scope) {
scope.$destroy();
if (scope.modal) {
scope.modal.remove();
}
};
_evalController = function(ctrlName) {
var fragments, result;
result = {
isControllerAs: false,
controllerName: '',
propName: ''
};
fragments = (ctrlName || '').trim().split(/\s+/);
result.isControllerAs = fragments.length === 3 && (fragments[1] || '').toLowerCase() === 'as';
if (result.isControllerAs) {
result.controllerName = fragments[0];
result.propName = fragments[2];
} else {
result.controllerName = ctrlName;
}
return result;
};
return {
show: show
};
}
]);
})();