Skip to content

Instantly share code, notes, and snippets.

@monkeyhouse
Last active December 26, 2016 05:07
Show Gist options
  • Save monkeyhouse/9a747f654c312dd4b18053cb83bcbb36 to your computer and use it in GitHub Desktop.
Save monkeyhouse/9a747f654c312dd4b18053cb83bcbb36 to your computer and use it in GitHub Desktop.
Aurealia Fa Icon Attribute - this attribute converts file extensions into the font awesome icon
<template>
<!-- require icon here or in resources file-->
<!-- this attribute converts file extensions into the font awesome icon, not comprehensive
basically copy pasta'd most of lookup table from elsewhere -->
<i class="fa fa-5x" icon="file-xls"></i>
</template>
import {autoinject, bindable, bindingMode} from 'aurelia-framework';
@autoinject()
export class IconCustomAttribute {
constructor(private element: Element) { }
value : string;
bind() {
debugger;
var tx = (this.value + '--').split('-');
this.setElementClass(tx[0], tx[1]);
}
setElementClass(type: string, extension: string){
let style = IconCustomAttribute.getStyle( type, extension);
this.element.classList.add( style );
}
static getStyle( type : string, extension : string ) : string {
switch( type ){
case 'folder':
return 'fa-folder-o';
case 'monkey'
return 'fa-monkey';
case 'house' :
return 'fa-home';
case 'file':
switch( extension ){
case 'jpeg':
case 'jpg':
case 'png':
case 'gif':
return 'fa-file-image-o';
case 'xls':
case 'xlsx':
return 'fa-file-excel-o';
case 'doc':
case 'docx':
return 'fa-file-word-o';
case 'ppt':
case 'pptx':
return 'fa-file-powerpoint-o';
case 'zip':
case 'rar':
case 'tar':
case 'bz2':
case 'xz':
case 'gz':
return 'fa-file-archive-o';
case 'mp3':
return 'fa-file-audio-o';
case 'avi':
case 'mov':
return 'fa-file-video-o';
case 'php':
case 'html':
case 'css':
return 'fa-file-code-o';
case 'pdf':
return 'fa-file-pdf-o';
default:
return 'fa-file-o';
}
default:
return 'fa-question';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment