﻿(function ($) {
    $.fn.ellipsis = function () {
        return this.each(function () {
            var el = $(this);
            var link = $(el.find(".link"));
            var title = $(el.find(".title"));
            var author = $(el.find(".author"));

            var titleText = title.html();
            title.html("&hellip;");
            var minTitleHeight = 2 * title.height();
            title.html(titleText);

            var authorText = author.html();

            while (link.height() + (author.height() || 0) > el.height()) {
                if (title.height() > minTitleHeight) {
                    titleText = titleText.substr(0, titleText.length - 3);
                    title.html(titleText + "&hellip;");
                }
                else {
                    authorText = authorText.substr(0, authorText.length - 3);
                    author.html(authorText + "&hellip;");
                }
            }
        });
    };
})(jQuery);
