YUI.add("moodle-form-shortforms",function(e,t){function n(){n.superclass.constructor.apply(this,arguments)}var r={COLLAPSEEXPAND:".collapsible-actions .collapseexpand",COLLAPSED:".collapsed",FIELDSETCOLLAPSIBLE:"fieldset.collapsible",FIELDSETLEGENDLINK:"fieldset.collapsible .fheader",FHEADER:".fheader",LEGENDFTOGGLER:"legend.ftoggler"},i={COLLAPSEALL:"collapse-all",COLLAPSED:"collapsed",FHEADER:"fheader"},s={};s.formid={value:null},e.extend(n,e.Base,{form:null,initializer:function(){var t=e.one("#"+this.get("formid")),n,i,s,o;if(!t)return;this.form=t,n=t.all(r.FIELDSETCOLLAPSIBLE),n.each(this.process_fieldset,this),t.delegate("click",this.switch_state,r.FIELDSETLEGENDLINK,this),t.delegate("key",this.switch_state,"down:enter,32",r.FIELDSETLEGENDLINK,this),e.Global.on(M.core.globalEvents.FORM_ERROR,this.expand_fieldset,this),i=t.one(r.COLLAPSEEXPAND),i&&(s=e.Node.create('<a href="#"></a>'),s.setHTML(i.getHTML()),s.setAttribute("class",i.getAttribute("class")),s.setAttribute("role","button"),o=[],t.all(r.FIELDSETLEGENDLINK).each(function(e){o[o.length]=e.generateID()}),s.setAttribute("aria-controls",o.join(" ")),s.on("click",this.set_state_all,this,!0),s.on("key",this.set_state_all,"down:enter,32",this,!0),i.replace(s),this.update_btns(t))},process_fieldset:function(t){var n=t.one(r.LEGENDFTOGGLER),s=e.Node.create('<a href="#"></a>');return s.addClass(i.FHEADER),s.appendChild(n.get("firstChild")),s.setAttribute("role","button"),s.setAttribute("aria-controls",t.generateID()),n.ancestor(r.COLLAPSED)?(s.setAttribute("aria-expanded","false"),require(["core/templates"],function(e){e.renderIcon("collapsed").done(function(e){s.get("aria-expanded")==="false"&&s.prepend(e)})})):(s.setAttribute("aria-expanded","true"),require(["core/templates"],function(e){e.renderIcon("expanded").done(function(e){s.get("aria-expanded")==="true"&&s.prepend(e)})})),n.prepend(s),this},set_state:function(e,t){var n=e.one(r.FHEADER),s=!1;t?(e.addClass(i.COLLAPSED),n&&(n.setAttribute("aria-expanded","false"),require(["core/templates"],function(e){e.renderIcon("collapsed").done(function(e){n.get("aria-expanded")==="false"&&(n.one(".flex-icon").remove(),n.prepend(e))})})),window.form_fieldset_collapse&&window.form_fieldset_collapse.constructor===Array&&(s=window.form_fieldset_collapse)):(e.removeClass(i.COLLAPSED),n&&(require(["core/templates"],function(e){e.renderIcon("expanded").done(function(e){n.get("aria-expanded")==="true"&&(n.one(".flex-icon").remove(),n.prepend(e))})}),n.setAttribute("aria-expanded","true")),window.form_fieldset_expand&&window.form_fieldset_expand.constructor===Array&&(s=window.form_fieldset_expand));var o=this.form.one("input[name=mform_isexpanded_"+e.get("id")+"]");if(!o)return this;o.set("value",t?0:1);if(s){var u;for(u=0;u<s.length;u++)s[u].callback.apply(s[u].context,[e.getDOMNode()])}return this},set_state_all:function(e){e.preventDefault();var t=e.target.hasClass(i.COLLAPSEALL),n=this.form.all(r.FIELDSETCOLLAPSIBLE);n.each(function(e){this.set_state(e,t)},this),this.update_btns()},switch_state:function(e){e.preventDefault();var t=e.target.ancestor(r.FIELDSETCOLLAPSIBLE);this.set_state(t,!t.hasClass(i.COLLAPSED)),this.update_btns()},update_btns:function(){var e,t=0,n=!1,s;return e=this.form.one(r.COLLAPSEEXPAND),e?(s=this.form.all(r.FIELDSETCOLLAPSIBLE),s.each(function(e){e.hasClass(i.COLLAPSED)&&t++}),t!==0&&(n=!0),n?(e.removeClass(i.COLLAPSEALL),e.setHTML(M.util.get_string("expandall","moodle")),require(["core/templates"],function(t){t.renderIcon("collapsed").done(function(t){e.hasClass("aria-expanded")||(e.one(".flex-icon")&&e.one(".flex-icon").remove(),e.prepend(t))})})):(e.addClass(i.COLLAPSEALL),e.setHTML(M.util.get_string("collapseall","moodle")),require(["core/templates"],function(t){t.renderIcon("expanded").done(function(t){e.hasClass(i.COLLAPSEALL)&&(e.one(".flex-icon")&&e.one(".flex-icon").remove(),e.prepend(t))})})),this):this},expand_fieldset:function(t){t.stopPropagation();var n=t.formid;if(n===this.form.getAttribute("id")){var r=e.one("#"+t.elementid).ancestor("fieldset");r&&this.set_state(r,!1)}}},{NAME:"moodle-form-shortforms",ATTRS:s}),M.form=M.form||{},M.form.shortforms=M.form.shortforms||function(e){return new n(e)}},"@VERSION@",{requires:["node","base","selector-css3","moodle-core-event"]});
