rviscomi / trunk8

jQuery Truncation Plugin -- THIS PROJECT IS NO LONGER MAINTAINED
MIT License
703 stars 95 forks source link

I Now Use This CSS Alternative #60

Closed simonferndriger closed 9 years ago

simonferndriger commented 9 years ago

CSS

.is-clickable {
    cursor:pointer !important;
}
.is-cut {
    white-space:nowrap !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
}

JavaScript

var $CSS = {
    active:     'is-cut',
    dynamic:    'is-clickable'
};

var fittext = function($scope, static){
    var
        $texts = $($scope || $(document)).find('.fittext')
    ;

    $texts.addClass($CSS.active);

    if(static)
        return;

    //¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
    // Toggle
    //¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
    $texts
        .addClass($CSS.dynamic)
        .click(function(){
            $(this).toggleClass($CSS.active);
        })
    ;
};
BlueRaja commented 9 years ago

text-overflow:ellipsis does not work for multiline text, that's the main draw of this plugin.

simonferndriger commented 9 years ago

OK, thank you for this info.

However, in our case, we found that single line overflow cut is sufficient.