UNPKG

vpn.email

Version:
214 lines (172 loc) 6.71 kB
$.widget( "metro.wizard2" , { version: "3.0.0", options: { start: 1, finish: 'default', buttonLabels: { prev: '&lt;', next: '&gt;', finish: 'OK', help: '?' }, onPrior: function(page, wiz){return true;}, onNext: function(page, wiz){return true;}, onFinish: function(page, wiz){}, onHelp: function(page, wiz){}, onPage: function(page, wiz){} }, _step: 1, _steps: undefined, _create: function () { var that = this, element = this.element, o = this.options; $.each(element.data(), function(key, value){ if (key in o) { try { o[key] = $.parseJSON(value); } catch (e) { o[key] = value; } } }); this._step = o.start; this._steps = element.children('.step'); this._height = 0; this._width = 0; if (o.finish === 'default') { o.finish = this._steps.length; } $.each(this._steps, function(i, v){ if ($(v).outerHeight() > that._height) {that._height = $(v).outerHeight();} //console.log(i, $(v).outerHeight(), that._height); if ($(v).hasClass('active')) { that._step = i + 1; } }); this._width = element.innerWidth() - ( (this._steps.length - 1) * 24 + (this._steps.length)); element.children('.step').css({ height: this._height + 48 }); $(window).resize(function(){ that._width = element.innerWidth() - ( (that._steps.length - 1) * 24 + (that._steps.length)); that.step(that._step); }); this._createActionBar(); this.step(o.start); this._placeActionBar(); element.data('wizard2', this); }, _createActionBar: function(){ var that = this, element = this.element, o = this.options; var bar = $("<div/>").addClass('action-bar').appendTo(element); var btn_prev, btn_next, btn_help, btn_finish; btn_help = $("<button/>").html(o.buttonLabels.help).addClass('button cycle-button medium-button wiz-btn-help place-left').appendTo(bar); btn_finish = $("<button/>").html(o.buttonLabels.finish).addClass('button cycle-button medium-button wiz-btn-finish place-right').appendTo(bar); btn_next = $("<button/>").html(o.buttonLabels.next).addClass('button cycle-button medium-button wiz-btn-next place-right').appendTo(bar); btn_prev = $("<button/>").html(o.buttonLabels.prev).addClass('button cycle-button medium-button wiz-btn-prev place-right').appendTo(bar); btn_help.on('click', function(){ if (typeof o.onHelp === 'function') { o.onHelp(that._step, that); } else { if (typeof window[o.onHelp] === 'function') { window[o.onHelp](that._step, that); } else { var result = eval("(function(){"+o.onHelp+"})"); result.call(that._step, that); } } }); btn_finish.on('click', function(){ if (typeof o.onFinish === 'function') { o.onFinish(that._step, that); } else { if (typeof window[o.onFinish] === 'function') { window[o.onFinish](that._step, that); } else { var result = eval("(function(){"+o.onFinish+"})"); result.call(that._step, that); } } }); btn_prev.on('click', function(){ if (typeof o.onPrior === 'function') { if (o.onPrior(that._step, element)) {that.prior();} } else { if (typeof window[o.onPrior] === 'function') { if (window[o.onPrior](that._step, element)) {that.prior();} } else { var result = eval("(function(){"+o.onPrior+"})"); if (result.call(that._step, element)) {that.prior();} } } }); btn_next.on('click', function(){ if (typeof o.onNext === 'function') { if (o.onNext(that._step, element)) {that.next();} } else { if (typeof window[o.onNext] === 'function') { if (window[o.onNext](that._step, element)) {that.next();} } else { var result = eval("(function(){"+o.onNext+"})"); if (result.call(that._step, element)) {that.next();} } } }); }, _placeActionBar: function(){ var element = this.element, o = this.options; var action_bar = element.find('.action-bar'); var curr_frame = element.find('.step.active'); var left = curr_frame.position().left, right = curr_frame.innerWidth(); action_bar.css({ left: left, width: right }); }, step: function(index){ var o = this.options; this.element.children('.step') .removeClass('active prev next'); $(this.element.children('.step')[index - 1]) .addClass('active') .css('width', this._width); this.element.children('.step.active').prevAll().addClass('prev').css('width', 0); this.element.children('.step.active').nextAll().addClass('next').css('width', 0); this._placeActionBar(); if (index === 1) { this.element.find('.wiz-btn-prev').hide(); } else { this.element.find('.wiz-btn-prev').show(); } if (index === this._steps.length) { this.element.find('.wiz-btn-next').hide(); } else { this.element.find('.wiz-btn-next').show(); } if (index !== o.finish) { this.element.find('.wiz-btn-finish').hide(); } else { this.element.find('.wiz-btn-finish').show(); } }, prior: function(){ var new_step = this._step - 1; if (new_step <= 0) { return false; } this._step = new_step; this.step(new_step); return true; }, next: function(){ var new_step = this._step + 1; if (new_step > this._steps.length) {return false;} this._step = new_step; this.step(new_step); return true; }, _destroy: function () { }, _setOption: function ( key, value ) { this._super('_setOption', key, value); } });