Created
August 23, 2012 21:25
-
-
Save michaeljacobdavis/3442037 to your computer and use it in GitHub Desktop.
FileNameFormat
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 ($) { | |
$.fn.formatfilename = function (options) { | |
var settings = $.extend({ | |
'length': '40' | |
}, options); | |
return this.each(function () { | |
var $this = $(this); | |
var text = $.trim($this.text()); | |
if (text.length >= settings.length) { | |
var ext = (function () { | |
var loc = text.lastIndexOf("."); | |
if (loc) { | |
var ext = text.substring(loc, text.length); | |
text = text.substring(0, loc); | |
return ext; | |
} | |
else { | |
return ""; | |
} | |
})(); | |
text = text.substring(0, settings.length-ext.length) + ext; | |
} | |
$this.text(text); | |
}); | |
}; | |
})(jQuery); | |
$("body").append($("<span>blah.txt</span>").formatfilename({length:6})); // bl.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment