123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- require('./idealsteps');
- module.exports = {
- name: 'steps',
- options: {
- steps: {
- container: '.idealsteps-container',
- nav: '.idealsteps-nav',
- navItems: 'li',
- buildNavItems: function(i) {
- return this.opts.steps.i18n.step +' '+ (i+1);
- },
- wrap: '.idealsteps-wrap',
- step: '.idealsteps-step',
- activeClass: 'idealsteps-step-active',
- before: $.noop,
- after: $.noop,
- fadeSpeed: 0,
- i18n: {
- step: 'Step'
- }
- }
- },
- methods: {
- // @extend
- _init: function() {
- this._buildSteps();
- },
- // @extend
- _validate: function() {
- var self = this;
- this._updateSteps();
- if (this._hasExtension('ajax')) {
- $.each($.idealforms._requests, function(key, request) {
- request.done(function(){ self._updateSteps() });
- });
- }
- },
- // @extend
- focusFirstInvalid: function(firstInvalid) {
- var self = this;
- this.$stepsContainer.idealsteps('go', function() {
- return this.$steps.filter(function() {
- return $(this).find(firstInvalid).length;
- }).index();
- });
- },
- _buildSteps: function() {
- var self = this, options
- , hasRules = ! $.isEmptyObject(this.opts.rules)
- , buildNavItems = this.opts.steps.buildNavItems
- , counter = hasRules
- ? '<span class="counter"/>'
- : '<span class="counter zero">0</span>';
- if (this.opts.steps.buildNavItems) {
- this.opts.steps.buildNavItems = function(i) {
- return buildNavItems.call(self, i) + counter;
- };
- }
- this.$stepsContainer = this.$form
- .closest(this.opts.steps.container)
- .idealsteps(this.opts.steps);
- },
- _updateSteps: function() {
- var self = this;
- this.$stepsContainer.idealsteps('_inject', function() {
- var idealsteps = this;
- this.$navItems.each(function(i) {
- var invalid = idealsteps.$steps.eq(i).find(self.getInvalid()).length;
- $(this).find('span').text(invalid).toggleClass('zero', ! invalid);
- });
- });
- },
- // @extend
- addRules: function() {
- this.firstStep();
- },
- // @extend
- addFields: function(field) {
- field.after = this.$stepsContainer
- .find(this.opts.steps.step)
- .eq(field.appendToStep)
- .find('input, textarea, select')
- .last()[0].name;
- },
- // @extend
- toggleFields: function() {
- this._updateSteps();
- },
- // @extend
- removeFields: function() {
- this._updateSteps();
- },
- goToStep: function(idx) {
- this.$stepsContainer.idealsteps('go', idx);
- },
- prevStep: function() {
- this.$stepsContainer.idealsteps('prev');
- },
- nextStep: function() {
- this.$stepsContainer.idealsteps('next');
- },
- firstStep: function() {
- this.$stepsContainer.idealsteps('first');
- },
- lastStep: function() {
- this.$stepsContainer.idealsteps('last');
- }
- }
- };
|