Easy & Customizable Link Decoration Plugin - jQuery Link Decorators

File Size: 61.1 KB
Views Total: 123
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Easy & Customizable Link Decoration Plugin - jQuery Link Decorators

The Link Decorators is a jquery plugin that provides you the ability to decorate file links and display tooltips containing information about the files when hovering over them.

Its primary purpose is for displaying the size and type information about file downloads, such as word documents or pdf files, directly on your download links. This information may be used in a number of ways such as informing visitors about the size of a file before they download it, or helping them decide if they want to download it based on its type.

How to use it:

1. Download and include the minified version of the Link Decorators plugin on the page.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/dist/jquery.link-decorators.min.js"></script>

2. Add an extension class (pdf, txt, etc) to the target link. Available selectors:

  • a:external: external link
  • a:internal: internal link
  • a:mailto: email address
  • a:pathStartsWith(/path/to): starts with
  • a:pathEndsWith(.pdf): ends with
  • a:pathContains(string): contains anything
<a href="/documents/doc.pdf">
  PDF File
.pdf {
  /* style the PDF link */

3. Add a custom CSS class to the PDF link:

.custom {
  /* more styles here */

4. Display file information in the tooltip.

  • ext: File extension
  • EXT: File extension in uppercase
  • size: File size in bytes
  • formattedSize: Formatted file size: KB, MB, or GB.
  • rawType: File Type
  • mimeType: MIME type
  .decorate(function(data) {
    $(this).append("<span class='popup'>[" + data.EXT + ": " + data.formattedSize + "]</span>");
/* style the popup */
span.popup {
  font-size: 14px;
  font-weight: 400;
  background: black !important;
  border: none !important;
  color: #fff;

span.popup:before {
  border-right-color: black !important;

5. Map file extensions to Font Awesome icons classes and decorate links with icons.

var classmap = {
  pdf: "fa fa-file-pdf-o",
  txt: "fa fa-file-text",
  doc: "fa fa-file-word-o",
  docx: "fa fa-file-word-o",
  xls: "fa fa-file-excel-o",
  xlsx: "fa fa-file-excel-o",
  jpg: "fa fa-file-image-o"

var success = function(data) {
  // Decorate link with icon for file type, and popup showing size
  $(this).append(" <i class='" + classmap[data.ext] + "'></i><span class='popup'>[" + data.EXT + ": " + data.formattedSize + "]</span>");

var fail = function() {
  // Decorate missing link with warning
  $(this).append(" <i class='fa fa-exclamation-triangle'></i>")
  .append("<span class='popup'>This file is missing</span>")

// Decorate document links using the above callbacks
  .decorate(success, fail)

6. Open the link in a new window.


7. Add rel='nofollow' and rel='noopener' to the link.


This awesome jQuery plugin is developed by CarlRaymond. For more Advanced Usages, please check the demo page or visit the official website.