Skip to content

Instantly share code, notes, and snippets.

@jhonsore
Created February 24, 2016 14:00
Show Gist options
  • Save jhonsore/d1f7c6c221d35f83b0f1 to your computer and use it in GitHub Desktop.
Save jhonsore/d1f7c6c221d35f83b0f1 to your computer and use it in GitHub Desktop.
Jquery Notification
<button class="bt bt-error">
<span>Add Notification Error</span>
</button>
<button class="bt bt-alert">
<span>Add Notification Alert</span>
</button>
<button class="bt bt-notif">
<span>Add Notification </span>
</button>
//Add notification
/*
* text:'It's tha message'
* timerClose:5000
* class:"alert"
* position: top-left / top-right / bottom-left/ bottom-right
*
*/
jQuery(document).ready(
function ()
{
$.notification = new Notification();
$('.bt-error').click(function(){
$.notification.callNotification({
text: 'Fill in mandatory fields!',
timerClose: 8000,
class: "error",
position:"bottom-right"
});
});
//------
$('.bt-alert').click(function(){
$.notification.callNotification({
text: 'Make some Alert!',
timerClose: 8000,
class: "alert",
position:"bottom-left"
});
});
//------
$('.bt-notif').click(function(){
$.notification.callNotification({
text: 'Some notification!',
timerClose: 8000,
position:"top-right"
});
});
});
//adiciona uma notificação simples por algum evento ocorrido
/*
* text:'Esta é a mensagem'
* timerClose:5000
* class:"alert"
* position: top-left / top-right / bottom-left/ bottom-right
*
* */
function Notification(){
"use strict";
}
Notification.prototype.constructor = Notification;
Notification.prototype.callNotification = function(__options__){
var defaults =
{
position : 'top-right'
};
if($('.wrapper-notification').length)
{
$('.wrapper-notification').remove();
}
var _options = $.extend(defaults, __options__)
var _html = "<div class='wrapper-notification "+_options.class+ " "+_options.position+"'>";
_html += "<div class='wrapper-notification-inner'><p class='wrapper-notification-text'>"+_options.text+"</p></div>";
_html += "<a class='wrapper-notification-close' href='#'><em class='spt spt-close-white'></em></a>";
_html += "</div>";
$('body').append(_html);
$('.wrapper-notification-close').click(function(){
$.notification.removeNotification();
return false;
});
$('.wrapper-notification').fadeIn(300);
if(_options.timerClose)
{
var _timer = setTimeout(function(){ $.notification.removeNotification();},_options.timerClose);
this.timeout = _timer;
}
}
Notification.prototype.removeNotification = function(__options__){
clearTimeout(this.timeout);
this.timeout = null;
$(".wrapper-notification").stop(true,true).fadeOut(300,function(){
$(".wrapper-notification").remove();
});
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
/*fonts*/
@import url('https://fonts.googleapis.com/css?family=Roboto:300');
/**/
body{ background-color:#fb8383;font-family: 'Roboto', sans-serif;}
/*reset button appearance*/
button{
background:none;
border: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
outline:none;
}
.bt{ cursor:pointer; margin:20px 0 0 20px; font-size:15px; color:#ffffff;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
background:#323232;
border-bottom: 3px solid #1e1d1d;}
.bt span{ padding:10px; display:block;}
.wrapper-notification{ background-color: #323232; width: 360px; position: fixed; z-index: 999999; display: none;
-webkit-box-shadow: 0px 3px 8px 0px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 0px 3px 8px 0px rgba(0, 0, 0, 0.4);
box-shadow: 0px 3px 8px 0px rgba(0, 0, 0, 0.4);}
.wrapper-notification.error{ background-color: #b10000;}
.wrapper-notification.alert{ background-color: #f1c40f;}
.bt-alert{ background-color: #f1c40f; border-color:#e3b602;}
.bt-error{background:#b10000;
border-bottom: 3px solid #9f0101;}
.wrapper-notification.alert .wrapper-notification-text{ color:#ffffff; font-weight:bold;}
.wrapper-notification .wrapper-notification-inner{ padding: 22px 40px 22px 25px;}
.wrapper-notification .wrapper-notification-text{ color: #ffffff; font-size:15px; line-height:20px;}
.wrapper-notification .wrapper-notification-close{ position: absolute; right: 20px; top: 50%; margin-top: -8px;}
.wrapper-notification .wrapper-notification-close em {width: 16px;height: 16px; display:block; background-image: url(data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUg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40OTF6IiBmaWxsPSIjRkZGRkZGIi8+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPC9zdmc+Cg==)}
.wrapper-notification.bottom-left{ bottom: 20px; left: 20px;}
.wrapper-notification.top-left{ top: 20px; left: 20px;}
.wrapper-notification.bottom-right{ bottom: 20px; right: 20px;}
.wrapper-notification.top-right{ top: 20px; right: 20px;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment