Advertisement
rAthus

Fonction "patientez()"

Mar 12th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Fonction "patientez()" par rAthus, permet de masquer un élément avec un message d'attente, nécessite jQuery. */
  2. /* Exemple d'utilisation : */
  3. /* Sur un formulaire d'inscription, au submit : */
  4. /** var uniqid = patientez("Nous enregistrons votre inscription...","#formulaire"); **/
  5. /* Et lorsque l'inscription est enregistrée : */
  6. /** $('#'+uniqid).remove(); **/
  7.  
  8. patientez = function(message,target)
  9. {
  10.     if (typeof(message)!='undefined' && typeof(target)!='undefined')
  11.     {
  12.         if (typeof(target)=='string')
  13.             var obj = $(target);
  14.         else if (typeof(target)=='object')
  15.             var obj = target;
  16.         else
  17.             console.log("Erreur lors de la déclaration de la cible pour la fonction patientez() : "+target);
  18.         var rand = Math.random()*10;
  19.         uniqid = 'patientez_'+rand.toString().replace('.','');
  20.         $('body').append('<div id="'+uniqid+'" style="background: rgba(255,255,255,0.9); position: absolute; left: '+$(target).offset().left+'px; top: '+$(target).offset().top+'px; width: '+$(target).outerWidth()+'px; height: '+$(target).outerHeight()+'px; z-index: 1000000; line-height: '+$(target).outerHeight()+'px; color: #000; text-align: center; font-size: 14px; text-shadow: 2px 0 0 #fff, -2px 0 0 #fff, 0 2px 0 #fff, 0 -2px 0 #fff, 1px 1px #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;"><img src="images/ajax-loader-gris.gif" style="vertical-align: middle; margin-top: -3px; margin-right: 10px;" /> '+message+'</div>');
  21.         return uniqid;
  22.     }
  23.     else
  24.     {
  25.         console.log("Erreur lors de l'appel de la fonction patientez()");
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement