]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui3/build/dom/dom-style.js
Release 6.2.0beta4
[Github/sugarcrm.git] / include / javascript / yui3 / build / dom / dom-style.js
1 /*
2  Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3  Code licensed under the BSD License:
4  http://developer.yahoo.net/yui/license.txt
5  version: 3.0.0
6  build: 1549
7  */
8 YUI.add('dom-style',function(Y){(function(Y){var DOCUMENT_ELEMENT='documentElement',DEFAULT_VIEW='defaultView',OWNER_DOCUMENT='ownerDocument',STYLE='style',FLOAT='float',CSS_FLOAT='cssFloat',STYLE_FLOAT='styleFloat',TRANSPARENT='transparent',GET_COMPUTED_STYLE='getComputedStyle',DOCUMENT=Y.config.doc,UNDEFINED=undefined,re_color=/color$/i;Y.mix(Y.DOM,{CUSTOM_STYLES:{},setStyle:function(node,att,val,style){style=style||node.style;var CUSTOM_STYLES=Y.DOM.CUSTOM_STYLES;if(style){if(val===null){val='';}
9 if(att in CUSTOM_STYLES){if(CUSTOM_STYLES[att].set){CUSTOM_STYLES[att].set(node,val,style);return;}else if(typeof CUSTOM_STYLES[att]==='string'){att=CUSTOM_STYLES[att];}}
10 style[att]=val;}},getStyle:function(node,att){var style=node[STYLE],CUSTOM_STYLES=Y.DOM.CUSTOM_STYLES,val='';if(style){if(att in CUSTOM_STYLES){if(CUSTOM_STYLES[att].get){return CUSTOM_STYLES[att].get(node,att,style);}else if(typeof CUSTOM_STYLES[att]==='string'){att=CUSTOM_STYLES[att];}}
11 val=style[att];if(val===''){val=Y.DOM[GET_COMPUTED_STYLE](node,att);}}
12 return val;},setStyles:function(node,hash){var style=node.style;Y.each(hash,function(v,n){Y.DOM.setStyle(node,n,v,style);},Y.DOM);},getComputedStyle:function(node,att){var val='',doc=node[OWNER_DOCUMENT];if(node[STYLE]){val=doc[DEFAULT_VIEW][GET_COMPUTED_STYLE](node,null)[att];}
13 return val;}});if(DOCUMENT[DOCUMENT_ELEMENT][STYLE][CSS_FLOAT]!==UNDEFINED){Y.DOM.CUSTOM_STYLES[FLOAT]=CSS_FLOAT;}else if(DOCUMENT[DOCUMENT_ELEMENT][STYLE][STYLE_FLOAT]!==UNDEFINED){Y.DOM.CUSTOM_STYLES[FLOAT]=STYLE_FLOAT;}
14 if(Y.UA.opera){Y.DOM[GET_COMPUTED_STYLE]=function(node,att){var view=node[OWNER_DOCUMENT][DEFAULT_VIEW],val=view[GET_COMPUTED_STYLE](node,'')[att];if(re_color.test(att)){val=Y.Color.toRGB(val);}
15 return val;};}
16 if(Y.UA.webkit){Y.DOM[GET_COMPUTED_STYLE]=function(node,att){var view=node[OWNER_DOCUMENT][DEFAULT_VIEW],val=view[GET_COMPUTED_STYLE](node,'')[att];if(val==='rgba(0, 0, 0, 0)'){val=TRANSPARENT;}
17 return val;};}})(Y);(function(Y){var PARSE_INT=parseInt,RE=RegExp;Y.Color={KEYWORDS:{black:'000',silver:'c0c0c0',gray:'808080',white:'fff',maroon:'800000',red:'f00',purple:'800080',fuchsia:'f0f',green:'008000',lime:'0f0',olive:'808000',yellow:'ff0',navy:'000080',blue:'00f',teal:'008080',aqua:'0ff'},re_RGB:/^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,re_hex:/^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,re_hex3:/([0-9A-F])/gi,toRGB:function(val){if(!Y.Color.re_RGB.test(val)){val=Y.Color.toHex(val);}
18 if(Y.Color.re_hex.exec(val)){val='rgb('+[PARSE_INT(RE.$1,16),PARSE_INT(RE.$2,16),PARSE_INT(RE.$3,16)].join(', ')+')';}
19 return val;},toHex:function(val){val=Y.Color.KEYWORDS[val]||val;if(Y.Color.re_RGB.exec(val)){val=[Number(RE.$1).toString(16),Number(RE.$2).toString(16),Number(RE.$3).toString(16)];for(var i=0;i<val.length;i++){if(val[i].length<2){val[i]=val[i].replace(Y.Color.re_hex3,'$1$1');}}
20 val='#'+val.join('');}
21 if(val.length<6){val=val.replace(Y.Color.re_hex3,'$1$1');}
22 if(val!=='transparent'&&val.indexOf('#')<0){val='#'+val;}
23 return val.toLowerCase();}};})(Y);(function(Y){var HAS_LAYOUT='hasLayout',PX='px',FILTER='filter',FILTERS='filters',OPACITY='opacity',AUTO='auto',BORDER_WIDTH='borderWidth',BORDER_TOP_WIDTH='borderTopWidth',BORDER_RIGHT_WIDTH='borderRightWidth',BORDER_BOTTOM_WIDTH='borderBottomWidth',BORDER_LEFT_WIDTH='borderLeftWidth',WIDTH='width',HEIGHT='height',TRANSPARENT='transparent',VISIBLE='visible',GET_COMPUTED_STYLE='getComputedStyle',UNDEFINED=undefined,documentElement=document.documentElement,re_unit=/^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz|%){1}?/i,_getStyleObj=function(node){return node.currentStyle||node.style;},ComputedStyle={CUSTOM_STYLES:{},get:function(el,property){var value='',current;if(el){current=_getStyleObj(el)[property];if(property===OPACITY&&Y.DOM.CUSTOM_STYLES[OPACITY]){value=Y.DOM.CUSTOM_STYLES[OPACITY].get(el);}else if(!current||(current.indexOf&&current.indexOf(PX)>-1)){value=current;}else if(Y.DOM.IE.COMPUTED[property]){value=Y.DOM.IE.COMPUTED[property](el,property);}else if(re_unit.test(current)){value=ComputedStyle.getPixel(el,property)+PX;}else{value=current;}}
24 return value;},sizeOffsets:{width:['Left','Right'],height:['Top','Bottom'],top:['Top'],bottom:['Bottom']},getOffset:function(el,prop){var current=_getStyleObj(el)[prop],capped=prop.charAt(0).toUpperCase()+prop.substr(1),offset='offset'+capped,pixel='pixel'+capped,sizeOffsets=ComputedStyle.sizeOffsets[prop],value='';if(current===AUTO||current.indexOf('%')>-1){value=el['offset'+capped];if(sizeOffsets[0]){value-=ComputedStyle.getPixel(el,'padding'+sizeOffsets[0]);value-=ComputedStyle.getBorderWidth(el,'border'+sizeOffsets[0]+'Width',1);}
25 if(sizeOffsets[1]){value-=ComputedStyle.getPixel(el,'padding'+sizeOffsets[1]);value-=ComputedStyle.getBorderWidth(el,'border'+sizeOffsets[1]+'Width',1);}}else{if(!el.style[pixel]&&!el.style[prop]){el.style[prop]=current;}
26 value=el.style[pixel];}
27 return value+PX;},borderMap:{thin:'2px',medium:'4px',thick:'6px'},getBorderWidth:function(el,property,omitUnit){var unit=omitUnit?'':PX,current=el.currentStyle[property];if(current.indexOf(PX)<0){if(ComputedStyle.borderMap[current]){current=ComputedStyle.borderMap[current];}else{}}
28 return(omitUnit)?parseFloat(current):current;},getPixel:function(node,att){var val=null,style=_getStyleObj(node),styleRight=style.right,current=style[att];node.style.right=current;val=node.style.pixelRight;node.style.right=styleRight;return val;},getMargin:function(node,att){var val,style=_getStyleObj(node);if(style[att]==AUTO){val=0;}else{val=ComputedStyle.getPixel(node,att);}
29 return val+PX;},getVisibility:function(node,att){var current;while((current=node.currentStyle)&&current[att]=='inherit'){node=node.parentNode;}
30 return(current)?current[att]:VISIBLE;},getColor:function(node,att){var current=_getStyleObj(node)[att];if(!current||current===TRANSPARENT){Y.DOM.elementByAxis(node,'parentNode',null,function(parent){current=_getStyleObj(parent)[att];if(current&&current!==TRANSPARENT){node=parent;return true;}});}
31 return Y.Color.toRGB(current);},getBorderColor:function(node,att){var current=_getStyleObj(node),val=current[att]||current.color;return Y.Color.toRGB(Y.Color.toHex(val));}},IEComputed={};try{if(documentElement.style[OPACITY]===UNDEFINED&&documentElement[FILTERS]){Y.DOM.CUSTOM_STYLES[OPACITY]={get:function(node){var val=100;try{val=node[FILTERS]['DXImageTransform.Microsoft.Alpha'][OPACITY];}catch(e){try{val=node[FILTERS]('alpha')[OPACITY];}catch(err){}}
32 return val/100;},set:function(node,val,style){var current,styleObj;if(val===''){styleObj=_getStyleObj(node);current=(OPACITY in styleObj)?styleObj[OPACITY]:1;val=current;}
33 if(typeof style[FILTER]=='string'){style[FILTER]='alpha('+OPACITY+'='+val*100+')';if(!node.currentStyle||!node.currentStyle[HAS_LAYOUT]){style.zoom=1;}}}};}}catch(e){}
34 try{document.createElement('div').style.height='-1px';}catch(e){Y.DOM.CUSTOM_STYLES.height={set:function(node,val,style){var floatVal=parseFloat(val);if(isNaN(floatVal)||floatVal>=0){style.height=val;}else{}}};Y.DOM.CUSTOM_STYLES.width={set:function(node,val,style){var floatVal=parseFloat(val);if(isNaN(floatVal)||floatVal>=0){style.width=val;}else{}}};}
35 IEComputed[WIDTH]=IEComputed[HEIGHT]=ComputedStyle.getOffset;IEComputed.color=IEComputed.backgroundColor=ComputedStyle.getColor;IEComputed[BORDER_WIDTH]=IEComputed[BORDER_TOP_WIDTH]=IEComputed[BORDER_RIGHT_WIDTH]=IEComputed[BORDER_BOTTOM_WIDTH]=IEComputed[BORDER_LEFT_WIDTH]=ComputedStyle.getBorderWidth;IEComputed.marginTop=IEComputed.marginRight=IEComputed.marginBottom=IEComputed.marginLeft=ComputedStyle.getMargin;IEComputed.visibility=ComputedStyle.getVisibility;IEComputed.borderColor=IEComputed.borderTopColor=IEComputed.borderRightColor=IEComputed.borderBottomColor=IEComputed.borderLeftColor=ComputedStyle.getBorderColor;if(!Y.config.win[GET_COMPUTED_STYLE]){Y.DOM[GET_COMPUTED_STYLE]=ComputedStyle.get;}
36 Y.namespace('DOM.IE');Y.DOM.IE.COMPUTED=IEComputed;Y.DOM.IE.ComputedStyle=ComputedStyle;})(Y);},'3.0.0',{requires:['dom-base']});