Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
A small js library for alerts
####View a demo here
Alert-js is an easy way to integrate userfriendly, smoothly animated, in material design held alerts. Use them to display important information that needs to be seen NOW and let the user take actions. The action buttons have ripple effects, which are also styleable. You can show alerts with one function call and detect the clicked action just as easily. Users can also dismiss an alert by pressing esc
and click the right-most action with enter
. If you try to show an alert while one is already open, it gets stored in a queue and shown after the current one gets closed.
With npm:
1. At the root of your index, type npm install ripple-js
into the command line.
2. Add the tag <script src="node_modules/alert-js/alert.min.js"></script>
to your index file. If you want to show alerts on finished load, also add the script tag <script src="node_modules/ripple-js/ripple.min.js"></script>
BEFORE!
string
°Corresponds to the css color
and ripple-color
property. Click here for more information
°Example: alert.accentColor = "green";
°Default value: "orange"
Float
°Corresponds to the ripple-opacity
property. Click here for more information
°Example: alert.rippleOpacity = 0.3;
°Default value: 0.6
Float
°Corresponds to the ripple-press-expand-time
property. Click here for more information
°Example: alert.ripplePressExpandTime = 3.3;
°Default value: 1.5
Float
°Corresponds to the ripple-release-expand-time
property. Click here for more information
°Example: alert.rippleReleaseExpandTime = 0.5;
°Default value: 0.3
Float
°Corresponds to the ripple-leave-collapse-time
property. Click here for more information
°Example: alert.rippleLeaveCollapseTime = 0.1;
°Default value: 0.4
Boolean
read-only
°Example: var isAlertOpen = alert.open;
###Methods
°Parameters:
text: String
The text the alert should display. You can use html elements and style attributes just like in the document.
actions: Array of Strings
optional
For every entry a corresponding button will be displayed in the alert. If ommited or empty, only an "OK" button will be displayed
options: Object
optional
If you don't want to apply the global options to this alert, you can change the settings for only this alert with all properties (except open) described here. Possible example: {accentColor: "blue", rippleOpacity: 0.7}
mode String
optional
Change how the queue should behave with one of the three following options:
"replace" This clears the queue, closes the old alert and instantly shows the new one
"next-in-queue" Instead of putting the alert at the end of the queue, this places the alert as the next one in the waiting queue
"next" Use this to show the new alert instantly instead of the current one, but preserve the queue
°Return value:
The function returns a Promise, which resolves to the action the user clicked. See the examples for working code
°Examples:
-alert.show("Hello world");
The most simple form of an alert.
-alert.show("We couldn't find your position for one of the following reasons:<ul><li>Your device doesn't support gps</li><li>You didn't grant us access to your position</li><li>The device can't find it's position</li></ul>");
You can use html tags just as you would expect.
-alert.show("Do you want to switch to our mobile website?", ["No", "Yes"]);
While you should build responsive websites, this approach is also possible.
-alert.show("If you prefer green more...", [], {accentColor: "green"});
How to change the settings for only this alert. Note how actions
is empty, so only "OK" will be displayed.
-alert.show("This information is so important that it needs to be displayed instantly, instead of all other alerts!", [], {}, "replace");
This will clear the queue and display the alert instantly.
-alert.show("Dou you want to delete this photo? There is no going back!", ["Cancel", "OK"]).then(function(action) { if(action == "OK") { //delete the photo }});
Detect what action the user clicks with this pattern.
°Example: alert.hide();
°Example: alert.clearQueue();
alert.clearQueue();
before calling alert.hide();
.ripple-js
before importing alert-js
. If those uses don't fit your use case, you don't need to import ripple-js
, as it will be imported automatically.rippleOpacity
to 0
.FAQs
A small js library for alerts
We found that alert-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.