com web/php: The poor comment opacity level is now determined using a well-known, generic data normalization function. It's quite flexible and is
hopefully easier to adjust for the future.: js/common.js
| From: | Levi Morrison | Date: | Thu, 05 Dec 2013 01:31:37 +0000 |
| Subject: | com web/php: The poor comment opacity level is now determined using a well-known, generic data normalization function. It's quite flexible and is hopefully easier to adjust for the future.: js/common.js |
||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-17378@lists.php.net to get a copy of this message | ||
Commit: f23622c261f5644a16feef92ac3c95a8a46cb1c1
Author: Levi Morrison <levim@php.net> Wed, 4 Dec 2013 18:31:37 -0700
Parents: e691cc3281bdff8d79c4f49a2569dca91e176167
Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=f23622c261f5644a16feef92ac3c95a8a46cb1c1
Log:
The poor comment opacity level is now determined using a well-known, generic data normalization
function. It's quite flexible and is hopefully easier to adjust for the future.
Changed paths:
M js/common.js
Diff:
diff --git a/js/common.js b/js/common.js
index a82518b..4039438 100755
--- a/js/common.js
+++ b/js/common.js
@@ -263,23 +263,32 @@ $(document).ready(function() {
});
/* {{{ Negative user notes fade-out */
- if (!!document.getElementById('usernotes'))
- {
- // Default: -5+ votes will have opacity: 0.1
- // Scale: 0-10
- var settings = {minFade: 5, maxFade: 9};
- $('.note .tally:contains("-")').each(function()
- {
+ var usernotes = document.getElementById('usernotes');
+ if (usernotes != null) {
+ var mapper = new function() {
+ this.domain = {
+ "max": -1,
+ "min": -5
+ };
+ this.range = {
+ "max": .75,
+ "min": .25
+ };
+
+ // This is a generic normalizaion algorithm:
+ // range.min + (value - domain.min)(range.max - range.min)/(domain.max-domain.min)
+ // Note that some of this computation is not dependent on the input value, so we
+ // compute it at object creation time.
+ var multiplier = (this.range.max - this.range.min)/(this.domain.max - this.domain.min);
+ this.normalize = function(value) {
+ value = Math.max(value, this.domain.min);
+ return (value - this.domain.min) * multiplier + this.range.min;
+ };
+ };
+ $(usernotes).find('.note .tally:contains("-")').each(function() {
var id = this.id.replace('V', '');
-
- // get negative votes value and make it positive
- var v = this.innerHTML.toInt() * -1;
- // determine fade level based on votes (step=1)
- var f = (settings.minFade - 1) + v;
- // set back to maxFade if level is above max
- f = f > settings.maxFade ? settings.maxFade : f;
-
- $('#' + id).css('opacity', '0.' + (10 - f));
+ var v = mapper.normalize(this.innerHTML.toInt());
+ $('#' + id).css('opacity', v);
});
}
/* }}} */