Documentation
SoloAlert is a Lightweight Alert library for displaying awesome custom SoloLearn Alerts. It is Promise based and easy to use with many customizable options.
Including the library:
Its so easy to include SoloAlert.js to your website. Just Copy the following code below and put in the <head></head>
of your website and done.
<script src="https://unpkg.com/soloalert" type="text/javascript"></script>
Getting Started:
Solo Alert requires DOM to be loaded to show the alert.
Here's a simple code for an alert with a Title
and body text.
Try runing it and see the alert.
Displaying an alert with an Icon.
There are three available icons: success
, warning
, error
. But you can
also add your own icons' html to SoloAlert.data_icons
and use them in icon
parameter.
Displaying an alert with a custom Icon.
Displaying a Simple Prompt with heading and text.
Displaying a Prompt Message and Getting the Entered Value.
Displaying a Confirm Message.
Displaying a Confirm Message. And getting User Choice
Displaying an Alert with a Light theme (default is "auto"
)
Displaying an Alert with a Dark theme (default is "auto"
)
Displaying an Alert with Transparency effect is (default is false
)
More on alerts
The alert method extra options to customize your SoloAlert.
Embeding HTML:To embed HTML in the alert just put your html code as html
property in the alert.
To maintain the alert's height, the html contet will become scrollable if its long.
OnOk
property
onOk
property is useful when you want to perform a spectic function when user clicks the ok
button.
One of its implementation could be playing audio when user clicks ok.
More on Prompts
type
property
type
property sets the type of the input in the prompt.
attributes
property
attributes
property sets the attributes to the input element in the prompt.
onCancel
property
onCancel
property is useful when you want to perform a spectic function when user clicks the
cancel button.
onInput
property
onInput
property is useful when you want to perform a spectic function everytime user entered
something into the input. You can get the value of input by event.target.value
textLimit
property
textLimit
property is used to set the textlimit of the prompt input. the default value is 100
Options:
SoloAlert.alert({...options});
There are many options to customize your alert.
Name | Value | Use |
---|---|---|
title |
String |
Sets the title of SoloAlert |
body |
String |
Sets the body text of SoloAlert |
html |
String |
Sets the html content you want to display in SoloAlert |
useTransparency |
Boolean |
Sets whether the SoloAlert Backdrop backgound is semi-transparent. |
theme |
auto | light | dark |
Sets the theme of the SoloAlert |
icon |
success | error | warning | "any" |
Sets the icon to display in SoloAlert |
onOk |
JavaScript Function |
runs the given function when ok button is clicked |
options to customize your prompt.
SoloAlert.prompt({...options});
Name | Value | Use |
---|---|---|
title |
String |
Sets the title of SoloAlert |
body |
String |
Sets the body text of SoloAlert |
type |
String |
Sets the type of the input box shown in the prompt. all the HTML Input types are valid value for type. |
attributes |
Object |
Sets the attribues to the input element in the prompt. It accepts an Object with the
keys as attribute names and values as respective values.
|
useTransparency |
Boolean |
Sets whether the SoloAlert Backdrop backgound is semi-transparent. |
theme |
auto | light | dark |
Sets the theme of the SoloAlert |
textLimit |
number |
Sets the text limit of the prompt input |
onOk |
JavaScript Function |
runs the given function when ok button is clicked |
onCancel |
JavaScript Function |
runs the given function when Cancel button is clicked |
onInput |
JavaScript Function |
runs the given function when User Inputs Texts in the Input |
options to customize your confirm.
SoloAlert.confirm({...options});
Name | Value | Use |
---|---|---|
title |
String |
Sets the title of SoloAlert |
body |
String |
Sets the body text of SoloAlert |
useTransparency |
Boolean |
Sets whether the SoloAlert Backdrop backgound is semi-transparent. |
theme |
auto | light | dark |
Sets the theme of the SoloAlert |
onOk |
JavaScript Function |
runs the given function when ok button is clicked |
onCancel |
JavaScript Function |
runs the given function when Cancel button is clicked |
SoloAlert Options:
Properties and method that are available on the global object SoloAlert
:
SoloAlert.defaults
It is an object that stores the default values to be used within the alerts
,
prompts
, confirm
. You can change the default values by this object
.
The defaults' properties are given below
{
title: "Title",
body: "",
icon: "",
theme: "auto",
html: "",
type: "text",
textLimit: 100,
useTransparency: false,
onOk: function () { },
onCancel: function () { },
onInput: function () { },
}
you can change defaults' properties to anything that you want as the default
.
SoloAlert.changeTheme(theme)
changeTheme changes the theme of the SoloAlert. The valid values for the theme are "auto", "dark", "light".
SoloAlert.setAsDefault()
This replaces the browser's default alert()
, prompt()
and confirm()
with the SoloAlert's alert
, prompt
, confirm
. Means when you trigger the
browser default alerts it will instead show a SoloAlert
when you set SoloAlert
to as default browser alerts then there's a slight change in the syntax
of writing alerts also.
when SoloAlert
set to default its first argument is the body of the alert and the second
argument is the alert options
. and you don't have to define body in options
. Also
now the second argument options
becomes optional.
Then the title
can be set using the SoloAlert.defaults
so that
title
stays same in every alert and you don't have to everytime set the alert title
.
Example using SoloAlert as default Browser alert with a default title
set to the alert.
The same logic applies with the prompts
and confirm
also!
SoloAlert.resetDefaults()
This method removes SoloAlert as Browser default and now alert()
, confirm()
, and
prompt()
would show the browser UI.
Example using resetDefaults();
Made With ❤ By Arnav Kumar
Feel Free to Contribute and notify me of any bugs.