1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- ;(function ( $, window, document, undefined ) {
- var pluginName = 'tabs',
- defaults = {
- activeClass : 'current',
- event : 'click',
- fx : 0,
- selected : 0,
- onShow : $.noop
- };
-
- function Plugin( element, selector, options ) {
- this.element = element;
- this.selector = selector;
- this.options = $.extend( {}, defaults, options) ;
- this.init();
- }
- Plugin.prototype.init = function () {
- var element = this.element,
- selector = this.selector,
- options = this.options,
- navList = element.children(),
- contentList = $(selector);
-
-
- element.attr('role','tablist');
- navList.attr('role','tab');
- contentList.attr({'role':'tabpanel','aria-hidden':'true'});
-
- function show(index) {
- var selected_element = navList.eq(index);
- selected_element.addClass( options.activeClass ).siblings().removeClass( options.activeClass );
- var currentContent = contentList.eq(index);
- currentContent.show( options.fx ,options.onShow.call(currentContent)).attr('aria-hidden','false').siblings().hide( options.fx ).attr('aria-hidden','true');
- }
- show(options.selected);
-
- navList.bind(options.event,function(e) {
- e.preventDefault();
- e.stopPropagation();
- var index = $(this).index();
- show(index);
- });
- navList.find(' > a').bind('focus',function(e) {
- e.stopPropagation();
- e.preventDefault();
- $(this).parent().trigger(options.event);
- });
- };
- $.fn[pluginName] = function ( selector, options ) {
- return this.each(function () {
- if (!$.data(this, 'plugin_' + pluginName)) {
- $.data(this, 'plugin_' + pluginName, new Plugin( $(this), selector ,options ));
- }
- });
- }
- })( jQuery, window );
|