forked from yui/yui3-gallery
/
gallery-dropdown-min.js
1 lines (1 loc) · 2.45 KB
/
gallery-dropdown-min.js
1
YUI.add("gallery-dropdown",function(a){a.namespace("HTML");a.HTML.DropDown=function(b){this.init(b);};a.HTML.DropDown.prototype={init:function(b){this.setDefaults(b);this.transform();},setDefaults:function(b){if(!b){b={};}b.src=(b.src)?b.src:"select";b.resize=(b.resize!=undefined)?b.resize:true;this.conf=b;this.srcNode=a.all(this.conf.src);},transform:function(){this.srcNode.each(function(h,f){if(h.get("tagName")=="SELECT"||h.get("tagName")=="select"){var d=h.get("name"),e=h.getStyle("width");var b='<div class="yui-gallery-select">',l={markup:"",value:""},c=h.getAttribute("id"),g=h.getAttribute("class"),k=['<div class="container"><ul>'];if(h.all("optgroup").size()>0){h.all("optgroup").each(function(n,m){var i=n.get("label");k.push("<li>"+i+"<ul>");n.get("options").each(function(p,o){this.buildMarkup(p,k,l,o+m);},this);k.push("</ul></li>");},this);}else{h.get("options").each(function(n,m){this.buildMarkup(n,k,l,m);},this);}k.push('</ul></div><input type="hidden" name="'+d+'" value="'+l.value+'"/></div>');k=b+l.markup+k.join("");var j=a.Node.create(k);h.insert(j,h);h.remove(true);j.set("id",c);j.set("className",g+" "+j.get("className"));if(this.conf.resize){this.resizeWidth(j,e);}j.one(".anchor").plug(a.Plugin.SimpleMenu);this.registerEvents(j);}},this);},resizeWidth:function(b,c){c=parseInt(c,10)+20;b.one(".anchor").setStyle("width",c+"px");b.one(".container").setStyle("width",(c+20)+"px");},buildMarkup:function(b,k,j,d){var c=b.get("selected"),f=b.get("title"),g=b.get("value"),h=b.get("text"),e="";if(f){e=' title="'+f+'"';}if(d==0||c){j.markup='<a class="anchor" href="#"><label>'+h+'</label><span class="arrow"><label></label></span></a>';j.value=g;}if(c){k.push("<li><strong"+e+' value="'+g+'">'+h+"</strong></li>");}else{k.push("<li><a"+e+' value="'+g+'">'+h+"</a></li>");}},registerEvents:function(b){b.delegate("click",function(j,p){var f=j.currentTarget;var n=f.get("text"),l=f.getAttribute("value"),k=f.getAttribute("title"),h="",c=p.one("input").get("value"),o=p.one(".anchor label").get("text");if(k){h=' title="'+k+'"';}p.one(".anchor label").set("text",n);p.one("input").set("value",l);var g=b.one("strong");var q=g.getAttribute("title"),m="";if(q){m=' title="'+q+'"';}var d="<a"+m+' value="'+c+'">'+o+"</a>";g.insert(d,g);g.remove(true);var i="<strong"+h+' value="'+l+'">'+n+"</strong>";f.insert(i,f);f.remove(true);b.one(".container").removeClass("menu-visible");},".container a",this,b);}};},"gallery-2011.06.01-20-18",{requires:["node","event","gallery-simple-menu"]});