1/* 2Yetii - Yet (E)Another Tab Interface Implementation 3version 1.7 4http://www.kminek.pl/lab/yetii/ 5Copyright (c) Grzegorz Wojcik 6Code licensed under the BSD License: 7http://www.kminek.pl/bsdlicense.txt 8*/ 9 10function Yetii() { 11 12 this.defaults = { 13 id: null, 14 active: 1, 15 interval: null, 16 wait: null, 17 persist: null, 18 tabclass: 'tab', 19 activeclass: 'active', 20 callback: null, 21 leavecallback: null 22 23 }; 24 25 this.activebackup = null; 26 27 for (var n in arguments[0]) { 28 this.defaults[n]=arguments[0][n]; 29 }; 30 31 this.getTabs = function() { 32 var retnode = []; 33 var elem = document.getElementById(this.defaults.id).getElementsByTagName('*'); 34 var regexp = new RegExp("(^|\\s)" + this.defaults.tabclass.replace(/\-/g, "\\-") + "(\\s|$)"); 35 for (var i = 0; i < elem.length; i++) { 36 if (regexp.test(elem[i].className)) retnode.push(elem[i]); 37 } 38 return retnode; 39 }; 40 41 this.links = document.getElementById(this.defaults.id + '-nav').getElementsByTagName('a'); 42 this.listitems = document.getElementById(this.defaults.id + '-nav').getElementsByTagName('li'); 43 44 this.show = function(number) { 45 for (var i = 0; i < this.tabs.length; i++) { 46 this.tabs[i].style.display = ((i+1)==number) ? 'block' : 'none'; 47 if ((i+1)==number) { 48 this.addClass(this.links[i], this.defaults.activeclass); 49 this.addClass(this.listitems[i], this.defaults.activeclass + 'li'); 50 } else { 51 this.removeClass(this.links[i], this.defaults.activeclass); 52 this.removeClass(this.listitems[i], this.defaults.activeclass + 'li'); 53 } 54 } 55 if (this.defaults.leavecallback && (number != this.activebackup)) this.defaults.leavecallback(this.defaults.active); 56 this.activebackup = number; 57 this.defaults.active = number; 58 if (this.defaults.callback) this.defaults.callback(number); 59 }; 60 61 this.rotate = function(interval) { 62 this.show(this.defaults.active); 63 this.defaults.active++; 64 if (this.defaults.active > this.tabs.length) this.defaults.active = 1; 65 var self = this; 66 if (this.defaults.wait) clearTimeout(this.timer2); 67 this.timer1 = setTimeout(function(){ 68 self.rotate(interval); 69 }, interval*1000); 70 }; 71 72 this.next = function() { 73 var _target = (this.defaults.active + 1 > this.tabs.length) ? 1 : this.defaults.active + 1; 74 this.show(_target); 75 this.defaults.active = _target; 76 }; 77 78 this.previous = function() { 79 var _target = ((this.defaults.active - 1) == 0) ? this.tabs.length : this.defaults.active - 1; 80 this.show(_target); 81 this.defaults.active = _target; 82 }; 83 84 this.previous = function() { 85 this.defaults.active--; 86 if(!this.defaults.active) this.defaults.active = this.tabs.length; 87 this.show(this.defaults.active); 88 }; 89 90 this.gup = function(name) { 91 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 92 var regexS = "[\\?&]"+name+"=([^&#]*)"; 93 var regex = new RegExp( regexS ); 94 var results = regex.exec( window.location.href ); 95 if (results == null) return null; 96 else return results[1]; 97 }; 98 99 this.parseurl = function(tabinterfaceid) { 100 var result = this.gup(tabinterfaceid); 101 if (result==null) return null; 102 if (parseInt(result)) return parseInt(result); 103 if (document.getElementById(result)) { 104 for (var i=0;i<this.tabs.length;i++) { 105 if (this.tabs[i].id == result) return (i+1); 106 } 107 } 108 return null; 109 }; 110 111 this.createCookie = function(name,value,days) { 112 if (days) { 113 var date = new Date(); 114 date.setTime(date.getTime()+(days*24*60*60*1000)); 115 var expires = "; expires="+date.toGMTString(); 116 } 117 else var expires = ""; 118 document.cookie = name+"="+value+expires+"; path=/"; 119 }; 120 121 this.readCookie = function(name) { 122 var nameEQ = name + "="; 123 var ca = document.cookie.split(';'); 124 for(var i=0;i < ca.length;i++) { 125 var c = ca[i]; 126 while (c.charAt(0)==' ') c = c.substring(1,c.length); 127 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 128 } 129 return null; 130 }; 131 132 this.hasClass = function(el, className){ 133 var classes = el.className.split(' '); 134 for (var i = 0; i < classes.length; i++) { 135 if (classes[i] == className) return true; 136 } 137 return false;
138 }; 139 140 this.addClass = function(el, className){ 141 if (!this.hasClass(el, className)) el.className = (el.className + ' ' + className).replace(/\s{2,}/g, ' ').replace(/^\s+|\s+$/g, ''); 142 }; 143 144 this.removeClass = function(el, className){ 145 el.className = el.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1'); 146 el.className.replace(/\s{2,}/g, ' ').replace(/^\s+|\s+$/g, ''); 147 }; 148 149 this.tabs = this.getTabs(); 150 this.defaults.active = (this.parseurl(this.defaults.id)) ? this.parseurl(this.defaults.id) : this.defaults.active; 151 if (this.defaults.persist && this.readCookie(this.defaults.id)) this.defaults.active = this.readCookie(this.defaults.id); 152 this.activebackup = this.defaults.active; 153 this.show(this.defaults.active); 154 155 var self = this; 156 for (var i = 0; i < this.links.length; i++) { 157 this.links[i].customindex = i+1; 158 this.links[i].onclick = function(){ 159 160 if (self.timer1) clearTimeout(self.timer1); 161 if (self.timer2) clearTimeout(self.timer2); 162 163 self.show(this.customindex); 164 if (self.defaults.persist) self.createCookie(self.defaults.id, this.customindex, 0); 165 166 if (self.defaults.wait) self.timer2 = setTimeout(function(){ 167 self.rotate(self.defaults.interval); 168 }, self.defaults.wait*1000); 169 170 return false; 171 }; 172 } 173 174 if (this.defaults.interval) this.rotate(this.defaults.interval); 175 176};
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.