1/*! 2 * myFocus JavaScript Library v2.0.4 3 * https://github.com/koen301/myfocus 4 * 5 * Copyright 2012, Koen Lee 6 * Released under the MIT license 7 * 8 * Date: 2012/10/28 9 */ 10(function(){ 11 //DOMåºç¡æä½å½æ° 12 var $id=function(id){ 13 return typeof id==='string'?document.getElementById(id):id; 14 }, 15 $tag=function(tag,parentNode){ 16 return ($id(parentNode)||document).getElementsByTagName(tag); 17 }, 18 $tag_=function(tag,parentNode){ 19 return $getChild(tag,parentNode,'tag'); 20 }, 21 $class=function(className,parentNode){ 22 var doms=$tag('*',parentNode),arr=[]; 23 for(var i=0,l=doms.length;i<l;i++){ 24 if(hasClass(className,doms[i])){ 25 arr.push(doms[i]); 26 } 27 } 28 return arr; 29 }, 30 $class_=function(className,parentNode){ 31 return $getChild(className,parentNode); 32 }, 33 $getChild=function(selector,parentNode,type){ 34 var arr=[],fn=type==='tag'?$tag:$class,doms=fn(selector,parentNode),len=doms.length; 35 for(var i=0;i<len;i++){ 36 if(doms[i].parentNode===parentNode) arr.push(doms[i]); 37 i+=fn(selector,doms[i]).length; 38 } 39 return arr; 40 }, 41 hasClass=function(className,node){ 42 return eval('/(^|\\s)'+className+'(\\s|$)/').test(node.className); 43 }; 44 //å®ä¹myFocuså ¨å±åé 45 myFocus=function(settings){ 46 return new myFocus.constr(settings); 47 }; 48 //æ©å± 49 myFocus.extend=function(){ 50 var arg=arguments,len=arg.length; 51 if(this===myFocus){//ä½ä¸ºæ¹æ³æ©å±ï¼å¦æåªæä¸ä¸ªåæ°æ©å±æ¬èº« 52 if(len===1) dest=myFocus,i=0;//æ©å±myFocusç±» 53 else dest=arg[0],i=1; 54 }else{//æ©å±å¼ç¨å¯¹è±¡æ¬èº« 55 dest=this,i=0; 56 } 57 for(i;i<len;i++){ 58 for(var p in arg[i]){ 59 dest[p]=arg[i][p];//dest屿§æä½ 60 } 61 } 62 return dest; 63 }; 64 myFocus.extend({ 65 defConfig:{//å ¨å±é»è®¤è®¾ç½® 66 pattern:'mF_fancy',//飿 ¼æ ·å¼ 67 trigger:'click',//触ååæ¢æ¨¡å¼['click'(é¼ æ ç¹å»)|'mouseover'(é¼ æ æ¬å)] 68 txtHeight:'default',//æåå±é«åº¦è®¾ç½®[num(æ°å,åä½åç´ ,0表示éèæåå±,çç¥è®¾ç½®å³ä¸ºé»è®¤é«åº¦)]
69 wrap:true,//æ¯å¦éè¦è®©ç¨åºæ·»å ç¦ç¹å¾çå¤å´html(wrap)å ç´ (ç®çæ¯ä¸ºäºæ·»å æäºé£æ ¼çè¾¹æ¡)[true|false] 70 auto:true,//æ¯å¦èªå¨ææ¾(忢)[true|false] 71 time:4,//æ¯æ¬¡åçæ¶é´[num(æ°å,åä½ç§)] 72 index:0,//å¼å§æ¾ç¤ºçå¾çåºå·(ä»0ç®èµ·)[num(æ°å)] 73 loadingShow:true,//æ¯å¦æ¾ç¤ºLoadingç»é¢[true(æ¾ç¤ºï¼å³çå¾ å¾çå è½½å®)|false(䏿¾ç¤ºï¼å³ä¸çå¾ å¾çå è½½å®)] 74 delay:100,//触ååæ¢æ¨¡å¼ä¸'mouseover'模å¼ä¸ç忢延è¿[num(æ°å,å使¯«ç§)] 75 autoZoom:false,//æ¯å¦å 许å¾çèªå¨ç¼©æ¾å± ä¸[true|false] 76 onChange:null,//忢å¾ççæ¶åæ§è¡çèªå®ä¹å½æ°ï¼å¸¦æä¸ä¸ªå½åå¾ç´¢å¼çåæ° 77 xmlFile:'',//myfocuså¾ççxmlé ç½®æä»¶è·¯å¾,ç空å³ä¸è¯»åxmlæä»¶ 78 __focusConstr__:true//ç¨åºæé åæ° 79 }, 80 constr:function(settings){//æé 彿° 81 var e=settings,len=e&&e.length; 82 if(e instanceof myFocus.constr) return e;//myFocus::[] 83 this.length=0; 84 if(!e||(e.sort&&!len)||(e.item&&!len)){//null/array::[]/nodeList::[] 85 Array.prototype.push.call(this); 86 }else if(e.__focusConstr__){//new myFocus 87 e=$id(e.id); 88 Array.prototype.push.call(this,e); 89 this.settings=settings; 90 this.HTMLUList=$tag('li',$tag('ul',e)[0]); 91 this.HTMLUListLength=this.HTMLUList.length; 92 }else if(len){//nodeList/Array/å符串 93 for(var i=0;i<len;i++) Array.prototype.push.call(this,e[i]); 94 }else{//node 95 Array.prototype.push.call(this,e); 96 } 97 return this; 98 }, 99 fn:{splice:[].splice},//åå½¢ 100 pattern:{},//飿 ¼é 101 config:{}
101//åæ°é 102 }); 103 myFocus.constr.prototype=myFocus.fn; 104 myFocus.fn.extend=myFocus.pattern.extend=myFocus.config.extend=myFocus.extend; 105 myFocus.fn.extend({//DOM 106 find:function(selector){//éæ©å¨åªåºç¨åºæ¬æ¥æ¾,æä¸èèç¨querySelectorAll 107 var parent=this,isChild=false,$=myFocus; 108 var arr=this.parseSelector(selector); 109 if(this.length) for(var i=0,len=arr.length;i<len;i++){ 110 var dom=[],s=arr[i]; 111 switch(s.charAt(0)){ 112 case '>'://children 113 isChild=true; 114 break; 115 case '.'://class 116 var cls=s.slice(1); 117 var fn=isChild?$class_:$class; 118 $(parent).each(function(){ 119 dom=dom.concat(fn(cls,this)); 120 }); 121 isChild=false; 122 break; 123 case '#'://id 124 var id=s.slice(1),e=$id(id); 125 if(e) dom.push($id(id)); 126 isChild=false; 127 break; 128 default://tag(æ¯æ'tag.class'寻æ¾,䏿¯æä¹ä¸å»ºè®®ç¨'tag#id'寻æ¾,请ç¨'#id') 129 var fn=isChild?$tag_:$tag,sArr=s.split('.'); 130 var tag=sArr[0],cls=sArr[1]; 131 $(parent).each(function(){ 132 var arr=fn(tag,this); 133 for(var i=0,len=arr.length;i<len;i++){ 134 if(cls&&!hasClass(cls,arr[i])) continue; 135 dom.push(arr[i]); 136 } 137 }); 138 isChild=false; 139 } 140 if(!isChild) parent=dom;//循ç¯èµå¼ç¶å ç´ 141 } 142 return $(parent); 143 }, 144 parent:function(){ 145 return myFocus(this[0].parentNode); 146 }, 147 html:function(s){ 148 if(typeof s!=='undefined'){this[0].innerHTML=s;return this;} 149 else return this[0].innerHTML; 150 }, 151 each:function(fn){ 152 var doms=this; 153 for(var i=0,len=doms.length;i<len;i++){ 154 var flag=fn.call(doms[i],i); 155 if(flag===false) break; 156 if(flag===true) continue; 157 } 158 return this; 159 }, 160 eq:function(n){ 161 return myFocus(this[n]); 162 }, 163 parseSelector:function(selector){ 164 var chunker=/(([^[\]'"]+)+\]|\\.|([^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g; 165 var parts=[],m; 166 while((m = chunker.exec(selector)) !== null ) { 167 parts.push( m[1] );//åå¨å¹é çåç¬¦ä¸²ä¿¡æ¯ 168 } 169 return parts; 170 }, 171 wrap:function(html){//æ¯æ¬¡åªwrapä¸ä¸ªå ç´ ,å¤ä¸ªè¯·ç¨each 172 var o=this[0],e=document.createElement('div'); 173 e.innerHTML=html; 174 var wrap=e.firstChild; 175 o.parentNode.replaceChild(wrap,o); 176 wrap.appendChild(o); 177 return this; 178 }, 179 addHtml:function(html){ 180 var parent=this[0]; 181 var e=document.createElement('div'); 182 e.innerHTML=html; 183 var dom=e.childNodes[0]; 184 parent.appendChild(dom); 185 return myFocus(dom); 186 }, 187 addList:function(className,type){ 188 var li=this.HTMLUList,n=this.HTMLUListLength; 189 var strArr=['<div class="'+className+'"><ul>']; 190 for(var i=0;i<n;i++){ 191 var img=$tag('img',li[i])[0],html; 192 switch(type){ 193 case 'num' :html='<a>'+(i+1)+'</a><b></b>';break;//bæ ç¾ä¸»è¦æ¯ä¸ºäºåéæèæ¯,ä¸å 194 case 'txt' :html=img?li[i].innerHTML.replace(/\<img(.|\n|\r)*?\>/i,img.alt)+'<p>'+img.getAttribute("text")+'</p><b></b>':'';break; 195 case 'thumb':html=img?'<a><img src='+(img.getAttribute("thumb")||img.src)+' /></a><b></b>':'';break; 196 default :html='<a></a><b></b>'; 197 } 198 strArr.push('<li>'+html+'</li>'); 199 } 200 strArr.push('</ul></div>'); 201 return this.addHtml(strArr.join('')); 202 }, 203 addListNum:function(className){ 204 return this.addList(className||'num','num');//é»è®¤class=num 205 }, 206 addListTxt:function(className){ 207 return this.addList(className||'txt','txt');//é»è®¤class=txt 208 }, 209 addListThumb:function(className){ 210 return this.addList(className||'thumb','thumb');//é»è®¤class=thumb 211 }, 212 remove:function(){ 213 var o=this[0]; 214 if(o) o.parentNode.removeChild(o); 215 }, 216 repeat:function(n){ 217 var n=n||2,pNode=this[0].parentNode,html=pNode.innerHTML,s=[]; 218 for(var i=0;i<n;i++) s.push(html); 219 pNode.innerHTML=s.join(''); 220 return myFocus(pNode).find(this[0].nodeName); 221 } 222 }); 223 myFocus.fn.extend({//CSS 224 css:function(css){//å¯è·å¼æè®¾å¼ 225 var o=this[0],value,arr=[';'],isIE=myFocus.isIE; 226 if(!o) return this; 227 if(typeof css==='string'){//è·å¾css屿§å¼,è¿åå¼ä¸å¸¦åä½ 228 if(css==='float') css=isIE?'styleFloat':'cssFloat'; 229 if(!(value=o.style[css])) value=(isIE?o.currentStyle:getComputedStyle(o,''))[css]; 230 if(css==='opacity'&&value===undefined) value=1;//ä» ä¸ºå¨IEä¸å¾å°é»è®¤å¼1 231 if(value==='auto'&&(css==='width'||css==='height')) value=o['offset'+css.replace(/\w/i,function(a){return a.toUpperCase()})]; 232 var numVal=parseFloat(value); 233 return isNaN(numVal)?value:numVal; 234 }else{//设置css屿§å¼,䏿¯æ('height','300px')å½¢å¼,请åæ-->({height:'300px'}),å¯ä»¥ä¸å¸¦åä½px
235 for(var p in css){ 236 if(typeof css[p]==='number'&&!this.cssNumber[p]) css[p]+='px'; 237 arr.push(p.replace(/([A-Z])/g,'-$1')+':'+css[p]+';'); 238 if(p==='opacity') arr.push('filter:alpha(opacity='+css[p]*100+')'); 239 } 240 o.style.cssText+=arr.join(''); 241 return this; 242 } 243 }, 244 setOpacity:function(value){//ä» ç¨äºanimateè¦æ±é«æçæ ¸å¿ç®æ³ä¸,å ¶å®æ åµå¯ç¨css()ä»£æ¿ 245 this[0].style.opacity=value,this[0].style.filter='alpha(opacity='+value*100+')'; 246 }, 247 setAnimateStyle:function(value,prop,m){//ä» ç¨äºanimateè¦æ±é«æçæ ¸å¿ç®æ³ä¸,å ¶å®æ åµå¯ç¨css()ä»£æ¿ 248 this[0].style[prop]=Math[m](value)+'px'; 249 }, 250 addClass:function(className){ 251 this[0].className+=' '+className; 252 return this; 253 }, 254 removeClass:function(className){ 255 var o=this[0],cls=className&&o.className,reg="/\\s*\\b"+className+"\\b/g"; 256 o.className=cls?cls.replace(eval(reg),''):''; 257 return this; 258 }, 259 cssNumber:{fillOpacity:true,fontWeight:true,lineHeight:true,opacity:true,orphans:true,widows:true,zIndex:true,zoom:true}//ä¸å pxçcss,åèjQuery 260 }); 261 myFocus.fn.extend({//Animate 262 animate:function(attr,value,time,type,funcBefore,funcAfter){//valueæ¯æç¸å¯¹å¢å¼'+=100',ç¸å¯¹åå¼'-=100'å½¢å¼ 263 var $o=this,o=$o[0],isOpacity=attr==='opacity',diffValue=false; 264 funcBefore&&funcBefore.call(o); 265 if(typeof value==='string'){ 266 if(/^[+-]=\d+/.test(value)) value=value.replace('=',''),diffValue=true; 267 value=parseFloat(value); 268 } 269 var oriVal=$o.css(attr),//åå§å±æ§å¼ 270 b=isNaN(oriVal)?0:oriVal,//å¼å§å¼,æ 弿¶ä¸º0 271 c=diffValue?value:value-b,//å·®å¼ 272 d=time,//æ»è¿è¡æ¶é´ 273 e=this.easing[type],//ç¼å¨ç±»å 274 m=c>0?'ceil':'floor',//åæå¤§ç»å¯¹å¼ 275 timerId='__myFocusTimer__'+attr,//计æ°å¨id 276 setProperty=$o[isOpacity?'setOpacity':'setAnimateStyle'],//屿§è®¾ç½®æ¹æ³ 277 origTime=(new Date)*1;//åå§æ¶é´å¼ 278 o[timerId]&&clearInterval(o[timerId]); 279 o[timerId]=setInterval(function(){ 280 var t=(new Date)-origTime;//å·²è¿è¡æ¶é´ 281 if(t<=d){ 282 setProperty.call($o,e(t,b,c,d),attr,m); 283 }else{ 284 setProperty.call($o,b+c,attr,m);//设置æç»å¼ 285 clearInterval(o[timerId]),o[timerId]=null; 286 funcAfter&&funcAfter.call(o); 287 } 288 },13); 289 return this; 290 }, 291 fadeIn:function(time,type,fn){ 292 if(typeof time!=='number') fn=time,time=400;//é»è®¤400æ¯«ç§ 293 if(typeof type==='function') fn=type,type=''; 294 this.animate('opacity',1,time,type||'linear',function(){ 295 myFocus(this).css({display:'block',opacity:0}
295); 296 },fn); 297 return this; 298 }, 299 fadeOut:function(time,type,fn){ 300 if(typeof time!=='number') fn=time,time=400;//é»è®¤400æ¯«ç§ 301 if(typeof type==='function') fn=type,type=''; 302 this.animate('opacity',0,time,type||'linear',null,function(){ 303 this.style.display='none'; 304 fn&&fn.call(this); 305 }); 306 return this; 307 }, 308 slide:function(params,time,type,fn){ 309 if(typeof time!=='number') fn=time,time=800;//é»è®¤800æ¯«ç§ 310 if(typeof type==='function') fn=type,type=''; 311 for(var p in params) this.animate(p,params[p],time,type||'easeOut',null,fn); 312 return this; 313 }, 314 stop:function(){//忢ææè¿å¨ 315 var o=this[0]; 316 for(var p in o) if(p.indexOf('__myFocusTimer__')!==-1) o[p]&&clearInterval(o[p]); 317 return this; 318 }, 319 easing:{ 320 linear:function(t,b,c,d){return c*t/d + b;}, 321 swing:function(t,b,c,d) {return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;}, 322 easeIn:function(t,b,c,d){return c*(t/=d)*t*t*t + b;}, 323 easeOut:function(t,b,c,d){return -c*((t=t/d-1)*t*t*t - 1) + b;}, 324 easeInOut:function(t,b,c,d){return ((t/=d/2) < 1)?(c/2*t*t*t*t + b):(-c/2*((t-=2)*t*t*t - 2) + b);} 325 } 326 }); 327 myFocus.fn.extend({//Method(fn) 328 bind:function(type,fn){ 329 myFocus.addEvent(this[0],type,fn); 330 return this; 331 }, 332 play:function(funcLastFrame,funcCurrentFrame,seamless){ 333 var this_=this,p=this_.settings,n=this_.HTMLUListLength,t=p.time*1000,seamless=seamless||false,//æ¯å¦æ ç¼ 334 float=myFocus(this_.HTMLUList).css('float'),isLevel=float==='left',//ä» æ¯æ'left'æ¹åå'top'æ¹å 335 direction=isLevel?'left':'top',distance=isLevel?p.width:p.height,//è¿å¨è·ç¦» 336 indexLast=0,indexCurrent=p.index;//帧索å¼å¼,é»è®¤0 337 this_.find('.loading').remove();//å é¤loading... 338 this_.run=function(value){//循ç¯è¿å¨å½æ°,æ¯æ+-=value 339 funcLastFrame&&funcLastFrame(indexLast,n);//è¿è¡åä¸å¸§ 340 indexCurrent=typeof value==='string'?indexLast+parseInt(value.replace('=','')):value;//fixed index 341 if(indexCurrent<=-1){//prev run 342 indexCurrent=n-1;//è½¬å°æåä¸å¸§ 343 if(seamless) this_.HTMLUList[0].parentNode.style[direction]=-n*distance+'px';//æ ç¼çULå®ä½ 344 } 345 if(indexCurrent>=n){//next run 346 if(!seamless) indexCurrent=0;//éæ ç¼æ¶è½¬å°ç¬¬ä¸å¸§ 347 if(indexCurrent>=2*n){//æ ç¼ 348 this_.HTMLUList[0].parentNode.style[direction]=-(n-1)*distance+'px';//æ ç¼çULå®ä½ 349 indexCurrent=n; 350 } 351 } 352 if(seamless&&indexLast>=n&&indexCurrent<n) indexCurrent+=n;//æ ç¼æ¶çæé®ç¹å»(ä¿æå䏿¹å) 353 funcCurrentFrame&&funcCurrentFrame(indexCurrent,n,indexLast);//è¿è¡å½å帧 354 this_.runIndex=indexLast=indexCurrent;//ä¿åå·²è¿è¡çå¸§ç´¢å¼ 355 //å¢å èªå®ä¹åè°å½æ°@10.27 356 p.onChange&&p.onChange.call(this_,indexCurrent); 357 }; 358 //è¿è¡...(tryæ¯ä¸ºäºå ¼å®¹é£æ ¼jsä¸playæ¯bindControlå æ§è¡) 359 try{this_.run(indexCurrent)}catch(e){setTimeout(function(){this_.run(indexCurrent)},0)}; 360 if(p.auto&&n>1){//èªå¨åæ¢ 361 this_.runTimer=setInterval(function(){this_.run('+=1')},t);//é»è®¤éå¢è¿è¡æ¯å¸§ 362 this_.bind('mouseover',function(){//ç»å®äºä»¶ 363 clearInterval(this_.runTimer); 364 this_.runTimer='pause';//æ è®°ä»¥é²æ¢æ§è¡ä¸¤æ¬¡this_.runTimer 365 }).bind('mouseout',function(){ 366 if(!this_.isStop&&this_.runTimer==='pause') this_.runTimer=setInterval(function(){this_.run('+=1')},t); 367 }); 368 } 369 this_.find('a').each(function(){//å»é¤IE龿¥è线 370 this.onfocus=function(){this.blur();} 371 }); 372 }, 373 bindControl:function($btnList,params){//params={thumbShowNum(ç¥ç¼©å¾æ¾ç¤ºæ°ç®(妿æ)):num,isRunning(è¿è¡ä¸çæ è®°(å½éè¦å¤ææ¶)):boolean} 374 var this_=this,p=this_.settings,type=p.trigger,delay=p.delay,par=params||{},tsNum=par.thumbShowNum||p.thumbShowNum; 375 var run=function(){ 376 if(this.index!==this_.runIndex&&!par.isRunning){ 377 this_.run(this.index); 378 return false;//黿¢å泡&é»è®¤äºä»¶ 379 } 380 }; 381 $btnList.each(function(i){ 382 this.index=i;//è®°å½èªèº«ç´¢å¼ 383 var o=this,$o=myFocus(o); 384 if(type==='click'){ 385 $o.bind('mouseover',function(){ 386 $o.addClass('hover'); 387 }).bind('mouseout',function(){ 388 $o.removeClass('hover'); 389 }).bind('click',run); 390 }else if(type==='mouseover'){ 391 $o.bind('mouseover',function(){ 392 if(delay===0) run.call(o); 393 else $btnList.mouseoverTimer=setTimeout(function(){run.call(o)},delay); 394 }).bind('mouseout',function(){ 395 $btnList.mouseoverTimer&&clearTimeout($btnList.mouseoverTimer); 396 }); 397 }else{ 398 alert('myFocus Error Setting(trigger) : \"'+type+'\"'); 399 return false;
400 }; 401 }); 402 if(tsNum){//thumb 403 var float=$btnList.css('float'),isLevel=float==='left'||float==='right'; 404 $btnList.dir=isLevel?'left':'top';//æ¹å 405 $btnList.n=this_.HTMLUListLength;//æ»æ° 406 $btnList.showNum=tsNum;//æ¾ç¤ºæ°ç® 407 $btnList.showStart=p.index;//æ¾ç¤ºçå¼å§ç´¢å¼ 408 $btnList.showEnd=$btnList.showStart+tsNum-1;//æ¾ç¤ºçç»å°¾ç´¢å¼ 409 $btnList.distance=$btnList.css(isLevel?'width':'height');//è¿å¨è·ç¦» 410 $btnList.slideBody=$btnList.parent();//è¿å¨å¯¹è±¡(ul) 411 } 412 }, 413 scrollTo:function(i,time){ 414 var n=this.n,dir=this.dir,$ul=this.slideBody,css={};//æ»æ°/æ¹å/æ»å¨body(ul)/æ ·å¼ 415 if(i>=this.showEnd){//next 416 this.showEnd=i<n-1?i+1:i; 417 418 this.showStart=this.showEnd-this.showNum+1; 419 }else if(i<=this.showStart){//prev 420 this.showStart=i>0?i-1:0; 421 this.showEnd=this.showStart+this.showNum-1; 422 } 423 css[dir]=-this.showStart*this.distance; 424 $ul.slide(css,time||500,'easeOut'); 425 return this; 426 } 427 }); 428 myFocus.extend({//Init 429 set:function(p,callback){ 430 var F=this,id=p.id,oStyle=F.initBaseCSS(id); 431 p.pattern=p.pattern||F.defConfig.pattern; 432 p.__clsName=p.pattern+'_'+id; 433 F.addEvent(window,'load',function(){F.onloadWindow=true}); 434 F.loadPattern(p,function(){ 435 p=F.extend({},F.defConfig,F.config[p.pattern],p);//æ¶é宿´åæ° 436 F.getBoxReady(p,function(){ 437 var $o=F($id(id)); 438 p.$o=$o;//ä¿ånode 439 //xml load 440 p.xmlFile&&F.loadXML(p); 441 p.pic=$class('pic',$o[0])[0];//ä¿ånode foræ¯å¦æ å飿 ¼ç夿忝å¦éè¦initcss 442 p.width=p.width||$o.css('width'),p.height=p.height||$o.css('height');//è·å¾boxé«/宽 443 F.initCSS(p,oStyle);//css 444 $o.addClass(p.pattern+' '+p.__clsName);//+className 445 F.getIMGReady(p,function(arrSize){ 446 if(p.autoZoom) F.zoomIMG(p,arrSize);//缩æ¾å¾ç 447 F.pattern[p.pattern](p,F);//è¿è¡pattern代ç 448 callback&&callback(); 449 }); 450 }); 451 }); 452 }, 453 onloadWindow:false, 454 loadPattern:function(p,callback){ 455 if(this.pattern[p.pattern]){callback();return;}//妿已å è½½pattern 456 var path=this.getFilePath()+'mf-pattern/'+p.pattern; 457 var js= document.createElement("script"),css=document.createElement("link"),src=path+'.js',href=path+'.css'; 458 js.type = "text/javascript",js.src=src; 459 css.rel = "stylesheet",css.href=href; 460 var head=$tag('head')[0],isSuccess=false,timeout=10*1000;//è¶ æ¶10ç§ 461 head.appendChild(css); 462 head.appendChild(js); 463 js.onload=js.onreadystatechange=function(){ 464 if(isSuccess) return;//鲿¢IE9+é夿§è¡ 465 if(!js.readyState||js.readyState=="loaded"||js.readyState=="complete"){ 466 isSuccess=true; 467 callback(); 468 js.onload=js.onreadystatechange=null; 469 } 470 }; 471 setTimeout(function(){if(!isSuccess) $id(p.id).innerHTML='å 载失败: '+src;},timeout); 472 }, 473 getFilePath:function(){ 474 var path=''; 475 var scripts=$tag("script"); 476 for(var i=0,len=scripts.length;i<len;i++){ 477 var src=scripts[i].src; 478 if(src&&/myfocus([\.-].*)?\.js/i.test(src)){//å ¼å®¹myfocus.js/myfocus.min.js/myfocus-2.x.js 479 path=src; 480 break; 481 } 482 }; 483 return path.slice(0,path.lastIndexOf('/')+1); 484 }, 485 getBoxReady:function(p,fn){ 486 var F=this; 487 (function(){ 488 try{ 489 if(F.isIE) $id(p.id).doScroll(); 490 else $id(p.id).innerHTML; 491 fn(); 492 }catch(e){ 493 if(!F.onloadWindow) setTimeout(arguments.callee,0); 494 } 495 })(); 496 }, 497 getIMGReady:function(p,callback){ 498 var isShow=p.loadingShow; 499 var box=$id(p.id),img=$tag('img',p.pic),len=img.length, 500 count=0,done=false,arrSize=new Array(len); 501 if(!isShow||!len){callback();return;}//æ å»¶è¿ 502 for(var i=0;i<len;i++){ 503 var IMG=new Image(); 504 IMG.i=i;//æ è®°ååé¡ºåº 505 IMG.onload=function(){ 506 count+=1; 507 arrSize[this.i]={w:this.width,h:this.height};//å¨åfor zoomIMG 508 if(count==len&&!done){done=true,callback(arrSize);} 509 }; 510 IMG.src=img[i].src; 511 }; 512 }, 513 zoomIMG:function(p,arrSize){ 514 var imgs=$tag('img',p.pic),len=imgs.length,boxWidth=p.width,boxHeight=p.height; 515 for(var i=0;i<len;i++){ 516 var w=arrSize[i].w,h=arrSize[i].h; 517 if(w == boxWidth && h == boxHeight) continue; 518 if(w < boxWidth && h < boxHeight){ 519 var width=w,height=h,top=(boxHeight-height)/2; 520 }else if(w / h >= boxWidth / boxHeight){ 521 var width=boxWidth,height=boxWidth/w*h,top=(boxHeight-height)/2; 522 }else{ 523 var width=boxHeight/h*w,height=boxHeight,top=0; 524 } 525 imgs[i].style.cssText=';width:'+width+'px;height:'+height+'px;margin-top:'+top+'px;'; 526 }; 527 }, 528 initCSS:function(p,oStyle){ 529 var css=[],w=p.width||'',h=p.height||''; 530 if(p.pic){ 531 css.push('.'+p.__clsName+' *{margin:0;padding:0;border:0;list-style:none;}.'+p.__clsName+'{position:relative;width:'+w+'px;height:'+h+'px;overflow:hidden;font:12px/1.5 Verdana;text-align:left;background:#fff;visibility:visible!important;}.'+p.__clsName+' .pic{position:relative;width:'+w+'px;height:'+h+'px;overflow:hidden;}.'+p.__clsName+' .txt li{width:'+w+'px;height:'+p.txtHeight+'px!important;overflow:hidden;}'); 532 if(p.wrap) p.$o.wrap('<div class="'+p.pattern+'_wrap"></div>'); 533 if(p.autoZoom) css.push('.'+p.__clsName+' .pic li{text-align:center;width:'+w+'px;height:'+h+'px;}');//缩æ¾å¾çå± ä¸ 534 } 535 try{oStyle.styleSheet.cssText=css.join('')}catch(e){oStyle.innerHTML=css.join('')} 536 }, 537 initBaseCSS:function(id){
538 var s='#'+id+' *{display:none}',oStyle=document.createElement('style'); 539 oStyle.type='text/css'; 540 try{oStyle.styleSheet.cssText=s}catch(e){oStyle.innerHTML=s} 541 var oHead = $tag('head',document)[0]; 542 oHead.insertBefore(oStyle,oHead.firstChild); 543 return oStyle; 544 } 545 }); 546 myFocus.extend({//Method(myFocus) 547 isIE:!!(document.all&&navigator.userAgent.indexOf('Opera')===-1),//!(+[1,]) BUG IN IE9+ 548 addEvent:function(o,type,fn){ 549 var ie=this.isIE,e=ie?'attachEvent':'addEventListener',t=(ie?'on':'')+type; 550 o[e](t,function(e){ 551 var e=e||window.event,flag=fn.call(o,e); 552 if(flag===false){ 553 if(ie) e.cancelBubble=true,e.returnValue=false; 554 else e.stopPropagation(),e.preventDefault(); 555 } 556 },false); 557 }, 558 loadXML:function(p){ 559 var xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLDOM"); 560 xmlhttp.open("GET", p.xmlFile + "?" + Math.random(), false); 561 xmlhttp.send(null); 562 this.appendXML(xmlhttp.responseXML,p); 563 }, 564 appendXML:function(xml,p){ 565 var items=xml.documentElement.getElementsByTagName("item"),len=items.length; 566 var html=['<div class="loading"></div><div class="pic"><ul>']; 567 for(var i=0;i<len;i++){ 568 html.push('<li><a href="'+items[i].getAttribute('href')+'"><img src="'+items[i].getAttribute('image')+'" thumb="'+items[i].getAttribute('thumb')+'" alt="'+items[i].getAttribute('title')+'" text="'+items[i].getAttribute('text')+'" /></a></li>'); 569 } 570 html.push('</ul></div>'); 571 p.$o[0].innerHTML=html.join(''); 572 } 573 }); 574 //æ¯æJQ 575 if(typeof jQuery!=='undefined'){ 576 jQuery.fn.extend({ 577 myFocus:function(p,fn){ 578 if(!p) p={}; 579 p.id=this[0].id; 580 if(!p.id) p.id=this[0].id='mF__ID__'; 581 myFocus.set(p,fn); 582 } 583 }); 584 } 585})();
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.