Version 1.2

Updated to version 1.2 from the github tag.

Change-Id: I4096fba7573f5c8626a7d38252bff3529d5b00b9
This commit is contained in:
Radomir Dopieralski 2014-08-11 17:12:27 +02:00
parent ad6e5733d5
commit 87ce0243e5
2 changed files with 73 additions and 48 deletions

View File

@ -11,9 +11,9 @@ NAME = __name__.split('.')[-1] # package name (e.g. 'foo' or 'foo_bar')
# please use a all-lowercase valid python
# package name
VERSION = '1.0.0' # version of the packaged files, please use the upstream
VERSION = '1.2.0' # version of the packaged files, please use the upstream
# version number
BUILD = '1' # our package build number, so we can release new builds
BUILD = '0' # our package build number, so we can release new builds
# with fixes for xstatic stuff.
PACKAGE_VERSION = VERSION + '.' + BUILD # version used for PyPi

View File

@ -3,6 +3,7 @@
* Examples and documentation at: http://github.com/VinceG/twitter-bootstrap-wizard
* version 1.0
* Requires jQuery v1.3.2 or later
* Supports Bootstrap 2.2.x, 2.3.x, 3.0
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
@ -13,6 +14,9 @@ var bootstrapWizardCreate = function(element, options) {
var element = $(element);
var obj = this;
// selector skips any 'li' elements that do not contain a child with a tab data-toggle
var baseItemSelector = 'li:has([data-toggle="tab"])';
// Merge options with defaults
var $settings = $.extend({}, $.fn.bootstrapWizard.defaults, options);
var $activeTab = null;
@ -28,7 +32,7 @@ var bootstrapWizardCreate = function(element, options) {
if(!$activeTab.length) {
// Select first one
$navigation.find('a:first').tab('show');
$activeTab = $navigation.find('li:first');
$activeTab = $navigation.find(baseItemSelector + ':first');
}
// See if we're currently in the first/last then disable the previous and last buttons
@ -61,7 +65,7 @@ var bootstrapWizardCreate = function(element, options) {
$index = obj.nextIndex();
if($index > obj.navigationLength()) {
} else {
$navigation.find('li:eq('+$index+') a').tab('show');
$navigation.find(baseItemSelector + ':eq('+$index+') a').tab('show');
}
};
@ -79,7 +83,7 @@ var bootstrapWizardCreate = function(element, options) {
$index = obj.previousIndex();
if($index < 0) {
} else {
$navigation.find('li:eq('+$index+') a').tab('show');
$navigation.find(baseItemSelector + ':eq('+$index+') a').tab('show');
}
};
@ -92,7 +96,7 @@ var bootstrapWizardCreate = function(element, options) {
if(element.hasClass('disabled')) {
return false;
}
$navigation.find('li:eq(0) a').tab('show');
$navigation.find(baseItemSelector + ':eq(0) a').tab('show');
};
this.last = function(e) {
@ -104,10 +108,10 @@ var bootstrapWizardCreate = function(element, options) {
if(element.hasClass('disabled')) {
return false;
}
$navigation.find('li:eq('+obj.navigationLength()+') a').tab('show');
$navigation.find(baseItemSelector + ':eq('+obj.navigationLength()+') a').tab('show');
};
this.currentIndex = function() {
return $navigation.find('li').index($activeTab);
return $navigation.find(baseItemSelector).index($activeTab);
};
this.firstIndex = function() {
return 0;
@ -116,48 +120,48 @@ var bootstrapWizardCreate = function(element, options) {
return obj.navigationLength();
};
this.getIndex = function(e) {
return $navigation.find('li').index(e);
return $navigation.find(baseItemSelector).index(e);
};
this.nextIndex = function() {
return $navigation.find('li').index($activeTab) + 1;
return $navigation.find(baseItemSelector).index($activeTab) + 1;
};
this.previousIndex = function() {
return $navigation.find('li').index($activeTab) - 1;
return $navigation.find(baseItemSelector).index($activeTab) - 1;
};
this.navigationLength = function() {
return $navigation.find('li').length - 1;
return $navigation.find(baseItemSelector).length - 1;
};
this.activeTab = function() {
return $activeTab;
};
this.nextTab = function() {
return $navigation.find('li:eq('+(obj.currentIndex()+1)+')').length ? $navigation.find('li:eq('+(obj.currentIndex()+1)+')') : null;
return $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')').length ? $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')') : null;
};
this.previousTab = function() {
if(obj.currentIndex() <= 0) {
return null;
}
return $navigation.find('li:eq('+parseInt(obj.currentIndex()-1)+')');
return $navigation.find(baseItemSelector + ':eq('+parseInt(obj.currentIndex()-1)+')');
};
this.show = function(index) {
return element.find('li:eq(' + index + ') a').tab('show');
return element.find(baseItemSelector + ':eq(' + index + ') a').tab('show');
};
this.disable = function(index) {
$navigation.find('li:eq('+index+')').addClass('disabled');
$navigation.find(baseItemSelector + ':eq('+index+')').addClass('disabled');
};
this.enable = function(index) {
$navigation.find('li:eq('+index+')').removeClass('disabled');
$navigation.find(baseItemSelector + ':eq('+index+')').removeClass('disabled');
};
this.hide = function(index) {
$navigation.find('li:eq('+index+')').hide();
$navigation.find(baseItemSelector + ':eq('+index+')').hide();
};
this.display = function(index) {
$navigation.find('li:eq('+index+')').show();
$navigation.find(baseItemSelector + ':eq('+index+')').show();
};
this.remove = function(args) {
var $index = args[0];
var $removeTabPane = typeof args[1] != 'undefined' ? args[1] : false;
var $item = $navigation.find('li:eq('+$index+')');
var $item = $navigation.find(baseItemSelector + ':eq('+$index+')');
// Remove the tab pane first if needed
if($removeTabPane) {
@ -169,8 +173,50 @@ var bootstrapWizardCreate = function(element, options) {
$item.remove();
};
var innerTabClick = function (e) {
// Get the index of the clicked tab
var clickedIndex = $navigation.find(baseItemSelector).index($(e.currentTarget).parent(baseItemSelector));
if($settings.onTabClick && typeof $settings.onTabClick === 'function' && $settings.onTabClick($activeTab, $navigation, obj.currentIndex(), clickedIndex)===false){
return false;
}
};
var innerTabShown = function (e) { // use shown instead of show to help prevent double firing
$element = $(e.target).parent();
var nextTab = $navigation.find(baseItemSelector).index($element);
// If it's disabled then do not change
if($element.hasClass('disabled')) {
return false;
}
if($settings.onTabChange && typeof $settings.onTabChange === 'function' && $settings.onTabChange($activeTab, $navigation, obj.currentIndex(), nextTab)===false){
return false;
}
$activeTab = $element; // activated tab
obj.fixNavigationButtons();
};
this.resetWizard = function() {
// remove the existing handlers
$('a[data-toggle="tab"]', $navigation).off('click', innerTabClick);
$('a[data-toggle="tab"]', $navigation).off('shown shown.bs.tab', innerTabShown);
// reset elements based on current state of the DOM
$navigation = element.find('ul:first', element);
$activeTab = $navigation.find(baseItemSelector + '.active', element);
// re-add handlers
$('a[data-toggle="tab"]', $navigation).on('click', innerTabClick);
$('a[data-toggle="tab"]', $navigation).on('shown shown.bs.tab', innerTabShown);
obj.fixNavigationButtons();
};
$navigation = element.find('ul:first', element);
$activeTab = $navigation.find('li.active', element);
$activeTab = $navigation.find(baseItemSelector + '.active', element);
if(!$navigation.hasClass($settings.tabClass)) {
$navigation.addClass($settings.tabClass);
@ -186,33 +232,12 @@ var bootstrapWizardCreate = function(element, options) {
$settings.onShow($activeTab, $navigation, obj.nextIndex());
}
// Work the next/previous buttons
obj.fixNavigationButtons();
$('a[data-toggle="tab"]', $navigation).on('click', innerTabClick);
$('a[data-toggle="tab"]', $navigation).on('click', function (e) {
// Get the index of the clicked tab
var clickedIndex = $navigation.find('li').index($(e.currentTarget).parent('li'));
if($settings.onTabClick && typeof $settings.onTabClick === 'function' && $settings.onTabClick($activeTab, $navigation, obj.currentIndex(), clickedIndex)===false){
return false;
}
});
// attach to both shown and shown.bs.tab to support Bootstrap versions 2.3.2 and 3.0.0
$('a[data-toggle="tab"]', $navigation).on('shown shown.bs.tab', innerTabShown);
$('a[data-toggle="tab"]', $navigation).on('shown', function (e) { // use shown instead of show to help prevent double firing
$element = $(e.target).parent();
var nextTab = $navigation.find('li').index($element);
// If it's disabled then do not change
if($element.hasClass('disabled')) {
return false;
}
if($settings.onTabChange && typeof $settings.onTabChange === 'function' && $settings.onTabChange($activeTab, $navigation, obj.currentIndex(), nextTab)===false){
return false;
}
$activeTab = $element; // activated tab
obj.fixNavigationButtons();
});
this.fixNavigationButtons();
};
$.fn.bootstrapWizard = function(options) {
//expose methods