Created
August 13, 2012 21:37
-
-
Save isaacsanders/3344267 to your computer and use it in GitHub Desktop.
This is the js file. it isn't that bad.
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
(function($) { | |
this.FileLink = function(filename){ | |
this.filename = filename; | |
}; | |
FileLink.prototype = { | |
LAST_URL_SECTION_PATTERN: /\/?([^\/]+)$/i, | |
BEFORE_QUERY_STRING_PATTERN: /^([^?]+)/i, | |
FILE_EXTENSION_PATTERN: /\.([^\.]*)$/i, | |
extension: function(){ | |
var lastUrlSection = this.filename.match(this.LAST_URL_SECTION_PATTERN)[1]; | |
var bareFilename = lastUrlSection.match(this.BEFORE_QUERY_STRING_PATTERN)[1]; | |
return bareFilename.match(this.FILE_EXTENSION_PATTERN)[1]; | |
} | |
}; | |
$.fn.addFileTypeIcon = function(){ | |
return this.each(function(){ | |
$('a', $(this)).each(function(){ | |
var fileLink = new FileLink($(this).attr('href')); | |
$(this).addClass(fileLink.extension()); | |
$(this).addClass('file-text'); | |
$(this).prepend($('<span>').addClass('file-icon')); | |
}); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment