The simplest way to use this script is to use the helper functions:
JP.Notices.success_notice
JP.Notices.process_notice
JP.Notices.error_notice
Each of those takes one argument, the message to display. The above example was called with this code:
JP.Notices.success_notice('You have Displayed a Success Notice');
The success and error notices will automatically disappear after a bit (2.5 seconds by default), while the process notice will stay visible until it’s removed.
The notices is configured through the use of a JP.Notices.config object. If needed you can also pass a custom config object to the display function.
Configuration Attributes
Name
Type
Default Value
Description
close_icon
string
null
The close icon to be displayed. Generally just used in the config options passed to the display method.
duration
int
2500
How long the notices should be displayed by default in milliseconds.
icon_path
string
''
This is the path to where the icons can be found for the ajax_loader and the close icons.
notices_div
string
jp-notices
This is the id of the div that the notices will be placed in. If the div doesn't exist it will be created automatically.
show_close
boolean
true
If true it will show the close icon for each individual notice, if false the icon won't be shown.
show_spinner
boolean
false
Whether or not the spinner should be shown. Generally just used in the config options passed to the display method.
Methods
display
This function actually displays the notice and returns the id of the newly created notice.
Parameters:
msg - (string) The message to be displayed
css_class - (string) The CSS class to apply to this notice
duration - (int) The time in milliseconds that the notice should be visible before closing, if 0 then it will stay visible until specifically closed.
config - (object) a custom config object for specifying additional parameters
Returns: string (the notice id)
error_notice
This method displays a notice with the css class of ‘error’ and returns the id of the created notice. Only the “msg” parameter is required.
Parameters:
msg - (string) The message to be displayed
duration - (int) The time in milliseconds that the notice should be visible before closing, if 0 then it will stay visible until specifically closed.
Returns: string
process_notice
This method displays a notice with the css class of ‘processing’ that will be displayed until specifically removed. It returns the id of the created notice.
Parameters:
msg - (string) The message to be displayed
Returns: string
remove
This removes notice corresponding to the id passed so that notice is no longer displayed.
Parameters:
notice - (string) The id of the notice to be removed.
Returns: nothing
success_notice
This method displays a notice with the css class of ‘success’ and returns the id of the created notice. Only the “msg” parameter is required.
Parameters:
msg - (string) The message to be displayed
duration - (int) The time in milliseconds that the notice should be visible before closing, if 0 then it will stay visible until specifically closed.