widget-buttons-min.js revision e2bba5831aa9cbf731d5c6bcac5b973be9a108e1
YUI.add("widget-buttons",function(a){var h="boundingBox",g="visible",f="click",k="renderUI",e="bindUI",l="syncUI",j="button",d="buttonsChange",c=a.ClassNameManager.getClassName,b=a.Node.create;function i(m){a.after(this._renderUIButtons,this,k);a.after(this._bindUIButtons,this,e);a.after(this._syncUIButtons,this,l);}i.BUTTON_CLASS_NAMES={buttons:a.Widget.getClassName("buttons"),wrapper:a.Widget.getClassName(j,"wrapper"),button:c(j),content:c(j,"content"),icon:c(j,"icon"),iconClose:c(j,"icon","close")};i.ATTRS={buttons:{value:[{type:"close"}],validator:a.Lang.isArray}};i.DEFAULT_BUTTONS={"close":{value:'<span class="'+i.BUTTON_CLASS_NAMES.icon+" "+i.BUTTON_CLASS_NAMES.iconClose+'" />',action:function(m){m.preventDefault();this.hide();},section:a.WidgetStdMod.HEADER}};i.TEMPLATES={defaultTemplate:'<a href={href} class="'+i.BUTTON_CLASS_NAMES.button+'">'+'<span class="'+i.BUTTON_CLASS_NAMES.content+'">{value}</span></a>',wrapper:'<span class="'+i.BUTTON_CLASS_NAMES.wrapper+'"></span>',clearfix:'<div style="clear:both;"></div>'};i.prototype={_hdBtnNode:null,_ftBtnNode:null,_buttonsArray:null,_uiHandlesButtons:null,_renderUIButtons:function(){this.get(h).addClass(i.BUTTON_CLASS_NAMES.buttons);this._buttonsArray=[];this._removeButtonNode(true,true);this._hdBtnNode=b(i.TEMPLATES.wrapper);this._ftBtnNode=b(i.TEMPLATES.wrapper);this._createButtons();},_bindUIButtons:function(){var m=this;this._uiHandlesButtons=[];a.each(this._buttonsArray,function(n){m._attachEventsToButton(n);});this.after(d,this._afterButtonsChange);},_syncUIButtons:function(){if(this._hdBtnNode.hasChildNodes()){this.setStdModContent(a.WidgetStdMod.HEADER,this._hdBtnNode,a.WidgetStdMod.AFTER);this._appendClearFix();}if(this._ftBtnNode.hasChildNodes()){this.setStdModContent(a.WidgetStdMod.FOOTER,this._ftBtnNode,a.WidgetStdMod.AFTER);}},addButton:function(m){var n=this.get("buttons");n.push(m);this.set("buttons",n);},_createButtons:function(){var r=this.get("buttons"),o="",n="",q,m=this,p;a.each(r,function(s){if(s.type&&i.DEFAULT_BUTTONS[s.type]){s=i.DEFAULT_BUTTONS[s.type];}o=a.Lang.sub(i.TEMPLATES.defaultTemplate,{href:s.href||"#",value:s.value});q=b(o);m._buttonsArray.push({node:q,cb:s.action});if(s.section===a.WidgetStdMod.HEADER){m._hdBtnNode.appendChild(q);}else{if(s.section===a.WidgetStdMod.FOOTER){m._ftBtnNode.appendChild(q);}else{}}});return true;},_appendClearFix:function(){this.setStdModContent(a.WidgetStdMod.HEADER,b(i.TEMPLATES.clearfix),a.WidgetStdMod.AFTER);},_attachEventsToButton:function(m){this._uiHandlesButtons.push(m.node.after(f,m.cb,this));},_afterButtonsChange:function(m){this._detachEventsFromButtons();this._renderUIButtons();this._bindUIButtons();this._syncUIButtons();},_removeButtonNode:function(m,n){if(m&&this._hdBtnNode&&this._hdBtnNode.hasChildNodes()){this._hdBtnNode.remove();this._hdBtnNode=null;}if(n&&this._ftBtnNode&&this._ftBtnNode.hasChildNodes()){this._ftBtnNode.remove();this._ftBtnNode=null;}},_detachEventsFromButtons:function(){a.each(this._uiHandlesButtons,function(m){m.detach();});this._uiHandlesButtons=[];}};a.WidgetButtons=i;},"@VERSION@",{requires:["base-build","widget","widget-stdmod"]});