Last active
December 26, 2016 05:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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