Skip to content

Instantly share code, notes, and snippets.

@ovcharik
Created April 28, 2015 05:51
Show Gist options
  • Save ovcharik/1f269ed35431c1f507b8 to your computer and use it in GitHub Desktop.
Save ovcharik/1f269ed35431c1f507b8 to your computer and use it in GitHub Desktop.
Meteor bootbox
old = bootbox.dialog
bootbox.dialog = (options) ->
if options.template and not options.message
unless Blaze.isTemplate(options.template)
throw new Error "options.template should be Blaze template"
options.message = " "
renderTemplate = true
if options.titleTemplate and not options.title
unless Blaze.isTemplate(options.titleTemplate)
throw new Error "options.titleTemplate should be Blaze template"
options.title = " "
renderTitleTemplate = true
dialog = old(options)
if renderTemplate
body = dialog.find('.bootbox-body')[0]
if options.context?
messageView = Blaze.renderWithData(options.template, options.context, body)
else
messageView = Blaze.render(options.template, body)
if renderTitleTemplate
title = dialog.find('.modal-title')[0]
if options.titleContext?
titleView = Blaze.renderWithData(options.titleTemplate, options.titleContext, title)
else
titleView = Blaze.render(options.titleTemplate, title)
dialog.on 'hidden.bs.modal', ->
Blaze.remove(messageView) if messageView
Blaze.remove(titleView) if titleView
dialog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment