Вход Регистрация
Файл: js/jquery.smartWizard-2.0.js
Строк: 356
<?php
/*
 * SmartWizard 2.0 plugin
 * jQuery Wizard control Plugin
 * by Dipu 
 * 
 * http://www.techlaboratory.net 
 * http://tech-laboratory.blogspot.com
 */
 
(function($){
    $.
fn.smartWizard = function(action) {
        var 
options = $.extend({}, $.fn.smartWizard.defaultsaction);
        var 
args arguments;
        
        return 
this.each(function(){
                var 
obj = $(this);
                var 
curStepIdx options.selected;
                var 
steps = $("ul > li > a"obj); // Get all anchors in this array
                
var contentWidth 0;
                var 
loader,msgBox,elmActionBar,elmStepContainer,btNext,btPrevious,btFinish;
                
                
elmActionBar = $('.actionBar',obj);
                if(
elmActionBar.length == 0){
                  
elmActionBar = $('<div></div>').addClass("actionBar");                
                }

                
msgBox = $('.msgBox',obj);
                if(
msgBox.length == 0){
                  
msgBox = $('<div class="msgBox"><div class="content"></div><a href="#" class="close">X</a></div>');
                  
elmActionBar.append(msgBox);                
                }
                
                $(
'.close',msgBox).click(function() {
                    
msgBox.fadeOut("normal");
                    return 
false;
                });
                

                
// Method calling logic
                
if (!action || action === 'init' || typeof action === 'object') {
                  
init();
                }else if (
action === 'showMessage') {
                  
//showMessage(Array.prototype.slice.call( args, 1 ));
                  
var ar =  Array.prototype.slice.callargs);
                  
showMessage(ar[0]);
                  return 
true;
                }else if (
action === 'setError') {
                  var 
ar =  Array.prototype.slice.callargs);
                  
setError(ar[0].stepnum,ar[0].iserror);
                  return 
true;
                } else {
                  $.
error'Method ' +  action ' does not exist' );
                }
                
                function 
init(){
                  var 
allDivs =obj.children('div'); //$("div", obj);                
                  
obj.children('ul').addClass("anchor");
                  
allDivs.addClass("content");
                  
// Create Elements
                  
loader = $('<div>Loading</div>').addClass("loader");
                  
elmActionBar = $('<div></div>').addClass("actionBar");
                  
elmStepContainer = $('<div></div>').addClass("stepContainer");
                  
btNext = $('<a class="btn">'+options.labelNext+'</a>').attr("href","#").addClass("buttonNext");
                  
btPrevious = $('<a class="btn">'+options.labelPrevious+'</a>').attr("href","#").addClass("buttonPrevious");
                  
btFinish = $('<a class="btn">'+options.labelFinish+'</a>').attr("href","#").addClass("buttonFinish");
                  
                  
// highlight steps with errors
                  
if(options.errorSteps && options.errorSteps.length>0){
                    $.
each(options.errorSteps, function(in){
                      
setError(n,true);
                    });
                  }


                  
elmStepContainer.append(allDivs);
                  
elmActionBar.append(loader);
                  
obj.append(elmStepContainer);
                  
obj.append(elmActionBar); 
                  
elmActionBar.append(btFinish).append(btNext).append(btPrevious); 
                  
contentWidth elmStepContainer.width();

                  $(
btNext).click(function() {
                      
doForwardProgress();
                      return 
false;
                  }); 
                  $(
btPrevious).click(function() {
                      
doBackwardProgress();
                      return 
false;
                  }); 
                  $(
btFinish).click(function() {
                      if(!$(
this).hasClass('disabled')){
                         if($.
isFunction(options.onFinish)) {
                            if(!
options.onFinish.call(this,$(steps))){
                              return 
false;
                            }
                         }else{
                           var 
frm obj.parents('form');
                           if(
frm && frm.length){
                             
frm.submit();
                           }                         
                         }                      
                      }

                      return 
false;
                  }); 
                  
                  $(
steps).bind("click", function(e){
                      if(
steps.index(this) == curStepIdx){
                        return 
false;                    
                      }
                      var 
nextStepIdx steps.index(this);
                      var 
isDone steps.eq(nextStepIdx).attr("isDone") - 0;
                      if(
isDone == 1){
                        
LoadContent(nextStepIdx);                    
                      }
                      return 
false;
                  }); 
                  
                  
// Enable keyboard navigation                 
                  
if(options.keyNavigation){
                      $(
document).keyup(function(e){
                          if(
e.which==39){ // Right Arrow
                            
doForwardProgress();
                          }else if(
e.which==37){ // Left Arrow
                            
doBackwardProgress();
                          }
                      });
                  }
                  
//  Prepare the steps
                  
prepareSteps();
                  
// Show the first slected step
                  
LoadContent(curStepIdx);                  
                }

                function 
prepareSteps(){
                  if(!
options.enableAllSteps){
                    $(
stepsobj).removeClass("selected").removeClass("done").addClass("disabled"); 
                    $(
stepsobj).attr("isDone",0);                 
                  }else{
                    $(
stepsobj).removeClass("selected").removeClass("disabled").addClass("done"); 
                    $(
stepsobj).attr("isDone",1); 
                  }

                    $(
stepsobj).each(function(i){
                        $($(
this).attr("href"), obj).hide();
                        $(
this).attr("rel",i+1);
                  });
                }
                
                function 
LoadContent(stepIdx){
                    var 
selStep steps.eq(stepIdx);
                    var 
ajaxurl options.contentURL;
                    var 
hasContent =  selStep.data('hasContent');
                    
stepNum stepIdx+1;
                    if(
ajaxurl && ajaxurl.length>0){
                       if(
options.contentCache && hasContent){
                           
showStep(stepIdx);                          
                       }else{
                           $.
ajax({
                            
urlajaxurl,
                            
type"POST",
                            
data: ({step_number stepNum}),
                            
dataType"text",
                            
beforeSend: function(){ loader.show(); },
                            
error: function(){loader.hide();},
                            
success: function(res){ 
                              
loader.hide();       
                              if(
res && res.length>0){  
                                 
selStep.data('hasContent',true);            
                                 $($(
selStepobj).attr("href"), obj).html(res);
                                 
showStep(stepIdx);
                              }
                            }
                          }); 
                      }
                    }else{
                      
showStep(stepIdx);
                    }
                }
                
                function 
showStep(stepIdx){
                    var 
selStep steps.eq(stepIdx); 
                    var 
curStep steps.eq(curStepIdx);
                    if(
stepIdx != curStepIdx){
                      if($.
isFunction(options.onLeaveStep)) {
                        if(!
options.onLeaveStep.call(this,$(curStep))){
                          return 
false;
                        }
                      }
                    }     
                    
elmStepContainer.height($($(selStepobj).attr("href"), obj).outerHeight());               
                    if(
options.transitionEffect == 'slide'){
                      $($(
curStepobj).attr("href"), obj).slideUp("fast",function(e){
                            $($(
selStepobj).attr("href"), obj).slideDown("fast");
                            
curStepIdx =  stepIdx;                        
                            
SetupStep(curStep,selStep);
                          });
                    } else if(
options.transitionEffect == 'fade'){                      
                      $($(
curStepobj).attr("href"), obj).fadeOut("fast",function(e){
                            $($(
selStepobj).attr("href"), obj).fadeIn("fast");
                            
curStepIdx =  stepIdx;                        
                            
SetupStep(curStep,selStep);                           
                          });                    
                    } else if(
options.transitionEffect == 'slideleft'){
                        var 
nextElmLeft 0;
                        var 
curElementLeft 0;
                        if(
stepIdx curStepIdx){
                            
nextElmLeft1 contentWidth 10;
                            
nextElmLeft2 0;
                            
curElementLeft - $($(curStepobj).attr("href"), obj).outerWidth();
                        } else {
                            
nextElmLeft1 - $($(selStepobj).attr("href"), obj).outerWidth() + 20;
                            
nextElmLeft2 0;
                            
curElementLeft 10 + $($(curStepobj).attr("href"), obj).outerWidth();
                        }
                        if(
stepIdx == curStepIdx){
                            
nextElmLeft1 = $($(selStepobj).attr("href"), obj).outerWidth() + 20;
                            
nextElmLeft2 0;
                            
curElementLeft - $($(curStepobj).attr("href"), obj).outerWidth();                           
                        }else{
                            $($(
curStepobj).attr("href"), obj).animate({left:curElementLeft},"fast",function(e){
                              $($(
curStepobj).attr("href"), obj).hide();
                            });                       
                        }

                        $($(
selStepobj).attr("href"), obj).css("left",nextElmLeft1);
                        $($(
selStepobj).attr("href"), obj).show();
                        $($(
selStepobj).attr("href"), obj).animate({left:nextElmLeft2},"fast",function(e){
                          
curStepIdx =  stepIdx;                        
                          
SetupStep(curStep,selStep);                      
                        });
                    } else{
                        $($(
curStepobj).attr("href"), obj).hide(); 
                        $($(
selStepobj).attr("href"), obj).show();
                        
curStepIdx =  stepIdx;                        
                        
SetupStep(curStep,selStep);
                    }
                    return 
true;
                }
                
                function 
SetupStep(curStep,selStep){
                   $(
curStepobj).removeClass("selected");
                   $(
curStepobj).addClass("done");
                   
                   $(
selStepobj).removeClass("disabled");
                   $(
selStepobj).removeClass("done");
                   $(
selStepobj).addClass("selected");
                   $(
selStepobj).attr("isDone",1);
                   
adjustButton();
                   if($.
isFunction(options.onShowStep)) {
                      if(!
options.onShowStep.call(this,$(selStep))){
                        return 
false;
                      }
                   } 
                }                
                
                function 
doForwardProgress(){
                  var 
nextStepIdx curStepIdx 1;
                  if(
steps.length <= nextStepIdx){
                    if(!
options.cycleSteps){
                      return 
false;
                    }                  
                    
nextStepIdx 0;
                  }
                  
LoadContent(nextStepIdx);
                }
                
                function 
doBackwardProgress(){
                  var 
nextStepIdx curStepIdx-1;
                  if(
nextStepIdx){
                    if(!
options.cycleSteps){
                      return 
false;
                    }
                    
nextStepIdx steps.length 1;
                  }
                  
LoadContent(nextStepIdx);
                }  
                
                function 
adjustButton(){
                  if(!
options.cycleSteps){                
                    if(
>= curStepIdx){
                      $(
btPrevious).addClass("disabled");
                    }else{
                      $(
btPrevious).removeClass("disabled");
                    }
                    if((
steps.length-1) <= curStepIdx){
                      $(
btNext).addClass("disabled");
                    }else{
                      $(
btNext).removeClass("disabled");
                    }
                  }
                  
// Finish Button 
                  
if(!steps.hasClass('disabled') || options.enableFinishButton){
                    $(
btFinish).removeClass("disabled");
                  }else{
                    $(
btFinish).addClass("disabled");
                  }                  
                }
                
                function 
showMessage(msg){
                  $(
'.content',msgBox).html(msg);
                      
msgBox.show();
                }
                
                function 
setError(stepnum,iserror){
                  if(
iserror){                    
                    $(
steps.eq(stepnum-1), obj).addClass('error')
                  }else{
                    $(
steps.eq(stepnum-1), obj).removeClass("error");
                  }                                   
                }                        
        });  
    };  
 
    
// Default Properties and Events
    
$.fn.smartWizard.defaults = {
          
selected0,  // Selected Step, 0 = first step   
          
keyNavigationtrue// Enable/Disable key navigation(left and right keys are used if enabled)
          
enableAllStepsfalse,
          
transitionEffect'fade'// Effect on navigation, none/fade/slide/slideleft
          
contentURL:null// content url, Enables Ajax content loading
          
contentCache:true// cache step contents, if false content is fetched always from ajax url
          
cycleStepsfalse// cycle step navigation
          
enableFinishButtonfalse// make finish button enabled always
          
errorSteps:[],    // Array Steps with errors
          
labelNext:'Далее',
          
labelPrevious:'Назад',
          
labelFinish:'Готово',          
          
onLeaveStepnull// triggers when leaving a step
          
onShowStepnull,  // triggers when showing a step
          
onFinishnull  // triggers when Finish button is clicked
    
};    
    
})(
jQuery);
?>
Онлайн: 1
Реклама