/** * @author mvideaud */ jQuery(function($) { $.fn.notification = function(options) { var options = $.extend({ fixe : false, type : "info", contenu : "Ma super notification.", delai : 5000, }, options); var iconeBootstrap = null; var alertBootstrap = null; switch(options.type) { case 'success': iconeBootstrap = 'check'; alertBootstrap = 'success'; break; case 'confirm': iconeBootstrap = 'check'; alertBootstrap = 'confirm'; break; case 'error': iconeBootstrap = 'times'; alertBootstrap = 'danger'; break; case 'warning' : iconeBootstrap = 'warning'; alertBootstrap = 'warning'; break; default: iconeBootstrap = 'info'; alertBootstrap = 'info'; break; } var notification = $('
'); var timerSeconds = 0; var timerFinish = 0; var timer = null; return this.each(function() { var self = $(this); //recherche si notifications existe var notifications = $('.notifications', self); // si absent -> injection if(notifications.length == 0){ notifications = $(''); self.append(notifications); } // insertion de la notification notifications.append(notification); // ajout modal-backdrop if(options.fixe == true) { $('header').prepend(''); } // ajout fermeture manuelle if(options.fixe == true) { var close = $(''); notification.prepend(close); // fermer une notification au click close.click(function(e){ e.preventDefault(); fermer(); }); } // fermer une notification au délai si celle-ci n'est pas fixe if(options.fixe == false) { //lancement du timer timerSeconds = options.delai/1000; timerFinish = new Date().getTime()+(timerSeconds*1000); timer = setInterval(function(){ stopWatch(); }, 50); drawTimer(100); setTimeout(function () { fermer(); }, options.delai); } function fermer() { notification.addClass('bounceOutUp').delay(500).fadeOut(300, function(){ notification.remove(); $('.modal-backdrop').remove(); }); } function drawTimer(percent){ $('div.timer').html('