/*
* jQuery UI Button 1.8rc3
*
* Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://docs.jquery.com/UI/Button
*
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
*/
(function(d){var c,b="ui-button ui-widget ui-state-default ui-corner-all",a="ui-state-hover ui-state-active ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon ui-button-text-only";d.widget("ui.button",{options:{text:true,label:null,icons:{primary:null,secondary:null}},_create:function(){this._determineButtonType();this.hasTitle=!!this.buttonElement.attr("title");var e=this,g=this.options,h=this.type==="checkbox"||this.type==="radio",i="ui-state-hover"+(!h?" ui-state-active":""),f="ui-state-focus";if(g.label===null){g.label=this.buttonElement.html()}this.buttonElement.addClass(b).attr("role","button").bind("mouseenter.button",function(){if(g.disabled){return}d(this).addClass("ui-state-hover");if(this===c){d(this).addClass("ui-state-active")}}).bind("mouseleave.button",function(){if(g.disabled){return}d(this).removeClass(i)}).bind("focus.button",function(){d(this).addClass(f)}).bind("blur.button",function(){d(this).removeClass(f)});if(this.type==="checkbox"){this.buttonElement.bind("click.button",function(){if(g.disabled){return}d(this).toggleClass("ui-state-active");e.buttonElement.attr("aria-pressed",e.element[0].checked)})}else{if(this.type==="radio"){this.buttonElement.bind("click.button",function(){if(g.disabled){return}d(this).addClass("ui-state-active");e.buttonElement.attr("aria-pressed",true);var k=e.element[0],j=k.name,l=k.form,m;if(j){if(l){m=d(l).find("[name="+j+"]")}else{m=d("[name="+j+"]",k.ownerDocument).filter(function(){return !this.form})}m.not(k).map(function(){return d(this).button("widget")[0]}).removeClass("ui-state-active").attr("aria-pressed",false)}})}else{this.buttonElement.bind("mousedown.button",function(){if(g.disabled){return}d(this).addClass("ui-state-active");c=this;d(document).one("mouseup",function(){c=null})}).bind("mouseup.button",function(){if(g.disabled){return}d(this).removeClass("ui-state-active")}).bind("keydown.button",function(j){if(j.keyCode==d.ui.keyCode.SPACE||j.keyCode==d.ui.keyCode.ENTER){d(this).addClass("ui-state-active")}}).bind("keyup.button",function(){d(this).removeClass("ui-state-active")});if(this.buttonElement.is("a")){this.buttonElement.keyup(function(j){if(j.keyCode==d.ui.keyCode.SPACE){d(this).trigger("click")}})}}}this._resetButton()},_determineButtonType:function(){this.type=this.element.is(":checkbox")?"checkbox":this.element.is(":radio")?"radio":this.element.is("input")?"input":"button";if(this.type==="checkbox"||this.type==="radio"){this.buttonElement=d("[for="+this.element.attr("id")+"]");this.element.hide();var e=this.element.is(":checked");if(e){this.buttonElement.addClass("ui-state-active")}this.buttonElement.attr("aria-pressed",e)}else{this.buttonElement=this.element}},widget:function(){return this.buttonElement},destroy:function(){this.buttonElement.removeClass(b+" "+a).removeAttr("role").removeAttr("aria-pressed").html(this.buttonElement.find(".ui-button-text").html());if(!this.hasTitle){this.buttonElement.removeAttr("title")}if(this.type==="checkbox"||this.type==="radio"){this.element.show()}d.Widget.prototype.destroy.call(this)},_setOption:function(e,f){d.Widget.prototype._setOption.apply(this,arguments);this._resetButton()},_resetButton:function(){if(this.type==="input"){if(this.options.label){this.element.val(this.options.label)}return}var h=this.buttonElement,g=d("").addClass("ui-button-text").html(this.options.label).appendTo(h.empty()).text();var f=this.options.icons,e=f.primary&&f.secondary;if(f.primary||f.secondary){h.addClass("ui-button-text-icon"+(e?"s":""));if(f.primary){h.prepend("")}if(f.secondary){h.append("")}if(!this.options.text){h.addClass(e?"ui-button-icons-only":"ui-button-icon-only").removeClass("ui-button-text-icons ui-button-text-icon");if(!this.hasTitle){h.attr("title",g)}}}else{h.addClass("ui-button-text-only")}}});d.widget("ui.buttonset",{_create:function(){this.element.addClass("ui-button-set");this.buttons=this.element.find(":button, :submit, :reset, :checkbox, :radio, a, .ui-button").button().map(function(){return d(this).button("widget")[0]}).removeClass("ui-corner-all").filter(":first").addClass("ui-corner-left").end().filter(":last").addClass("ui-corner-right").end().end()},_setOption:function(e,f){if(e==="disabled"){this.buttons.button("option",e,f)}d.Widget.prototype._setOption.apply(this,arguments)},destroy:function(){this.element.removeClass("ui-button-set");this.buttons.button("destroy").removeClass("ui-corner-left ui-corner-right");d.Widget.prototype.destroy.call(this)}})})(jQuery);