/**
* jQuery webUI 1.1.0
*
*
*/
if (typeof (WebUIManagers) == "undefined") WebUIManagers = {};
(function($)
{
///
$.fn.webGetAccordionManager = function()
{
return WebUIManagers[this[0].id + "_Accordion"];
};
$.fn.webRemoveAccordionManager = function()
{
return this.each(function()
{
WebUIManagers[this.id + "_Accordion"] = null;
});
};
$.fn.webAccordion = function(p)
{
this.each(function()
{
p = $.extend({
height: null,
speed : "normal",
changeHeightOnResize: false,
heightDiff: 0 // 高度补差
}, p || {});
if (this.usedAccordion) return;
var g = {
onResize: function()
{
if (!p.height || typeof (p.height) != 'string' || p.height.indexOf('%') == -1) return false;
//set accordion height
if (g.accordion.parent()[0].tagName.toLowerCase() == "body")
{
var windowHeight = $(window).height();
windowHeight -= parseInt(g.layout.parent().css('paddingTop'));
windowHeight -= parseInt(g.layout.parent().css('paddingBottom'));
g.height = p.heightDiff + windowHeight * parseFloat(g.height) * 0.01;
}
else
{
g.height = p.heightDiff + (g.accordion.parent().height() * parseFloat(p.height) * 0.01);
}
g.accordion.height(g.height);
g.setContentHeight(g.height - g.headerHoldHeight);
},
setHeight: function(height)
{
g.accordion.height(height);
height -= g.headerHoldHeight;
$("> .n-accordion-content", g.accordion).height(height);
}
};
g.accordion = $(this);
if (!g.accordion.hasClass("n-accordion-panel")) g.accordion.addClass("n-accordion-panel");
var selectedIndex = 0;
if ($("> div[lselected=true]", g.accordion).length > 0)
selectedIndex = $("> div", g.accordion).index($("> div[lselected=true]", g.accordion));
$("> div", g.accordion).each(function(i, box)
{
var header = $('
');
if (i == selectedIndex)
$(".n-accordion-toggle", header).addClass("n-accordion-toggle-open");
if ($(box).attr("title"))
{
$(".n-accordion-header-inner", header).html($(box).attr("title"));
$(box).attr("title","");
}
$(box).before(header);
if (!$(box).hasClass("n-accordion-content")) $(box).addClass("n-accordion-content");
});
//add Even
$(".n-accordion-toggle", g.accordion).each(function()
{
if (!$(this).hasClass("n-accordion-toggle-open") && !$(this).hasClass("n-accordion-toggle-close"))
{
$(this).addClass("n-accordion-toggle-close");
}
if ($(this).hasClass("n-accordion-toggle-close"))
{
$(this).parent().next(".n-accordion-content:visible").hide();
}
});
$(".n-accordion-header", g.accordion).hover(function()
{
$(this).addClass("n-accordion-header-over");
}, function()
{
$(this).removeClass("n-accordion-header-over");
});
$(".n-accordion-toggle", g.accordion).hover(function()
{
if ($(this).hasClass("n-accordion-toggle-open"))
$(this).addClass("n-accordion-toggle-open-over");
else if ($(this).hasClass("n-accordion-toggle-close"))
$(this).addClass("n-accordion-toggle-close-over");
}, function()
{
if ($(this).hasClass("n-accordion-toggle-open"))
$(this).removeClass("n-accordion-toggle-open-over");
else if ($(this).hasClass("n-accordion-toggle-close"))
$(this).removeClass("n-accordion-toggle-close-over");
});
$(">.n-accordion-header", g.accordion).click(function()
{
var togglebtn = $(".n-accordion-toggle:first",this);
if (togglebtn.hasClass("n-accordion-toggle-close"))
{
togglebtn.removeClass("n-accordion-toggle-close")
.removeClass("n-accordion-toggle-close-over n-accordion-toggle-open-over")
togglebtn.addClass("n-accordion-toggle-open");
$(this).next(".n-accordion-content")
.show(p.speed)
.siblings(".n-accordion-content:visible").hide(p.speed);
$(this).siblings(".n-accordion-header").find(".n-accordion-toggle").removeClass("n-accordion-toggle-open").addClass("n-accordion-toggle-close");
}
else
{
togglebtn.removeClass("n-accordion-toggle-open")
.removeClass("n-accordion-toggle-close-over n-accordion-toggle-open-over")
.addClass("n-accordion-toggle-close");
$(this).next(".n-accordion-content").hide(p.speed);
}
});
//init
g.headerHoldHeight = 0;
$("> .n-accordion-header", g.accordion).each(function()
{
g.headerHoldHeight += $(this).height();
});
if (p.height && typeof (p.height) == 'string' && p.height.indexOf('%') > 0)
{
g.onResize();
if (p.changeHeightOnResize)
{
$(window).resize(function()
{
g.onResize();
});
}
}
else
{
if (p.height)
{
g.height = p.heightDiff + p.height;
g.accordion.height(g.height);
g.setHeight(p.height);
}
else
{
g.header = g.accordion.height();
}
}
if (this.id == undefined) this.id = "WebUI_" + new Date().getTime();
WebUIManagers[this.id + "_Accordion"] = g;
this.usedAccordion = true;
});
if (this.length == 0) return null;
if (this.length == 1) return WebUIManagers[this[0].id + "_Accordion"];
var managers = [];
this.each(function() {
managers.push(WebUIManagers[this.id + "_Accordion"]);
});
return managers;
};
})(jQuery);