Skip to content

Instantly share code, notes, and snippets.

@thetrickster
Last active December 19, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thetrickster/1dd069beb6becf56e891 to your computer and use it in GitHub Desktop.
Save thetrickster/1dd069beb6becf56e891 to your computer and use it in GitHub Desktop.
Use custom icons for the media downloads list view on Adobe Business Catalyst

Custom Icons for the media downloads module on Business Catalyst

Business Catalyst offers a great media downloads solution but there's no native way to use your own icons in the list view for media downloads. Furthermore, while you can update the list view layout of the media downloads module, there is no tag available to us that renders the filetype of the download that would make it possible for us to use specific images for the different file types in the list either by creating a CSS hook via a classname or even rendering our own image tag using a filetype tag.

Solution

The idea here is that since we don't have any CSS hooks via a tag like a filetype tag then we are just going to upload our new icon images to another folder on our site and use jQuery to change the URL from "/CatalystImages/Literature/" to "/images/Literature/" or another custom folder where you are storing your custom icons.

We'll be keeping the same base filename for our custom icons that BC uses for their images to make it easier. BC uses the same image file for multipe filetypes (MOV, WMV) and since there's no tag for a filetype we can't tell the difference between the types of files that share the same icon.

Dependencies

Our solution involves jQuery so make sure it's loaded in the <head> of your template or page or at least referenced before you add this jQuery solution to your template or page.


Let's get started!

  1. Create your custom icons. See the list below for all the icon filenames you'll need to reproduce. Start with pre-made custom icons or create your own with Fontello icon fonts
  2. Upload these icons to a custom folder. For our example, we created a folder called "Literature" inside our "images" folder on our BC site.
  3. Download the bcCustomMediaIcons jQuery plugin and upload it to your site. Reference our script after jQuery has been loaded in your page or page template:
<script src="/js/jquery.bcCustomMediaIcons.js"></script>
  1. Add our CSS styles to hide the BC icons and only show our custom icons when our jQuery is loaded. This CSS is based on the default media download container class of "literature-container". If you've updated your layout for the media downloads then you should update the CSS references as well to suit.
  2. Call our jQuery plugin by adding this javascript once to your page or page template:
<script>
         (function($){
           $(document).ready(function() {
               $(".literature-container").bcCustomMediaIcons();
           });
         })(jQuery); 
      </script>
  1. You can customize the script by passing in parameters which we'll cover in the next section.

That's it, you're done!

Customizing the jQuery script

You can customize a few aspects of the script by passing in parameters to the plugin.

  • If you want to change the size of the icons from the default 16px x 16px, pass in an array of parameters that include iconWidth and iconHeight. Be sure to use "px" in your value:
    • $(".literature-container").bcCustomMediaIcons({iconWidth: "24px", iconHeight: "24px"})
  • If you've created a custom layout for the media downloads module and changed the class name of the container, when calling our jQuery plugin on the page just change the main jQuery object this method is acting on from ".literature-container" to the object reference of your custom literature container element:
    • $(".custom-container").bcCustomMediaIcons();
  • If you used a different folder on your site to store your custom fonts instead of /images/Literature/ then pass in a dir parameter to your directory where you keep your icons: $(".literature-container").bcCustomMediaIcons({dir: "/images/mydir/"});

List of icon filenames used by the BC System

Here's a list of all the filenames for the icons used by BC for the media downloads module. You'll need to upload new icons with these filenames into your custom directory. Some of these icons are used over multiple filetypes like wmv.png which is used for all streaming video types. This list is subject to change if BC adds more filetype support and adds new icons. Please don't hold me responsible.

  • MP3 - mp3.png
  • WMV - wmv.png
  • PDF - pdf.png
  • FLASH - flash.png
  • EXECUTABLE - executable.png
  • HELP - help.png
  • MSACCESS - msaccess.png
  • MSEXCEL - msexcel.png
  • MSPOWERPOINT - mspowerpoint.png
  • PROJECT - project.png
  • VISIO - visio.png
  • WORD - word.png
  • OTHER - other.png
  • REALAUDIO - realaudio.png
  • TEXT - text.png
  • WORDPERFECT - wordperfect.png
  • ZIP - zip.png

## Replacement icons

Download this ZIP archive of 3 sets of icons already renamed and in folders. The icons are free for commercial use and author credit is in a text file in each folder.

To use on your site, unzip the file locally and upload the whole "Literature" folder into your "images" folder or another folder where you'll keep your icons.

Then, when calling the jQuery plugin on your page or template, pass in a dir parameter that is the location of your icons you downloaded above. To use the "perqui" icons, point to that directory:

     $(".literature-container").bcCustomMediaIcons({dir: "/images/Literature/perqui/"});

from Teambox

Download the ZIP file from Github, extract locally and change the filenames to the ones above for the applicable icons. Not everything is there like "visio" or "wordperfect" but the major filetype icons are there and most people don't share Visio files or Wordperfect files anymore.

Make your own icons with Fontello

I've created a custom font package on [Fontello] which you can use to create your own filetype icons.

  1. Save this JSON config file locally
  2. Visit Fontello and click the "wrench" icon for settings
  3. Choose "import config" and upload the config file you downloaded.
  4. Download your custom font package
  5. Install the font in the zip file you downloaded
  6. Use the font in Photoshop or other image editor to create custom icons

Our icons glyphs are mapped to the main alphabet keys: a-z (lowercase) and A-J (uppercase). Here's a preview of each icon and the corresponding keystroke which will render the glyph using our custom fontello font.

Font map

Todos

  • Add a function that adds a class if extensions are found in the "name" field of the media download item so we can have more unique icons for files like ".mov" and ".wmv"
  • Add a function that let's you add a class for CSS hooks if the file is a streaming file and also the option to use alternate icon filenames like "mp3-streaming.png" for mp3's that stream and "mp3.png" for non-streaming. Same goes with all streaming file types.
/* Hide the original icons */
.literature-container .icon img {
display: none;
}
/* Show the new icons when our jQuery is done */
.literature-container.loaded .icon img {
display: inline;
}
{
"name": "",
"css_prefix_text": "icon-",
"css_use_suffix": false,
"glyphs": [
{
"uid": "9ea0a737ccc45d6c510dcbae56058849",
"css": "music",
"code": 97,
"src": "fontawesome"
},
{
"uid": "872d9516df93eb6b776cc4d94bd97dac",
"css": "video",
"code": 98,
"src": "fontawesome"
},
{
"uid": "0f99ab40ab0b4d64a74f2d0deeb03e42",
"css": "videocam",
"code": 99,
"src": "fontawesome"
},
{
"uid": "381da2c2f7fd51f8de877c044d7f439d",
"css": "picture",
"code": 100,
"src": "fontawesome"
},
{
"uid": "b1887b423d2fd15c345e090320c91ca0",
"css": "th",
"code": 101,
"src": "fontawesome"
},
{
"uid": "17ebadd1e3f274ff0205601eef7b9cc4",
"css": "help-circled",
"code": 102,
"src": "fontawesome"
},
{
"uid": "e82cedfa1d5f15b00c5a81c9bd731ea2",
"css": "info-circled",
"code": 103,
"src": "fontawesome"
},
{
"uid": "1b5a5d7b7e3c71437f5a26befdd045ed",
"css": "doc-1",
"code": 104,
"src": "fontawesome"
},
{
"uid": "c8585e1e5b0467f28b70bce765d5840c",
"css": "docs",
"code": 105,
"src": "fontawesome"
},
{
"uid": "5408be43f7c42bccee419c6be53fdef5",
"css": "doc-text",
"code": 106,
"src": "fontawesome"
},
{
"uid": "f8aa663c489bcbd6e68ec8147dca841e",
"css": "folder",
"code": 107,
"src": "fontawesome"
},
{
"uid": "b091a8bd0fdade174951f17d936f51e4",
"css": "folder-empty",
"code": 108,
"src": "fontawesome"
},
{
"uid": "04ff8d6592fe548b332b27ed87ce397a",
"css": "box",
"code": 109,
"src": "fontawesome"
},
{
"uid": "e99461abfef3923546da8d745372c995",
"css": "cog",
"code": 110,
"src": "fontawesome"
},
{
"uid": "76857a03fbaa6857fe063b6c25aa98ed",
"css": "volume-up",
"code": 111,
"src": "fontawesome"
},
{
"uid": "f27bba41a700af51a4dd23cf4edea61d",
"css": "headphones",
"code": 112,
"src": "fontawesome"
},
{
"uid": "8fb55fd696d9a0f58f3b27c1d8633750",
"css": "table",
"code": 113,
"src": "fontawesome"
},
{
"uid": "9755f76110ae4d12ac5f9466c9152031",
"css": "book",
"code": 114,
"src": "fontawesome"
},
{
"uid": "d6fcb9886485b0bdb41b94521e7a3311",
"css": "ticket",
"code": 115,
"src": "fontawesome"
},
{
"uid": "f4445feb55521283572ee88bc304f928",
"css": "floppy",
"code": 116,
"src": "fontawesome"
},
{
"uid": "795efd07cd5205b589c883916a76cff0",
"css": "hdd",
"code": 117,
"src": "fontawesome"
},
{
"uid": "6fe95ffc3c807e62647d4f814a96e0d7",
"css": "sitemap",
"code": 118,
"src": "fontawesome"
},
{
"uid": "8aff323697468c4a63993cde00386ec6",
"css": "windows",
"code": 119,
"src": "fontawesome"
},
{
"uid": "6341ebcbe1ed1f6777c1b9527ead368e",
"css": "video-1",
"code": 120,
"src": "entypo"
},
{
"uid": "1189604bf305b6b03a74685ce60e6632",
"css": "doc-text-1",
"code": 121,
"src": "entypo"
},
{
"uid": "51727ca007aa35ceabcaffc28934faee",
"css": "book-open",
"code": 122,
"src": "entypo"
},
{
"uid": "48b79f27e4798f23bafa07b55dbe5b73",
"css": "book-1",
"code": 65,
"src": "entypo"
},
{
"uid": "96ea1be71f597a5bdfc8f791ada4f651",
"css": "archive",
"code": 66,
"src": "entypo"
},
{
"uid": "cc05df515bebe11df3ada0a5910a8f6d",
"css": "box-1",
"code": 67,
"src": "entypo"
},
{
"uid": "2f9f67ee4354feef8c1f51e03bac6ef3",
"css": "lifebuoy",
"code": 68,
"src": "entypo"
},
{
"uid": "11dd26ebf6934bf750a9156b353d7f2d",
"css": "suitcase",
"code": 69,
"src": "entypo"
},
{
"uid": "248db7c0563d8cee80b7041f7736dcad",
"css": "database",
"code": 70,
"src": "entypo"
},
{
"uid": "8beac4a5fd5bed9f82ca7a96cc8ba218",
"css": "key",
"code": 71,
"src": "entypo"
},
{
"uid": "8a1d446e5555e76f82ddb1c8b526f579",
"css": "flow-tree",
"code": 72,
"src": "entypo"
},
{
"uid": "76dfadaf502e065ac7b2689948f49cb0",
"css": "chart-pie-outline",
"code": 73,
"src": "typicons"
},
{
"uid": "56a766cedf13005162899b02cf9546b9",
"css": "library",
"code": 74,
"src": "maki"
}
]
}
// Override BC's icons used in the media downloads module
(function($){
var BCCustomMediaIcons = function(element, options)
{
var elem = $(element);
var obj = this;
var settings = $.extend({
catalystDir: "/CatalystImages/Literature/"
,dir: "/images/Literature/"
,iconWidth: ""
,iconHeight: ""
,debug: false
}, options || {});
// Private method - can only be called from within this object
var createIcons = function()
{
if ( !elem.length ) {
return false;
if (settings.debug) alert("Couldn't find the jQuery object to execute our plugin on. Make sure when calling this plugin you are pointing to the container holding your media download items. (Typically '.literature-container').")
}
var icon = elem.find("img");
var imageURL = icon.attr("src");
imageURL = imageURL.replace(settings.catalystDir, settings.dir);
icon.attr("src", imageURL);
if (settings.iconWidth && settings.iconWidth != "" ) {
icon.css("width", settings.iconWidth);
}
if (settings.iconHeight && settings.iconHeight != "") {
icon.css("height", settings.iconHeight);
}
elem.addClass("loaded");
};
createIcons();
};
$.fn.bcCustomMediaIcons = function(options)
{
return this.each(function()
{
var element = $(this);
// Return early if this element already has a plugin instance
if (element.data('bcCustomMediaIcons')) return;
// pass options to plugin constructor
var bcCustomMediaIcons = new BCCustomMediaIcons(this, options);
// Store plugin object in this element's data
element.data('bcCustomMediaIcons', bcCustomMediaIcons);
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment