Path: blob/master/web-gui/buildyourownbotnet/assets/js/jquery.bootstrap.wizard.min.js
1292 views
/*!1* jQuery twitter bootstrap wizard plugin2* Examples and documentation at: http://github.com/VinceG/twitter-bootstrap-wizard3* version 1.04* Requires jQuery v1.3.2 or later5* Supports Bootstrap 2.2.x, 2.3.x, 3.06* Dual licensed under the MIT and GPL licenses:7* http://www.opensource.org/licenses/mit-license.php8* http://www.gnu.org/licenses/gpl.html9* Authors: Vadim Vincent Gabriel (http://vadimg.com), Jason Gill (www.gilluminate.com)10*/11;(function($) {12var bootstrapWizardCreate = function(element, options) {13var element = $(element);14var obj = this;1516// selector skips any 'li' elements that do not contain a child with a tab data-toggle17var baseItemSelector = 'li:has([data-toggle="tab"])';1819// Merge options with defaults20var $settings = $.extend({}, $.fn.bootstrapWizard.defaults, options);21var $activeTab = null;22var $navigation = null;2324this.rebindClick = function(selector, fn)25{26selector.unbind('click', fn).bind('click', fn);27}2829this.fixNavigationButtons = function() {30// Get the current active tab31if(!$activeTab.length) {32// Select first one33$navigation.find('a:first').tab('show');34$activeTab = $navigation.find(baseItemSelector + ':first');35}3637// See if we're currently in the first/last then disable the previous and last buttons38$($settings.previousSelector, element).toggleClass('disabled', (obj.firstIndex() >= obj.currentIndex()));39$($settings.nextSelector, element).toggleClass('disabled', (obj.currentIndex() >= obj.navigationLength()));4041// We are unbinding and rebinding to ensure single firing and no double-click errors42obj.rebindClick($($settings.nextSelector, element), obj.next);43obj.rebindClick($($settings.previousSelector, element), obj.previous);44obj.rebindClick($($settings.lastSelector, element), obj.last);45obj.rebindClick($($settings.firstSelector, element), obj.first);4647if($settings.onTabShow && typeof $settings.onTabShow === 'function' && $settings.onTabShow($activeTab, $navigation, obj.currentIndex())===false){48return false;49}50};5152this.next = function(e) {53e.preventDefault();5455// If we clicked the last then dont activate this56if(element.hasClass('last')) {57return false;58}5960if($settings.onNext && typeof $settings.onNext === 'function' && $settings.onNext($activeTab, $navigation, obj.nextIndex())===false){61return false;62}6364// Did we click the last button65$index = obj.nextIndex();66if($index > obj.navigationLength()) {67} else {68$navigation.find(baseItemSelector + ':eq('+$index+') a').tab('show');69}70};7172this.previous = function(e) {73e.preventDefault();7475// If we clicked the first then dont activate this76if(element.hasClass('first')) {77return false;78}7980if($settings.onPrevious && typeof $settings.onPrevious === 'function' && $settings.onPrevious($activeTab, $navigation, obj.previousIndex())===false){81return false;82}8384$index = obj.previousIndex();85if($index < 0) {86} else {87$navigation.find(baseItemSelector + ':eq('+$index+') a').tab('show');88}89};9091this.first = function(e) {92e.preventDefault();9394if($settings.onFirst && typeof $settings.onFirst === 'function' && $settings.onFirst($activeTab, $navigation, obj.firstIndex())===false){95return false;96}9798// If the element is disabled then we won't do anything99if(element.hasClass('disabled')) {100return false;101}102$navigation.find(baseItemSelector + ':eq(0) a').tab('show');103104};105106this.last = function(e) {107e.preventDefault();108109if($settings.onLast && typeof $settings.onLast === 'function' && $settings.onLast($activeTab, $navigation, obj.lastIndex())===false){110return false;111}112113// If the element is disabled then we won't do anything114if(element.hasClass('disabled')) {115return false;116}117$navigation.find(baseItemSelector + ':eq('+obj.navigationLength()+') a').tab('show');118};119120this.currentIndex = function() {121return $navigation.find(baseItemSelector).index($activeTab);122};123this.firstIndex = function() {124return 0;125};126this.lastIndex = function() {127return obj.navigationLength();128};129this.getIndex = function(e) {130return $navigation.find(baseItemSelector).index(e);131};132this.nextIndex = function() {133return $navigation.find(baseItemSelector).index($activeTab) + 1;134};135this.previousIndex = function() {136return $navigation.find(baseItemSelector).index($activeTab) - 1;137};138this.navigationLength = function() {139return $navigation.find(baseItemSelector).length - 1;140};141this.activeTab = function() {142return $activeTab;143};144this.nextTab = function() {145return $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')').length ? $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')') : null;146};147this.previousTab = function() {148if(obj.currentIndex() <= 0) {149return null;150}151return $navigation.find(baseItemSelector + ':eq('+parseInt(obj.currentIndex()-1)+')');152};153this.show = function(index) {154return element.find(baseItemSelector + ':eq(' + index + ') a').tab('show');155};156this.disable = function(index) {157$navigation.find(baseItemSelector + ':eq('+index+')').addClass('disabled');158};159this.enable = function(index) {160$navigation.find(baseItemSelector + ':eq('+index+')').removeClass('disabled');161};162this.hide = function(index) {163$navigation.find(baseItemSelector + ':eq('+index+')').hide();164};165this.display = function(index) {166$navigation.find(baseItemSelector + ':eq('+index+')').show();167};168this.remove = function(args) {169var $index = args[0];170var $removeTabPane = typeof args[1] != 'undefined' ? args[1] : false;171var $item = $navigation.find(baseItemSelector + ':eq('+$index+')');172173// Remove the tab pane first if needed174if($removeTabPane) {175var $href = $item.find('a').attr('href');176$($href).remove();177}178179// Remove menu item180$item.remove();181};182183$navigation = element.find('ul:first', element);184$activeTab = $navigation.find(baseItemSelector + '.active', element);185186if(!$navigation.hasClass($settings.tabClass)) {187$navigation.addClass($settings.tabClass);188}189190// Load onInit191if($settings.onInit && typeof $settings.onInit === 'function'){192$settings.onInit($activeTab, $navigation, 0);193}194195// Load onShow196if($settings.onShow && typeof $settings.onShow === 'function'){197$settings.onShow($activeTab, $navigation, obj.nextIndex());198}199200// Work the next/previous buttons201obj.fixNavigationButtons();202203$('a[data-toggle="tab"]', $navigation).on('click', function (e) {204// Get the index of the clicked tab205var clickedIndex = $navigation.find(baseItemSelector).index($(e.currentTarget).parent(baseItemSelector));206if($settings.onTabClick && typeof $settings.onTabClick === 'function' && $settings.onTabClick($activeTab, $navigation, obj.currentIndex(), clickedIndex)===false){207return false;208}209});210211// attach to both shown and shown.bs.tab to support Bootstrap versions 2.3.2 and 3.0.0212$('a[data-toggle="tab"]', $navigation).on('shown shown.bs.tab', function (e) { // use shown instead of show to help prevent double firing213$element = $(e.target).parent();214var nextTab = $navigation.find(baseItemSelector).index($element);215216// If it's disabled then do not change217if($element.hasClass('disabled')) {218return false;219}220221if($settings.onTabChange && typeof $settings.onTabChange === 'function' && $settings.onTabChange($activeTab, $navigation, obj.currentIndex(), nextTab)===false){222return false;223}224225$activeTab = $element; // activated tab226obj.fixNavigationButtons();227});228};229$.fn.bootstrapWizard = function(options) {230//expose methods231if (typeof options == 'string') {232var args = Array.prototype.slice.call(arguments, 1)233if(args.length === 1) {234args.toString();235}236return this.data('bootstrapWizard')[options](args);237}238return this.each(function(index){239var element = $(this);240// Return early if this element already has a plugin instance241if (element.data('bootstrapWizard')) return;242// pass options to plugin constructor243var wizard = new bootstrapWizardCreate(element, options);244// Store plugin object in this element's data245element.data('bootstrapWizard', wizard);246});247};248249// expose options250$.fn.bootstrapWizard.defaults = {251tabClass: 'nav nav-pills',252nextSelector: '.wizard li.next',253previousSelector: '.wizard li.previous',254firstSelector: '.wizard li.first',255lastSelector: '.wizard li.last',256onShow: null,257onInit: null,258onNext: null,259onPrevious: null,260onLast: null,261onFirst: null,262onTabChange: null,263onTabClick: null,264onTabShow: null265};266267})(jQuery);268269