-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.dynForm.js
More file actions
654 lines (576 loc) · 23.6 KB
/
jquery.dynForm.js
File metadata and controls
654 lines (576 loc) · 23.6 KB
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/* **************************************
- add a form tag to your document
- define your dynForm with a jsonSchema defintion of each field input
- The process will then
- first build the specified HTML for each different field and input according to types
- bind any needed events according to types
- bind the save Process if needed
- apply any onLoad process
parameters :
formId : is the <form> tag in the destination html
formObj: is the form object containg the form field definition and jsonSchema
formValues: contains the values if needed
onLoad : (optional) is a function that is launched once the form has been created and written into the DOM
onSave: (optional) overloads the generic saveProcess
***************************************** */
(function($) {
"use strict";
var thisBody = document.body || document.documentElement,
thisStyle = thisBody.style,
$this,
initValues = {},
supportTransition = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
/*$(subviewBackClass).on("click", function(e) {
$.hideSubview();
e.preventDefault();
});*/
$.extend({
dynForm: function(options)
{
// extend the options from pre-defined values:
var defaults = {
formId : "",
formObj: {},
formValues: {},
onLoad : null,
onSave: null,
savePath : '/ph/common/save'
};
var settings = $.extend({}, defaults, options);
$this = this;
console.info("build Form dynamically into form tag : ",settings.formId);
console.dir(settings.formObj);
/* **************************************
* BUILD FORM based on formObj
***************************************** */
var form = {
rules : {}
};
var fieldHTML = '';
/* **************************************
* Error Section
***************************************** */
var errorHTML = '<div class="errorHandler alert alert-danger no-display">'+
'<i class="fa fa-remove-sign"></i> You have some form errors. Please check below.'+
'</div>';
$(settings.formId).append(errorHTML);
$.each(settings.formObj.jsonSchema.properties,function(field,fieldObj) {
if(fieldObj.rules)
form.rules[field] = fieldObj.rules;//{required:true}
buildInputField(settings.formId,field, fieldObj, settings.formValues);
});
/* **************************************
* CONTEXT ELEMENTS, used for saving purposes
***************************************** */
fieldHTML = '<input type="hidden" name="key" value="'+settings.formObj.key+'"/>';
fieldHTML += '<input type="hidden" name="collection" value="'+settings.formObj.collection+'"/>';
fieldHTML += '<input type="hidden" name="id" value="'+((settings.formObj.id) ? settings.formObj.id : "")+'"/>';
fieldHTML += '<div class="form-actions">'+
'<button type="submit" class="btn btn-green pull-right">'+
'Submit <i class="fa fa-arrow-circle-right"></i>'+
'</button>'+
'</div>';
$(settings.formId).append(fieldHTML);
/* **************************************
* bind any events Post building
***************************************** */
bindDynFormEvents(settings,form.rules);
if(settings.onLoad && jQuery.isFunction( settings.onLoad ) )
settings.onLoad();
return form;
},
/*buildForm: function() {
console.dir($this.formObj);
},*/
});
/* **************************************
*
* each input field type has a corresponding HTMl to build
*
***************************************** */
function buildInputField(id, field, fieldObj,formValues)
{
var fieldHTML = '<div class="form-group '+field+fieldObj.inputType+'">';
var required = "";
if(fieldObj.rules && fieldObj.rules.required)
required = "*";
if(fieldObj.label)
fieldHTML += '<label class=" control-label" for="'+field+'">'+
fieldObj.label+required+
'</label>';
var iconOpen = (fieldObj.icon) ? '<span class="input-icon">' : '';
var iconClose = (fieldObj.icon) ? '<i class="'+fieldObj.icon+'"></i> </span>' : '';
var placeholder = (fieldObj.placeholder) ? fieldObj.placeholder+required : '';
var placeholder2 = (fieldObj.placeholder2) ? fieldObj.placeholder2 : '';
var fieldClass = (fieldObj.class) ? fieldObj.class : '';
var initField = '';
var value = "";
var style = "";
if( fieldObj.value )
value = fieldObj.value;
else if (formValues && formValues[field])
value = formValues[field];
/* **************************************
*
***************************************** */
if( field.indexOf("separator")>=0 ) {
if(fieldClass == '' )
fieldClass = "panel-blue";
fieldHTML += '<div class="text-large text-bold '+fieldClass+' text-white center padding-10 ">'+iconOpen+iconClose+fieldObj.title+'</div>';
}
/* **************************************
* STANDARD TEXT INPUT
***************************************** */
else if( !fieldObj.inputType || fieldObj.inputType == "text" || fieldObj.inputType == "numeric" || fieldObj.inputType == "tags" ) {
if(fieldObj.inputType == "tags"){
fieldClass += " select2TagsInput";
initValues[field] = fieldObj.values;
style = "style='width:100%'"
}
fieldHTML += iconOpen+'<input type="text" class="form-control '+fieldClass+'" name="'+field+'" id="'+field+'" value="'+value+'" placeholder="'+placeholder+'" '+style+'/>'+iconClose;
}
/* **************************************
* HIDDEN
***************************************** */
else if( fieldObj.inputType == "hidden" || fieldObj.inputType == "timestamp" ) {
if ( fieldObj.inputType == "timestamp" )
value = Date.now();
fieldHTML += '<input type="hidden" name="'+field+'" id="'+field+'" value="'+value+'"/>';
}
/* **************************************
* TEXTAREA
***************************************** */
else if ( fieldObj.inputType == "textarea" || fieldObj.inputType == "wysiwyg" ){
if(fieldObj.inputType == "wysiwyg")
fieldClass += " wysiwygInput";
fieldHTML += '<textarea id="'+field+'" class="form-control '+fieldClass+'" name="'+field+'" placeholder="'+placeholder+'">'+value+'</textarea>';
}
/* **************************************
* CHECKBOX
***************************************** */
else if ( fieldObj.inputType == "checkbox" ) {
if(value == "")
value="25/01/2014";
var checked = ( fieldObj.checked ) ? "checked" : "";
fieldHTML += '<input type="checkbox" class="'+fieldClass+'" name="'+field+'" id="'+field+'" value="'+value+'" '+checked+'/> '+placeholder;
}
/* **************************************
* SELECT , we use select2
***************************************** */
else if ( fieldObj.inputType == "select" || fieldObj.inputType == "selectMultiple" ) {
var multiple = (fieldObj.inputType == "selectMultiple") ? 'multiple="multiple"' : '';
fieldHTML += '<select class="select2Input '+fieldClass+'" '+multiple+' name="'+field+'" id="'+field+'" style="width: 100%;height:30px" data-placeholder="'+placeholder+'">';
fieldHTML += '<option></option>';
$.each(fieldObj.options, function(optKey, optVal) {
selected = ( fieldObj.value && optVal == fieldObj.value ) ? "selected" : "";
fieldHTML += '<option value="'+optKey+'" '+selected+'>'+optVal+'</option>';
});
fieldHTML += '</select>';
}
/* **************************************
* DATE INPUT , we use bootstrap-datepicker
***************************************** */
else if ( fieldObj.inputType == "date" ) {
if(placeholder == "")
placeholder="25/01/2014";
fieldHTML += iconOpen+'<input type="text" class="form-control dateInput '+fieldClass+'" name="'+field+'" id="'+field+'" value="'+value+'" placeholder="'+placeholder+'"/>'+iconClose;
}
/* **************************************
* DATE RANGE INPUT
***************************************** */
else if ( fieldObj.inputType == "daterange" ) {
if(placeholder == "")
placeholder="25/01/2014";
fieldHTML += iconOpen+'<input type="text" class="form-control daterangeInput '+fieldClass+'" name="'+field+'" id="'+field+'" value="'+value+'" placeholder="'+placeholder+'"/>'+iconClose;
}
/* **************************************
* TIME INPUT , we use
***************************************** */
else if ( fieldObj.inputType == "time" ) {
if(placeholder == "")
placeholder="20:30";
fieldHTML += iconOpen+'<input type="text" class="form-control timeInput '+fieldClass+'" name="'+field+'" id="'+field+'" value="'+value+'" placeholder="'+placeholder+'"/>'+iconClose;
}
/* **************************************
* LINK
***************************************** */
else if ( fieldObj.inputType == "link" ) {
if(fieldObj.url.indexOf("http://") < 0 )
fieldObj.url = "http://"+fieldObj.url;
fieldHTML += '<a class="btn btn-primary '+fieldClass+'" href="'+fieldObj.url+'">Go There</a>';
}
/* **************************************
* ARRAY , is a list of sequential values
***************************************** */
else if ( fieldObj.inputType == "array" ) {
fieldHTML += '<div class="inputs array">'+
'<div class="col-sm-10">'+
'<input type="text" name="properties[]" class="addmultifield form-control input-md" value="" placeholder="'+placeholder+'"/>'+
'</div>'+
'<div class="col-sm-2">'+
'<button data-id="'+field+fieldObj.inputType+'" class="removePropLineBtn btn btn-xs btn-blue" alt="Remove this line"><i class=" fa fa-minus-circle" ></i></button>'+
'</div>'+
'</div>'+
'<span class="form-group '+field+fieldObj.inputType+'Btn">'+
'<div class="col-sm-12">'+
'<div class="space10"></div>'+
'<a href="javascript:;" data-id="'+field+fieldObj.inputType+'" class="addPropBtn btn btn-xs btn-blue" alt="Add a line"><i class=" fa fa-plus-circle" ></i></button> '+
'</div></span>'+
'<div class="space5"></div>';
initField = initMultiFields;
}
/* **************************************
* PROPERTIES , is a list of pairs key/values
***************************************** */
else if ( fieldObj.inputType == "properties" ) {
fieldHTML += '<div class="inputs properties">'+
'<div class="col-sm-3">'+
'<input type="text" name="properties[]" class="addmultifield form-control input-md" value="" placeholder="'+placeholder+'"/>'+
'</div>'+
'<div class="col-sm-7">'+
'<textarea type="text" name="values[]" class="addmultifield1 form-control input-md pull-left" onkeyup="AutoGrowTextArea(this);" placeholder="'+placeholder2+'"></textarea>'+
'<button data-id="'+field+fieldObj.inputType+'" class="pull-right removePropLineBtn btn btn-xs btn-blue" alt="Remove this line"><i class=" fa fa-minus-circle" ></i></button>'+
'</div>'+
'</div>'+
'<span class="form-group '+field+fieldObj.inputType+'Btn">'+
'<div class="col-sm-12">'+
'<div class="space10"></div>'+
'<a href="javascript:;" data-id="'+field+fieldObj.inputType+'" class="addPropBtn btn btn-xs btn-blue" alt="Add a line"><i class=" fa fa-plus-circle" ></i></button> '+
'</div></span>'+
'<div class="space5"></div>';
initField = initMultiFields;
}
/* **************************************
* CUSTOM
***************************************** */
else if ( fieldObj.inputType == "custom" ) {
fieldHTML += fieldObj.html;
}
else
fieldHTML += iconOpen+'<input type="text" class="form-control '+fieldClass+'" name="'+field+'" id="'+field+'" value="'+value+'" placeholder="'+placeholder+'"/>'+iconClose;
fieldHTML += '</div>';
$(id).append(fieldHTML);
if( fieldObj.init && $.isFunction(fieldObj.init) )
fieldObj.init(field+fieldObj.inputType);
else if(initField && $.isFunction(initField) )
initField ('.'+field+fieldObj.inputType);
}
/* **************************************
*
* any event to be initiated
*
***************************************** */
var afterDynBuildSave = null;
function bindDynFormEvents (params, formRules) {
/* **************************************
* FORM VALIDATION and save process binding
***************************************** */
console.info("connecting submit btn to $.validate pluggin");
console.dir(formRules);
var errorHandler = $('.errorHandler', $(params.formId));
$(params.formId).validate({
rules : formRules,
submitHandler : function(form) {
errorHandler.hide();
console.info("form submitted "+params.formId);
if(params.onSave && jQuery.isFunction( params.onSave ) ){
params.onSave();
return false;
}
else
{
console.info("default SaveProcess",params.savePath);
console.dir($(params.formId).serializeFormJSON());
$.ajax({
type: "POST",
url: params.savePath,
data: $(params.formId).serializeFormJSON(),
dataType: "json"
}).done( function(data){
if( afterDynBuildSave && typeof afterDynBuildSave == "function" )
afterDynBuildSave(data.map,data.id);
console.info('saved successfully !');
});
return false;
}
},
invalidHandler : function(event, validator) {//display error alert on form submit
errorHandler.show();
}
});
console.info("connecting any specific input event select2, datepicker...");
/* **************************************
* SELECTs , we use https://github.com/select2/select2
***************************************** */
if( $(".select2Input").length){
if( jQuery.isFunction(jQuery.fn.select2) )
$(".select2Input").select2();
else
console.error("select2 library is missing");
}
if( $(".select2TagsInput").length){
if( jQuery.isFunction(jQuery.fn.select2) )
$.each($(".select2TagsInput"),function () {
//console.log("id xxxxxxxxxxxxxxxxx ",$(this).attr("id"),initValues[$(this).attr("id")]);
$(this).removeClass("form-control").select2({
"tags": initValues[$(this).attr("id")],
"tokenSeparators": [',', ' ']
});
});
else
console.error("select2 library is missing");
}
/* **************************************
* DATE INPUT , we use https://github.com/eternicode/bootstrap-datepicker
***************************************** */
if( $(".dateInput").length){
if( jQuery.isFunction(jQuery.fn.datepicker) )
$(".dateInput").datepicker({
autoclose: true,
language: "fr",
format: "dd/mm/yy"
});
else
console.error("datepicker library is missing");
}
/* **************************************
* DATE RANGE INPUT , we use https://github.com/dangrossman/bootstrap-daterangepicker
***************************************** */
if( $(".daterangeInput").length){
if( jQuery.isFunction(jQuery.fn.daterangepicker) )
$('#reservationtime').daterangepicker({
timePicker: true,
timePickerIncrement: 30,
format: 'MM/DD/YYYY h:mm A'
}, function(start, end, label) {
console.log(start.toISOString(), end.toISOString(), label);
});
else
console.error("daterangepicker library is missing")
/*$('.daterangeInput').val(moment().format('DD/MM/YYYY h:mm A') + ' - ' + moment().add('days', 1).format('DD/MM/YYYY h:mm A'))
.daterangepicker({
startDate: moment(),
endDate: moment().add('days', 1),
timePicker: true,
timePickerIncrement: 30,
format: 'DD/MM/YYYY h:mm A'
});*/
}
/* **************************************
* PROPERTIES
***************************************** */
if( $(".addmultifield").length )
{
if( $(".addmultifield1").length )
$('head').append('<style type="text/css">.inputs textarea.addmultifield1{width:90%; height:34px;}</style>');
$('.addPropBtn').unbind("click").click(function()
{
var field = $(this).data('id');
if( $('.'+field+' .inputs .addmultifield:visible').length==0 || ( $("."+field+" .addmultifield:last").val() != "" && $( "."+field+" .addmultifield1:last" ).val() != "") )
addfield('.'+field);
else
toastr.info("please fill properties first");
} );
}
/* **************************************
* WYSIWYG
***************************************** */
if( $(".wysiwygInput").length )
{
$(".wysiwygInput").summernote({
oninit: function() {
/*if ($(this).code() == "" || $(this).code().replace(/(<([^>]+)>)/ig, "") == "") {
$(this).code($(this).attr("placeholder"));
}*/
}, onfocus: function(e) {
/*if ($(this).code() == $(this).attr("placeholder")) {
$(this).code("");
}*/
}, onblur: function(e) {
/*if ($(this).code() == "" || $(this).code().replace(/(<([^>]+)>)/ig, "") == "") {
$(this).code($(this).attr("placeholder"));
}*/
}, onkeyup: function(e) {},
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
]
});
}
}
/* **************************************
*
* specific methods for each type of input
*
***************************************** */
/* **************************************
* PROPERTIES , is a list of pairs key/values
***************************************** */
function addfield(parentContainer)
{
console.log("addfield",parentContainer);
if(!$.isEmptyObject($(parentContainer+' .inputs')))
{
if($(parentContainer+' .properties').length > 0)
$(propertyLineHTML( {"label":"","value":""} ) ).fadeIn('slow').appendTo(parentContainer+' .inputs');
else
$(arrayLineHTML("") ).fadeIn('slow').appendTo(parentContainer+' .inputs');
$(parentContainer+' .addmultifield:last').focus();
initMultiFields(parentContainer);
}else
console.error("container doesn't seem to exist : "+parentContainer+' .inputs');
}
function initMultiFields(parentContainer){
console.log("initMultiFields",parentContainer);
$(parentContainer+' .addmultifield').unbind('keydown').keydown(function(event)
{
if ( event.keyCode == 13)
{
event.preventDefault();
if( $(this).val() != ""){
if( $( this ).parent().next().children(".addmultifield1").val() != "" )
addfield(parentContainer);
else
$( this ).parent().next().children(".addmultifield1").focus();
}
else
toastr.warning("La paire (clef/valeure) doit etre remplie.");
}
});
$(parentContainer+' .addmultifield1').unbind('keydown').keydown(function(event)
{
if ( event.ctrlKey && event.keyCode == 13)
{
event.preventDefault();
if( $(this).val() != "" && $( this ).parent().prev().children(".addmultifield").val() != "" )
addfield(parentContainer);
else
toastr.warning("La paire (clef/valeure) doit etre remplie.");
}
});
$(parentContainer+' .removePropLineBtn').click(function(){
$(this).parent().prev().remove();
$(this).parent().remove();
});
}
function clearProperties(where)
{
$("#ajaxSV "+where+" .inputs").html("");
propertyLineHTML( {"label":"","value":""} );
}
function propertyLineHTML(propVal)
{
var str = '<div class="space5"></div><div class="col-sm-3">'+
'<input type="text" name="properties[]" class="addmultifield form-control input-md" value="'+propVal.label+'" />'+
'</div>'+
'<div class="col-sm-7">'+
'<textarea type="text" name="values[]" class="addmultifield1 form-control input-md pull-left" onkeyup="AutoGrowTextArea(this);" placeholder="valeur" >'+propVal.value+'</textarea>'+
'<button class="pull-right removePropLineBtn btn btn-xs btn-blue tooltips pull-right" data- data-original-title="Retirer cette ligne" data-placement="bottom"><i class=" fa fa-minus-circle" ></i></button>'+
'</div>';
return str;
}
function arrayLineHTML(val)
{
var str = '<div class="space5"></div><div class="col-sm-10">'+
'<input type="text" name="properties[]" class="addmultifield form-control input-md" value="'+val+'"/>'+
'</div>'+
'<div class="col-sm-2">'+
'<button class="pull-right removePropLineBtn btn btn-xs btn-blue tooltips pull-left" data- data-original-title="Retirer cette ligne" data-placement="bottom"><i class=" fa fa-minus-circle" ></i></button>'+
'</div>';
return str;
}
function drawPropertiesForm(list,where)
{
propHTML = "";
$.each( list , function(propKey,propVal){
propHTML += propertyLineHTML(propVal);
});
//console.info("editPerimeter",propHTML);
if(propHTML != "")
$("#ajaxSV "+where+" .inputs").html(propHTML);
}
})(jQuery);
$.fn.serializeFormJSON = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
/* **************************************
* PROPERTIES functions called externally
***************************************** */
// here's our click function for when the forms submitted
function getPairs(parentContainer)
{
//console.log("getPairs",parentContainer);
var properties = {};
$.each($(parentContainer+' .addmultifield'), function(i,el) {
if( $(this).val() != "" && $( this ).parent().next().children(".addmultifield1") != "" ){
properties[ slugify($(this).val()) ] = { "label" : $(this).val(),
"value" : $( this ).parent().next().children(".addmultifield1").val()};
}
});
//console.dir("getPairs",properties);
return properties;
}
function getArray(parentContainer)
{
//console.log("getArray",parentContainer);
var list = [];
$.each($(parentContainer+' .addmultifield'), function(i,el) {
if( $(this).val() != "" ){
list.push( $(this).val() );
}
});
//console.dir("getArray",list);
return list;
}
function AutoGrowTextArea(textField)
{
if (textField.clientHeight < textField.scrollHeight)
{
textField.style.height = textField.scrollHeight + "px";
if (textField.clientHeight < textField.scrollHeight)
{
textField.style.height =
(textField.scrollHeight * 2 - textField.clientHeight) + "px";
}
}
}
function slugify (value) {
var rExps=[
{re:/[\xC0-\xC6]/g, ch:'A'},
{re:/[\xE0-\xE6]/g, ch:'a'},
{re:/[\xC8-\xCB]/g, ch:'E'},
{re:/[\xE8-\xEB]/g, ch:'e'},
{re:/[\xCC-\xCF]/g, ch:'I'},
{re:/[\xEC-\xEF]/g, ch:'i'},
{re:/[\xD2-\xD6]/g, ch:'O'},
{re:/[\xF2-\xF6]/g, ch:'o'},
{re:/[\xD9-\xDC]/g, ch:'U'},
{re:/[\xF9-\xFC]/g, ch:'u'},
{re:/[\xC7-\xE7]/g, ch:'c'},
{re:/[\xD1]/g, ch:'N'},
{re:/[\xF1]/g, ch:'n'} ];
// converti les caractères accentués en leurs équivalent alpha
for(var i=0, len=rExps.length; i<len; i++)
value=value.replace(rExps[i].re, rExps[i].ch);
// 1) met en bas de casse
// 2) remplace les espace par des tirets
// 3) enleve tout les caratères non alphanumeriques
// 4) enlève les doubles tirets
return value.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^a-z0-9-]/g, '')
.replace(/\-{2,}/g,'-');
};