Skip to content

Instantly share code, notes, and snippets.

@cemeng
Last active August 29, 2015 14:25
Show Gist options
  • Save cemeng/6a1cb617581f7b71f47f to your computer and use it in GitHub Desktop.
Save cemeng/6a1cb617581f7b71f47f to your computer and use it in GitHub Desktop.
angular-ui modal implemented with angular-strap modal
.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