1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
| <!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0">
<meta name="author" content="Daniel Hagnoul">
<title>Forum jQuery</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/headjs/0.99/head.min.js"></script>
<script>
"use strict";
head.js(
"http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js",
"http://code.jquery.com/jquery-2.0.0.min.js",
"http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/i18n/jquery-ui-i18n.min.js",
"http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js",
"http://danielhagnoul.developpez.com/lib/dvjh/base.js",
function(){
/*
* Daniel Hagnoul
*
* Plugin jquery.dvjhDialogModal-1.0.0.js
*
* Code v1.0.0 2013-01-13
*
* Le plugin affiche un dialogue modal.
*
* Par défaut, le dialogue affiche un titre, un message
* et un bouton d'annulation.
*
* Le dialogue peut afficher : une division
* éditable (contenteditable), un formulaire (form) et
* des boutons.
*
* Voir les exemples sur :
* http://danielhagnoul.developpez.com/plugin-dvjh/dialogModal/dialogModal.php
*/
(function($){
$.dvjhDialogModal = function( options ){
var opts = $.extend( true, {}, $.dvjhDialogModal.defaults, options ),
jObjDialog = $( "<div/>", {
"id" : $.now(),
"css" : opts.objCSSDialogModal,
"html" : '<h1 class="dialogTitre">' + opts.titre + '</h1>' +
'<div class="dialogBox">' +
'<div class="dialogMessage">' + opts.message + '</div>' +
'<div class="dialogForm"></div>' +
'<div class="dialogButtons"></div>' +
'</div>'
}).appendTo( "body" ),
jObjVoileNoir = $( "<div/>", {
"css" : opts.objCSSVoileNoir
}).appendTo( "body" ),
jObjDialogTitre = $( ".dialogTitre", jObjDialog ),
jObjDialogMessage = $( ".dialogMessage", jObjDialog ),
jObjDialogBox = $( ".dialogBox", jObjDialog ),
jObjDialogForm = $( ".dialogForm", jObjDialog ),
jObjDialogButton = $( ".dialogButtons", jObjDialog ),
jObjDialogEditable = null,
jObjForm = null,
tabIndex = 0;
$.each( opts.boutons, function( key, obj ){
$( "<button/>", {
"tabIndex" : ++tabIndex,
"css" : opts.objCSSDialogButton,
"text" : key,
"click" : function( event ){
var strEditable = "",
strSerialize = "",
serializeArray = [];
if ( jObjDialogEditable ){
strEditable = jObjDialogEditable.text();
}
if ( jObjForm ){
strSerialize = jObjForm.serialize();
serializeArray = jObjForm.serializeArray();
}
obj( event, strEditable, strSerialize, serializeArray );
jObjDialog.remove();
jObjVoileNoir.remove();
}
}).appendTo( jObjDialogButton )
});
if ( opts.editable ){
jObjDialogForm
.append( '<div class="dialogEditable" contentEditable></div>' );
jObjDialogEditable = $( ".dialogEditable", jObjDialog );
jObjDialogEditable.attr( "tabIndex", ++tabIndex );
}
/*
* L'objet jQuery doit contenir un élément "<form>".
*/
if ( opts.form != null && opts.form[0].tagName == "FORM" ){
jObjDialogForm
.attr( "tabIndex", ++tabIndex )
.append( opts.form );
jObjForm = $( "form", jObjDialog );
}
jObjDialogTitre.css( opts.objCSSDialogTitre );
jObjDialogBox.css( opts.objCSSDialogBox );
jObjDialogMessage.css( opts.objCSSDialogMessage );
jObjDialogForm.css( opts.objCSSDialogForm );
if ( jObjDialogEditable ){
jObjDialogEditable.css( opts.objCSSDialogEditable );
}
/*
* Le dialogue modal doit avoir sa taille définitive
* avant le calcul de outerHeight et de outerWidth
*/
jObjDialog.css({
"margin-top" : -jObjDialog.outerHeight(true)/2,
"margin-left" : -jObjDialog.outerWidth(true)/2
}).fadeIn( 800 );
$( "[tabIndex='1']" ).trigger( "focus" );
jObjVoileNoir.fadeIn( 500 );
};
$.dvjhDialogModal.defaults = {
"objCSSVoileNoir" : {
"position" : "fixed",
"display" : "none",
"left" : 0,
"top" : 0,
"width" : "100%",
"height" : "100%",
"opacity" : "0.75",
"filter" : "alpha(opacity=80)",
"background" : "gray",
"zIndex" : 99998
},
"objCSSDialogModal" : {
"position" : "fixed",
"display" : "none",
"top" : "50%",
"left" : "50%",
"min-width" : "300px",
"max-width" : "600px",
"zIndex" : 99999,
"padding" : "6px",
"text-align" : "left",
"fontSize" : "12px",
"background" : "#fff",
"border" : "20px solid #ddd",
"boxShadow": "0px 0px 20px #000",
"borderRadius" : "10px"
},
"objCSSDialogTitre" : {
"text-align" : "center"
},
"objCSSDialogBox" : {
"text-align" : "left",
"padding" : "6px"
},
"objCSSDialogMessage" : {
"text-align" : "justify",
"padding" : "6px",
"hyphens": "auto"
},
"objCSSDialogForm" : {
"text-align" : "left",
"padding" : "6px"
},
"objCSSDialogEditable" : {
"padding" : "6px",
"height" : "60px",
"overflow" : "auto",
"border" : "1px solid orange",
"hyphens": "auto"
},
"objCSSDialogButton" : {
"margin" : "6px",
"padding" : "6px",
"float" : "right"
},
"titre" : "Titre du message",
"message" : "<p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis\
praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint\
occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia\
animi, id est laborum et dolorum fuga.</p>",
"editable" : false, // true ou false
"form" : null, // un objet jQuery contenant un formulaire ou null
"boutons" : {
"Annuler" : function(){}
}
};
})(jQuery);
$( function(){
var jObjForm = $( "<form/>", {
"class" : "monFormulaire"
}).append( $( "#formHidden" ).html() );
$( "#btn" ).on( "click", function(){
$.dvjhDialogModal({
"titre" : "Formulaire d'inscription",
"message" : "Veuillez remplir le formulaire",
"objCSSDialogModal" : {
"min-width" : "400px",
"max-width" : "800px",
},
"form" : jObjForm,
"boutons" : {
"OK" : function(){
/*
* Avant de détruire le dialogue et le voile noir le plugin appelle
* la fonction associée au bouton en lui transmettant 4 arguments :
* obj( event, strEditable, strSerialize, serializeArray );
* event : l'événement "click"
* strEditable : "" ou le texte contenu dans la division éditable
* strSerialize : "" ou le résultat de $( "form" ).serialize()
* serializeArray : "" ou le résultat de la méthode $( "form" ).serializeArray()
*
* arguments[ 2 ] pour strSerialize
*
* Exemple : "id=&nom=Hagnoul&prenom=Daniel&mail=danielhagnoul%4
rand&admin=1&resp_pedagog=0&par_defaut=0&bloque=0"
*/
// debug
console.log( arguments[ 2 ] )
/*
* Votre transaction AJAX
*/
},
"Refus" : function(){
alert( "Vous avez refusé de vous inscrire !")
// debug
console.log( arguments );
}
}
});
});
});
$( window ).load( function(){
});
}
);
</script>
<link href='http://fonts.googleapis.com/css?family=Sofia|Ubuntu:400|Kreon'>
<link rel="stylesheet" href="http://danielhagnoul.developpez.com/styles/dvjhRemBase.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/sunny/jquery-ui.min.css">
<style>
/* TEST -- Nota bene : ici 1 rem est égal à 1 px, voir dvjhRemBase.css */
.monFormulaire fieldset { border: 1px dotted grey; }
.monFormulaire label { display: block; margin: 6px; padding: 3px; }
</style>
</head>
<body>
<header>
<hgroup>
<h1>Forum jQuery</h1>
<h2>
<a href="">Lien</a>
</h2>
</hgroup>
</header>
<section class="conteneur">
<button id="btn">Formulaire dans un dialogue modal.</button>
<div id="formHidden" style="display:none">
<fieldset id="leftpop">
<input type="hidden" name="id" value="">
<label class="libelle">Nom :<input type="text" name="nom" id="nomM" value="" /></label>
<label class="libelle">Prénom :<input type="text" name="prenom" id="prenomM" value="" /></label>
<label class="libelle">Adresse Mail :<input type="text" name="mail" value="" /></label>
<label class="libelle">Langue :<input type="text" name="langue" value="" /></label>
<label class="libelle">Poste:<input type="text" name="poste" value="" /></label>
<label class="libelle">Login :<input type="text" name="login" value="" /></label>
<label class="libelle">Mot de passe :<input type="text" name="mdp" value="" /></label>
</fieldset>
<fieldset id="rightpop">
<label class="libelle">Administrateur :
<select name="admin" class="libelle">
<option value="1" checked="checked">Oui</option>
<option value="0">Non</option>
</select>
</label>
<label class="libelle">Responsable Pédagogique :
<select name="resp_pedagog" class="libelle">
<option value="1" checked="checked">Oui</option>
<option value="0">Non</option>
</select>
</label>
<label class="libelle">Par défaut :
<select name="par_defaut" class="libelle">
<option value="1" checked="checked">Oui</option>
<option value="0">Non</option>
</select>
</label>
<label class="libelle">Bloquer l'accès :
<select name="bloque" class="libelle">
<option value="1" checked="checked">Oui</option>
<option value="0">Non</option>
</select>
</label>
</fieldset>
</div>
</section>
<footer itemscope itemtype="http://danielhagnoul.developpez.com/">
<time datetime="2013-06-05T01:40:03.201+02:00" pubdate>2013-06-05T01:40:03.201+02:00</time>
<span itemprop="name">Daniel Hagnoul</span>
<a href="http://www.developpez.net/forums/u285162/danielhagnoul/" itemprop="url">@danielhagnoul</a>
<a href="http://danielhagnoul.developpez.com/" itemprop="url">Mon cahier dexercices</a>
<a href="http://javascript.developpez.com/faq/jquery/" itemprop="url">FAQ</a>
<a href="http://javascript.developpez.com/cours/?page=frameworks#jquery" itemprop="url">Tutoriels</a>
</footer>
</body>
</html> |
Partager