]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui3/build/widget/widget-stdmod.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / yui3 / build / widget / widget-stdmod.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('widget-stdmod',function(Y){var L=Y.Lang,Node=Y.Node,UA=Y.UA,Widget=Y.Widget,EMPTY="",HD="hd",BD="bd",FT="ft",HEADER="header",BODY="body",FOOTER="footer",FILL_HEIGHT="fillHeight",STDMOD="stdmod",NODE_SUFFIX="Node",CONTENT_SUFFIX="Content",FIRST_CHILD="firstChild",CHILD_NODES="childNodes",OWNER_DOCUMENT="ownerDocument",CONTENT_BOX="contentBox",HEIGHT="height",OFFSET_HEIGHT="offsetHeight",AUTO="auto",HeaderChange="headerContentChange",BodyChange="bodyContentChange",FooterChange="footerContentChange",FillHeightChange="fillHeightChange",HeightChange="heightChange",ContentUpdate="contentUpdate",RENDERUI="renderUI",BINDUI="bindUI",SYNCUI="syncUI",APPLY_PARSED_CONFIG="_applyParsedConfig",UI=Y.Widget.UI_SRC;function StdMod(config){this._stdModNode=this.get(CONTENT_BOX);Y.before(this._renderUIStdMod,this,RENDERUI);Y.before(this._bindUIStdMod,this,BINDUI);Y.before(this._syncUIStdMod,this,SYNCUI);}
9 StdMod.HEADER=HEADER;StdMod.BODY=BODY;StdMod.FOOTER=FOOTER;StdMod.AFTER="after";StdMod.BEFORE="before";StdMod.REPLACE="replace";var STD_HEADER=StdMod.HEADER,STD_BODY=StdMod.BODY,STD_FOOTER=StdMod.FOOTER,HEADER_CONTENT=STD_HEADER+CONTENT_SUFFIX,FOOTER_CONTENT=STD_FOOTER+CONTENT_SUFFIX,BODY_CONTENT=STD_BODY+CONTENT_SUFFIX;StdMod.ATTRS={headerContent:{value:null},footerContent:{value:null},bodyContent:{value:null},fillHeight:{value:StdMod.BODY,validator:function(val){return this._validateFillHeight(val);}}};StdMod.HTML_PARSER={headerContent:function(contentBox){return this._parseStdModHTML(STD_HEADER);},bodyContent:function(contentBox){return this._parseStdModHTML(STD_BODY);},footerContent:function(contentBox){return this._parseStdModHTML(STD_FOOTER);}};StdMod.SECTION_CLASS_NAMES={header:Widget.getClassName(HD),body:Widget.getClassName(BD),footer:Widget.getClassName(FT)};StdMod.TEMPLATES={header:'<div class="'+StdMod.SECTION_CLASS_NAMES[STD_HEADER]+'"></div>',body:'<div class="'+StdMod.SECTION_CLASS_NAMES[STD_BODY]+'"></div>',footer:'<div class="'+StdMod.SECTION_CLASS_NAMES[STD_FOOTER]+'"></div>'};StdMod.prototype={_syncUIStdMod:function(){var stdModParsed=this._stdModParsed;if(!stdModParsed||!stdModParsed[HEADER_CONTENT]){this._uiSetStdMod(STD_HEADER,this.get(HEADER_CONTENT));}
10 if(!stdModParsed||!stdModParsed[BODY_CONTENT]){this._uiSetStdMod(STD_BODY,this.get(BODY_CONTENT));}
11 if(!stdModParsed||!stdModParsed[FOOTER_CONTENT]){this._uiSetStdMod(STD_FOOTER,this.get(FOOTER_CONTENT));}
12 this._uiSetFillHeight(this.get(FILL_HEIGHT));},_renderUIStdMod:function(){this._stdModNode.addClass(Widget.getClassName(STDMOD));this._renderStdModSections();},_renderStdModSections:function(){if(L.isValue(this.get(HEADER_CONTENT))){this._renderStdMod(STD_HEADER);}
13 if(L.isValue(this.get(BODY_CONTENT))){this._renderStdMod(STD_BODY);}
14 if(L.isValue(this.get(FOOTER_CONTENT))){this._renderStdMod(STD_FOOTER);}},_bindUIStdMod:function(){this.after(HeaderChange,this._afterHeaderChange);this.after(BodyChange,this._afterBodyChange);this.after(FooterChange,this._afterFooterChange);this.after(FillHeightChange,this._afterFillHeightChange);this.after(HeightChange,this._fillHeight);this.after(ContentUpdate,this._fillHeight);},_afterHeaderChange:function(e){if(e.src!==UI){this._uiSetStdMod(STD_HEADER,e.newVal,e.stdModPosition);}},_afterBodyChange:function(e){if(e.src!==UI){this._uiSetStdMod(STD_BODY,e.newVal,e.stdModPosition);}},_afterFooterChange:function(e){if(e.src!==UI){this._uiSetStdMod(STD_FOOTER,e.newVal,e.stdModPosition);}},_afterFillHeightChange:function(e){this._uiSetFillHeight(e.newVal);},_validateFillHeight:function(val){return!val||val==StdMod.BODY||val==StdMod.HEADER||val==StdMod.FOOTER;},_uiSetFillHeight:function(fillSection){var fillNode=this.getStdModNode(fillSection);var currNode=this._currFillNode;if(currNode&&fillNode!==currNode){currNode.setStyle(HEIGHT,EMPTY);}
15 if(fillNode){this._currFillNode=fillNode;}
16 this._fillHeight();},_fillHeight:function(){if(this.get(FILL_HEIGHT)){var height=this.get(HEIGHT);if(height!=EMPTY&&height!=AUTO){this.fillHeight(this._currFillNode);}}},_uiSetStdMod:function(section,content,where){if(L.isValue(content)){var node=this.getStdModNode(section)||this._renderStdMod(section);this._addStdModContent(node,content,where);this.set(section+CONTENT_SUFFIX,this._getStdModContent(section),{src:UI});}else{this._eraseStdMod(section);}
17 this.fire(ContentUpdate);},_renderStdMod:function(section){var contentBox=this.get(CONTENT_BOX),sectionNode=this._findStdModSection(section);if(!sectionNode){sectionNode=this._getStdModTemplate(section);}
18 this._insertStdModSection(contentBox,section,sectionNode);this[section+NODE_SUFFIX]=sectionNode;return this[section+NODE_SUFFIX];},_eraseStdMod:function(section){var sectionNode=this.getStdModNode(section);if(sectionNode){sectionNode.remove(true);delete this[section+NODE_SUFFIX];}},_insertStdModSection:function(contentBox,section,sectionNode){var fc=contentBox.get(FIRST_CHILD);if(section===STD_FOOTER||!fc){contentBox.appendChild(sectionNode);}else{if(section===STD_HEADER){contentBox.insertBefore(sectionNode,fc);}else{var footer=this[STD_FOOTER+NODE_SUFFIX];if(footer){contentBox.insertBefore(sectionNode,footer);}else{contentBox.appendChild(sectionNode);}}}},_getStdModTemplate:function(section){return Node.create(StdMod.TEMPLATES[section],this._stdModNode.get(OWNER_DOCUMENT));},_addStdModContent:function(node,children,where){switch(where){case StdMod.BEFORE:where=0;break;case StdMod.AFTER:where=undefined;break;default:where=StdMod.REPLACE;}
19 node.insert(children,where);},_getPreciseHeight:function(node){var height=(node)?node.get(OFFSET_HEIGHT):0,getBCR="getBoundingClientRect";if(node&&node.hasMethod(getBCR)){var preciseRegion=node.invoke(getBCR);if(preciseRegion){height=preciseRegion.bottom-preciseRegion.top;}}
20 return height;},_findStdModSection:function(section){return this.get(CONTENT_BOX).one("> ."+StdMod.SECTION_CLASS_NAMES[section]);},_parseStdModHTML:function(section){var node=this._findStdModSection(section);if(node){if(!this._stdModParsed){this._stdModParsed={};Y.before(this._applyStdModParsedConfig,this,APPLY_PARSED_CONFIG);}
21 this._stdModParsed[section+CONTENT_SUFFIX]=1;return node.get("innerHTML");}
22 return null;},_applyStdModParsedConfig:function(node,cfg,parsedCfg){var parsed=this._stdModParsed;if(parsed){parsed[HEADER_CONTENT]=!(HEADER_CONTENT in cfg)&&(HEADER_CONTENT in parsed);parsed[BODY_CONTENT]=!(BODY_CONTENT in cfg)&&(BODY_CONTENT in parsed);parsed[FOOTER_CONTENT]=!(FOOTER_CONTENT in cfg)&&(FOOTER_CONTENT in parsed);}},_getStdModContent:function(section){return(this[section+NODE_SUFFIX])?this[section+NODE_SUFFIX].get(CHILD_NODES):null;},setStdModContent:function(section,content,where){this.set(section+CONTENT_SUFFIX,content,{stdModPosition:where});},getStdModNode:function(section){return this[section+NODE_SUFFIX]||null;},fillHeight:function(node){if(node){var contentBox=this.get(CONTENT_BOX),stdModNodes=[this.headerNode,this.bodyNode,this.footerNode],stdModNode,cbContentHeight,filled=0,remaining=0,validNode=false;for(var i=0,l=stdModNodes.length;i<l;i++){stdModNode=stdModNodes[i];if(stdModNode){if(stdModNode!==node){filled+=this._getPreciseHeight(stdModNode);}else{validNode=true;}}}
23 if(validNode){if(UA.ie||UA.opera){node.set(OFFSET_HEIGHT,0);}
24 cbContentHeight=contentBox.get(OFFSET_HEIGHT)-
25 parseInt(contentBox.getComputedStyle("paddingTop"),10)-
26 parseInt(contentBox.getComputedStyle("paddingBottom"),10)-
27 parseInt(contentBox.getComputedStyle("borderBottomWidth"),10)-
28 parseInt(contentBox.getComputedStyle("borderTopWidth"),10);if(L.isNumber(cbContentHeight)){remaining=cbContentHeight-filled;if(remaining>=0){node.set(OFFSET_HEIGHT,remaining);}}}}}};Y.WidgetStdMod=StdMod;},'3.3.0',{requires:['base-build','widget']});