﻿/*
* Expandable, a jQuery plugin to dynamically group and hide web content
* Copyright (C) 2009 Marc Diethelm
* License: (GPL 3, http://www.gnu.org/licenses/gpl-3.0.txt) see license.txt
*/
(function(a){a.fn.expandable=function(){var c;var d={};if(arguments.length==1){c=(arguments[0].constructor==String?arguments[0]:null);d=(arguments[0].constructor==Object?arguments[0]:null)}else{if(arguments.length==2){c=(arguments[0].constructor==String?arguments[0]:null);d=arguments[1]}}var b=a.extend({},a.fn.expandable.defaults,d);return this.each(function(){if(c=="destroy"){a(this).removeClass("ui-widget ui-expandable ui-expandable-open");a(".ui-widget-content",this).remove().contents().appendTo(this);if(a(this).data("elTitle")){a(".ui-widget-header",this).unbind("click").remove();a(this).prepend(a(this).data("elTitle"))}return this}else{if(c=="close"){this.closeExpandable();return this}else{if(c=="open"){this.openExpandable(null,b);return this}}}a(this).hide().addClass("ui-expandable ui-widget");var p="";if(a(".ui-expandable-title",this).length>0){var n=a(".ui-expandable-title",this).eq(0).remove();p=n.text();a(this).data("elTitle",n);delete n}p=b.title||p;if(a(".ui-widget-content",this).length==0){var i='<div class="ui-widget-content ui-helper-clearfix"></div>';var m=jQuery(this);if(m.contents().length){m.contents().wrapAll(i)}else{m.html(i)}}var h=a(".ui-widget-content",this);if(b.startopen){a(this).addClass("ui-expandable-open")}else{h.hide()}if(b.uiIconClosed&&b.uiIconOpen){var o=(b.startopen?b.uiIconOpen:b.uiIconClosed);var g=b.uiIconClosed;var e=b.uiIconOpen}else{var o=(b.startopen?"icon-open":"icon-closed");var g="icon-closed";var e="icon-open"}var l="";if(b.extraIcon){l=" ui-icon "+b.extraIcon}var n=a('<div class="ui-state-default ui-widget-header" title="'+b.tooltip+'"> <div class="ui-expandable-icon ui-icon '+o+'"></div> <div class="ui-expandable-title">'+p+'</div> <div class="ui-expandable-extraIcon'+l+'"></div></div>');a(".ui-widget-header",this).length?a(".ui-widget-header",this).replaceWith(n):a(this).prepend(n);a(this).show();var j=a(".ui-icon",this);var f=Math.floor(((n.innerHeight()-j.height())/2));if(f>0){j.css("margin-top",f)}var k=a(this);var q=this;if(b.close){this._close=b.close}if(b.open){this._open=b.open}n.bind("click",null,function(r){if(k.hasClass("ui-expandable-open")){q.closeExpandable(r)}else{q.openExpandable(r,b)}});this.closeExpandable=function(r){a(".ui-expandable-icon",n).removeClass(e).addClass(g);h.animate(b.animationClose,b.duration,b.easing,function(){k.removeClass("ui-expandable-open");if(b.close){q._close(r,b)}})};this.openExpandable=function(r,s){a(".ui-expandable-icon",n).removeClass(g).addClass(e);h.animate(s.animationOpen,s.duration,s.easing,function(){k.addClass("ui-expandable-open");if(s.open){q._open(r,s)}})};n.hover(function(){a(this).removeClass("ui-state-default").addClass("ui-state-hover")},function(){a(this).removeClass("ui-state-hover").addClass("ui-state-default")});return this})};a.fn.expandable.defaults={startopen:false,title:null,tooltip:"Click to expand",uiIconClosed:"ui-icon-triangle-1-e",uiIconOpen:"ui-icon-triangle-1-s",animationClose:{height:"hide"},animationOpen:{height:"show"},duration:500,easing:"swing",open:null,close:null,extraIcon:null}})(jQuery);
