Giter VIP home page Giter VIP logo

bootstrap-3-modal's Introduction

bootstrap-3-modal

A Meteor package making it easy to use bootstrap 3 modals in Meteor.

Note 1: In order for this package to work, you must include bootstrap 3 in your meteor project. You can add bootstrap 3 to your project by adding the package twbs:bootstrap:

meteor add twbs:bootstrap

This package does not include twbs:bootstrap automatically (in case you have included bootstrap 3 in another way).

Include this package with:

meteor add peppelg:bootstrap-3-modal

Usage

To define your own modals, simply define new templates containing your modals (important: your modals must have the class modal):

<template name="exampleModal">
	<div class="modal fade">
		<div class="modal-dialog">
			<div class="modal-content">
				
				<div class="modal-header">
					<h4 class="modal-title">Modal example</h4>
				</div>
				
				<div class="modal-body">
					<p>A modal example.</p>
				</div>
				
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				</div>
				
			</div>
		</div>
	</div>
</template>

Modal templates can be used as ordinary templates in Meteor (created, helpers, rendered, events and destroyed all works as you're used to).

No modal is shown (or even inserted into the DOM) by default. By calling Modal.show(<templateName>), the modal is inserted into the DOM and shown.

Meteor.startup(function(){
	// Show the example modal 3 seconds after startup.
	setTimeout(function(){
		Modal.show('exampleModal')
	}, 3000)
})

If a second argument is passed to Modal.show (Modal.show(<templateName>, <dataContext>)), it will be used as the data context for the template (works as the data parameter for Blaze.renderWithData).

The modal can be removed by calling Modal.hide() (or by using the other ways to remove modals in bootstrap).

You can also pass Bootstrap modal options to Modal.show as a third argument. Otherwise, you can define the options in the template via data attributes.

Using multiple modals

As written in the documentation for Bootstrap, Bootstrap does not support showing multiple modals at a time:

Overlapping modals not supported

Be sure not to open a modal while another is still visible. Showing more than one modal at a time requires custom code.

This package does not contain any "custom code" for showing multiple modals at a time, but it is not limited to only inserting one modal at a time. To enable insertions of multiple modals, just set Modal.allowMultiple to true:

Modal.allowMultiple = true

Meteor.startup(function(){
	
	// Show the example modal directly on startup...
	Modal.show('exampleModal')
	
	// ...and also 3 seconds later, even if the first one hasn't been closed.
	setTimeout(function(){
		Modal.show('exampleModal')
	}, 3000)
	
})

To remove a modal, you need to pass the modal's template instance as the first argument to Modal.hide. Usually, this is done in an event handler, where the template instance is provided as the second argument.

Examples

At the moment there is one sign up modal and one sign in modal in the directory examples. When a proper way to do this in Meteor (settings min password length, and things like that) exists in Meteor, I will probably create a package like accounts-ui, but with modals instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.