Skip to content

Commit c52f881

Browse files
authored
Positioning (#26)
Introduces positioning for top-center and bottom-center.
1 parent eb73e85 commit c52f881

8 files changed

Lines changed: 27 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Modify the global variables to apply specific rules/styles to all your toasts.
1717

1818
```javascript
1919
$.toastDefaults = {
20-
position: 'top-right', /** top-left/top-right/bottom-left/bottom-right - Where the toast will show up **/
20+
position: 'top-right', /** top-left/top-right/top-center/bottom-left/bottom-right/bottom-center - Where the toast will show up **/
2121
dismissible: true, /** true/false - If you want to show the button to dismiss the toast manually **/
2222
stackable: true, /** true/false - If you want the toasts to be stackable **/
2323
pauseDelayOnHover: true, /** true/false - If you want to pause the delay of toast when hovering over the toast **/

dist/toast.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/toast.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ <h3 class="text-center">A jQuery plugin for Bootstrap 4.2+</h3>
163163
'warning': 'It\'s all about to go wrong',
164164
'error': 'It all went wrong.'
165165
},
166-
POSITION = ['top-right', 'top-left', 'bottom-right', 'bottom-left'];
166+
POSITION = ['top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center'];
167167

168-
$.toastDefaults.position = POSITION[Math.floor(Math.random() * POSITION.length)];
168+
$.toastDefaults.position = 'bottom-center';
169169
$.toastDefaults.dismissible = true;
170170
$.toastDefaults.stackable = true;
171171
$.toastDefaults.pauseDelayOnHover = true;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bs4-toast",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Toast - A Bootstrap 4.2+ jQuery plugin for the toast component",
55
"main": "dist/toast.min.js",
66
"repository": {

src/css/toast.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author Script47 (https://github.com/Script47/Toast)
33
* @description Toast - A Bootstrap 4.2+ jQuery plugin for the toast component
4-
* @version 1.0.0
4+
* @version 1.1.0
55
**/
66
.toast-container {
77
position: fixed;
@@ -19,6 +19,12 @@
1919
left: 0;
2020
}
2121

22+
.top-center {
23+
transform: translateX(-50%);
24+
top: 0;
25+
left: 50%;
26+
}
27+
2228
.bottom-right {
2329
right: 0;
2430
bottom: 0;
@@ -29,6 +35,12 @@
2935
bottom: 0;
3036
}
3137

38+
.bottom-center {
39+
transform: translateX(-50%);
40+
bottom: 0;
41+
left: 50%;
42+
}
43+
3244
.toast-container > .toast {
3345
min-width: 150px;
3446
background: transparent;

src/js/toast.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author Script47 (https://github.com/Script47/Toast)
33
* @description Toast - A Bootstrap 4.2+ jQuery plugin for the toast component
4-
* @version 1.0.0
4+
* @version 1.1.0
55
**/
66
(function ($) {
77
const TOAST_CONTAINER_HTML = `<div id="toast-container" class="toast-container" aria-live="polite" aria-atomic="true"></div>`;
@@ -29,7 +29,7 @@
2929
function render(opts) {
3030
/** No container, create our own **/
3131
if (!$('#toast-container').length) {
32-
const position = ['top-right', 'top-left', 'bottom-right', 'bottom-left'].includes($.toastDefaults.position) ? $.toastDefaults.position : 'top-right';
32+
const position = ['top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center'].includes($.toastDefaults.position) ? $.toastDefaults.position : 'top-right';
3333

3434
$('body').prepend(TOAST_CONTAINER_HTML);
3535
$('#toast-container').addClass(position);

0 commit comments

Comments
 (0)