1/* 2idTabs ~ Sean Catchpole - Version 2.2 - MIT/GPL 3www.sunsean.com/idTabs/ 4*/ 5 6(function($){ 7 8 $.fn.idTabs = function(){ 9 //Loop Arguments matching options 10 var s = {}; 11 for(var i=0; i<arguments.length; ++i) { 12 var a=arguments[i]; 13 switch(a.constructor){ 14 case Object: $.extend(s,a); break; 15 case Boolean: s.change = a; break; 16 case Number: s.start = a; break; 17 case Function: s.click = a; break; 18 case String: 19 if(a.charAt(0)=='.') s.selected = a; 20 else if(a.charAt(0)=='!') s.event = a; 21 else s.start = a; 22 break; 23 } 24 } 25 26 if(typeof s['return'] == "function") //backwards compatible 27 s.change = s['return']; 28 29 return this.each(function(){ $.idTabs(this,s); }); //Chainable 30 } 31 32 $.idTabs = function(tabs,options) { 33 //Settings 34 var meta = ($.metadata)?$(tabs).metadata():{}; 35 var s = $.extend({},$.idTabs.settings,meta,options); 36 37 //Play nice 38 if(s.selected.charAt(0)=='.') s.selected=s.selected.substr(1); 39 if(s.event.charAt(0)=='!') s.event=s.event.substr(1); 40 if(s.start==null) s.start=-1; //no tab selected 41 42 //Setup Tabs 43 var showId = function(){ 44 if($(this).is('.'+s.selected)) 45 return s.change; //return if already selected 46 var id = "#"+this.href.split('#')[1]; 47 var aList = []; //save tabs 48 var idList = []; //save possible elements 49 $("a",tabs).each(function(){ 50 if(this.href.match(/#/)) { 51 aList.push(this); 52 idList.push("#"+this.href.split('#')[1]); 53 } 54 }); 55 if(s.click && !s.click.apply(this,[id,idList,tabs,s])) return s.change; 56 //Clear tabs, and hide all 57 for(i in aList) $(aList[i]).removeClass(s.selected); 58 for(i in idList) $(idList[i]).hide(); 59 //Select clicked tab and show content 60 $(this).addClass(s.selected); 61 $(id).show(); 62 return s.change; //Option for changing url 63 } 64 65 //Bind idTabs 66 var list = $("a[href*='#']",tabs).unbind(s.event,showId).bind(s.event,showId); 67 list.each(function(){ $("#"+this.href.split('#')[1]).hide(); }); 68 69 //Select default tab 70 var test=false; 71 if((test=list.filter('.'+s.selected)).length); //Select tab with selected class 72 else if(typeof s.start == "number" &&(test=list.eq(s.start)).length); //Select num tab 73 else if(typeof s.start == "string" //Select tab linking to id 74 &&(test=list.filter("[href*='#"+s.start+"']")).length); 75 if(test) { test.removeClass(s.selected); test.trigger(s.event); } //Select tab 76 77 return s; //return current settings (be creative) 78 } 79 80 //Defaults 81 $.idTabs.settings = { 82 start:0, 83 change:false, 84 click:null, 85 selected:".active_tab", 86 event:"!click" 87 }; 88 89 //Version 90 $.idTabs.version = "2.2"; 91 92 //Auto-run 93 $(function(){ $(".idTabs").idTabs(); }); 94 95})(jQuery); 96 97 98
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.