]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui3/build/imageloader/imageloader.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / yui3 / build / imageloader / imageloader.js
1 /*
2  Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3  Code licensed under the BSD License:
4  http://developer.yahoo.com/yui/license.html
5  version: 3.3.0
6  build: 3167
7  */
8 YUI.add('imageloader',function(Y){Y.ImgLoadGroup=function(){this._init();Y.ImgLoadGroup.superclass.constructor.apply(this,arguments);};Y.ImgLoadGroup.NAME='imgLoadGroup';Y.ImgLoadGroup.ATTRS={name:{value:''},timeLimit:{value:null},foldDistance:{validator:Y.Lang.isNumber,setter:function(val){this._setFoldTriggers();return val;},lazyAdd:false},className:{value:null,setter:function(name){this._className=name;return name;},lazyAdd:false}};var groupProto={_init:function(){this._triggers=[];this._imgObjs={};this._timeout=null;this._classImageEls=null;this._className=null;this._areFoldTriggersSet=false;this._maxKnownHLimit=0;Y.on('domready',this._onloadTasks,this);},addTrigger:function(obj,type){if(!obj||!type){return this;}
9 var wrappedFetch=function(){this.fetch();};this._triggers.push(Y.on(type,wrappedFetch,obj,this));return this;},addCustomTrigger:function(name,obj){if(!name){return this;}
10 var wrappedFetch=function(){this.fetch();};if(Y.Lang.isUndefined(obj)){this._triggers.push(Y.on(name,wrappedFetch,this));}
11 else{this._triggers.push(obj.on(name,wrappedFetch,this));}
12 return this;},_setFoldTriggers:function(){if(this._areFoldTriggersSet){return;}
13 var wrappedFoldCheck=function(){this._foldCheck();};this._triggers.push(Y.on('scroll',wrappedFoldCheck,window,this));this._triggers.push(Y.on('resize',wrappedFoldCheck,window,this));this._areFoldTriggersSet=true;},_onloadTasks:function(){var timeLim=this.get('timeLimit');if(timeLim&&timeLim>0){this._timeout=setTimeout(this._getFetchTimeout(),timeLim*1000);}
14 if(!Y.Lang.isUndefined(this.get('foldDistance'))){this._foldCheck();}},_getFetchTimeout:function(){var self=this;return function(){self.fetch();};},registerImage:function(){var domId=arguments[0].domId;if(!domId){return null;}
15 this._imgObjs[domId]=new Y.ImgLoadImgObj(arguments[0]);return this._imgObjs[domId];},fetch:function(){this._clearTriggers();this._fetchByClass();for(var id in this._imgObjs){if(this._imgObjs.hasOwnProperty(id)){this._imgObjs[id].fetch();}}},_clearTriggers:function(){clearTimeout(this._timeout);for(var i=0,len=this._triggers.length;i<len;i++){this._triggers[i].detach();}},_foldCheck:function(){var allFetched=true,viewReg=Y.DOM.viewportRegion(),hLimit=viewReg.bottom+this.get('foldDistance'),id,imgFetched,els,i,len;if(hLimit<=this._maxKnownHLimit){return;}
16 this._maxKnownHLimit=hLimit;for(id in this._imgObjs){if(this._imgObjs.hasOwnProperty(id)){imgFetched=this._imgObjs[id].fetch(hLimit);allFetched=allFetched&&imgFetched;}}
17 if(this._className){if(this._classImageEls===null){this._classImageEls=[];els=Y.all('.'+this._className);els.each(function(node){this._classImageEls.push({el:node,y:node.getY(),fetched:false});},this);}
18 els=this._classImageEls;for(i=0,len=els.length;i<len;i++){if(els[i].fetched){continue;}
19 if(els[i].y&&els[i].y<=hLimit){els[i].el.removeClass(this._className);els[i].fetched=true;}
20 else{allFetched=false;}}}
21 if(allFetched){this._clearTriggers();}},_fetchByClass:function(){if(!this._className){return;}
22 Y.all('.'+this._className).removeClass(this._className);}};Y.extend(Y.ImgLoadGroup,Y.Base,groupProto);Y.ImgLoadImgObj=function(){Y.ImgLoadImgObj.superclass.constructor.apply(this,arguments);this._init();};Y.ImgLoadImgObj.NAME='imgLoadImgObj';Y.ImgLoadImgObj.ATTRS={domId:{value:null,writeOnce:true},bgUrl:{value:null},srcUrl:{value:null},width:{value:null},height:{value:null},setVisible:{value:false},isPng:{value:false},sizingMethod:{value:'scale'},enabled:{value:'true'}};var imgProto={_init:function(){this._fetched=false;this._imgEl=null;this._yPos=null;},fetch:function(withinY){if(this._fetched){return true;}
23 var el=this._getImgEl(),yPos;if(!el){return false;}
24 if(withinY){yPos=this._getYPos();if(!yPos||yPos>withinY){return false;}}
25 if(this.get('bgUrl')!==null){if(this.get('isPng')&&Y.UA.ie&&Y.UA.ie<=6){el.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+this.get('bgUrl')+'", sizingMethod="'+this.get('sizingMethod')+'", enabled="'+this.get('enabled')+'")');}
26 else{el.setStyle('backgroundImage',"url('"+this.get('bgUrl')+"')");}}
27 else if(this.get('srcUrl')!==null){el.setAttribute('src',this.get('srcUrl'));}
28 if(this.get('setVisible')){el.setStyle('visibility','visible');}
29 if(this.get('width')){el.setAttribute('width',this.get('width'));}
30 if(this.get('height')){el.setAttribute('height',this.get('height'));}
31 this._fetched=true;return true;},_getImgEl:function(){if(this._imgEl===null){this._imgEl=Y.one('#'+this.get('domId'));}
32 return this._imgEl;},_getYPos:function(){if(this._yPos===null){this._yPos=this._getImgEl().getY();}
33 return this._yPos;}};Y.extend(Y.ImgLoadImgObj,Y.Base,imgProto);},'3.3.0',{requires:['base-base','node-style','node-screen']});