(function($) {
$.fn.expandtext = function(options) {
var defaults = {
expandText: "続きを読む >>",
collapseText: "X 閉じる",
collapseTextContainer: "",
beforeExpand: function($thisEl) {},
afterExpand: function($thisEl) {},
onCollapse: function($thisEl) {}
};
var options = $.extend(defaults, options);
return this.each(function() {
var o = options;
var expandEle = $(this);
var collapseEle = null;
if (o.collapseTextContainer.length == 0) {
collapseEle = $(this).next(o.collapseTextContainer);
} else {
collapseEle = $(this).next();
}
if ($(collapseEle).html().length > 0) {
$(expandEle).append('' + o.expandText + '')
$(collapseEle).append('' + o.collapseText + '');
}
$('.ExpandText', this).click(function() {
o.beforeExpand($(this));
$(expandEle).hide();
$(collapseEle).show();
o.afterExpand($(this));
return false;
});
$('.CollapseText', collapseEle).click(function() {
$(collapseEle).hide();
$(expandEle).show();
o.onCollapse($(this));
return false;
});
});
};
})(jQuery);