Skip to content

Commit

Permalink
Item13193: deprecate jquery.gradient
Browse files Browse the repository at this point in the history
Item13138: finished jquery.stars, new rating formfield, docu and examples
  • Loading branch information
MichaelDaum committed Jan 9, 2015
1 parent 2240f5b commit aa89b32
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 35 deletions.
2 changes: 1 addition & 1 deletion JQueryPlugin/data/System/JQueryChili.txt
Expand Up @@ -42,7 +42,7 @@ Syntax can be highlighted using the *&lt;verbatim&gt;* tag and the <u>class</u>
<title>Hello World</title>
</head>
<body>
<font size="24px">Hello World</font>
<h1>Hello World</h1>
</body>
</html>

Expand Down
117 changes: 117 additions & 0 deletions JQueryPlugin/data/System/JQueryStars.txt
@@ -0,0 +1,117 @@
%META:TOPICINFO{author="micha" comment="reprev" date="1420807369" format="1.1" reprev="2" version="2"}%
%META:TOPICPARENT{name="JQueryPlugin"}%
---+ %TOPIC%
%JQPLUGINS{"stars"
format="
Homepage: $homepage <br />
Author(s): $author <br />
Version: $version
"
}%

%STARTSECTION{"summary"}%
Flexible and non-obstructive star rating. This plugin turns an HTML =&lt;input>= element into a star rating widget.
The design is heavily influenced by [[%SYSTEMWEB%.JQueryRating]] by Fyneworks.com bit requries considerably less HTML markup
which is of advantage with high precision ratings.

Features:

* arbitrary number of stars
* arbitrary precision of star rating by splitting each star
* mouse wheel support
* non-obstructive integration using CSS and HTML5

%ENDSECTION{"summary"}%

---++ Usage

There are two ways to make use of this plugin, either as part of a [[%SYSTEMWEB%.DataForms][DataForm definition]] (see [[#Formfield_61rating_61][Formfield =rating=]])
or writing HTML yourself.

<verbatim class="tml">
%JQREQUIRE{"stars"}%

<input class='jqStars'
value='...'
name='...'
data-num-stars='...'
data-split='...'
data-values='...'
disabled />
</verbatim>

* any =input= element with a CSS class =jqStars= will be initialized automatically
* =value= defines the initial value of the star rating
* the =disabled= property flags the =input= element as read-only
* the =data-num-stars= parameter specifies the maximum number of stars
* the =data-split= parameter specifies the precision of a sub-star rating by numbers of parts each star is split up
* the =data-values= parameter may optionally provide a json object of values to be selected

The json object in =data-values= can either be a plain array of values such as in

<verbatim class="html">
<input class="jqStars"
value="I like it"
data-values='["very low", "low", "substandard", "standard", "superior", "I like it", "quite good", "good", "very good", "excellent"]'
/>
</verbatim>

... or an array of objects of the form ={"label": "value"}=:

<verbatim class="html">
<input class="jqStars"
value="e"
data-values='[{"very low":"a"}, {"low":"b"}, {"substandard":"c"}, {"standard":"d"}, {"superior":"e"}, {"I like it":"f"}, {"quite good":"g"}, {"good":"i"}, {"very good":"j"}, {"excellent":"k"}]'
/>
</verbatim>

---++ Formfield =rating=

The jquery stars plugin is used to implement a =rating= formfield. Here are some examples:

| *Name* | *Type* | *Size* | *Values* | *Description* | *Attributes* |
| Rating1 | rating | 5 | | | |
| Rating2 | rating | 1 | very low, low, substandard, standard, superior, I like it, quite good, good, very good, excellent | | |
| Rating3 | rating | 10 | | | split:2 |
| Rating4 | rating+values | 1 | very low=1, low=2, substandard=3, standard=4, superior=5, I like it=6, quite good=7, good=8, very good=9, excellent=10 | | |

* Rating1 defines a simple numeric 5 star rating
* Rating2 defines a simple scheme using named categories.
* Rating3 defines a 10 star rating by increments of 0.5 steps
* Rating4 defines a numeric rating where each value is mapped to a named category

The =Size= column specifies the number of stars. If =Values= are defined as well, their number will overwrite the =Size= value.
Note, that the =Attributes= column will be used to parametrize the jquery.stars plugin.

---++ Examples
%JQREQUIRE{"stars"}%

---+++ default settings
<input class="jqStars" value="0" />

---+++ read only
<input class="jqStars" value="2" disabled />

<input class="jqStars" value="2.5" disabled />

<input class="jqStars" value="2.5" data-split="2" disabled />

---+++ 10 stars

<input class="jqStars" data-num-stars="10" />

---+++ 10 stars, split 10

<input class="jqStars" value="4.2" data-num-stars="10" data-split="10" />

---+++ 10 stars, split 100

<input class="jqStars" value="5.25" data-num-stars="10" data-split="100" />

---+++ named values

<input class="jqStars" value="I like it" data-values='["very low", "low", "substandard", "standard", "superior", "I like it", "quite good", "good", "very good", "excellent"]' />

---+++ mapped values

<input class="jqStars" value="e" data-values='[{"very low":"a"}, {"low":"b"}, {"substandard":"c"}, {"standard":"d"}, {"superior":"e"}, {"I like it":"f"}, {"quite good":"g"}, {"good":"i"}, {"very good":"j"}, {"excellent":"k"}]' />
@@ -0,0 +1,41 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::JQueryPlugin::Plugins::Gradient::Enabled;

use warnings;
use strict;

use Foswiki::Configure::Checker ();
our @ISA = qw( Foswiki::Configure::Checker );

sub check {
my $this = shift;
my $warnings;

if ( $Foswiki::cfg{JQueryPlugin}{Plugins}{Gradient}{Enabled} ) {
$warnings .= $this->WARN(<<'HERE');
This plugin is deprecated. Please use CSS. See http://colorzilla.com/gradient-editor/.
HERE
}

return $warnings;
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2014 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
72 changes: 45 additions & 27 deletions JQueryPlugin/lib/Foswiki/Form/Rating.pm
Expand Up @@ -7,15 +7,24 @@ use warnings;
use Foswiki::Form::ListFieldDefinition ();
use Foswiki::Plugins::JQueryPlugin ();
use Foswiki::Func ();
use JSON ();

our @ISA = ('Foswiki::Form::ListFieldDefinition');

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
$this->{size} ||= 0;
$this->{size} =~ s/\D//g;
$this->{size} ||= 0;
$this->{size} = 4 if ( $this->{size} < 1 );

my $options = $this->getOptions();
if ( $options && @$options ) {
$this->{size} = scalar(@$options);
}
else {
$this->{size} ||= 0;
$this->{size} =~ s/\D//g;
$this->{size} ||= 0;
$this->{size} = 5 if ( $this->{size} < 1 );
}

return $this;
}
Expand All @@ -24,6 +33,17 @@ sub finish {
my $this = shift;
$this->SUPER::finish();
undef $this->{valueMap};
undef $this->{json};
}

sub json {
my $this = shift;

unless ( $this->{json} ) {
$this->{json} = JSON->new->allow_nonref;
}

return $this->{json};
}

sub getOptions {
Expand All @@ -33,14 +53,6 @@ sub getOptions {
return $options if $options;
$options = $this->SUPER::getOptions();

unless (@$options) {
for ( my $i = 1 ; $i <= $this->{size} ; $i++ ) {
push @$options, $i;
}
$this->{_options} = $options;
return $options;
}

if ( $this->{type} =~ /\+values/ ) {
$this->{valueMap} = ();
$this->{_options} = ();
Expand All @@ -63,28 +75,36 @@ sub getOptions {
return $options;
}

sub renderForEdit {
my ( $this, $topicObject, $value ) = @_;

Foswiki::Plugins::JQueryPlugin::createPlugin("stars");
sub getDataValues {
my $this = shift;

my @vals = ();
my $options = $this->getOptions();
my @vals = ();

foreach my $val (@$options) {
if ( $this->{type} =~ /\+values/ && defined( $this->{valueMap}{$val} ) )
{
push @vals, '{"' . $val . '":"' . $this->{valueMap}{$val} . '"}';
push @vals, { $this->{valueMap}{$val} => $val };
}
else {
push @vals, '"' . $val . '"';
push @vals, $val;
}
}
my $dataVals = '';
$dataVals = join( ", ", @vals ) if @vals;

return '' unless @vals;
return "data-values='" . $this->json->encode( \@vals ) . "'";
}

sub renderForEdit {
my ( $this, $topicObject, $value ) = @_;

Foswiki::Plugins::JQueryPlugin::createPlugin("stars");

my $result =
"<input type='hidden' autocomplete='off' name='$this->{name}' value='$value' class='jqStars {$this->{attributes}}' "
. $dataVals . ">";
. "data-num-stars='"
. $this->{size} . "' "
. $this->getDataValues() . ">";

return ( '', $result );
}
Expand All @@ -105,13 +125,11 @@ sub renderDisplayValue {

my @htmlAttrs = ();

# if (defined $this->{valueMap}) {
# push @htmlAttrs, "data-values='[\"".join('", "', @{$this->getOptions()})."\"]";
# }

return
"<input type='hidden' disabled autocomplete='off' name='$this->{name}' value='$value' class='jqStars {$this->{attributes}}' "
. join( " ", @htmlAttrs ) . ">";
. "data-num-stars='"
. $this->{size} . "' "
. $this->getDataValues() . ">";
}

1;
Expand Down
8 changes: 4 additions & 4 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/Config.spec
Expand Up @@ -109,9 +109,6 @@ $Foswiki::cfg{JQueryPlugin}{Plugins}{Foswiki}{Enabled} = 1;
# **BOOLEAN**
$Foswiki::cfg{JQueryPlugin}{Plugins}{FluidFont}{Enabled} = 1;

# **BOOLEAN**
$Foswiki::cfg{JQueryPlugin}{Plugins}{Gradient}{Enabled} = 1;

# **BOOLEAN**
$Foswiki::cfg{JQueryPlugin}{Plugins}{HoverIntent}{Enabled} = 1;

Expand Down Expand Up @@ -245,11 +242,14 @@ $Foswiki::cfg{JQueryPlugin}{Plugins}{WikiWord}{Enabled} = 1;
# If enabled, they will be generate a Warning if deprecated, and an Error if the module has been removed from
# the Foswiki distribution.


# **BOOLEAN EXPERT**
# Warning: this plugin is deprecated. Please use the autocomplete plugin part of the jQuery-ui package.
$Foswiki::cfg{JQueryPlugin}{Plugins}{Autocomplete}{Enabled} = 0;

# **BOOLEAN**
# Warning: this plugin is deprecated. Please use CSS. See http://colorzilla.com/gradient-editor/.
$Foswiki::cfg{JQueryPlugin}{Plugins}{Gradient}{Enabled} = 0;

# **BOOLEAN EXPERT**
# Warning: This plugin is deprecated. Use Corner instead.
$Foswiki::cfg{JQueryPlugin}{Plugins}{Nifty}{Enabled} = 0;
Expand Down
1 change: 1 addition & 0 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/DEPENDENCIES
@@ -1,2 +1,3 @@
JSON,>=0,cpan,Required
ONLYIF ( $Foswiki::Plugins::VERSION < 2.1)
Foswiki::Plugins::ZonePlugin,>=3.1,perl,Required. required for Foswiki < 1.1
8 changes: 5 additions & 3 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/MANIFEST
Expand Up @@ -42,6 +42,7 @@ data/System/JQueryShake.txt 0644
data/System/JQueryShrinkUrls.txt 0644
data/System/JQuerySimpleModal.txt 0644
data/System/JQuerySlimbox.txt 0644
data/System/JQueryStars.txt 0644
data/System/JQuerySuperfish.txt 0644
data/System/JQuerySupersubs.txt 0644
data/System/JQueryTabpane.txt 0644
Expand All @@ -68,11 +69,12 @@ data/System/VarTABPANE.txt 0644
data/System/VarTAB.txt 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/JQueryVersion.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Autocomplete/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Shake/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Tooltip/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Gradient/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Nifty/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Tmpl/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Rating/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Shake/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Tmpl/Enabled.pm 0644
lib/Foswiki/Configure/Checkers/JQueryPlugin/Plugins/Tooltip/Enabled.pm 0644
lib/Foswiki/Form/Color.pm 0644
lib/Foswiki/Form/Rating.pm 0644
lib/Foswiki/Form/Textboxlist.pm 0644
Expand Down

0 comments on commit aa89b32

Please sign in to comment.