1/* 2 * mbScrollable, developed by Matteo Bicocchi on JQuery 3 * © 2002-2009 Open Lab srl, Matteo Bicocchi 4 * www.open-lab.com - [email protected] 5 * version 1.0 6 * tested on: Explorer, Chrome, FireFox for PC 7 * FireFox and Safari for Mac Os X 8 * FireFox for Linux 9 * MIT (MIT-LICENSE.txt) licenses. 10 */ 11 12(function(jQuery) { 13 jQuery.mbScrollable= { 14 plugin:"mb.scroller", 15 author:"MB", 16 version:"1.0", 17 defaults:{ 18 width:650, 19 elementsInPage:4, 20 elementMargin:2, 21 shadow:false, 22 height:"auto", 23 controls:"#controls1, #controls2", 24 slideTimer:600, 25 autoscroll:false, 26 scrollTimer:6000 27 }, 28 buildMbScrollable: function(options){ 29 30 return this.each (function (){ 31 this.options = {}; 32 jQuery.extend (this.options, jQuery.mbScrollable.defaults); 33 jQuery.extend (this.options, options); 34 35 var mbScrollable=this; 36 var el=this; 37 var controller=jQuery(this.options.controls); 38 this.idx=1; 39 this.scrollTo=0; 40 this.elements= jQuery(this).children(); 41 this.elements.addClass("scrollEl1"); 42 43 controller.hide(); 44 jQuery(this).children().each(function(){jQuery(this).wrap("<div class='SECont1'></div>");}); 45 if (this.options.shadow){ 46 jQuery(this.elements).css("-moz-box-shadow",this.options.shadow); 47 jQuery(this.elements).css("-webkit-box-shadow",this.options.shadow); 48 } 49 this.elements= jQuery(this).children(); 50 51 this.singleElWidth= (this.options.width/this.options.elementsInPage)-this.options.elementMargin; 52 this.elementsWidth= (this.singleElWidth*this.elements.size())+(this.options.elementMargin*this.elements.size()); 53 this.totalPages= Math.ceil(this.elements.size()/this.options.elementsInPage); 54 if (this.options.elementsInPage<this.options.elementsInPage){ 55 this.totalPages-=this.options.elementsInPage-this.options.elementsInPage; 56 } 57 58 this.elementsInpage= Math.floor(this.options.width/this.singleElWidth); 59 jQuery(this.elements).css({marginRight:this.options.elementMargin, width:this.singleElWidth, display:"inline-block" }); //float:"left" 60 61 var adj= jQuery.browser.safari && el.options.elementsInPage>2?this.options.elementMargin/(this.options.elementsInPage):0; 62 63 jQuery(mbScrollable).css({overflow:"hidden", width:this.options.width-adj,height:this.options.height,paddingBottom:5, position:"relative"}); 64 jQuery(this.elements).wrapAll("<div class='scrollableStrip'><\/div>"); 65 this.mbscrollableStrip= jQuery(this).find(".scrollableStrip"); 66 jQuery(this.mbscrollableStrip).css({width:this.elementsWidth, position:"relative"}); 67 jQuery(this.elements).hover( 68 function(){ 69 if(jQuery(mbScrollable)[0].autoScrollActive) 70 jQuery(mbScrollable).mbStopAutoscroll(); 71 }, 72 function(){ 73 if(jQuery(mbScrollable)[0].autoScrollActive) 74 jQuery(mbScrollable).mbAutoscroll(); 75 } 76 ); 77 if(this.options.autoscroll && this.elements.size()>this.options.elementsInPage){ 78 this.autoScrollActive=true; 79 jQuery(this).mbAutoscroll(); 80 } 81 jQuery(this).mbPageIndex(); 82 jQuery(mbScrollable).mbActivateControls(); 83 jQuery(mbScrollable).mbManageControls(); 84 setTimeout(function(){ 85 jQuery(".scrollEl1").fadeIn(); 86 controller.fadeIn(); 87 },0); 88 }); 89 }, 90 mbNextPage: function(){ 91 var el= jQuery(this).get(0); 92 if(el.idx==el.totalPages){ 93 jQuery(this).mbManageControls(); 94 return; 95 } 96 97 98 var adj= jQuery.browser.safari && el.options.elementsInPage>2?el.options.elementMargin/el.options.elementsInPage:0; 99 100 el.scrollTo-=((el.singleElWidth+el.options.elementMargin)*el.options.elementsInPage)-adj; 101 if (el.scrollTo<-el.elementsWidth+el.options.width) 102 el.scrollTo=-el.elementsWidth+el.options.width; 103 jQuery(el.mbscrollableStrip).animate({marginLeft:el.scrollTo}
103,el.options.slideTimer); 104 el.idx+=1; 105 jQuery(this).mbManageControls(); 106 }, 107 mbPrevPage: function(){ 108 var el= jQuery(this).get(0); 109 if(el.idx==1){ 110 jQuery(this).mbManageControls(); 111 return; 112 } 113 var adj= jQuery.browser.safari && el.options.elementsInPage>2?el.options.elementMargin/el.options.elementsInPage:0; 114 115 el.scrollTo+=((el.singleElWidth+el.options.elementMargin)*el.options.elementsInPage)+adj; 116 if (el.scrollTo>=0) 117 el.scrollTo=0; 118 jQuery(el.mbscrollableStrip).animate({marginLeft:el.scrollTo},el.options.slideTimer); 119 el.idx-=1; 120 jQuery(this).mbManageControls(); 121 }, 122 mbFirstPage: function(){ 123 var mbScrollable=this; 124 var el= jQuery(this).get(0); 125 el.scrollTo=0; 126 jQuery(el.mbscrollableStrip).animate({marginLeft:el.scrollTo},el.options.slideTimer); 127 el.idx=1; 128 jQuery(this).mbManageControls(); 129 jQuery(mbScrollable).mbStopAutoscroll(); 130 }, 131 mbLastPage: function(){ 132 var mbScrollable=this; 133 var el= jQuery(this).get(0); 134 el.scrollTo=-el.elementsWidth+el.options.width; 135 jQuery(el.mbscrollableStrip).animate({marginLeft:el.scrollTo},el.options.slideTimer); 136 el.idx=el.totalPages; 137 jQuery(this).mbManageControls(); 138 jQuery(mbScrollable).mbStopAutoscroll(); 139 }, 140 mbPageIndex: function(){ 141 var mbScrollable=this; 142 var el= jQuery(mbScrollable).get(0); 143 var controls=jQuery(el.options.controls); 144 var pages=controls.find(".pageIndex"); 145 if (pages){ 146 function getPage(i){ 147 el.scrollTo=-((el.singleElWidth+el.options.elementMargin)*(el.options.elementsInPage*(i-1))); 148 if (el.scrollTo<-el.elementsWidth+el.options.width) 149 el.scrollTo=-el.elementsWidth+el.options.width; 150 jQuery(el.mbscrollableStrip).animate({marginLeft:el.scrollTo},el.options.slideTimer); 151 el.idx = Math.floor(i); 152 jQuery(mbScrollable).mbManageControls(); 153 } 154 var n=0; 155 for(var i=1;i<=el.totalPages;i++){ 156 n++; 157 var p=jQuery("<span class='page'> "+n+" <\/span>").bind("click",function(){ 158 getPage(jQuery(this).html()); 159 jQuery(mbScrollable).mbStopAutoscroll(); 160 }); 161 pages.append(p); 162 }; 163 } 164 }, 165 mbAutoscroll:function(){ 166 var dir= "next"; 167 var mbScrollable=this; 168 var el= jQuery(mbScrollable).get(0); 169 170 if(el.autoscroll) return; 171 var timer=el.options.scrollTimer; 172 el.autoscroll = true; 173 el.auto = setInterval(function(){ 174 dir= el.idx==1?"next":el.idx==el.totalPages?"prev":dir; 175 if(dir=="next") 176 jQuery(mbScrollable).mbNextPage(); 177 else 178 jQuery(mbScrollable).mbPrevPage(); 179 },timer); 180 jQuery(this).mbManageControls(); 181 }, 182 mbStopAutoscroll: function(){ 183 var mbScrollable=this; 184 var el= jQuery(mbScrollable).get(0); 185 el.autoscroll = false; 186 clearInterval(el.auto); 187 jQuery(this).mbManageControls(); 188 }, 189 mbActivateControls: function(){ 190 var mbScrollable=this; 191 var el= jQuery(mbScrollable).get(0); 192 var controls=jQuery(el.options.controls); 193 controls.find(".first").bind("click",function(){jQuery(mbScrollable).mbFirstPage();}); 194 controls.find(".prev").bind("click",function(){jQuery(mbScrollable).mbStopAutoscroll();jQuery(mbScrollable).mbPrevPage();}); 195 controls.find(".next").bind("click",function(){jQuery(mbScrollable).mbStopAutoscroll();jQuery(mbScrollable).mbNextPage();}); 196 controls.find(".last").bind("click",function(){jQuery(mbScrollable).mbLastPage();}); 197 controls.find(".start").bind("click",function(){jQuery(mbScrollable).mbAutoscroll();jQuery(mbScrollable)[0].autoScrollActive=true;}); 198 controls.find(".stop").bind("click",function(){jQuery(mbScrollable).mbStopAutoscroll();jQuery(mbScrollable)[0].autoScrollActive=false;}); 199 }, 200 mbManageControls:function(){ 201 var mbScrollable=this; 202 var el= jQuery(mbScrollable).get(0); 203 var controls=jQuery(el.options.controls); 204 if (el.elements.size()<=el.options.elementsInPage){ 205 controls.hide(); 206 } 207 /* 208 if (!el.options.autoscroll){ 209 controls.find(".start").hide(); 210 controls.find(".stop").hide(); 211 } 212 */ 213 if (el.idx==el.totalPages){ 214 controls.find(".last").addClass("disabled"); 215 controls.find(".next").addClass("disabled"); 216 }else{ 217 controls.find(".last").removeClass("disabled"); 218 controls.find(".next").removeClass("disabled"); 219 } 220 221 if (el.idx==1){ 222 controls.find(".first").addClass("disabled"); 223 controls.find(".prev").addClass("disabled"); 224 }else{ 225 controls.find(".first").removeClass("disabled"); 226 controls.find(".prev").removeClass("disabled"); 227 } 228 229 if (el.autoscroll){ 230 controls.find(".start").addClass("sel"); 231 controls.find(".stop").removeClass("sel"); 232 }else{ 233 controls.find(".start").removeClass("sel"); 234 controls.find(".stop").addClass("sel"); 235 } 236 237 controls.find(".page").removeClass("sel"); 238 controls.find(".page").eq(el.idx-1).addClass("sel"); 239 controls.find(".idx").html(el.idx+" / "+el.totalPages); 240 } 241 }; 242 243 jQuery.fn.mbScrollable=jQuery.mbScrollable.buildMbScrollable; 244 jQuery.fn.mbNextPage=jQuery.mbScrollable.mbNextPage; 245 jQuery.fn.mbPrevPage=jQuery.mbScrollable.mbPrevPage; 246 jQuery.fn.mbFirstPage=jQuery.mbScrollable.mbFirstPage; 247 jQuery.fn.mbLastPage=jQuery.mbScrollable.mbLastPage; 248 jQuery.fn.mbPageIndex=jQuery.mbScrollable.mbPageIndex; 249 jQuery.fn.mbAutoscroll=jQuery.mbScrollable.mbAutoscroll; 250 jQuery.fn.mbStopAutoscroll=jQuery.mbScrollable.mbStopAutoscroll; 251 jQuery.fn.mbActivateControls=jQuery.mbScrollable.mbActivateControls; 252 jQuery.fn.mbManageControls=jQuery.mbScrollable.mbManageControls; 253 254}
254)(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.