• This repository has been archived on 22/Apr/2018
  • Stars
    star
    283
  • Rank 141,312 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy-to-use dialog system for modern web-apps.

[Deprecated] basicModal

Easy-to-use dialog system for modern web-apps.

Modal Screenshot

basicModal is a dialog-system for modern web-apps. It includes everything you need to display information, ask questions or request input from the user. Dialogs can be chained, so you can easily build a setup-assistant or show messages in a predefined order. Invalid input can be highlighted and handled using the included function.

basicModal is written in Vanilla JS and has zero dependencies. It uses SASS and Flexbox.

Tested with the latest versions of Mozilla Firefox, Apple Safari, Google Chrome, Microsoft Internet Explorer (10+) and Opera.

Contents

Demos

Name Description Link
Alert Modal similar to alert(). The modal contains a message and a button. The message can be filled with HTML and the button fires the specified function when pressed. Demo
Prompt The prompt dialog is great when you want a decision or answer from the user. Demo
Login Building a login with basicModal is super easy. It includes everything you need, like the ability to highlight invalid input. Demo

Features

  • Works in all modern browsers
  • Zero dependencies
  • CommonJS and AMD support
  • Support for text inputs
  • Highlight invalid input
  • Execute dialogs in row

Requirements

basicModal depends on the following browser APIs:

Some of these APIs are capable of being polyfilled in older browsers. Check the linked resources above to determine if you must polyfill to achieve your desired level of browser support.

Setup

We recommend to install basicModal using Bower or npm.

bower install basicModal
npm install basicmodal

Include the CSS file in the head tag and the JS file at the end of your body tag…

<link rel="stylesheet" href="dist/basicModal.min.css">
<script src="dist/basicModal.min.js"></script>

…or skip the JS file and use basicModal as a module:

const basicModal = require('basicmodal')

Usage

Alert

Lets start with a modal similar to alert(). The modal contains a message and a button. The message can be filled with HTML and the button fires the specified function when pressed.

basicModal.show({
	body: '<p>This is a dead-simple alert modal!<br>The message can be filled with anything you want.</p>',
	buttons: {
		action: {
			title: 'Dismiss',
			fn: basicModal.close
		}
	}
})

Prompt

The prompt dialog is great when you want a decision or answer from the user. The only difference from the first example is the additional button.

basicModal.show({
	body: '<p>This type of modal can be used to ask the user questions. Are you sure you want to continue?</p>',
	buttons: {
		cancel: {
			title: 'Cancel',
			fn: basicModal.close
		},
		action: {
			title: 'Continue',
			fn: basicModal.close
		}
	}
})

Input

Building an input-dialog with basicModal is super easy. It includes everything you need, like the ability to highlight invalid fields. The specified action-button-function receives an object which includes the values of all inputs. Use the name attribute in your HTML to set the name of the inputs.

basicModal.show({
	body: '<p>This type of modal can be used to ask the user questions. Please enter your name:</p><input class="basicModal__text" type="text" name="name" placeholder="Jane Doe">',
	buttons: {
		cancel: {
			title: 'Cancel',
			fn: basicModal.close
		},
		action: {
			title: 'Continue',
			fn: (data) => {

				if (data.name.length===0) return basicModal.error('name')

				console.log(data)
				basicModal.close()

			}
		}
	}
})

Functions

basicModal comes with a handful of handy functions. Below are all of them along with a short description.

Show

The most important function of basicModal. Call show to show a modal. The object you pass to the function includes all the information about the modal. Take a look at the demos above to get a feel of the capabilities.

basicModal.show(options: object)

Error

Use the error function to highlight invalid input. This function can only be used when the modal has input elements. Each input needs a name attribute as shown in the example above. The input with the matching attribute will be marked red and the modal will shake to signal an error. This function also executes the reset function, to remove previous errors and to reactive the buttons.

basicModal.error(nameAttribute: string)

Visible

Check if there's a visible modal. Returns true when a modal is visible and false otherwise.

basicModal.visible() : boolean

Action & Cancel

You can trigger the buttons of the modal manually if wanted. Triggering a button is equivalent to clicking them.

basicModal.action() : boolean
basicModal.cancel() : boolean

Reset

In order to avoid multiple executions of the same function, buttons can only be pressed once before being disabled. Use reset if you want to reactivate the buttons or to reset the highlighted input errors.

basicModal.reset() : boolean

Get Values

The following function returns an object, which includes all input values from the current modal.

basicModal.getValues() : object

Close

And finally: Close the modal. You can force close a modal by passing true to the function. This is required when the modal is created with the closable property set to false.

basicModal.close(forceClose: boolean) : boolean

Options

List of options you can pass to the basicModal.show function:

basicModal.show({

	// String containing HTML (required)
	body: '<p>String containing HTML</p>',

	// String - List of custom classes added to the modal (optional)
	class: 'customClass01 customClass02',

	// Boolean - Define if the modal can be closed with the close-function (optional)
	closable: true,

	// Function - Will fire when modal is visible (optional)
	callback: undefined,

	// Object - basicModal accepts up to two buttons and requires at least one of them
	buttons: {

		cancel: {

			// String (optional)
			title: 'Cancel',

			// String - List of custom classes added to the button (optional)
			class: 'customButtonClass',

			// Function - Will fire when user clicks the button (required)
			fn: basicModal.close

		},

		action: {

			// String (optional)
			title: 'OK',

			// String - List of custom classes added to the button (optional)
			class: 'customButtonClass',

			// Function - Will fire when user clicks the button (required)
			fn: (data) => basicModal.close()

		}

	}

})

More Repositories

1

Lychee

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.
PHP
6,312
star
2

Ackee

Self-hosted, Node.js based analytics tool for those who care about privacy.
JavaScript
4,121
star
3

basicScroll

Standalone parallax scrolling for mobile and desktop with CSS variables.
JavaScript
3,633
star
4

formbase

Better default styles for common input elements.
SCSS
567
star
5

basicLightbox

The lightest lightbox ever made.
JavaScript
532
star
6

ackee-tracker

Transfer data to Ackee.
JavaScript
190
star
7

basicContext

Easy-to-use context-menu for your website or webapp.
JavaScript
168
star
8

Rosid

Just-in-time development server and static site generator.
JavaScript
143
star
9

nice-try

Tries to execute a function and discards any error that occurs.
JavaScript
66
star
10

basicGrid

A Foundation-like grid system based on the flex display property.
SCSS
56
star
11

basicSlider

A slider in its purest form.
JavaScript
33
star
12

scrollSnap

Section-based scrolling for your site.
JavaScript
27
star
13

fsify

Convert an array of objects into a persistent or temporary directory structure.
JavaScript
26
star
14

Skeleton-Components

A front-end Malvid template build upon Rosid.
CSS
24
star
15

use-ackee

Use Ackee in React.
JavaScript
23
star
16

basicRotate

Rotate throw a set of 360 degree images using your mouse or finger.
JavaScript
20
star
17

ackee-bitbar

Ackee stats in your macOS menu bar.
JavaScript
16
star
18

ackee-lighthouse

Send Lighthouse reports to Ackee.
JavaScript
13
star
19

Skeleton-EJS

A front-end template build upon Rosid.
CSS
13
star
20

basicPlaceholder

Easy-to-use persistent placeholders for input fields.
JavaScript
10
star
21

basicNotification

Easy-to-use notification-system for your website or webapp.
CoffeeScript
9
star
22

basicPaginate

Paginate a NodeList like there's no tomorrow.
JavaScript
9
star
23

limit-number

Limit a number between a min and max value.
JavaScript
7
star
24

zbarimg

Scan photos using ZBar in Node.js.
CoffeeScript
6
star
25

dribbble-2x

Safari extension for Dribbble, which always shows the @2x version.
JavaScript
6
star
26

rosid-handler-sass

Load SCSS and transform to CSS, add vendor prefixes and minify.
JavaScript
6
star
27

basicTasks

A collection of gulp-tasks used in personal projects.
JavaScript
5
star
28

rosid-handler-twig

Load Twig templates and render them.
JavaScript
5
star
29

Feedboard

Design your feed.
JavaScript
5
star
30

Skeleton-NJK

A front-end template build upon Rosid.
CSS
5
star
31

key-value-replace

Replace key/value pairs in a string.
JavaScript
5
star
32

rosid-handler-ejs

Load EJS templates and render them.
JavaScript
5
star
33

lychee-watermark

Adds a second watermarked photo when uploading images to Lychee.
PHP
5
star
34

require-data

Extracts data out of multiple file types.
JavaScript
5
star
35

lychee-redirect

Redirect from an album-name to a Lychee-album.
PHP
5
star
36

rename-extension

Changes the the extension of a given filename or path.
JavaScript
5
star
37

rosid-handler-njk

Load Nunjucks templates and render them.
JavaScript
4
star
38

rosid-handler-js

Load, transform, bundle and compress JS.
JavaScript
4
star
39

basicFit

Turn elements on your site into a responsive unified grid.
CoffeeScript
4
star
40

rosid-handler-node

Load JS and transform to HTML.
JavaScript
3
star
41

count-between

Counts up and down between two numbers.
JavaScript
3
star
42

ausgabe

Tiny logger with zero defaults.
JavaScript
3
star
43

modulizer

Wrap this snippets around your code to support CommonJS, AMD and non-module-definitions.
JavaScript
3
star
44

eslint-config

ESLint configuration for my personal projects.
JavaScript
2
star
45

pdfconcat

Concat multiple pdfs using pdfunite in Node.js.
CoffeeScript
2
star
46

continuous-stealthy-require

Requires a fresh, uncached module without causing a memory leak.
JavaScript
2
star
47

ackee-faker

Fills Ackee with fake data.
JavaScript
2
star
48

Ackee-Netlify-Test-Instance

JavaScript
1
star
49

rosid-handler-js-next

Load, transform, bundle and compress modern JS.
JavaScript
1
star
50

Skeleton-React

A front-end template build upon Rosid.
JavaScript
1
star
51

vh-variable

TypeScript
1
star