1 |
- !function(e){"use strict";e.fn.accordionjs=function(c){if(this.length>1)return this.each(function(){e(this).accordionjs(c)}),this;var n=this,t={isInteger:function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},isObject:function(e){return"[object Object]"===Object.prototype.toString.call(e)},sectionIsOpen:function(e){return e.hasClass("acc_active")},getHash:function(){return window.location.hash?window.location.hash.substring(1):!1}},i=e.extend({closeAble:!1,closeOther:!0,slideSpeed:150,activeIndex:1,openSection:!1,beforeOpenSection:!1},c);e.each(i,function(e){var c=e.replace(/([A-Z])/g,"-$1").toLowerCase().toString(),t=n.data(c);(t||!1===t)&&(i[e]=t)}),(i.activeIndex===!1||i.closeOther===!1)&&(i.closeAble=!0);var o=function(){n.create(),n.openOnClick(),e(window).on("load",function(){n.openOnHash()}),e(window).on("hashchange",function(){n.openOnHash()})};return this.openSection=function(c,n){e(document).trigger("accjs_before_open_section",[c]),"function"==typeof i.beforeOpenSection&&i.beforeOpenSection.call(this,c),n=n>=0?n:i.slideSpeed;var t=c.children().eq(1);t.slideDown(n,function(){e(document).trigger("accjs_open_section",[c]),"function"==typeof i.openSection&&i.openSection.call(this,c)}),c.addClass("acc_active")},this.closeSection=function(c,n){e(document).trigger("accjs_before_close_section",[c]),"function"==typeof i.beforeCloseSection&&i.beforeCloseSection.call(this,c),n=n>=0?n:i.slideSpeed;var t=c.children().eq(1);t.slideUp(n,function(){e(document).trigger("accjs_close_section",[c]),"function"==typeof i.closeSection&&i.closeSection.call(this,c)}),c.removeClass("acc_active")},this.closeOtherSections=function(c,t){var i=c.closest(".accordionjs").children();e(i).each(function(){n.closeSection(e(this).not(c),t)})},this.create=function(){n.addClass("accordionjs");var c=n.children();if(e.each(c,function(c,t){n.createSingleSection(e(t))}),t.isArray(i.activeIndex))for(var o=i.activeIndex,s=0;s<o.length;s++)n.openSection(c.eq(o[s]-1),0);else i.activeIndex>1?n.openSection(c.eq(i.activeIndex-1),0):!1!==i.activeIndex&&n.openSection(c.eq(0),0)},this.createSingleSection=function(c){var n=c.children();c.addClass("acc_section"),e(n[0]).addClass("acc_head"),e(n[1]).addClass("acc_content"),c.hasClass("acc_active")||c.children(".acc_content").hide()},this.openOnClick=function(){n.on("click",".acc_head",function(c){c.stopImmediatePropagation();var o=e(this).closest(".acc_section");t.sectionIsOpen(o)?i.closeAble?n.closeSection(o):1===n.children().length&&n.closeSection(o):i.closeOther?(n.closeOtherSections(o),n.openSection(o)):n.openSection(o)})},this.openOnHash=function(){if(t.getHash()){var c=e("#"+t.getHash());c.hasClass("acc_section")&&(n.openSection(c),i.closeOther&&n.closeOtherSections(c),e("html, body").animate({scrollTop:parseInt(c.offset().top)-50},150))}},o(),this}}(jQuery);
|