2.1.1 • Published 8 months ago

jquery-emodal v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

jQuery eModal Plugin

GitHub Release GitHub License

$.eModal is a easy way to manage Bootstrap 4 modal dialogs using javaScript. It is not only a system that facilitates the use of the Bootstrap modal dialog, but an alternative to dialog boxes, such as alert, confirm and prompt.

Bootstrap 4 and jQuery are dependencies to jquery.eModal.js.

This plugin is based on the work of Samuel Pinto (saribe), but has been completely reengineered. https://github.com/saribe/eModal

Dependencies

The plugin requires jQuery 3 and Bootstrap 4.

Installation

NPM: npm install jquery-emodal

Yarn: yarn add jquery-emodal

Bower: bower install Reload-Lab/jquery-eModal

Example And Usage

The index.html file in the example/ folder contains many examples of using the script that illustrate its full potential.

You can see the plugin in action at this url: https://www.reloadlab.it/cantieri/jquery-eModal/example/

To initialize your modal: 1. Add the script to your page:

<script src=path/to/emodal/folder/dist/ jquery.eModal.min.js></script>
  1. Call one of the methods of the $.eModal object to open your modal dialog
<script>
$(document).ready(function(){
   $.eModal.ajax('ajax.html?_uid' + Math.random(), 'Ajax modal');
}); 
</script> 

or add an event to some element.

<button class="open-ajax" type="button">OPEN MODAL</button>
<script>
$(document).ready(function(){
   $('.open-ajax').on('click', function(e){
      $.eModal.ajax('ajax.html?_uid' + Math.random(), 'Ajax modal');
   });
}); 
</script> 

Modal methods

All methods take two arguments: 1. data (required): the value passed can be a string that represents the message to be displayed, or an object that configures the characteristics of the modal dialog. 2. title (optional): the value passed must be a string representing the title that appears in the modal header.

MethodDescription
$.eModal.alertTraditional notice box. You can pass a text or a reference to a jQuery object to the method.
$.eModal.ajaxThis method allows you to get remote views into your modal using an URL.
$.eModal.confirmGet an okay from user with a traditional confirm modal.
$.eModal.promptA simple form to ask the user a question and get an answer.
$.eModal.iframeThis method allows you to open a page in an iframe within the modal dialog.
$.eModal.embedA modal dialog that allows you to show a video from YouTube or a map from Gmap embedded in an iframe.

Available Options

It is possible to set numerous characteristics of the modal through an object to be passed as the first argument of the methods described above.

OptionsTypeDescription
messagejQuery, Html, Url, StringContent to be loaded inside the body element of the modal. It can be a text string, a url to a web resource, html content or a jQuery object. The variable is mandatory.
asyncBooleanIf the variable is set to true, the $.eModal functions return a Promise, that is resolved when the modal is closed. For modal confirm and prompt, the value must be true. Default: false
useBinBooleanIf set to true, $.eModal keeps the content uploaded in the body element of the modal in a recycle bin can, so that it can be recalled without a new upload from the web. Default: false
binIdString, falseUnique identifier of the content saved in the recycle bin. In case the useBin variable is set to true, binId must be set in order for the content to be saved. Default: false
idString, falseSet the ID attribute of the modal dialog. Default: false
cssClassString, falseCSS class to apply to the modal dialog. Default: false
bodyStylesObject, falseInline CSS styles to be applied to the body element of the modal. Default: false
headerBooleanIf the value is set to false, $.eModal does not show the Bootstrap modal header. Default: true
titleStringThe property sets the title that appears in the modal header. Default: Attention
wrapTitleStringHtml that frames the title that appears in the modal header. Default: <h5>
subtitleString, falseThe property sets the subtitle that appears in the modal header. Default: false
wrapSubtitleStringHtml that frames the subtitle that appears in the modal header. Default: <small>
headerCloseBooleanIf the value is set to false, $.eModal does not show the close button in Bootstrap's modal header. Default: true
headerCloseHtmlHtmlClose button html in Bootstrap modal header.
footerBooleanIf the value is set to false, $.eModal does not show the Bootstrap modal footer. Default: true
buttonsArray, String, false, nullYou can set all button attributes and actions to be displayed in the modal footer. If the value is an array it is possible to set the characteristics of the button through an object. For example text (string) for the button label, style (string) for the css class to be applied to the button, close (boolean) if the button has to close the modal, click (function) to execute a function when the button is clicked. All other attributes can be passed through the properties of the object (key is the attribute and value is the attribute's value) If a string is passed, the text will appear in the footer. If the value is false, no footer is shown. By default, a close modal button appears. Default: null
widthNumber, String, falseWidth of the modal relative to the browser window. You can use a numeric value, a pixel value or a percentage value. Default: false
heightNumber, String, falseHeight of the modal relative to the browser window. You can use a numeric value, a pixel value or a percentage value. Default: false
sizeStringSet modal width according to Bootstrap measurements: small (sm), large (lg) and extra large (xl). Default: empty string
positionArraySets the vertical and horizontal position of the modal relative to the screen. The first element of the array is the vertical position (top, middle and bottom). The second element indicates the horizontal position (left, center, right). Default: top, center
animationStringYou can choose the animation that will be performed when the modal is opened. If an empty string is passed there will be no animation. Default: 'fade'
modalOptionsObject, falseOptions to pass to Bootstrap's modal function. Default: false
overlayCloseBooleanIf the variable is set to false, the possibility of closing the modal by clicking on the backdrop is inhibited. Default: true
onHideFunction, falseFunction that is performed when the modal is closed. Default: false

Ajax modal options

OptionsTypeDescription
ajax.dataTypeStringIn the case of modal ajax, the variable indicates the type of content (html, text, json, xml) returned by the ajax call. Default: html
ajax.errorFunction, falseFunction to be performed in case of error in the ajax call. The function receives three arguments: The jqXHR object, a string describing the type of error that occurred and the configuration params passed to ajax modal. Default: false
ajax.loadingBooleanIn the case of an ajax modal, if the variable is set to true, $.eModal displays a content loading bar. Default: true
ajax.loadingHtmlHtmlIn the case of an ajax, Html of the content loading bar.
ajax.successFunction, falseFunction to be performed in case of success in the ajax call. The function gets passed one argument: The data returned from the server, formatted according to the dataType parameter. Default: false
ajax.urlString, falseIn the case of modal ajax, the variable sets the url of the resource to be loaded in the body element of the modal. Default: false
ajax.xhrObject, falseIn the case of modal ajax, you can set the properties of the call. To know all the values that can be set, you can read the documentation of the jQuery $.ajax function: https://api.jquery.com/jquery.ajax/. Default: false

Confirm modal options

OptionsTypeDescription
confirm.labelStringConfirm button label in confirm modals. Default: Ok
confirm.styleArrayCSS class of the confirmation and rejection buttons of the modal confirm. Default: btn-primary, btn-danger

Prompt modal options

OptionsTypeDescription
prompt.autocompleteBooleanIn the case of a modal prompt, if the variable is set to true, the value ON is assigned to the autocomplete attribute of the field. Default: false
prompt.autofocusBooleanIn the case of a modal prompt, if the variable is set to true, the focus is assigned to the input field when the modal is opened. Default: false
prompt.checkValidityBooleanIn the case of a modal prompt, if the variable is set to true, a check is made on the validity of the content of the input field, using the browser api. Default: false
prompt.labelStringConfirm button label in prompt modals. Default: Ok
prompt.patternString, falseIn the case of modal prompt, you can set the pattern attribute of the INPUT tag, so that the value entered by the user in the field can be validated using a regular expression. Default: false
prompt.placeholderString, falseIn the case of modal prompt, you can set the placeholder attribute of the INPUT tag, so that a placeholder text is displayed in the input field. Default: false
prompt.requiredBooleanIn the case of modal prompt, set the required attribute of the INPUT tag, so that it is mandatory to fill in the input field before sending it. Default: false
prompt.styleArrayCSS class of the confirmation and rejection buttons of the modal prompt. Default: btn-primary, btn-danger
prompt.typeStringIn the case of modal prompt you can set the type attribute of the INPUT tag. Default: text
prompt.valueString, falseIn the case of modal prompt, you can set the value of the value attribute of the INPUT tag. Default: false

Iframe and embed modal options

OptionsTypeDescription
iframe.loadingHtmlHtmlIn the case of an embed and iframe modal, Html of the content loading bar.
iframe.urlString, falseIn the case of modal embed and iframe, the variable sets the url of the resource to be loaded in the body element of the modal. Default: false
iframe.attributesObject, falseIn the case of modal iframe and embed, you can set the attributes of the IFRAME tag. The object keys correspond to the attributes and the values to the attribut's values. Default: false

Utility methods

MethodDescription
$.eModal.closeCloses the modal. The onHide function is not performed. Nothing returns
$.eModal.labelAdds new labels. It takes two arguments: confirm button label and reject button label. Returns the $.eModal object for concatenation.
$.eModal.modalReturns the jQuery object of the modal dialog.
$.eModal.deferReturn the Promise to be able to perform a resolve or reject.
$.eModal.sizeIt is possible to add a size to those provided by Bootstrap (sm, lg, xl). Returns the $.eModal object for concatenation.
$.eModal.emptyBinThe method empties the recycle bin. Returns the $.eModal object for concatenation.

Created by Domenico Gigante - Reload Laboratorio Multimediale, Rome, IT