PageSourceSearch

https://bkys.erciyes.edu.tr/resources/gentelella/jquery.smartWizard.js

js erciyes.edu.tr collected 2026-10-02 04:53:16 UTC 18,501 bytes, 477 lines download raw bytes

1/*
2 * SmartWizard 3.3.1 plugin
3 * jQuery Wizard control Plugin
4 * by Dipu
5 *
6 * Refactored and extended:
7 * https://github.com/mstratman/jQuery-Smart-Wizard
8 *
9 * Original URLs:
10 * http://www.techlaboratory.net
11 * http://tech-laboratory.blogspot.com
12 */
13
14function SmartWizard(target, options) {
15    this.target       = target;
16    this.options      = options;
17    this.curStepIdx   = options.selected;
18    this.steps        = $(target).children("ul").children("li").children("a"); // Get all anchors
19    this.contentWidth = 0;
20    this.msgBox = $('<div class="msgBox"><div class="content"></div><a href="#" class="close">X</a></div>');
21    this.elmStepContainer = $('<div></div>').addClass("stepContainer");
22    this.loader = $('<div>Loading</div>').addClass("loader");
23    this.buttons = {
24    		previous : $('<a>'+options.labelPrevious+'</a>').attr("href","#").addClass("btn btn-primary"),
25	        finish  : $('<a>'+options.labelFinish+'</a>').attr("href","./listPersonelCV").addClass("btn btn-default"),
26	        next : $('<a>'+options.labelNext+'</a>').attr("href","#").addClass("btn btn-success")
27    }; 
28
29    /*
30     * Private functions
31     */
32
33    var _init = function($this) {
34        var elmActionBar = $('<div></div>').addClass("actionBar");
35        //elmActionBar.append($this.msgBox);
36        $('.close',$this.msgBox).click(function() {
37            $this.msgBox.fadeOut("normal");
38            return false;
39        });
40
41        var allDivs = $this.target.children('div');
42        // CHeck if ul with steps has been added by user, if not add them
43        if($this.target.children('ul').length == 0 ){
44            var ul = $("<ul/>");
45            target.prepend(ul)
46
47            // for each div create a li
48            allDivs.each(function(i,e){
49                var title = $(e).first().children(".StepTitle").text();
50                var s = $(e).attr("id")
51                // if referenced div has no id, add one.
52                if (s==undefined){
53                    s = "step-"+(i+1)
54                    $(e).attr("id",s);
55                }
56                var span = $("<span/>").addClass("stepDesc").text(title);
57                var li = $("<li></li>").append($("<a></a>").attr("href", "#" + s).append($("<label></label>").addClass("stepNumber").text(i + 1)).append(span));
58                ul.append(li);
59            });
60            // (re)initialise the steps property
61            $this.steps = $(target).children("ul").children("li").children("a"); // Get all anchors
62        }
63        $this.target.children('ul').addClass("anchor");
64        allDivs.addClass("wizard_content");
65
66        // highlight steps with errors
67        if($this.options.errorSteps && $this.options.errorSteps.length>0){
68            $.each($this.options.errorSteps, function(i, n){
69                $this.setError({ stepnum: n, iserror:true });
70            });
71        }
72
73        $this.elmStepContainer.append(allDivs);
74        //elmActionBar.append($this.loader);
75        $this.target.append($this.elmStepContainer);
76
77        if ($this.options.includeFinishButton){
78            elmActionBar.append($this.buttons.finish)
79        }
80
81        elmActionBar.append($this.buttons.previous)
82            .append($this.buttons.next);
83        $this.target.append(elmActionBar);
84        this.contentWidth = $this.elmStepContainer.width();
85
86        $($this.buttons.next).click(function() {
87            $this.goForward();
88            return false;
89        });
90        $($this.buttons.previous).click(function() {
91            $this.goBackward();
92            return false;
93        });
94        $($this.buttons.finish).click(function() {
95        	location.href='./listPersonelCV';
96        	return false;
97        });
98
99        $($this.steps).bind("click", function(e){
100            if($this.steps.index(this) == $this.curStepIdx){
101                return false;
102            }
103            var nextStepIdx = $this.steps.index(this);
104            var isDone = $this.steps.eq(nextStepIdx).attr("isDone") - 0;
105            if(isDone == 1){
106                _loadContent($this, nextStepIdx);
107            }
108            return false;
109        });
110
111        // Enable keyboard navigation
112        if($this.options.keyNavigation){
113            $(document).keyup(function(e){
114                if(e.which==39){ // Right Arrow
115                    $this.goForward();
116                }else if(e.which==37){ // Left Arrow
117                    $this.goBackward();
118                }
119            });
120        }
121        //  Prepare the steps
122        _prepareSteps($this);
123        // Show the first slected step
124        _loadContent($this, $this.curStepIdx);
125    };
126
127    var _prepareSteps = function($this) {
128        if(! $this.options.enableAllSteps){
129            $($this.steps, $this.target).removeClass("selected").removeClass("done").addClass("disabled");
130            $($this.steps, $this.target).attr("isDone",0);
131        }else{
132            $($this.steps, $this.target).removeClass("selected").removeClass("disabled").addClass("done");
133            $($this.steps, $this.target).attr("isDone",1);
134        }
135
136        $($this.steps, $this.target).each(function(i){
137            $($(this).attr("href").replace(/^.+#/, '#'), $this.target).hide();
138            $(this).attr("rel",i+1);
139        });
140    };
141
142    var _step = function ($this, selStep) {
143        return $(
144            $(selStep, $this.target).attr("href").replace(/^.+#/, '#'),
145            $this.target
146        );
147    };
148
149    var _loadContent = function($this, stepIdx) {
150        var selStep = $this.steps.eq(stepIdx);
151        var ajaxurl = $this.options.contentURL;
152        var ajaxurl_data = $this.options.contentURLData;
153        var hasContent = selStep.data('hasContent');
154        var stepNum = stepIdx+1;
155        if (ajaxurl && ajaxurl.length>0) {
156            if ($this.options.contentCache && hasContent) {
157                _showStep($this, stepIdx);
158            } else {
159                var ajax_args = {
160                    url: ajaxurl,
161                    type: $this.options.ajaxType,
162                    data: ({step_number : stepNum}),
163                    dataType: "text",
164                    beforeSend: function(){
165                        $this.loader.show();
166                    },
167                    error: function(){
168                        $this.loader.hide();
169                    },
170                    success: function(res){
171                        $this.loader.hide();
172                        if(res && res.length>0){
173                            selStep.data('hasContent',true);
174                            _step($this, selStep).html(res);
175                            _showStep($this, stepIdx);
176                        }
177                    }
178                };
179                if (ajaxurl_data) {
180                    ajax_args = $.extend(ajax_args, ajaxurl_data(stepNum));
181                }
182                $.ajax(ajax_args);
183            }
184        }else{
185            _showStep($this,stepIdx);
186        }
187    };
188
189    var _showStep = function($this, stepIdx) {
190        var selStep = $this.steps.eq(stepIdx);
191        var curStep = $this.steps.eq($this.curStepIdx);
192        if(stepIdx != $this.curStepIdx){
193            if($.isFunction($this.options.onLeaveStep)) {
194                var context = { fromStep: $this.curStepIdx+1, toStep: stepIdx+1 };
195                if (! $this.options.onLeaveStep.call($this,$(curStep), context)){
196                    return false;
197                }
198            }
199        }
200        //$this.elmStepContainer.height(_step($this, selStep).outerHeight());
201        var prevCurStepIdx = $this.curStepIdx;
202        $this.curStepIdx =  stepIdx;
203        if ($this.options.transitionEffect == 'slide'){
204            _step($this, curStep).slideUp("fast",function(e){
205                _step($this, selStep).slideDown("fast");
206                _setupStep($this,curStep,selStep);
207            });
208        } else if ($this.options.transitionEffect == 'fade'){
209            _step($this, curStep).fadeOut("fast",function(e){
210                _step($this, selStep).fadeIn("fast");
211                _setupStep($this,curStep,selStep);
212            });
213        } else if ($this.options.transitionEffect == 'slideleft'){
214            var nextElmLeft = 0;
215            var nextElmLeft1 = null;
216            var nextElmLeft = null;
217            var curElementLeft = 0;
218            if(stepIdx > prevCurStepIdx){
219                nextElmLeft1 = $this.elmStepContainer.width() + 10;
220                nextElmLeft2 = 0;
221                curElementLeft = 0 - _step($this, curStep).outerWidth();
222            } else {
223                nextElmLeft1 = 0 - _step($this, selStep).outerWidth() + 20;
224                nextElmLeft2 = 0;
225                curElementLeft = 10 + _step($this, curStep).outerWidth();
226            }
227            if (stepIdx == prevCurStepIdx) {
228                nextElmLeft1 = $($(selStep, $this.target).attr("href"), $this.target).outerWidth() + 20;
229                nextElmLeft2 = 0;
230                curElementLeft = 0 - $($(curStep, $this.target).attr("href"), $this.target).outerWidth();
231            } else {
232                $($(curStep, $this.target).attr("href"), $this.target).animate({left:curElementLeft},"fast",function(e){
233                    $($(curStep, $this.target).attr("href"), $this.target).hide();
234                });
235            }
236
237            _step($this, selStep).css("left",nextElmLeft1).show().animate({left:nextElmLeft2},"fast",function(e){
238                _setupStep($this,curStep,selStep);
239            });
240        } else {
241            _step($this, curStep).hide();
242            _step($this, selStep).show();
243            _setupStep($this,curStep,selStep);
244        }
245        return true;
246    };
247
248    var _setupStep = function($this, curStep, selStep) {
249        $(curStep, $this.target).removeClass("selected");
250        $(curStep, $this.target).addClass("done");
251
252        $(selStep, $this.target).removeClass("disabled");
253        $(selStep, $this.target).removeClass("done");
254        $(selStep, $this.target).addClass("selected");
255
256        $(selStep, $this.target).attr("isDone",1);
257
258        _adjustButton($this);
259
260        if($.isFunction($this.options.onShowStep)) {
261            var context = { fromStep: parseInt($(curStep).attr('rel')), toStep: parseInt($(selStep).attr('rel')) };
262            if(! $this.options.onShowStep.call(this,$(selStep),context)){
263                return false;
264            }
265        }
266        if ($this.options.noForwardJumping) {
267            // +2 == +1 (for index to step num) +1 (for next step)
268            for (var i = $this.curStepIdx + 2; i <= $this.steps.length; i++) {
269                $this.disableStep(i);
270            }
271        }
272    };
273
274    var _adjustButton = function($this) {
275        if (! $this.options.cycleSteps){
276            if (0 >= $this.curStepIdx) {
277                $($this.buttons.previous).addClass("buttonDisabled");
278                if ($this.options.hideButtonsOnDisabled) {
279                    $($this.buttons.previous).hide();
280                }
281            }else{
282                $($this.buttons.previous).removeClass("buttonDisabled");
283                if ($this.options.hideButtonsOnDisabled) {
284                    $($this.buttons.previous).show();
285                }
286            }
287            if (($this.steps.length-1) <= $this.curStepIdx){
288                $($this.buttons.next).addClass("buttonDisabled");
289                if ($this.options.hideButtonsOnDisabled) {
290                    $($this.buttons.next).hide();
291                }
292            }else{
293                $($this.buttons.next).removeClass("buttonDisabled");
294                if ($this.options.hideButtonsOnDisabled) {
295                    $($this.buttons.next).show();
296                }
297            }
298        }
299        // Finish Button
300        $this.enableFinish($this.options.enableFinishButton);
301    };
302
303    /*
304     * Public methods
305     */
306
307    SmartWizard.prototype.goForward = function(){
308        var nextStepIdx = this.curStepIdx + 1;
309        if (this.steps.length <= nextStepIdx){
310            if (! this.options.cycleSteps){
311                return false;
312            }
313            nextStepIdx = 0;
314        }
315        _loadContent(this, nextStepIdx);
316    };
317
318    SmartWizard.prototype.goBackward = function(){
319        var nextStepIdx = this.curStepIdx-1;
320        if (0 > nextStepIdx){
321            if (! this.options.cycleSteps){
322                return false;
323            }
324            nextStepIdx = this.steps.length - 1;
325        }
326        _loadContent(this, nextStepIdx);
327    };
328
329    SmartWizard.prototype.goToStep = function(stepNum){
330        var stepIdx = stepNum - 1;
331        if (stepIdx >= 0 && stepIdx < this.steps.length) {
332            _loadContent(this, stepIdx);
333        }
334    };
335    SmartWizard.prototype.enableStep = function(stepNum) {
336        var stepIdx = stepNum - 1;
337        if (stepIdx == this.curStepIdx || stepIdx < 0 || stepIdx >= this.steps.length) {
338            return false;
339        }
340        var step = this.steps.eq(stepIdx);
341        $(step, this.target).attr("isDone",1);
342        $(step, this.target).removeClass("disabled").removeClass("selected").addClass("done");
343    }
344    SmartWizard.prototype.disableStep = function(stepNum) {
345        var stepIdx = stepNum - 1;
346        if (stepIdx == this.curStepIdx || stepIdx < 0 || stepIdx >= this.steps.length) {
347            return false;
348        }
349        var step = this.steps.eq(stepIdx);
350        $(step, this.target).attr("isDone",0);
351        $(step, this.target).removeClass("done").removeClass("selected").addClass("disabled");
352    }
353    SmartWizard.prototype.currentStep = function() {
354        return this.curStepIdx + 1;
355    }
356
357    SmartWizard.prototype.showMessage = function (msg) {
358        $('.content', this.msgBox).html(msg);
359        this.msgBox.show();
360    }
361
362    SmartWizard.prototype.enableFinish = function (enable) {
363        // Controll status of finish button dynamically
364        // just call this with status you want
365        this.options.enableFinishButton = enable;
366        if (this.options.includeFinishButton){
367            if (!this.steps.hasClass('disabled') || this.options.enableFinishButton){
368                $(this.buttons.finish).removeClass("buttonDisabled");
369                if (this.options.hideButtonsOnDisabled) {
370                    $(this.buttons.finish).show();
371                }
372            }else{
373                $(this.buttons.finish).addClass("buttonDisabled");
374                if (this.options.hideButtonsOnDisabled) {
375                    $(this.buttons.finish).hide();
376                }
377            }
378        }
379        return this.options.enableFinishButton;
380    }
381
382    SmartWizard.prototype.hideMessage = function () {
383        this.msgBox.fadeOut("normal");
384    }
385    SmartWizard.prototype.showError = function(stepnum) {
386        this.setError(stepnum, true);
387    }
388    SmartWizard.prototype.hideError = function(stepnum) {
389        this.setError(stepnum, false);
390    }
391    SmartWizard.prototype.setError = function(stepnum,iserror) {
392        if (typeof stepnum == "object") {
393            iserror = stepnum.iserror;
394            stepnum = stepnum.stepnum;
395        }
396
397        if (iserror){
398            $(this.steps.eq(stepnum-1), this.target).addClass('error')
399        }else{
400            $(this.steps.eq(stepnum-1), this.target).removeClass("error");
401        }
402    }
403
404    SmartWizard.prototype.fixHeight = function(){
405        var height = 0;
406
407        var selStep = this.steps.eq(this.curStepIdx);
408        var stepContainer = _step(this, selStep);
409        stepContainer.children().each(function() {
410            if($(this).is(':visible')) {
411                 height += $(this).outerHeight(true);
412            }
413        });
414
415        // These values (5 and 20) are experimentally chosen.
416        stepContainer.height(height + 5);
417        this.elmStepContainer.height(height + 20); 
418   }
419
420    _init(this);
421};
422
423
424
425(function($){
426
427    $.fn.smartWizard = function(method) {
428        var args = arguments;
429        var rv = undefined;
430        var allObjs = this.each(function() {
431            var wiz = $(this).data('smartWizard');
432            if (typeof method == 'object' || ! method || ! wiz) {
433                var options = $.extend({}, $.fn.smartWizard.defaults, method || {});
434                if (! wiz) {
435                    wiz = new SmartWizard($(this), options);
436                    $(this).data('smartWizard', wiz);
437                }
438            } else {
439                if (typeof SmartWizard.prototype[method] == "function") {
440                    rv = SmartWizard.prototype[method].apply(wiz, Array.prototype.slice.call(args, 1));
441                    return rv;
442                } else {
443                    $.error('Method ' + method + ' does not exist on jQuery.smartWizard');
444                }
445            }
446        });
447        if (rv === undefined) {
448            return allObjs;
449        } else {
450            return rv;
451        }
452    };
453
454// Default Properties and Events
455    $.fn.smartWizard.defaults = {
456        selected: 0,  // Selected Step, 0 = first step
457        keyNavigation: true, // Enable/Disable key navigation(left and right keys are used if enabled)
458        enableAllSteps: true,
459        transitionEffect: 'fade', // Effect on navigation, none/fade/slide/slideleft
460        contentURL:null, // content url, Enables Ajax content loading
461        contentCache:true, // cache step contents, if false content is fetched always from aja
461x url
462        cycleSteps: false, // cycle step navigation
463        enableFinishButton: false, // make finish button enabled always
464        hideButtonsOnDisabled: false, // when the previous/next/finish buttons are disabled, hide them instead?
465        errorSteps:[],    // Array Steps with errors
466        labelNext:'İleri',
467        labelPrevious:'Geri',
468        labelFinish:'Bitti',
469        noForwardJumping: false,
470        ajaxType: "POST",
471        onLeaveStep: null, // triggers when leaving a step
472        onShowStep: null,  // triggers when showing a step
473        onFinish: null,  // triggers when Finish button is clicked
474        includeFinishButton : true   // Add the finish button
475    };
476
477})(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.