mobomo/ng-trunk8

Name: ng-trunk8

Owner: mobomo

Description: Angular fork of the popular jQuery truncation plugin.

Created: 2014-08-06 19:18:50.0

Updated: 2017-10-23 02:10:29.0

Pushed: 2014-08-07 00:55:59.0

Homepage: null

Size: 208

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Work In Progress

NOTE: This is a work-in-progress, so it will likely not work as expected. This README will be updated as the project progresses. In the meantime, check the status of it on the Angular Conversion Milestone.

trunk8

About

trunk8 is an intelligent text truncation extension to jQuery. When applied to a large block of text, trunk8 will cut off just enough text to prevent it from spilling over.

Unlike conventional truncation that just limits the character length of text, trunk8 measures the content area for spill-over and intelligently chooses the text that best fits in the given space.

Play with the live demo.

Bonus: Global heatmap of trunk8 stargazers.

Usage

Default Settings

too-long').trunk8(); // Lorem ipsum dolor sit amet, consect?

By default, trunk8 will add an ellipsis (…) after the truncated text.

Method Invocation

too-long').trunk8('update', new_string); // Lorem ipsum dolor sit amet, consect?

To invoke built-in trunk8 methods, supply the method name as a string. Method arguments are listed after the method name as necessary. See the section below entitled Methods for a full specification.

Custom Settings

too-long').trunk8({
fill: '[snip]',
side: 'center'
// Lorem ipsum dol[snip]id est laborum.

You may change the settings at any time by passing an object to trunk8. In the example above, the filler text is overwritten from an ellipsis to a custom string and the placement of the truncation is overwritten from the right side to the center. Continue reading the section below for a full list of customizable settings.

Settings
Public Methods

[Constructor] Initializes the settings and immediately truncates the targeted HTML element. This method is called when arguments are omitted and when the first argument is an object. When supplied with an object, trunk8 will merge the user-defined settings with the predefined settings object and immediately truncate the targeted HTML element with the custom settings.

efault settings */
too-long').trunk8();

ustom settings */
too-long').trunk8({
ines: 2

update Updates the text value of the targeted HTML elements while maintaining truncation.

runcate the original text. */
too-long').trunk8(); // Lorem ipsum...

efine the new text. */
new_string = 'Torquent sollicitudin.';

runcate the new text. */
too-long').trunk8('update', new_string); // Torquent so...

revert Reverts the text value of the targeted HTML elements to their untruncated states.

too-long').trunk8('revert'); // Torquent sollicitudin.

getSettings Returns an object representation of the settings currently in effect. Because a return value is expected, this method does not promote the jQuery pattern of method chaining:

ood */
setings = $('.too-long').trunk8('getSettings'); // {...}

ad */
too-long').trunk8('getSettings').addClass('wrong'); // error
MIT License

Copyright (c) 2012 Rick Viscomi (rviscomi@gmail.com)

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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.