fixed the resizable text area with IE problem fixed the ad space with IE problem merged the 7.2.0 and 7.1.4 change logs
48 lines
No EOL
17 KiB
JavaScript
48 lines
No EOL
17 KiB
JavaScript
/*
|
|
* YUI Extensions
|
|
* Copyright(c) 2006, Jack Slocum.
|
|
*
|
|
* This code is licensed under BSD license.
|
|
* http://www.opensource.org/licenses/bsd-license.php
|
|
*/
|
|
|
|
|
|
YAHOO.ext.Element=function(elementId,forceNew){var dom=YAHOO.util.Dom.get(elementId);if(!dom){return;}
|
|
if(!forceNew&&YAHOO.ext.Element.cache[dom.id]){return YAHOO.ext.Element.cache[dom.id];}
|
|
this.dom=dom;this.id=this.dom.id;this.visibilityMode=YAHOO.ext.Element.VISIBILITY;this.originalDisplay=YAHOO.util.Dom.getStyle(this.dom,'display');if(!this.originalDisplay||this.originalDisplay=='none'){this.originalDisplay='';}
|
|
this.defaultUnit='px';this.originalClip=YAHOO.util.Dom.getStyle(this.dom,'overflow');this.onVisibilityChanged=new YAHOO.util.CustomEvent('visibilityChanged');this.onMoved=new YAHOO.util.CustomEvent('moved');this.onResized=new YAHOO.util.CustomEvent('resized');this.visibilityDelegate=this.fireVisibilityChanged.createDelegate(this);this.resizedDelegate=this.fireResized.createDelegate(this);this.movedDelegate=this.fireMoved.createDelegate(this);}
|
|
YAHOO.ext.Element.prototype={fireMoved:function(){this.onMoved.fireDirect(this,this.getX(),this.getY());},fireVisibilityChanged:function(){this.onVisibilityChanged.fireDirect(this,this.isVisible());},fireResized:function(){this.onResized.fireDirect(this,this.getWidth(),this.getHeight());},setVisibilityMode:function(visMode){this.visibilityMode=visMode;},enableDisplayMode:function(){this.setVisibilityMode(YAHOO.ext.Element.DISPLAY)},animate:function(args,duration,onComplete,easing,animType){this.anim(args,duration,onComplete,easing,animType);},anim:function(args,duration,onComplete,easing,animType){animType=animType||YAHOO.util.Anim;var anim=new animType(this.dom,args,duration||.35,easing||YAHOO.util.Easing.easeBoth);if(onComplete){if(!(onComplete instanceof Array)){anim.onComplete.subscribe(onComplete);}else{for(var i=0;i<onComplete.length;i++){var fn=onComplete[i];if(fn)anim.onComplete.subscribe(fn);}}}
|
|
anim.animate();},isVisible:function(deep){var vis=YAHOO.util.Dom.getStyle(this.dom,'visibility')!='hidden'&&YAHOO.util.Dom.getStyle(this.dom,'display')!='none';if(!deep||!vis){return vis;}
|
|
var p=this.dom.parentNode;while(p&&p.tagName.toLowerCase()!='body'){if(YAHOO.util.Dom.getStyle(p,'visibility')=='hidden'||YAHOO.util.Dom.getStyle(p,'display')=='none'){return false;}
|
|
p=p.parentNode;}
|
|
return true;},setVisible:function(visible,animate,duration,onComplete,easing){if(!animate||!YAHOO.util.Anim){if(this.visibilityMode==YAHOO.ext.Element.DISPLAY){this.setDisplayed(visible);}else{YAHOO.util.Dom.setStyle(this.dom,'visibility',visible?'visible':'hidden');}
|
|
this.fireVisibilityChanged();}else{YAHOO.util.Dom.setStyle(this.dom,'visibility','visible');if(this.visibilityMode==YAHOO.ext.Element.DISPLAY){this.setDisplayed(true);}
|
|
var args={opacity:{from:(visible?0:1),to:(visible?1:0)}};var anim=new YAHOO.util.Anim(this.dom,args,duration||.35,easing||(visible?YAHOO.util.Easing.easeIn:YAHOO.util.Easing.easeOut));anim.onComplete.subscribe((function(){if(this.visibilityMode==YAHOO.ext.Element.DISPLAY){this.setDisplayed(visible);}else{YAHOO.util.Dom.setStyle(this.dom,'visibility',visible?'visible':'hidden');}
|
|
this.fireVisibilityChanged();}).createDelegate(this));if(onComplete){anim.onComplete.subscribe(onComplete);}
|
|
anim.animate();}},isDisplayed:function(){return YAHOO.util.Dom.getStyle(this.dom,'display')!='none';},toggle:function(animate,duration,onComplete,easing){this.setVisible(!this.isVisible(),animate,duration,onComplete,easing);},setDisplayed:function(value){YAHOO.util.Dom.setStyle(this.dom,'display',value?this.originalDisplay:'none');},focus:function(){try{this.dom.focus();}catch(e){}},addClass:function(className){YAHOO.util.Dom.addClass(this.dom,className);},radioClass:function(className){var siblings=this.dom.parentNode.childNodes;for(var i=0;i<siblings.length;i++){var s=siblings[i];if(s.nodeType==1){YAHOO.util.Dom.removeClass(s,className);}}
|
|
YAHOO.util.Dom.addClass(this.dom,className);},removeClass:function(className){YAHOO.util.Dom.removeClass(this.dom,className);},toggleClass:function(className){if(YAHOO.util.Dom.hasClass(this.dom,className)){YAHOO.util.Dom.removeClass(this.dom,className);}else{YAHOO.util.Dom.addClass(this.dom,className);}},hasClass:function(className){return YAHOO.util.Dom.hasClass(this.dom,className);},replaceClass:function(oldClassName,newClassName){YAHOO.util.Dom.replaceClass(this.dom,oldClassName,newClassName);},getStyle:function(name){return YAHOO.util.Dom.getStyle(this.dom,name);},setStyle:function(name,value){YAHOO.util.Dom.setStyle(this.dom,name,value);},getX:function(){return YAHOO.util.Dom.getX(this.dom);},getY:function(){return YAHOO.util.Dom.getY(this.dom);},getXY:function(){return YAHOO.util.Dom.getXY(this.dom);},setX:function(x){YAHOO.util.Dom.setX(this.dom,x);this.fireMoved();},setY:function(y){YAHOO.util.Dom.setY(this.dom,y);this.fireMoved();},setLeft:function(left){YAHOO.util.Dom.setStyle(this.dom,'left',this.addUnits(left));this.fireMoved();},setTop:function(top){YAHOO.util.Dom.setStyle(this.dom,'top',this.addUnits(top));this.fireMoved();},setRight:function(right){YAHOO.util.Dom.setStyle(this.dom,'right',this.addUnits(right));this.fireMoved();},setBottom:function(bottom){YAHOO.util.Dom.setStyle(this.dom,'bottom',this.addUnits(bottom));this.fireMoved();},setXY:function(pos,animate,duration,onComplete,easing){if(!animate||!YAHOO.util.Anim){YAHOO.util.Dom.setXY(this.dom,pos);this.fireMoved();}else{this.anim({points:{to:pos}},duration,[onComplete,this.movedDelegate],easing,YAHOO.util.Motion);}},setLocation:function(x,y,animate,duration,onComplete,easing){this.setXY([x,y],animate,duration,onComplete,easing);},moveTo:function(x,y,animate,duration,onComplete,easing){this.setXY([x,y],animate,duration,onComplete,easing);},getRegion:function(){return YAHOO.util.Dom.getRegion(this.dom);},getHeight:function(){return this.dom.offsetHeight;},getWidth:function(){return this.dom.offsetWidth;},getSize:function(){return{width:this.getWidth(),height:this.getHeight()};},adjustWidth:function(width){if(this.autoBoxAdjust&&typeof width=='number'&&!this.isBorderBox()){width-=(this.getBorderWidth('lr')+this.getPadding('lr'));}
|
|
return width;},adjustHeight:function(height){if(this.autoBoxAdjust&&typeof height=='number'&&!this.isBorderBox()){height-=(this.getBorderWidth('tb')+this.getPadding('tb'));}
|
|
return height;},setWidth:function(width,animate,duration,onComplete,easing){width=this.adjustWidth(width);if(!animate||!YAHOO.util.Anim){YAHOO.util.Dom.setStyle(this.dom,'width',this.addUnits(width));this.fireResized();}else{this.anim({width:{to:width}},duration,[onComplete,this.resizedDelegate],easing||(width>this.getWidth()?YAHOO.util.Easing.easeOut:YAHOO.util.Easing.easeIn));}},setHeight:function(height,animate,duration,onComplete,easing){height=this.adjustHeight(height);if(!animate||!YAHOO.util.Anim){YAHOO.util.Dom.setStyle(this.dom,'height',this.addUnits(height));this.fireResized();}else{this.anim({height:{to:height}},duration,[onComplete,this.resizedDelegate],easing||(height>this.getHeight()?YAHOO.util.Easing.easeOut:YAHOO.util.Easing.easeIn));}},setSize:function(width,height,animate,duration,onComplete,easing){if(!animate||!YAHOO.util.Anim){this.setWidth(width);this.setHeight(height);this.fireResized();}else{width=this.adjustWidth(width);height=this.adjustHeight(height);this.anim({width:{to:width},height:{to:height}},duration,[onComplete,this.resizedDelegate],easing);}},setBounds:function(x,y,width,height,animate,duration,onComplete,easing){if(!animate||!YAHOO.util.Anim){this.setWidth(width);this.setHeight(height);this.setLocation(x,y);this.fireResized();this.fireMoved();}else{width=this.adjustWidth(width);height=this.adjustHeight(height);this.anim({points:{to:[x,y]},width:{to:width},height:{to:height}},duration,[onComplete,this.movedDelegate],easing,YAHOO.util.Motion);}},setRegion:function(region,animate,duration,onComplete,easing){this.setBounds(region.left,region.top,region.right-region.left,region.bottom-region.top,animate,duration,onComplete,easing);},addListener:function(eventName,handler,scope,override){YAHOO.util.Event.addListener(this.dom,eventName,handler,scope,override);},addHandler:function(eventName,stopPropagation,handler,scope,override){var fn=YAHOO.ext.Element.createStopHandler(stopPropagation,handler,scope,override);YAHOO.util.Event.addListener(this.dom,eventName,fn);},on:function(eventName,handler,scope,override){YAHOO.util.Event.addListener(this.dom,eventName,handler,scope,override);},addManagedListener:function(eventName,fn,scope,override){return YAHOO.ext.EventManager.on(this.dom,eventName,fn,scope,override);},mon:function(eventName,fn,scope,override){return YAHOO.ext.EventManager.on(this.dom,eventName,fn,scope,override);},removeListener:function(eventName,handler){YAHOO.util.Event.removeListener(this.dom,eventName,handler);},removeAllListeners:function(){YAHOO.util.Event.purgeElement(this.dom);},setOpacity:function(opacity,animate,duration,onComplete,easing){if(!animate||!YAHOO.util.Anim){YAHOO.util.Dom.setStyle(this.dom,'opacity',opacity);}else{this.anim({opacity:{to:opacity}},duration,onComplete,easing);}},getLeft:function(){return this.getX();},getRight:function(){return this.getX()+this.getWidth();},getTop:function(){return this.getY();},getBottom:function(){return this.getY()+this.getHeight();},setAbsolutePositioned:function(zIndex){this.setStyle('position','absolute');if(zIndex){this.setStyle('z-index',zIndex);}},setRelativePositioned:function(zIndex){this.setStyle('position','relative');if(zIndex){this.setStyle('z-index',zIndex);}},clearPositioning:function(){this.setStyle('position','');this.setStyle('left','');this.setStyle('right','');this.setStyle('top','');this.setStyle('bottom','');},getPositioning:function(){return{'position':this.getStyle('position'),'left':this.getStyle('left'),'right':this.getStyle('right'),'top':this.getStyle('top'),'bottom':this.getStyle('bottom')};},getBorderWidth:function(side){var width=0;var b=YAHOO.ext.Element.borders;for(var s in b){if(typeof b[s]!='function'){if(side.indexOf(s)!==-1){var w=parseInt(this.getStyle(b[s]),10);if(!isNaN(w))width+=w;}}}
|
|
return width;},getPadding:function(side){var pad=0;var b=YAHOO.ext.Element.paddings;for(var s in b){if(typeof s[b]!='function'){if(side.indexOf(s)!==-1){var w=parseInt(this.getStyle(b[s]),10);if(!isNaN(w))pad+=w;}}}
|
|
return pad;},setPositioning:function(positionCfg){this.setStyle('position',positionCfg.position);this.setStyle('left',positionCfg.left);this.setStyle('right',positionCfg.right);this.setStyle('top',positionCfg.top);this.setStyle('bottom',positionCfg.bottom);},move:function(direction,distance,animate,duration,onComplete,easing){var xy=this.getXY();direction=direction.toLowerCase();switch(direction){case'left':this.moveTo(xy[0]-distance,xy[1],animate,duration,onComplete,easing);return;case'right':this.moveTo(xy[0]+distance,xy[1],animate,duration,onComplete,easing);return;case'up':this.moveTo(xy[0],xy[1]-distance,animate,duration,onComplete,easing);return;case'down':this.moveTo(xy[0],xy[1]+distance,animate,duration,onComplete,easing);return;}},clip:function(){this.setStyle('overflow','hidden');},unclip:function(){this.setStyle('overflow',this.originalClip);},alignTo:function(element,position,offsets,animate,duration,onComplete,easing){var otherEl=getEl(element);if(!otherEl){return;}
|
|
offsets=offsets||[0,0];var r=otherEl.getRegion();position=position.toLowerCase();switch(position){case'bl':this.moveTo(r.left+offsets[0],r.bottom+offsets[1],animate,duration,onComplete,easing);return;case'br':this.moveTo(r.right+offsets[0],r.bottom+offsets[1],animate,duration,onComplete,easing);return;case'tl':this.moveTo(r.left+offsets[0],r.top+offsets[1],animate,duration,onComplete,easing);return;case'tr':this.moveTo(r.right+offsets[0],r.top+offsets[1],animate,duration,onComplete,easing);return;}},clearOpacity:function(){if(window.ActiveXObject){this.dom.style.filter='';}else{this.dom.style.opacity='';this.dom.style['-moz-opacity']='';this.dom.style['-khtml-opacity']='';}},hide:function(animate,duration,onComplete,easing){this.setVisible(false,animate,duration,onComplete,easing);},show:function(animate,duration,onComplete,easing){this.setVisible(true,animate,duration,onComplete,easing);},addUnits:function(size){if(typeof size=='number'||!YAHOO.ext.Element.unitPattern.test(size)){return size+this.defaultUnit;}
|
|
return size;},beginMeasure:function(){var p=this.dom;if(p.offsetWidth||p.offsetHeight){return;}
|
|
var changed=[];var p=this.dom;while(p&&p.tagName.toLowerCase()!='body'){if(YAHOO.util.Dom.getStyle(p,'display')=='none'){changed.push({el:p,visibility:YAHOO.util.Dom.getStyle(p,'visibility')});p.style.visibility='hidden';p.style.display='block';}
|
|
p=p.parentNode;}
|
|
this._measureChanged=changed;},endMeasure:function(){var changed=this._measureChanged;if(changed){for(var i=0,len=changed.length;i<len;i++){var r=changed[i];r.el.style.visibility=r.visibility;r.el.style.display='none';}
|
|
this._measureChanged=null;}},update:function(html,loadScripts){this.dom.innerHTML=html;if(!loadScripts)return;var dom=this.dom;var _parseScripts=function(){var s=this.dom.getElementsByTagName("script");var docHead=document.getElementsByTagName("head")[0];if(s.length==0){var re=/(?:<script.*(?:src=[\"\'](.*)[\"\']).*>.*<\/script>)|(?:<script.*>([\S\s]*?)<\/script>)/ig;var match;while(match=re.exec(html)){var s0=document.createElement("script");if(match[1])
|
|
s0.src=match[1];else if(match[2])
|
|
s0.text=match[2];else
|
|
continue;docHead.appendChild(s0);}}else{for(var i=0;i<s.length;i++){var s0=document.createElement("script");s0.type=s[i].type;if(s[i].text){s0.text=s[i].text;}else{s0.src=s[i].src;}
|
|
docHead.appendChild(s0);}}}
|
|
setTimeout(_parseScripts,10);},getUpdateManager:function(){if(!this.updateManager){this.updateManager=new YAHOO.ext.UpdateManager(this);}
|
|
return this.updateManager;},getCenterXY:function(offsetScroll){var centerX=Math.round((YAHOO.util.Dom.getViewportWidth()-this.getWidth())/2);var centerY=Math.round((YAHOO.util.Dom.getViewportHeight()-this.getHeight())/2);if(!offsetScroll){return[centerX,centerY];}else{var scrollX=document.documentElement.scrollLeft||document.body.scrollLeft||0;var scrollY=document.documentElement.scrollTop||document.body.scrollTop||0;return[centerX+scrollX,centerY+scrollY];}},getChildrenByTagName:function(tagName){var children=this.dom.getElementsByTagName(tagName);var len=children.length;var ce=[len];for(var i=0;i<len;++i){ce[i]=YAHOO.ext.Element.get(children[i],true);}
|
|
return ce;},getChildrenByClassName:function(className,tagName){var children=YAHOO.util.Dom.getElementsByClassName(className,tagName,this.dom);var len=children.length;var ce=[len];for(var i=0;i<len;++i){ce[i]=YAHOO.ext.Element.get(children[i],true);}
|
|
return ce;},isBorderBox:function(){var el=this.dom;var b=YAHOO.ext.util.Browser;var strict=YAHOO.ext.Strict;return((b.isIE&&!b.isIE7)||(b.isIE7&&!strict&&el.style.boxSizing!='content-box')||(b.isGecko&&YAHOO.util.Dom.getStyle(el,"-moz-box-sizing")=='border-box')||(!b.isSafari&&YAHOO.util.Dom.getStyle(el,"box-sizing")=='border-box'));},getBox:function(contentBox){var xy=this.getXY();var el=this.dom;var w=el.offsetWidth;var h=el.offsetHeight;if(!contentBox){return{x:xy[0],y:xy[1],width:w,height:h};}else{var l=this.getBorderWidth('l')+this.getPadding('l');var r=this.getBorderWidth('r')+this.getPadding('r');var t=this.getBorderWidth('t')+this.getPadding('t');var b=this.getBorderWidth('b')+this.getPadding('b');return{x:xy[0]+l,y:xy[1]+t,width:w-(l+r),height:h-(t+b)};}},setBox:function(box,adjust,animate,duration,onComplete,easing){var w=box.width,h=box.height;if((adjust&&!this.autoBoxAdjust)&&!this.isBorderBox()){w-=(this.getBorderWidth('lr')+this.getPadding('lr'));h-=(this.getBorderWidth('tb')+this.getPadding('tb'));}
|
|
this.setBounds(box.x,box.y,w,h,animate,duration,onComplete,easing);},repaint:function(){var dom=this.dom;YAHOO.util.Dom.addClass(dom,'yui-ext-repaint');setTimeout(function(){YAHOO.util.Dom.removeClass(dom,'yui-ext-repaint');},1);}};YAHOO.ext.Element.prototype.autoBoxAdjust=true;YAHOO.ext.Element.unitPattern=/\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;YAHOO.ext.Element.VISIBILITY=1;YAHOO.ext.Element.DISPLAY=2;YAHOO.ext.Element.borders={l:'border-left-width',r:'border-right-width',t:'border-top-width',b:'border-bottom-width'};YAHOO.ext.Element.paddings={l:'padding-left',r:'padding-right',t:'padding-top',b:'padding-bottom'};YAHOO.ext.Element.createStopHandler=function(stopPropagation,handler,scope,override){return function(e){if(e){if(stopPropagation){YAHOO.util.Event.stopEvent(e);}else{YAHOO.util.Event.preventDefault(e);}}
|
|
handler.call(override&&scope?scope:window,e,scope);};};YAHOO.ext.Element.cache={};YAHOO.ext.Element.get=function(el,autoGenerateId){if(!el){return null;}
|
|
if(el instanceof YAHOO.ext.Element){el.dom=YAHOO.util.Dom.get(el.id);YAHOO.ext.Element.cache[el.id]=el;return el;}
|
|
var key=el;if(typeof el!='string'){if(!el.id&&!autoGenerateId){return null;}
|
|
YAHOO.util.Dom.generateId(el,'elgen-');key=el.id;}
|
|
var element=YAHOO.ext.Element.cache[key];if(!element){element=new YAHOO.ext.Element(key);YAHOO.ext.Element.cache[key]=element;}else{element.dom=YAHOO.util.Dom.get(key);}
|
|
return element;};var getEl=YAHOO.ext.Element.get;YAHOO.util.Event.addListener(window,'unload',function(){YAHOO.ext.Element.cache=null;}); |