Skip to content

Commit

Permalink
Item15174: fixed jquery.stars in +values mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Jan 17, 2023
1 parent 88e16ef commit 62caca1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 53 deletions.
6 changes: 3 additions & 3 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/STARS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ sub new {
my $this = bless(
$class->SUPER::new(
name => 'Stars',
version => '2.20',
version => '3.01',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Extensions/JQueryPlugin',
css => [ 'jquery.stars.css', ],
javascript => [ 'jquery.stars.js', ],
dependencies => [ 'metadata', 'sprintf', 'mousewheel' ],
dependencies => [ 'sprintf', 'mousewheel' ],
),
$class
);
Expand All @@ -45,7 +45,7 @@ sub new {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2014-2020 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2014-2023 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* jQuery Stars plugin 3.00
* jQuery Stars plugin 3.01
*
* Copyright (c) 2014-2020 Foswiki Contributors http://foswiki.org
* Copyright (c) 2014-2022 Foswiki Contributors http://foswiki.org
*
* Licensed under the GPL licenses http://www.gnu.org/licenses/gpl.html
*
Expand Down Expand Up @@ -40,7 +40,7 @@
}
Stars.prototype._toFixed = function(num) {
num = Number(num);
return Number(num.toFixed(this.prec));
return Number(num.toFixed(this._prec));
};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -77,15 +77,16 @@
self.opts.split = 1;
}

self.prec = 0;

self._prec = 0;
if (self.opts.split > 1) {
self.prec++;
self._prec++;
}
if (self.opts.split > 10) {
self.prec++;
self._prec++;
}
if (self.opts.split > 100) {
self.prec++;
self._prec++;
}

self.blockMouseMove = false;
Expand Down Expand Up @@ -145,7 +146,7 @@
function() { self.display(self.elem.val()); }
);
self.deleteElem.on("click", function() {
self.select();
self.selectAtIndex(0);
return false;
});

Expand Down Expand Up @@ -218,37 +219,21 @@
});
}

self.select(self.elem.val());
};

////////////////////////////////////////////////////////////////////////////////
Stars.prototype.getStoreValue = function(index) {
var self = this, val;

index = index || 0;

val = typeof(self.mapping[index]) === 'undefined' ? self.getDisplayVal(index) : index;

//console.log("called getStoreValue(",index,") = ",val);

return val;
self.display(self.elem.val());
};

////////////////////////////////////////////////////////////////////////////////
Stars.prototype.getDisplayVal = function(index) {
var self = this, val;

//console.log("called getDisplayVal(",index,")");
//console.log("called getDisplayVal",index);
if (self.opts.values) {
val = self.opts.values[index];
//console.log("... val=",val);
if (typeof(self.mapping[val]) !== 'undefined') {
val = self.mapping[val];
//console.log("... mapping to",val);
}
} else {
val = sprintf("%." + self.prec + "f", index);
//console.log("... numerical value is",val);
val = sprintf("%." + self._prec + "f", index);
}

return val;
Expand All @@ -258,16 +243,14 @@
Stars.prototype.displayAtIndex = function(index) {
var self = this, width, label;

if (typeof(index) === 'undefined') {
index = 0;
}

//console.log("called displayAtIndex",index);
index = Math.ceil(index * self.opts.split) / self.opts.split;
index = self._toFixed(index);

width = self.widthStar * index;
label = self.getDisplayVal(index);

//console.log("... width=",width,"label=",label);
if (index === self._tmpIndex) {
return;
}
Expand All @@ -285,27 +268,27 @@
var self = this,
index;

//console.log("called display val=",val);
if (typeof(val) === 'undefined' || val === '') {
index = 0;
} else if (typeof(self.opts.values) !== 'undefined') {
index = self.opts.values.indexOf(val);
} else {
index = val;
}
//console.log("... index=",index);

self.displayAtIndex(index);
return index;
};

////////////////////////////////////////////////////////////////////////////////
Stars.prototype.selectAtIndex = function(index) {
var self = this, val;

//console.log("called selectAtIndex(",index,")");
//console.log("called selectAtIndex",index);
self._tmpIndex = undefined;

if (typeof(index) === 'undefined') {
index = 0;
}
index = index || 0;

if (typeof(self.opts.values) !== 'undefined') {
val = self.opts.values[index];
Expand All @@ -314,27 +297,16 @@
}

self.displayAtIndex(index);
val = self.getStoreValue(index);
//console.log("... val=",val);
self.elem.val(val);
};

////////////////////////////////////////////////////////////////////////////////
Stars.prototype.select = function(val) {
var self = this;

self._tmpIndex = undefined;

self.display(val);
self.elem.val(self.getStoreValue(val));
self.elem.val(val);
};

////////////////////////////////////////////////////////////////////////////////
// plugin wrapper around the constructor
$.fn.stars = function(opts) {
return this.each(function() {
if (!$.data(this, 'stars')) {
$.data(this, 'stars', new Stars(this, opts));
if (!$.data(this, '_stars')) {
$.data(this, '_stars', new Stars(this, opts));
}
});
};
Expand Down

0 comments on commit 62caca1

Please sign in to comment.