Last active
August 29, 2015 14:25
-
-
Save cemeng/6a1cb617581f7b71f47f to your computer and use it in GitHub Desktop.
angular-ui modal implemented with angular-strap modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.factory "Modal", ($modal, $q) -> | |
open: (options) -> | |
deferred = $q.defer() | |
modal = {} | |
options.locals = | |
$modalInstance: | |
hide: -> | |
modal.hide() | |
close: (result) -> | |
modal.hide() | |
deferred.resolve result | |
decorateTemplateOptions = (modalOptions) -> | |
content = if modalOptions.templateUrl | |
"<ng-include src=\"'#{modalOptions.templateUrl}'\" />" | |
else | |
modalOptions.template | |
size = if modalOptions.size then "modal-#{modalOptions.size}" else "" | |
""" | |
<div class="modal #{modalOptions.windowClass}" tabindex="-1"> | |
<div class="modal-dialog #{size}"> | |
<div class="modal-content"> | |
#{content} | |
</div> | |
</div> | |
</div> | |
""" | |
options.template = decorateTemplateOptions options | |
options.templateUrl = false # templateUrl will be decorated and put on options.template on decorateTemplateOptions | |
modal = $modal options | |
modal.$scope.$close = (result) -> | |
modal.$scope.$hide() | |
deferred.resolve result | |
modal.$scope.$dismiss = modal.$scope.$hide | |
modal.result = deferred.promise | |
modal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment