﻿(function (a) { jQuery.fn.ryaccordion = function (l, f) { if (this.length > 1) { var j = new Array(); this.each(function (m) { j.push(a(this).ryaccordion(l, m)) }); return j } var b = a.extend({}, a().ryaccordion.defaults, l); this.Destroy = function (m) { var i = this; var m = (m != undefined) ? m : false; if (b.beforeDestroyFunction != null && a.isFunction(b.beforeDestroyFunction)) { b.beforeDestroyFunction(targetSection, b, m) } a("html, body").stop(); a(i).removeData("ryAccordion").removeClass(b.containerClass); a(i).children(b.contentElement).each(function (n) { var p = this; var o = a(p).children(b.handle + ":first"); if (o.size() > 0) { a(p).removeData("rHeight").removeData("handleHeight").stop().removeClass(b.openClass + " " + b.contentClass).removeClass(b.contentClass + "-" + (n + 1)); a(p).attr("style", ""); if (a(p).data("origStyle") != "") { a(p).attr("style", a(p).data("origStyle")) } o.unbind("click.ryAccordion.onHandleClick"); a(p).find("a").each(function (q) { a(this).unbind("click.ryAccordion.openSectionViaHash") }) } }); if (b.afterDestroyFunction != null && a.isFunction(b.afterDestroyFunction)) { b.afterDestroyFunction(targetSection, b, m) } }; this.Update = function (i) { b = null; b = a.extend({}, a().ryaccordion.defaults, i); this.Destroy(true); return this.Create() }; this.Create = function () { var n = null; var m = null; var i = this; if (a(i).data("ryAccordion") == true) { return this } if (b.beforeCreateFunction != null && a.isFunction(b.beforeCreateFunction)) { b.beforeCreateFunction(b) } a(i).data("ryAccordion", true); a(i).addClass(b.containerClass); a(i).children(b.contentElement).each(function (o) { var q = this; var p = a(q).children(b.handle + ":first"); if (p.size() > 0) { a(q).addClass(b.contentClass).addClass(b.contentClass + "-" + (o + 1)); if (a(q).attr("style") != undefined) { a(q).data("origStyle", a(q).attr("style")) } else { a(q).data("origStyle", "") } if (a(q).outerHeight(true) > n) { n = a(q).outerHeight(true) } a(q).data("rHeight", (a(q).outerHeight(true))); a(q).data("handleHeight", p.outerHeight()); a(q).css({ overflow: "hidden", position: "relative" }); if (b.openAllOnStart) { a(q).addClass(b.openClass); m += a(q).outerHeight(true) } else { if (b.startAsOpen == true && o + 1 == (b.startItem)) { a(q).addClass(b.openClass); m = a(q).outerHeight(true) } else { a(q).css({ height: p.outerHeight() }) } } p.bind("click.ryAccordion.onHandleClick", d) } }); a(i).children("." + b.contentClass).each(function (o) { var p = a(this); var q = p.children(b.handle + ":first"); p.find("a").each(function (s) { var r = this; if (r.hash + "" != "" && r.hash.length > 1) { if (a(i).find("#" + r.hash.slice(1)).size() > 0) { a(r).bind("click.ryAccordion.openSectionViaHash", function () { e(h(r.hash, i)); return false }) } } }) }); if (n != null && b.maintainHeight == true) { a(i).height(n + a(i).height() - m).css({ overflow: "auto" }) } if (document.location.hash + "" != "" && document.location.hash.length > 1) { if (a(i).find(document.location.hash).size() > 0) { k(i, c(document.location.hash, i)) } } if (b.afterCreateFunction != null && a.isFunction(b.afterCreateFunction)) { b.afterCreateFunction(i, b) } return this }; this.TogglePanel = function (i) { k(a(this), i) }; this.ShowAll = function () { if (!b.enableMulti) { return false } a(this).find("." + b.contentClass + ":not(." + b.openClass + ")").each(function () { a(this).animate({ height: a(this).data("rHeight") + a(this).data("handleHeight") }, { duration: b.speed, easing: b.easingMethod, complete: function () { if (b.afterToggleFunction != null && a.isFunction(b.afterToggleFunction)) { b.afterToggleFunction(a(this), b, "opened") } } }); a(this).addClass(b.openClass) }) }; this.HideAll = function () { if (!b.enableMulti) { return false } a(this).find("." + b.contentClass + "." + b.openClass).each(function () { a(this).animate({ height: a(this).data("handleHeight") }, { easing: b.easingMethod, duration: b.speed, complete: function () { if (b.afterToggleFunction != null && a.isFunction(b.afterToggleFunction)) { b.afterToggleFunction(a(this), b, "closed") } } }); a(this).removeClass(b.openClass) }) }; function h(n, i) { if (n + "" == "") { return null } var m = null; if (a(i).find("#" + n.slice(1)).size() > 0) { if (a(i).children("#" + n.slice(1)).size() == 0) { m = a("#" + n.slice(1)).closest("." + b.contentClass).attr("id") } else { m = n.slice(1) } } return m } function c(n, i) { if (n + "" == "") { return null } var m = null; if (a(i).find("#" + n.slice(1)).size() > 0) { if (a(i).children("#" + n.slice(1)).size() == 0) { m = a("#" + n.slice(1)).closest("." + b.contentClass).index() } else { m = a(i).children("#" + n.slice(1)).index() } } return m } function k(m, i) { if (m == null || i == null) { return null } if (a(m).children(b.contentElement + ":nth-child(" + (i + 1) + ")").hasClass(b.openClass)) { return null } g(a(m).children(b.contentElement + ":nth-child(" + (i + 1) + ")")) } function e(i) { g(a("#" + i)) } function d(i) { g(a(this).parent()); return false } function g(m) { if (m == null || !m.hasClass(b.contentClass)) { return false } var i = a(m).children(b.handle + ":first"); if (a(m).hasClass(b.openClass)) { if (b.beforeToggleFunction != null && a.isFunction(b.beforeToggleFunction)) { b.beforeToggleFunction(m, b, "closing") } } else { if (b.beforeToggleFunction != null && a.isFunction(b.beforeToggleFunction)) { b.beforeToggleFunction(m, b, "opening") } } a(m).stop(true, true); if (a(m).hasClass(b.openClass)) { a(m).animate({ height: a(m).data("handleHeight") }, { easing: b.easingMethod, duration: b.speed, complete: function () { if (b.afterToggleFunction != null && a.isFunction(b.afterToggleFunction)) { b.afterToggleFunction(m, b, "closed") } } }) } else { a(m).animate({ height: a(m).data("rHeight") + a(m).data("handleHeight") }, { duration: b.speed, easing: b.easingMethod, complete: function () { if (b.scrollToContent) { a("html, body").stop().animate({ scrollTop: a(m).offset().top - b.scrollOffset }, b.scrollSpeed); if (b.afterToggleFunction != null && a.isFunction(b.afterToggleFunction)) { b.afterToggleFunction(m, b, "opened") } } else { if (b.afterToggleFunction != null && a.isFunction(b.afterToggleFunction)) { b.afterToggleFunction(m, b, "opened") } } } }) } if (!b.enableMulti && !b.openAllOnStart) { a(m).siblings("." + b.openClass).each(function () { var n = this; a(n).animate({ height: a(n).data("handleHeight") }, { easing: b.easingMethod, duration: b.speed }).removeClass(b.openClass) }) } a(m).toggleClass(b.openClass) } return this.Create(f) }; jQuery.fn.ryaccordion.defaults = { speed: "slow", handle: "h3", enableMulti: false, maintainHeight: false, scrollToContent: true, scrollSpeed: "slow", scrollOffset: 100, startAsOpen: false, startItem: 1, easingMethod: null, openAllOnStart: false, contentElement: "div", containerClass: "ry_accordion", contentClass: "accordion_content", openClass: "expanded", beforeToggleFunction: null, afterToggleFunction: null, beforeCreateFunction: null, afterCreateFunction: null, beforeDestroyFunction: null, afterDestroyFunction: null} })(jQuery);
