Notifications
Notifications
The Notifications shortcode shows Bootstrap toast messages triggered by a click. Configure the message, type, position, and behavior with data-notify-* attributes and call the module from an onclick handler. Toasts are built and injected automatically, so you do not need to hand-write toast markup for the self-trigger mode.
Basic notification
Attach the attributes to any clickable element and invoke SEMICOLON.Modules.notifications(this) on click.
<a href="#" class="btn btn-info"
data-notify-type="info"
data-notify-msg="<i class='bi-info-circle-fill me-1'></i> Welcome to Canvas!"
onclick="SEMICOLON.Modules.notifications(this); return false;">Show Info</a>Key attributes
- data-notify-msg: the message HTML shown in the toast. Inline icons are fine.
- data-notify-type:
primary,info,success,warning,error, ordark. Controls the color scheme. - data-notify-position:
top-left,top-center,top-right(default),middle-left,middle-center,middle-right,bottom-left,bottom-center,bottom-right. - data-notify-timeout: auto-hide delay in milliseconds. Default
5000. - data-notify-autohide: set to
falseto keep the toast until manually closed. - data-notify-close: set to
falseto hide the close button. - data-notify-trigger:
self(default, plugin builds the toast) orcustom(you supply an existing toast viadata-notify-target). - data-notify-target: for
customtrigger, the selector of your own toast element.
Notification types
Each type maps to a Bootstrap background and matching text color.
<a href="#" class="btn btn-success me-2"
data-notify-type="success"
data-notify-msg="<i class='bi-check-circle-fill me-1'></i> Message Sent Successfully!"
onclick="SEMICOLON.Modules.notifications(this); return false;">Show Success</a>
<a href="#" class="btn btn-danger me-2"
data-notify-type="error"
data-notify-msg="<i class='bi-x-circle-fill me-1'></i> Incorrect Input. Please Try Again!"
onclick="SEMICOLON.Modules.notifications(this); return false;">Show Error</a>
<a href="#" class="btn btn-warning me-2"
data-notify-type="warning"
data-notify-msg="<i class='bi-exclamation-circle-fill me-1'></i> Please double-check your entry."
onclick="SEMICOLON.Modules.notifications(this); return false;">Show Warning</a>Positioning
<a href="#" class="btn btn-secondary"
data-notify-position="bottom-center"
data-notify-type="info"
data-notify-msg="<i class='bi-info-circle-fill me-1'></i> Saved to your list."
onclick="SEMICOLON.Modules.notifications(this); return false;">Bottom Center</a>Custom target (your own toast markup)
Use data-notify-trigger="custom" and point data-notify-target at a Bootstrap toast you have already placed in the page.
<button type="button" class="btn btn-primary"
data-notify-trigger="custom"
data-notify-target="#liveToast"
onclick="SEMICOLON.Modules.notifications(this); return false;">Show Notification</button>
<div class="position-fixed bottom-0 end-0 p-3 text-start" style="z-index: 699;">
<div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto">Hello!</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">Hello, world! This is a Notification!</div>
</div>
</div>Tips
- The
infoandwarningtypes use dark text, so the plugin automatically skips the white close-button styling for them. - Only one self-triggered toast shows at a time: opening a new one hides any existing toasts first.
- Set
data-notify-autohide="false"for messages users must dismiss themselves (for example a critical error). - Include an icon inside
data-notify-msg(likebi-check-circle-fill) for clearer, friendlier notifications.
Usage
<a href="#" class="btn btn-info" data-notify-type="info" data-notify-msg="<i class=icon-info-sign></i> Welcome to Canvas Demo!" onclick="SEMICOLON.widget.notifications(this); return false;">Show Info</a>Settings
| Setting | Description |
|---|---|
data-notify-position | Defines the Position of the Notification Message. Definable Options are as follows: Example: top-right |
data-notify-type | Defines the Type/Color of the Notification Message. Definable Options are as follows Example: info |
data-notify-timeout | Timeout in milliseconds for the Notification Example: 5000 |
data-notify-msg | Sets the Content of the Notification Message in HTML. Example: data-notify-msg="<i class=icon-info-sign> Welcome to Canvas Demo!" |
data-notify-close | Shows a Close Button in the Notification Box. Example: true |
Extras
Trigger a Bootstrap toast notification from any element using data-notify-* attributes. Canvas builds and shows the toast on click.
<button class="button"
data-notify-msg="Your changes have been saved."
data-notify-type="success"
data-notify-position="top-right"
data-notify-timeout="5000">
Show Notification
</button>Attributes read by the Notifications module:
data-notify-msg: message HTML (required).data-notify-type:primary,success,warning,error,info, ordark.data-notify-position:top-left,top-center,top-right,middle-left,middle-center,middle-right,bottom-left,bottom-center,bottom-right.data-notify-timeout: auto-hide delay in ms (default5000).data-notify-autohide:true/false.data-notify-close:true/falseto show the close button.
Set data-notify-trigger="custom" when the toast markup already exists in the page and you only want Canvas to show it.
