From 6fec48a814205e47ea73eb158e2659418c9119c5 Mon Sep 17 00:00:00 2001 From: Felipe Prestes Date: Fri, 27 Jan 2017 17:31:41 -0200 Subject: [PATCH] Update jquery.smartWizard.js #1. contentCache - Whether or not to cache ajax content. #2. leaveStep - Do not perform the ajax request before leaveStep --- js/jquery.smartWizard.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/js/jquery.smartWizard.js b/js/jquery.smartWizard.js index d8cb682..a29f503 100644 --- a/js/jquery.smartWizard.js +++ b/js/jquery.smartWizard.js @@ -40,6 +40,7 @@ enableAnchorOnDoneStep: true // Enable/Disable the done steps navigation }, contentURL: null, // content url, Enables Ajax content loading. Can also set as data data-content-url on anchor + contentCache: true, // cache step contents, if false content is fetched always from ajax url disabledSteps: [], // Array Steps disabled errorSteps: [], // Highlight step with errors hiddenSteps: [], // Hidden steps @@ -316,9 +317,35 @@ }, _loadStepContent: function (idx) { var mi = this; + // Get current step elements + var curTab = this.steps.eq(this.current_index); + var curPage = (curTab.length>0) ? $(curTab.attr("href"),this.main) : null; + // Get step to show elements + var selTab = this.steps.eq(idx); + var selPage = (selTab.length>0) ? $(selTab.attr("href"),this.main) : null; + // Get the direction of step navigation + var stepDirection = ''; var elm = this.steps.eq(idx); var contentURL = (elm.data('content-url') && elm.data('content-url').length > 0) ? elm.data('content-url') : this.options.contentURL; + + if(this.current_index !== null && this.current_index !== idx){ + stepDirection = (this.current_index < idx) ? "forward" : "backward"; + } + var stepPosition = 'middle'; + if(idx === 0){ + stepPosition = 'first'; + }else if(idx === (this.steps.length-1)){ + stepPosition = 'final'; + } + + // Trigger "leaveStep" event + if(this.current_index !== null && this._triggerEvent("leaveStep", [curTab, this.current_index, stepDirection]) === false){ return false; } + + // check contentCache + if(!this.options.contentCache){ + elm.data('has-content', false); + } if(contentURL && contentURL.length > 0 && !elm.data('has-content')){ // Get ajax content and then show step var selPage = (elm.length>0) ? $(elm.attr("href"),this.main) : null; @@ -364,10 +391,7 @@ }else if(idx === (this.steps.length-1)){ stepPosition = 'final'; } - - // Trigger "leaveStep" event - if(this.current_index !== null && this._triggerEvent("leaveStep", [curTab, this.current_index, stepDirection]) === false){ return false; } - + this.options.transitionEffect = this.options.transitionEffect.toLowerCase(); this.pages.finish(); if(this.options.transitionEffect === 'slide'){ // normal slide @@ -565,4 +589,4 @@ } }; -})(jQuery, window, document); \ No newline at end of file +})(jQuery, window, document);