JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="Click Me" />
JavaScript
var newRowCollection = []; //this is your row id collection
$('input').on('click', function() {
_notify('Hello Bucky', '22', function() {
alert('Showing!!');
}, function() {
alert('Completed!!');
});
});
_notify(); //calling toast without any values
function _notify(_txt, _id, _callback1, _callback2) {
if (newRowCollection.indexOf(_id) == -1) {
$('#toastNotifier').remove();
_id !== undefined ? newRowCollection.push(_id) : '';
var toastNotifier = $('<div id="toastNotifier"></div>'),
toastText = $('<div class="toastText"></div>'),
toastBt = $('<div class="toastButton">✕</div>');
_txt == undefined ? _txt = 'Just Saying hi!!' : '';
toastNotifier.append(toastText.html(_txt)).append(toastBt);
toastNotifier.css({
'display': 'none',
'background': '#2D2D2D',
'position': 'absolute',
'left': '10px',
'bottom': '-50px',
'border': '1px solid # 000',
'box-shadow': '0px 0px 13px rgba(0, 0, 0, 0.42)',
'border-radius': '6px'
}).find(toastBt).css({
'display': 'inline-block',
'padding': '15px',
'font-weight': 'bold',
'color': '#737373',
'cursor': 'pointer'
}).end().find(toastText).css({
'display': 'inline-block',
'padding': '15px 10px',
'text-transform': 'uppercase',
'color': '#fff'
});
$('body').append(toastNotifier);
toastNotifier.show().animate({
bottom: '30px'
}, {
complete: function() {
if (_callback1 !== undefined && typeof _callback1 === "function") {
_callback1();
};
}
});
toastBt.on('click', function() {
if (_callback2 !== undefined && typeof _callback2 === "function") {
_callback2();
};
toastNotifier.remove();
});
//if statement closed here
} else {
alert('Row Id exists!!');
}
}