﻿(function (d) { d.widget("ui.accordion", { _init: function () { var a = this.options, c = this; this.running = 0; if (a.collapsible == d.ui.accordion.defaults.collapsible && a.alwaysOpen != d.ui.accordion.defaults.alwaysOpen) a.collapsible = !a.alwaysOpen; if (a.navigation) { var b = this.element.find("a").filter(a.navigationFilter); if (b.length) b.filter(a.header).length ? this.active = b : (this.active = b.parent().parent().prev(), b.addClass("ui-accordion-content-active")) } this.element.addClass("ui-accordion ui-widget ui-helper-reset"); "UL" == this.element[0].nodeName && this.element.children("li").addClass("ui-accordion-li-fix"); this.headers = this.element.find(a.header).addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all").bind("mouseenter.accordion", function () { d(this).addClass("ui-state-hover") }).bind("mouseleave.accordion", function () { d(this).removeClass("ui-state-hover") }).bind("focus.accordion", function () { d(this).addClass("ui-state-focus") }).bind("blur.accordion", function () { d(this).removeClass("ui-state-focus") }); this.headers.next().addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom"); this.active = this._findActive(this.active || a.active).toggleClass("ui-state-default").toggleClass("ui-state-active").toggleClass("ui-corner-all").toggleClass("ui-corner-top"); this.active.next().addClass("ui-accordion-content-active"); d("<span/>").addClass("ui-icon " + a.icons.header).prependTo(this.headers); this.active.find(".ui-icon").toggleClass(a.icons.header).toggleClass(a.icons.headerSelected); d.browser.msie && this.element.find("a").css("zoom", "1"); this.resize(); this.element.attr("role", "tablist"); this.headers.attr("role", "tab").bind("keydown", function (a) { return c._keydown(a) }).next().attr("role", "tabpanel"); this.headers.not(this.active || "").attr("aria-expanded", "false").attr("tabIndex", "-1").next().hide(); this.active.length ? this.active.attr("aria-expanded", "true").attr("tabIndex", "0") : this.headers.eq(0).attr("tabIndex", "0"); d.browser.safari || this.headers.find("a").attr("tabIndex", "-1"); a.event && this.headers.bind(a.event + ".accordion", function (a) { return c._clickHandler.call(c, a, this) }) }, destroy: function () { var a = this.options; this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role").unbind(".accordion").removeData("accordion"); this.headers.unbind(".accordion").removeClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-corner-top").removeAttr("role").removeAttr("aria-expanded").removeAttr("tabindex"); this.headers.find("a").removeAttr("tabindex"); this.headers.children(".ui-icon").remove(); var c = this.headers.next().css("display", "").removeAttr("role").removeClass("ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active"); (a.autoHeight || a.fillHeight) && c.css("height", "") }, _setData: function (a, c) { "alwaysOpen" == a && (a = "collapsible", c = !c); d.widget.prototype._setData.apply(this, arguments) }, _keydown: function (a) { var c = d.ui.keyCode; if (!this.options.disabled && !a.altKey && !a.ctrlKey) { var b = this.headers.length, f = this.headers.index(a.target), g = !1; switch (a.keyCode) { case c.RIGHT: case c.DOWN: g = this.headers[(f + 1) % b]; break; case c.LEFT: case c.UP: g = this.headers[(f - 1 + b) % b]; break; case c.SPACE: case c.ENTER: return this._clickHandler({ target: a.target }, a.target) } return g ? (d(a.target).attr("tabIndex", "-1"), d(g).attr("tabIndex", "0"), g.focus(), !1) : !0 } }, resize: function () { var a = this.options, c; if (a.fillSpace) { if (d.browser.msie) { var b = this.element.parent().css("overflow"); this.element.parent().css("overflow", "hidden") } c = this.element.parent().height(); d.browser.msie && this.element.parent().css("overflow", b); this.headers.each(function () { c -= d(this).outerHeight() }); var f = 0; this.headers.next().each(function () { f = Math.max(f, d(this).innerHeight() - d(this).height()) }).height(Math.max(0, c - f)).css("overflow", "auto") } else a.autoHeight && (c = 0, this.headers.next().each(function () { c = Math.max(c, d(this).outerHeight()) }).height(c)) }, activate: function (a) { a = this._findActive(a)[0]; this._clickHandler({ target: a }, a) }, _findActive: function (a) { return a ? "number" == typeof a ? this.headers.filter(":eq(" + a + ")") : this.headers.not(this.headers.not(a)) : !1 === a ? d([]) : this.headers.filter(":eq(0)") }, _clickHandler: function (a, c) { var b = this.options; if (b.disabled) return !1; if (!a.target && b.collapsible) { this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all").find(".ui-icon").removeClass(b.icons.headerSelected).addClass(b.icons.header); this.active.next().addClass("ui-accordion-content-active"); var f = this.active.next(), b = { options: b, newHeader: d([]), oldHeader: b.active, newContent: d([]), oldContent: f }, g = this.active = d([]); this._toggle(g, f, b); return !1 } var e = d(a.currentTarget || c), h = e[0] == this.active[0]; if (this.running || !b.collapsible && h) return !1; this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all").find(".ui-icon").removeClass(b.icons.headerSelected).addClass(b.icons.header); this.active.next().addClass("ui-accordion-content-active"); h || (e.removeClass("ui-state-default ui-corner-all").addClass("ui-state-active ui-corner-top").find(".ui-icon").removeClass(b.icons.header).addClass(b.icons.headerSelected), e.next().addClass("ui-accordion-content-active")); var g = e.next(), f = this.active.next(), b = { options: b, newHeader: h && b.collapsible ? d([]) : e, oldHeader: this.active, newContent: h && b.collapsible ? d([]) : g.find("> *"), oldContent: f.find("> *") }, i = this.headers.index(this.active[0]) > this.headers.index(e[0]); this.active = h ? d([]) : e; this._toggle(g, f, b, h, i); return !1 }, _toggle: function (a, c, b, f, g) { var e = this.options, h = this; this.toShow = a; this.toHide = c; this.data = b; var i = function () { return !h ? void 0 : h._completed.apply(h, arguments) }; this._trigger("changestart", null, this.data); this.running = 0 === c.size() ? a.size() : c.size(); if (e.animated) { b = {}; b = e.collapsible && f ? { toShow: d([]), toHide: c, complete: i, down: g, autoHeight: e.autoHeight || e.fillSpace} : { toShow: a, toHide: c, complete: i, down: g, autoHeight: e.autoHeight || e.fillSpace }; if (!e.proxied) e.proxied = e.animated; if (!e.proxiedDuration) e.proxiedDuration = e.duration; e.animated = d.isFunction(e.proxied) ? e.proxied(b) : e.proxied; e.duration = d.isFunction(e.proxiedDuration) ? e.proxiedDuration(b) : e.proxiedDuration; var f = d.ui.accordion.animations, k = e.duration, j = e.animated; f[j] || (f[j] = function (a) { this.slide(a, { easing: j, duration: k || 700 }) }); f[j](b) } else e.collapsible && f ? a.toggle() : (c.hide(), a.show()), i(!0); c.prev().attr("aria-expanded", "false").attr("tabIndex", "-1").blur(); a.prev().attr("aria-expanded", "true").attr("tabIndex", "0").focus() }, _completed: function (a) { var c = this.options; this.running = a ? 0 : --this.running; this.running || (c.clearStyle && this.toShow.add(this.toHide).css({ height: "", overflow: "" }), this._trigger("change", null, this.data)) } }); d.extend(d.ui.accordion, { version: "1.7.2", defaults: { active: null, alwaysOpen: !0, animated: "slide", autoHeight: !0, clearStyle: !1, collapsible: !1, event: "click", fillSpace: !1, header: "> li > :first-child,> :not(li):even", icons: { header: "ui-icon-triangle-1-e", headerSelected: "ui-icon-triangle-1-s" }, navigation: !1, navigationFilter: function () { return this.href.toLowerCase() == location.href.toLowerCase() } }, animations: { slide: function (a, c) { a = d.extend({ easing: "swing", duration: 300 }, a, c); if (a.toHide.size()) if (a.toShow.size()) { var b = a.toShow.css("overflow"), f, g = {}, e = {}, h, i = a.toShow; h = i[0].style.width; i.width(parseInt(i.parent().width(), 10) - parseInt(i.css("paddingLeft"), 10) - parseInt(i.css("paddingRight"), 10) - (parseInt(i.css("borderLeftWidth"), 10) || 0) - (parseInt(i.css("borderRightWidth"), 10) || 0)); d.each(["height", "paddingTop", "paddingBottom"], function (b, c) { e[c] = "hide"; var f = ("" + d.css(a.toShow[0], c)).match(/^([\d+-.]+)(.*)$/); g[c] = { value: f[1], unit: f[2] || "px"} }); a.toShow.css({ height: 0, overflow: "hidden" }).show(); a.toHide.filter(":hidden").each(a.complete).end().filter(":visible").animate(e, { step: function (c, b) { "height" == b.prop && (f = (b.now - b.start) / (b.end - b.start)); a.toShow[0].style[b.prop] = f * g[b.prop].value + g[b.prop].unit }, duration: a.duration, easing: a.easing, complete: function () { a.autoHeight || a.toShow.css("height", ""); a.toShow.css("width", h); a.toShow.css({ overflow: b }); a.complete() } }) } else a.toHide.animate({ height: "hide" }, a); else a.toShow.animate({ height: "show" }, a) }, bounceslide: function (a) { this.slide(a, { easing: a.down ? "easeOutBounce" : "swing", duration: a.down ? 1E3 : 200 }) }, easeslide: function (a) { this.slide(a, { easing: "easeinout", duration: 700 }) } } }) })(jQuery);
