1(function ($) { 2 $.fn.formToWizard = function( options, cmdParam1 ) { 3 if( typeof options !== 'string' ) { 4 options = $.extend({ 5 submitButton: '', 6 showProgress: false, 7 showStepNo: true, 8 validateBeforeNext: null, 9 select: null, 10 progress: null, 11 nextBtnName: 'Suivant >', 12 prevBtnName: '< Précédent', 13 buttonTag: 'a', 14 nextBtnClass: 'btn next', 15 prevBtnClass: 'btn prev', 16 17 valSms: false, 18 afficheNav: true, 19 afficheButton: true, 20 typeForm: '' 21 }, options); 22 } 23 24 var element = this 25 , steps = $( element ).find( "fieldset" ) 26 , count = steps.size() 27 , submmitButtonName = "#" + options.submitButton 28 , commands = null; 29 30 if( typeof options !== 'string' ) { 31 //hide submit button initially 32 //$(submmitButtonName).hide(); 33 setTimeout(function () { 34 $(submmitButtonName).addClass('next').detach().appendTo("#step" + (steps.length - 1) + "commands"); 35 }, 500); 36 //assign options to current/selected form (element) 37 $(element).data('options', options); 38 39 /**************** Validate Options ********************/ 40 if(typeof(options.validateBeforeNext ) !== "function") 41 options.validateBeforeNext = function() { return true;}; 42 43 if(options.showProgress && typeof(options.progress) !== "function"){ 44 if(options.showStepNo ) 45 $(element).before("<ul id='steps' class='steps'></ul>"); 46 else if(options.afficheNav ) 47 $(element).before("<ul id='steps' class='steps breadcrumb'></ul>"); 48 else 49 $(element).before("<ul id='steps' class='steps hidden'></ul>"); 50 } 51 /************** End Validate Options ******************/ 52 steps.each(function(i) { 53 $(this).wrap('<div id="step' + i + '" class="stepDetails"></div>'); 54 $(this).append('<p id="step' + i + 'commands" class="commands"></p>'); 55 step = $(element).find("#step" + i); 56 if( options.showProgress && typeof(options.progress) !== "function") { 57 if( options.showStepNo ) 58 $(element).find("#steps").append("<li id='stepDesc" + i + "'>Step " + (i + 1) + "<span>" + $(this).find("legend").html() + "</span></li>"); 59 //$("#steps").append("<li id='stepDesc" + i + "'>Step " + (i + 1) + "<span>" + $(this).find("legend").html() + "</span></li>"); 60 else 61 $(element).find("#steps").append("<li id='stepDesc" + i + "'>" + $(this).find("legend").html() + "</li>"); 62 //$("#steps").append("<li id='stepDesc" + i + "'>" + $(this).find("legend").html() + "</li>"); 63 } 64 //console.log("i :"+i); 65 66 if (i == 0){ 67 // createNextButton(i); 68 // selectStep(i); 69 if(options.afficheButton >= 1 && options.typeForm == "" && i != count - 1)createNextButton(i); 70 selectStep(i); 71 }else if(i == count - 1){ 72 //$("#step" + i).hide(); 73 step.hide(); 74 //console.log("hide"); 75 if(options.afficheButton >= 1)createPrevButton(i); 76 }else{ 77 //$("#step" + i).hide(); 78 step.hide(); 79 //console.log("hide"); 80 if(options.afficheButton >= 1)createPrevButton(i); 81 if(options.afficheButton >= 1 && options.typeForm == "")createNextButton(i); 82 } 83 }); 84 if(options.valSms == true){ 85 $("#steps").append("<li id='stepDesc2'><a href='#'><span class='badge'>3</span> Validation SMS</a></li>"); 86 } 87 } else if( typeof options === 'string' ){ 88 var cmd = options; 89 initCommands(); 90 if( typeof commands[ cmd ] === 'function' ) { 91 commands[ cmd ]( cmdParam1 ); 92 } else { 93 throw cmd + ' is invalid command!'; 94 } 95 } 96 97 /******************** Command Methods ********************/ 98 function initCommands() { 99 //restore options object from form element 100 options = $( element ).data( 'options' ); 101 commands = { 102 GotoStep: function( stepNo ) { 103 var stepName = "step" + (--stepNo); 104 if( $( '#' + stepName )[ 0 ] === undefined ) { 105 throw 'Step No ' + stepNo + ' not found!'; 106 } 107 //if( $( '#' + stepName ).css( 'display' ) === 'none' ) { 108 if( $( element ).find( '#' + stepName ).css( 'display' ) === 'none' ){ 109 $( element ).find( '.stepDetails' ).hide(); 110 //$( '#' + stepName ).show(); 111 $( element ).find( '#' + stepName ).show(); 112 //console.log(stepName + 'show'); 113 selectStep( stepNo ); 114 } 115 }, 116 NextStep: function() { 117 //$( '.stepDetails:visible' ).find( 'a.next' ).click(); 118 $( element ).find( '.stepDetails:visible' ).find( 'a.next' ).click(); 119 }, 120 PreviousStep: function() { 121 //$( '.stepDetails:visible' ).find( 'a.prev' ).click(); 122 $( element ).find( '.stepDetails:visible' ).find( 'a.prev' ).click(); 123 } 124 }; 125 } 126 /******************** End Command Methods ********************/ 127 128 /******************** Private Methods ********************/ 129 function createPrevButton(i) { 130 var stepName = 'step' + i; 131 if(options.afficheButton == 2){ 132 btn = '<' + options.buttonTag + ' href="#" id="' + stepName + 'Prev" class="' + options.prevBtnClass + '">' + 133 options.prevBtnName + 134 '</' + options.buttonTag + '>'; 135 }else{ 136 btn = '<' + options.buttonTag + ' href="#" id="' + stepName + 'Prev" class="' + options.prevBtnClass + '">' + 137 options.prevBtnName + 138 '</' + options.buttonTag + '>'; 139 } 140 /* 141 $('#' + stepName + 'commands').append(btn); 142 $("#" + stepName + "Prev").bind("click", function(e) { 143 $("#" + stepName).hide(); 144 $("#step" + (i - 1)).show(); 145 selectStep(i - 1); 146 return false;
147 }); 148 */ 149 $(element).find('#' + stepName + 'commands').append(btn); 150 $(element).find("#" + stepName + "Prev").bind("click", function(e) { 151 $(element).find("#" + stepName).hide(); 152 $(element).find("#step" + (i - 1)).show(); 153 selectStep(i - 1); 154 return false; 155 }); 156 } 157 158 function createNextButton(i) { 159 var stepName = 'step' + i; 160 if(options.afficheButton == 2){ 161 btn = '<' + options.buttonTag + ' href="#" id="' + stepName + 'Next" class="' + options.nextBtnClass + '">' + 162 options.nextBtnName + 163 '</' + options.buttonTag + '>'; 164 }else{ 165 btn = '<' + options.buttonTag + ' href="#" id="' + stepName + 'Next" class="' + options.nextBtnClass + '">' + 166 options.nextBtnName + 167 '</' + options.buttonTag + '>'; 168 } 169 /* 170 $('#' + stepName + 'commands').append(btn); 171 $("#" + stepName + "Next").bind( "click", function(e) { 172 if( options.validateBeforeNext(element, $("#" + stepName)) === true ) { 173 $("#" + stepName).hide(); 174 $("#step" + (i + 1)).show(); 175 selectStep(i + 1); 176 } 177 return false; 178 }); 179 */ 180 $(element).find('#' + stepName + 'commands').append(btn); 181 $(element).find("#" + stepName + "Next").bind( "click", function(e) { 182 if( options.validateBeforeNext(element, $("#" + stepName)) === true ) { 183 $(element).find("#" + stepName).hide(); 184 $(element).find("#step" + (i + 1)).show(); 185 selectStep(i + 1); 186 } 187 return false; 188 }); 189 } 190 191 function selectStep(i) { 192 if ( typeof(options.progress) === "function" ) { 193 options.progress(i, count); 194 } else if( options.showProgress ) { 195 // $("#steps li").removeClass("current"); 196 // $("#stepDesc" + i).addClass("current"); 197 $(element).find("#steps li").removeClass("current"); 198 $(element).find("#stepDesc" + i).addClass("current"); 199 } 200 if( options.select ) { 201 options.select(element, $('#step'+i)); 202 } 203 } 204 /******************** End Private Methods ********************/ 205 return $( this ); 206 } 207})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.