Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
Created June 22, 2012 01:30
Show Gist options
  • Save joshmcarthur/2969690 to your computer and use it in GitHub Desktop.
Save joshmcarthur/2969690 to your computer and use it in GitHub Desktop.
A simple Coffeescript class to build a Twitter Bootstrap modal
# You may want to call this something more specific - for example, in
# Latter, this is called 'GameModal'
class ApplicationModal
constructor: (options) ->
@options = $.extend {
header: 'Modal Heading'
content: ''
open_now: true
}, options
@hideOtherModals()
@buildModal()
@openModal() if @options.open_now
hideOtherModals: ->
$('.modal').modal('hide').remove()
buildModal: ->
@container = $("<div></div>").addClass('modal')
header = $('<div></div>').addClass('modal-header')
header.append $('<button></button>').attr('data-dismiss', 'modal').addClass('close').text('x')
header.append $('<h3></h3>').text(@options.header)
@container.append header if @options.header
body = $('<div></div>').addClass('modal-body').html(@options.content)
@container.append body
$('body').append @container
openModal: ->
@container.modal('show')
window.ApplicationModal = ApplicationModal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment