YUI.add("moodle-mod_offlinequiz-util-slot",function(l,e){l.namespace("Moodle.mod_offlinequiz.util.slot"),l.Moodle.mod_offlinequiz.util.slot={CSS:{SLOT:"slot",QUESTIONTYPEDESCRIPTION:"qtype_description",CANNOT_DEPEND:"question_dependency_cannot_depend"},CONSTANTS:{SLOTIDPREFIX:"slot-",QUESTION:M.util.get_string("question","moodle")},SELECTORS:{SLOT:"li.slot",INSTANCENAME:".instancename",NUMBER:"span.slotnumber",PAGECONTENT:"div#page-content",PAGEBREAK:"span.page_split_join_wrapper",ICON:".icon",QUESTIONTYPEDESCRIPTION:".qtype_description",SECTIONUL:"ul.section",DEPENDENCY_WRAPPER:".question_dependency_wrapper",DEPENDENCY_LINK:".question_dependency_wrapper .cm-edit-action",DEPENDENCY_ICON:".question_dependency_wrapper .icon"},getSlotFromComponent:function(e){return l.one(e).ancestor(this.SELECTORS.SLOT,!0)},getId:function(e){e=e.get("id").replace(this.CONSTANTS.SLOTIDPREFIX,"");return!("number"!=typeof(e=parseInt(e,10))||!isFinite(e))&&e},getName:function(e){e=e.one(this.SELECTORS.INSTANCENAME);return e?e.get("firstChild").get("data"):null},getNumber:function(e){if(!e)return!1;e=e.one(this.SELECTORS.NUMBER).get("text").replace(this.CONSTANTS.QUESTION,"");return!("number"!=typeof(e=parseInt(e,10))||!isFinite(e))&&e},setNumber:function(e,t){e.one(this.SELECTORS.NUMBER).setHTML('<span class="accesshide">'+this.CONSTANTS.QUESTION+"</span> "+t)},getSlots:function(){return l.all(this.SELECTORS.PAGECONTENT+" "+this.SELECTORS.SECTIONUL+" "+this.SELECTORS.SLOT)},getNumberedSlots:function(){var e=this.SELECTORS.PAGECONTENT+" "+this.SELECTORS.SECTIONUL;return e+=" "+this.SELECTORS.SLOT+":not("+this.SELECTORS.QUESTIONTYPEDESCRIPTION+")",l.all(e)},getPrevious:function(e){return e.previous(this.SELECTORS.SLOT)},getPreviousNumbered:function(e){var t,i,o=e.previous(this.SELECTORS.SLOT+":not("+this.SELECTORS.QUESTIONTYPEDESCRIPTION+")");if(o)return o;for(t=e.ancestor("li.section").previous("li.section");t;){if(0<(i=t.all(this.SELECTORS.SLOT+":not("+this.SELECTORS.QUESTIONTYPEDESCRIPTION+")")).size())return i.item(i.size()-1);t=t.previous("li.section")}return!1},reorderSlots:function(){this.getSlots().each(function(e){var t,i;l.Moodle.mod_offlinequiz.util.page.getPageFromSlot(e)||(t=e.next(l.Moodle.mod_offlinequiz.util.page.SELECTORS.PAGE),e.swap(t)),t=this.getPreviousNumbered(e),i=0,e.hasClass(this.CSS.QUESTIONTYPEDESCRIPTION)||(t&&(i=this.getNumber(t)),this.setNumber(e,i+1))},this)},updateOneSlotSections:function(){l.all(".mod-offlinequiz-edit-content ul.slots li.section").each(function(e){1<e.all(this.SELECTORS.SLOT).size()?e.removeClass("only-has-one-slot"):e.addClass("only-has-one-slot")},this)},remove:function(e){var t=l.Moodle.mod_offlinequiz.util.page.getPageFromSlot(e);e.remove(),l.Moodle.mod_offlinequiz.util.page.isEmpty(t)&&l.Moodle.mod_offlinequiz.util.page.remove(t)},getPageBreaks:function(){var e=this.SELECTORS.PAGECONTENT+" "+this.SELECTORS.SECTIONUL;return e+=" "+this.SELECTORS.SLOT+this.SELECTORS.PAGEBREAK,l.all(e)},getPageBreak:function(e){return l.one(e).one(this.SELECTORS.PAGEBREAK)},addPageBreak:function(e){var t=M.mod_offlinequiz.resource_toolbox.get("config").addpageiconhtml,t=t.replace("%%SLOT%%",this.getNumber(e)),t=l.Node.create(t);return e.one("div").insert(t,"after"),t},removePageBreak:function(e){e=this.getPageBreak(e);return!!e&&(e.remove(),!0)},reorderPageBreaks:function(){var S=this.getSlots(),a=0;S.each(function(e,t){var i,o,n,s,r,E;if(a++,n=this.getPageBreak(e),i=e.next("li.activity")){for(E in(n=n||this.addPageBreak(e))&&t===S.size()-1&&this.removePageBreak(e),t=n.get("childNodes").item(0),e="",e=l.Moodle.mod_offlinequiz.util.page.isPage(i)?(o="removepagebreak","e/remove_page_break"):(o="addpagebreak","e/insert_page_break"),t.set("title",M.util.get_string(o,"offlinequiz")),t.setData("action",o),(n=t.one(this.SELECTORS.ICON)).set("title",M.util.get_string(o,"offlinequiz")),n.set("alt",M.util.get_string(o,"offlinequiz")),n.set("src",M.util.image_url(e)),(s=l.QueryString.parse(t.get("href"))).slot=a,r="",s)r.length&&(r+="&"),r+=E+"="+s[E];t.set("href",r)}},this)}}},"@VERSION@",{requires:["node","moodle-mod_offlinequiz-util-base"]});