(function($) {
$.fn.asciiProgress = function() {
return this.each(function() {
var self = $(this);
var raw = self.text();
// trim the [ and ]
raw = raw.substr(1);
raw = raw.substr(0, raw.length-1);
// here is our progress bar length
var length = raw.length;
// percent position of the handle
var value = (raw.indexOf("[]") + 1) / length;
// wrap with something for later manipulation
var txt = self.wrapInner("<i/>").find("i");
// add an invisible handle that can be dragged around
var handleContainer = $("<span/>", {
html: "",
css: {
left: value*100 + "%"
}
});
var handle = $("<em/>", {})
.appendTo(handleContainer);
handle
.mousedown(startDrag)
.mouseup(endDrag);
handleContainer.appendTo(this);
self.data("ascii", {
length: length,
value: value,
handle: handleContainer,
txt: txt
});
});
};
function startDrag(ev) {
var handlecontainer = $(this).parent();
var ascii = $(this).closest(".asciiprogress");
var data = ascii.data("ascii");
data.start = ev.pageX;
$("body").bind("mousemove.ascii", function(ev) {
var pos = ev.pageX - ascii.position().left;
handlecontainer.css("left", pos + "px");
var percent = Math.min(1, (pos / ascii.width()));
percent = Math.max(0, percent);
setValue(ascii, data, percent);
}).one("mouseup", endDrag);
}
function setValue(ascii, data, percent) {
var leftSide = Math.round(data.length * percent);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.