123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /*!
- * Ideal Steps
- */
- (function($, win, doc, undefined) {
- var plugin = {};
- plugin.name = 'idealsteps';
- plugin.defaults = {
- nav: '.idealsteps-nav',
- navItems: 'li',
- buildNavItems: true,
- wrap: '.idealsteps-wrap',
- step: '.idealsteps-step',
- activeClass: 'idealsteps-step-active',
- before: null,
- after: null,
- fadeSpeed: 0
- };
- plugin.methods = {
- _init: function() {
- var self = this,
- active = this.opts.activeClass;
- this.$el = $(this.el);
- this.$nav = this.$el.find(this.opts.nav);
- this.$navItems = this.$nav.find(this.opts.navItems);
- this.$wrap = this.$el.find(this.opts.wrap);
- this.$steps = this.$wrap.find(this.opts.step);
- if (this.opts.buildNavItems) this._buildNavItems();
- this.$steps.hide().first().show();
- this.$navItems.removeClass(active).first().addClass(active);
- this.$navItems.click(function() {
- self.go(self.$navItems.index(this));
- });
- },
- _buildNavItems: function() {
- var self = this,
- isCustom = typeof this.opts.buildNavItems == 'function',
- item = function(val){ return '<li><a href="#" tabindex="-1">'+ val +'</a></li>'; },
- items;
- items = isCustom ?
- this.$steps.map(function(i){ return item(self.opts.buildNavItems.call(self, i)) }).get() :
- this.$steps.map(function(i){ return item(++i); }).get();
- this.$navItems = $(items.join(''));
- this.$nav.append($('<ul/>').append(this.$navItems));
- },
- _getCurIdx: function() {
- return this.$steps.index(this.$steps.filter(':visible'));
- },
- go: function(idx) {
- var active = this.opts.activeClass,
- fadeSpeed = this.opts.fadeSpeed;
- if (typeof idx == 'function') idx = idx.call(this, this._getCurIdx());
- if (idx >= this.$steps.length) idx = 0;
- if (idx < 0) idx = this.$steps.length-1;
- if (this.opts.before) this.opts.before.call(this, idx);
- this.$navItems.removeClass(active).eq(idx).addClass(active);
- this.$steps.fadeOut(fadeSpeed).eq(idx).fadeIn(fadeSpeed);
- if (this.opts.after) this.opts.after.call(this, idx);
- },
- prev: function() {
- this.go(this._getCurIdx() - 1);
- },
- next: function() {
- this.go(this._getCurIdx() + 1);
- },
- first: function() {
- this.go(0);
- },
- last: function() {
- this.go(this.$steps.length-1);
- }
- };
- require('../../plugin')(plugin);
- }(jQuery, window, document));
|