2.0.0 • Published 7 years ago

aria-dialog-generator v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

ARIA DIALOG GENERATOR

Extremly small jQuery plugin extension for aria-dialog.js to dinamically inject dialogs in the markup.

Get aria-dialog.js at https://github.com/DavideTriso/aria-dialog.

Dependencies

jQuery aria-dialog.js

Settings / Options

NameDefaultTypeDescriptionRequired or optional
dialogId'' (empty)stringId of the dialog.optional (recommended)
dialogClassdialogstringClass of a dialog element.optional
wrapperClassdialog__wrapperstringClass of a dialog wrapper.optional
containerClassdialog__containerstringClass of a dialog container.optional
headerClassdialog__headerstringClass of a dialog header.optional
headingClassdialog__headingstringClass of a dialog heading.optional
bodyClassdialog__bodystringClass of a dialog bodyoptional
heading<h2 class="dialog__heading">Heading required</h2>stringThe heading of the dialog (include markup).required
visibleHeadingtrueboolIf false, the string passed to heading will be used to set the aria-label attribute on the dialog, instead of a visible heading.optional
dismissBtn'' (empty)stringAdd a close button in the header of the dialog (include markup)optional (recommended)
content'' (empty)stringThe content of the dialog (inlude markup).required

Usage

  1. Include the JS script aria-dialog-generator.js - or the minified production script aria-dialog-generator.min.js- in the head or the body of your HTML file.
  2. Initialise the widget within an inline script tag, or in an external JS file.

Example

$(document).ready(function () {
  'use strict';
  
  //Save main content of the dialog in a variable
  var dialogContent = '<p>Hey there! I am a dynamically generated dialog.' +
    'Close me with a click on the following button:</p>' +
    '<button type="button" id="dynamic-modal-close-btn">Close dialog</button>';
    
  //Call ariaDialogGenerator to inject a dialog in the markup
  //Append dialog as last child of the `<body>` 
  //it is possible to append the dialog to any html element inside the body
  $('body').ariaDialogGenerator(
  //pass array with settings as parameter
  {
    dialogId: 'dynamic-modal', //Set Id 
    dialogDismissBtn: '<button type="button" class="dialog__dismiss-btn" id="dynamic-modal-dismiss-btn">X</button>', //include a dismiss button in the dialog
    dialogContent: dialogContent
  });

  //After the dialog has been generated and injected in the html ...
  // .. initialise the dialog as described in the readme of the **aria-dialog.js** plugin
  $('#dynamic-dialog').ariaDialog({
    option1: value,
  });
  
});

LICENSE

This project is licensed under the terms of the MIT license.

See LICENSE.md for detailed informations.