1/*! 2 * jQuery twitter bootstrap wizard plugin 3 * Examples and documentation at: http://github.com/VinceG/twitter-bootstrap-wizard 4 * version 1.4.2 5 * Requires jQuery v1.3.2 or later 6 * Supports Bootstrap 2.2.x, 2.3.x, 3.0 7 * Dual licensed under the MIT and GPL licenses: 8 * http://www.opensource.org/licenses/mit-license.php 9 * http://www.gnu.org/licenses/gpl.html 10 * Authors: Vadim Vincent Gabriel (http://vadimg.com), Jason Gill (www.gilluminate.com) 11 */ 12; 13(function($) { 14 var bootstrapWizardCreate = function(element, options) { 15 var element = $(element); 16 var obj = this; 17 18 // selector skips any 'li' elements that do not contain a child with a tab data-toggle 19 var baseItemSelector = 'li:has([data-toggle="tab"])'; 20 var historyStack = []; 21 22 // Merge options with defaults 23 var $settings = $.extend({}, $.fn.bootstrapWizard.defaults, options); 24 var $activeTab = null; 25 var $navigation = null; 26 27 this.rebindClick = function(selector, fn) { 28 selector.unbind('click', fn).bind('click', fn); 29 } 30 31 this.fixNavigationButtons = function() { 32 // Get the current active tab 33 if (!$activeTab.length) { 34 // Select first one 35 $navigation.find('a:first').tab('show'); 36 $activeTab = $navigation.find(baseItemSelector + ':first'); 37 } 38 39 // See if we're currently in the first/last then disable the previous and last buttons 40 $($settings.previousSelector, element).toggleClass('disabled', (obj.firstIndex() >= obj.currentIndex())); 41 $($settings.nextSelector, element).toggleClass('disabled', (obj.currentIndex() >= obj.navigationLength())); 42 $($settings.nextSelector, element).toggleClass('hidden', (obj.currentIndex() >= obj.navigationLength() && $($settings.finishSelector, element).length > 0)); 43 $($settings.lastSelector, element).toggleClass('hidden', (obj.currentIndex() >= obj.navigationLength() && $($settings.finishSelector, element).length > 0)); 44 $($settings.finishSelector, element).toggleClass('hidden', (obj.currentIndex() < obj.navigationLength())); 45 $($settings.backSelector, element).toggleClass('disabled', (historyStack.length == 0)); 46 $($settings.backSelector, element).toggleClass('hidden', (obj.currentIndex() >= obj.navigationLength() && $($settings.finishSelector, element).length > 0)); 47 48 // We are unbinding and rebinding to ensure single firing and no double-click errors 49 obj.rebindClick($($settings.nextSelector, element), obj.next); 50 obj.rebindClick($($settings.previousSelector, element), obj.previous); 51 obj.rebindClick($($settings.lastSelector, element), obj.last); 52 obj.rebindClick($($settings.firstSelector, element), obj.first); 53 obj.rebindClick($($settings.finishSelector, element), obj.finish); 54 obj.rebindClick($($settings.backSelector, element), obj.back); 55 56 if ($settings.onTabShow && typeof $settings.onTabShow === 'function' && $settings.onTabShow($activeTab, $navigation, obj.currentIndex()) === false) { 57 return false; 58 } 59 }; 60 61 this.next = function(e) { 62 // If we clicked the last then dont activate this 63 if (element.hasClass('last')) { 64 return false; 65 } 66 67 if ($settings.onNext && typeof $settings.onNext === 'function' && $settings.onNext($activeTab, $navigation, obj.nextIndex()) === false) { 68 return false; 69 } 70 71 var formerIndex = obj.currentIndex(); 72 var $index = obj.nextIndex(); 73 74 // Did we click the last button 75 if ($index > obj.navigationLength()) {} else { 76 historyStack.push(formerIndex); 77 $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '') + ':eq(' + $index + ') a').tab('show'); 78 } 79 }; 80 81 this.previous = function(e) { 82 // If we clicked the first then dont activate this 83 if (element.hasClass('first')) { 84 return false;
85 } 86 87 if ($settings.onPrevious && typeof $settings.onPrevious === 'function' && $settings.onPrevious($activeTab, $navigation, obj.previousIndex()) === false) { 88 return false; 89 } 90 91 var formerIndex = obj.currentIndex(); 92 var $index = obj.previousIndex(); 93 94 if ($index < 0) {} else { 95 historyStack.push(formerIndex); 96 $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '') + ':eq(' + $index + ') a').tab('show'); 97 } 98 }; 99 100 this.first = function(e) { 101 if ($settings.onFirst && typeof $settings.onFirst === 'function' && $settings.onFirst($activeTab, $navigation, obj.firstIndex()) === false) { 102 return false; 103 } 104 105 // If the element is disabled then we won't do anything 106 if (element.hasClass('disabled')) { 107 return false; 108 } 109 110 111 historyStack.push(obj.currentIndex()); 112 $navigation.find(baseItemSelector + ':eq(0) a').tab('show'); 113 }; 114 115 this.last = function(e) { 116 if ($settings.onLast && typeof $settings.onLast === 'function' && $settings.onLast($activeTab, $navigation, obj.lastIndex()) === false) { 117 return false; 118 } 119 120 // If the element is disabled then we won't do anything 121 if (element.hasClass('disabled')) { 122 return false; 123 } 124 125 historyStack.push(obj.currentIndex()); 126 $navigation.find(baseItemSelector + ':eq(' + obj.navigationLength() + ') a').tab('show'); 127 }; 128 129 this.finish = function(e) { 130 if ($settings.onFinish && typeof $settings.onFinish === 'function') { 131 $settings.onFinish($activeTab, $navigation, obj.lastIndex()); 132 } 133 }; 134 135 this.back = function() { 136 if (historyStack.length == 0) { 137 return null; 138 } 139 140 var formerIndex = historyStack.pop(); 141 if ($settings.onBack && typeof $settings.onBack === 'function' && $settings.onBack($activeTab, $navigation, formerIndex) === false) { 142 historyStack.push(formerIndex); 143 return false; 144 } 145 146 element.find(baseItemSelector + ':eq(' + formerIndex + ') a').tab('show'); 147 }; 148 149 this.currentIndex = function() { 150 return $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '')).index($activeTab); 151 }; 152 153 this.firstIndex = function() { 154 return 0; 155 }; 156 157 this.lastIndex = function() { 158 return obj.navigationLength(); 159 }; 160 161 this.getIndex = function(e) { 162 return $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '')).index(e); 163 }; 164 165 this.nextIndex = function() { 166 var nextIndexCandidate = this.currentIndex(); 167 var nextTabCandidate = null; 168 do { 169 nextIndexCandidate++; 170 nextTabCandidate = $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '') + ":eq(" + nextIndexCandidate + ")"); 171 } while ((nextTabCandidate) && (nextTabCandidate.hasClass("disabled"))); 172 return nextIndexCandidate; 173 }; 174 this.previousIndex = function() { 175 var prevIndexCandidate = this.currentIndex(); 176 var prevTabCandidate = null; 177 do { 178 prevIndexCandidate--; 179 prevTabCandidate = $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '') + ":eq(" + prevIndexCandidate + ")"); 180 } while ((prevTabCandidate) && (prevTabCandidate.hasClass("disabled"))); 181 return prevIndexCandidate; 182 }; 183 this.navigationLength = function() { 184 return $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '')).length - 1; 185 }; 186 this.activeTab = function() { 187 return $activeTab; 188 }; 189 this.nextTab = function() { 190 return $navigation.find(baseItemSelector + ':eq(' + (obj.currentIndex() + 1) + ')').length ? $navigation.find(baseItemSelector + ':eq(' + (obj.currentIndex() + 1) + ')') : null; 191 }; 192 this.previousTab = function() { 193 if (obj.currentIndex() <= 0) { 194 return null; 195 } 196 return $navigation.find(baseItemSelector + ':eq(' + parseInt(obj.currentIndex() - 1) + ')'); 197 }; 198 this.show = function(index) { 199 var tabToShow = isNaN(index) ? 200 element.find(baseItemSelector + ' a[href="#' + index + '"]') : 201 element.find(baseItemSelector + ':eq(' + index + ') a'); 202 if (tabToShow.length > 0) { 203 historyStack.push(obj.currentIndex()); 204 tabToShow.tab('show'); 205 } 206 }; 207 this.disable = function(index) { 208 $navigation.find(baseItemSelector + ':eq(' + index + ')').addClass('disabled'); 209 }; 210 this.enable = function(index) { 211 $navigation.find(baseItemSelector + ':eq(' + index + ')').removeClass('disabled'); 212 }; 213 this.hide = function(index) { 214 $navigation.find(baseItemSelector + ':eq(' + index + ')').hide(); 215 }; 216 this.display = function(index) { 217 $navigation.find(baseItemSelector + ':eq(' + index + ')').show(); 218 }; 219 this.remove = function(args) { 220 var $index = args[0]; 221 var $removeTabPane = typeof args[1] != 'undefined' ? args[1] : false;
222 var $item = $navigation.find(baseItemSelector + ':eq(' + $index + ')'); 223 224 // Remove the tab pane first if needed 225 if ($removeTabPane) { 226 var $href = $item.find('a').attr('href'); 227 $($href).remove(); 228 } 229 230 // Remove menu item 231 $item.remove(); 232 }; 233 234 var innerTabClick = function(e) { 235 // Get the index of the clicked tab 236 var $ul = $navigation.find(baseItemSelector); 237 var clickedIndex = $ul.index($(e.currentTarget).parent(baseItemSelector)); 238 var $clickedTab = $($ul[clickedIndex]); 239 if ($settings.onTabClick && typeof $settings.onTabClick === 'function' && $settings.onTabClick($activeTab, $navigation, obj.currentIndex(), clickedIndex, $clickedTab) === false) { 240 return false; 241 } 242 }; 243 244 var innerTabShown = function(e) { 245 var $element = $(e.target).parent(); 246 var nextTab = $navigation.find(baseItemSelector).index($element); 247 248 // If it's disabled then do not change 249 if ($element.hasClass('disabled')) { 250 return false; 251 } 252 253 if ($settings.onTabChange && typeof $settings.onTabChange === 'function' && $settings.onTabChange($activeTab, $navigation, obj.currentIndex(), nextTab) === false) { 254 return false; 255 } 256 257 $activeTab = $element; // activated tab 258 obj.fixNavigationButtons(); 259 }; 260 261 this.resetWizard = function() { 262 263 // remove the existing handlers 264 $('a[data-toggle="tab"]', $navigation).off('click', innerTabClick); 265 $('a[data-toggle="tab"]', $navigation).off('show show.bs.tab', innerTabShown); 266 267 // reset elements based on current state of the DOM 268 $navigation = element.find('ul:first', element); 269 $activeTab = $navigation.find(baseItemSelector + '.active', element); 270 271 // re-add handlers 272 $('a[data-toggle="tab"]', $navigation).on('click', innerTabClick); 273 $('a[data-toggle="tab"]', $navigation).on('show show.bs.tab', innerTabShown); 274 275 obj.fixNavigationButtons(); 276 }; 277 278 $navigation = element.find('ul:first', element); 279 $activeTab = $navigation.find(baseItemSelector + '.active', element); 280 281 if (!$navigation.hasClass($settings.tabClass)) { 282 $navigation.addClass($settings.tabClass); 283 } 284 285 // Load onInit 286 if ($settings.onInit && typeof $settings.onInit === 'function') { 287 $settings.onInit($activeTab, $navigation, 0); 288 } 289 290 // Load onShow 291 if ($settings.onShow && typeof $settings.onShow === 'function') { 292 $settings.onShow($activeTab, $navigation, obj.nextIndex()); 293 } 294 295 $('a[data-toggle="tab"]', $navigation).on('click', innerTabClick); 296 297 // attach to both show and show.bs.tab to support Bootstrap versions 2.3.2 and 3.0.0 298 $('a[data-toggle="tab"]', $navigation).on('show show.bs.tab', innerTabShown); 299 }; 300 $.fn.bootstrapWizard = function(options) { 301 //expose methods 302 if (typeof options == 'string') { 303 var args = Array.prototype.slice.call(arguments, 1) 304 if (args.length === 1) { 305 args.toString(); 306 } 307 return this.data('bootstrapWizard')[options](args); 308 } 309 return this.each(function(index) { 310 var element = $(this); 311 // Return early if this element already has a plugin instance 312 if (element.data('bootstrapWizard')) return; 313 // pass options to plugin constructor 314 var wizard = new bootstrapWizardCreate(element, options); 315 // Store plugin object in this element's data 316 element.data('bootstrapWizard', wizard); 317 // and then trigger initial change 318 wizard.fixNavigationButtons(); 319 }); 320 }; 321 322 // expose options 323 $.fn.bootstrapWizard.defaults = { 324 withVisible: true, 325 tabClass: 'nav nav-pills', 326 nextSelector: '.wizard li.next', 327 previousSelector: '.wizard li.previous', 328 firstSelector: '.wizard li.first', 329 lastSelector: '.wizard li.last', 330 finishSelector: '.wizard li.finish', 331 backSelector: '.wizard li.back', 332 onShow: null, 333 onInit: null, 334 onNext: null, 335 onPrevious: null, 336 onLast: null, 337 onFirst: null, 338 onFinish: null, 339 onBack: null, 340 onTabChange: null, 341 onTabClick: null, 342 onTabShow: null 343 }; 344 345})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.