Skip to content

mkhodan/truncator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

jQuery HTML truncator

jQuery plugin to truncate HTML text.

Simple Example

For example, you might see:

Lorem ipsum dolor sit amet, consectetur...

Clicking "..." shows:

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum sequi molestiae dolores rem.
Ratione accusantium corporis aut accusamus fugiat! At modi eum sint, reiciendis maiores
commodi tempore ipsa earum accusantium!

Usage

Function get's only 1 parametr 'size'. It has a default value 'size = 100'.

  $('.example').trunc( 100 );

Size possible values:

Positive number

e.g. 100 - hides all but first 100 characters.

Before:

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum sequi molestiae dolores rem.
Ratione accusantium corporis aut accusamus fugiat! At modi eum sint, reiciendis maiores
commodi tempore ipsa earum accusantium!

After:

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum mollitia, deleniti perspiciatis! Mol...

Negative number

e.g. -100 - hides last 100 characters.

Before:

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum sequi molestiae dolores rem.
Ratione accusantium corporis aut accusamus fugiat! At modi eum sint, reiciendis maiores
commodi tempore ipsa earum accusantium!

After:

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum mollitia, deleniti perspiciatis! 
Molestias quam nobis ducim...

0

Actually does nothing

Possible errors

If size value is bigger then actually elemnt's size function doesn't truncate it.

Requirements

  • jQuery - You need jQuery to be included to your project.

Authors

  • Mykola Khodan - Initial work - mkhodan

License

This project is licensed under the MIT License:

Copyright (c) 2017 Mykola Khodan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

jQuery plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published