Giter VIP home page Giter VIP logo

jquery.haircut.js's Introduction

jquery.haircut.js

We've got plenty of long filenames in the LayerVault file dashboard. We needed a way to condense them to fit into the interface while still displaying important parts (like the file extension). Thus, Haircut was born.

Haircut will ellipsize a string of text to fit inside of its parent container without overflowing or breaking to another line.

You can see a video of it in action here: Haircut in Action.

When hovering over a piece of text that's been given a haircut, the full text is display in a nice bubble. This bubble can be styled to the user's desire. Haircut is smart enough to pull out and include anchor tags contained within ellipsized text.

Setup

First, include haircut on the page. Bonus points for rolling it into your asset pipeline.

<script type="text/javascript" src="/jquery.haircut.js"></script>

Next, select the items on the page you want to haircut.

$(function () {
  $('.Filename').haircut();
});

Next, you will need to call the method stringResize whenever your layout changes. This has been abstracted out for now so that users can use things like the Underscore throttle and debounce methods. It's highly recommended that you use these if you've got a heavy page.

$(window).resize(function () {
  $('.Filename').stringResize();
});

Configuration

Haircut has a few configuration parameters that will help with tweaking performance and deciding which part of the string get ellipsized. Set the options like so:

  $('.Filename').haircut({
    // The more haircut items on the page, the more it jitters during animation.
    // Adding padding reduces jitter but gives you less usable space.
    jitterPadding     : 30,

    // The placement of the ellipsis. Can be "beginning", "middle" or "end"
    // Defaults to "middle"
    placement         : "middle"
  });

Styling

To change the styling of the hover bubble, you will need to provide stylings for the classes ._LVshowHaircutExpand and ._LVhaircutExpand. You can see example CSS rules on the test page of this project.

Authors

Written by Allan Grinshtein and Kelly Sutton for LayerVault. More open-source projects are available in the LayerVault Cosmos. Licensed under the MIT License.

jquery.haircut.js's People

Contributors

kellysutton avatar allang avatar

Watchers

James Cloos avatar Orhun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.