Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalopitz committed Dec 6, 2010
1 parent 4263be0 commit f5950c5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
14 changes: 14 additions & 0 deletions index.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<p> <p>
<input type="button" value="alert serialized form" id="alert-form"> <input type="button" value="alert serialized form" id="alert-form">
</p> </p>

<p>
<input type="button" value="remove form percentages" id="remove-form">
</p>
</form> </form>


<p> <p>
Expand All @@ -30,6 +34,10 @@
<input type="button" value="alert serialized span" id="alert-span"> <input type="button" value="alert serialized span" id="alert-span">
</p> </p>


<p>
<input type="button" value="remove span percentage" id="remove-span">
</p>

<p class="percent">70%</p> <p class="percent">70%</p>


<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
Expand All @@ -40,13 +48,19 @@
$('#alert-form').click(function() { $('#alert-form').click(function() {
alert($(this).parents('form').serialize()); alert($(this).parents('form').serialize());
}); });
$('#remove-form').click(function() {
$('input.percent').percentage('destroy');
});


$('span.percent').percentage({ $('span.percent').percentage({
color: 'green' color: 'green'
}); });
$('#alert-span').click(function() { $('#alert-span').click(function() {
alert($('span.percent').text()); alert($('span.percent').text());
}); });
$('#remove-span').click(function() {
$('span.percent').percentage('destroy');
});


$('p.percent').percentage({ $('p.percent').percentage({
color: 'pink', color: 'pink',
Expand Down
28 changes: 24 additions & 4 deletions percentage.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
function render(conf) { function render(conf) {
var elems = this; var elems = this;


if(conf == 'destroy') {
$(elems).each(function() {
$(this).show();

if(this.percentage) {
$(this.percentage).remove();
}
})
return;
}

var defaults = { var defaults = {
width: 200, width: 200,
height: 15, height: 15,
border: '1px solid #000000', border: '1px solid #000000',
color: '#cc0000', color: '#cc0000',
background: '#ffffff', background: '#ffffff',
clickable: true clickable: true,
classname: 'percentage',
display: 'inline-block'
}; };

if(conf == undefined) { if(conf == undefined) {
conf = defaults; conf = defaults;
} else { } else {
Expand Down Expand Up @@ -53,10 +66,12 @@
.attr('value', percent) .attr('value', percent)
.val(percent) .val(percent)
.attr('title', percent + '%') .attr('title', percent + '%')
.trigger('clickupdate')
; ;
} else { } else {
$(elem) $(elem)
.text(percent + '%') .text(percent + '%')
.trigger('clickupdate')
; ;
} }


Expand All @@ -69,7 +84,7 @@


$(bar) $(bar)
.attr('title', percent + '%') .attr('title', percent + '%')
.css('display', 'inline-block') .css('display', conf.display)
.css('border', conf.border) .css('border', conf.border)
.css('background', conf.background) .css('background', conf.background)
.css('position', 'relative') .css('position', 'relative')
Expand All @@ -82,6 +97,10 @@
$(bar).click(handleClick); $(bar).click(handleClick);
} }


if(conf.classname) {
$(bar).addClass(conf.classname);
}

$(inner) $(inner)
.css('background', conf.color) .css('background', conf.color)
.css('position', 'absolute') .css('position', 'absolute')
Expand All @@ -96,6 +115,8 @@
.hide() .hide()
.after(bar) .after(bar)
; ;

this.percentage = bar;
}); });


return elems; return elems;
Expand All @@ -105,4 +126,3 @@
render.apply(this, arguments); render.apply(this, arguments);
}; };
})(); })();

0 comments on commit f5950c5

Please sign in to comment.