Skip to content

Commit

Permalink
Item14767: implement a proper icon service
Browse files Browse the repository at this point in the history
Item14762: fixed jquery.loader not clearing timeouts properly

also:

- deprecate all old jquery versions (< 2.2.3) basically non-functional anyway
- deprecate jquery for oldIEs
- added jquery-3.3.1
- docu fixes
  • Loading branch information
MichaelDaum committed Jan 10, 2019
1 parent 1b0d92a commit 81e6285
Show file tree
Hide file tree
Showing 32 changed files with 19,651 additions and 338 deletions.
2 changes: 2 additions & 0 deletions JQueryPlugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*,v
*,pfv
*.gz
*.jslint
/JQueryPlugin.md5
/JQueryPlugin.sha1
/JQueryPlugin.tgz
Expand Down Expand Up @@ -39,6 +40,7 @@
/pub/System/JQueryPlugin/jquery-2.2.3.js
/pub/System/JQueryPlugin/jquery-2.2.4.js
/pub/System/JQueryPlugin/jquery-3.2.1.js
/pub/System/JQueryPlugin/jquery-3.3.1.js
/pub/System/JQueryPlugin/plugins/fontawesome/icon-animate.css
/pub/System/JQueryPlugin/noconflict.js
/pub/System/JQueryPlugin/plugins/animate/animate.css
Expand Down
123 changes: 123 additions & 0 deletions JQueryPlugin/data/System/IconService.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1547043276" format="1.1" version="1"}%
%META:TOPICPARENT{name="VarJQICON"}%
---+!! %TOPIC%

The IconService functions as a central definition and delivery method for all sorts of icons: image icons as well as font icons.

---++ Different kinds of icons

Image icons are those that display a small icon using an image file. Each individual icon of that kind refers to exactly one file on the disk.
Font icons are bundled into a single web font file that holds all icons available via a this specific font. Web fonts are normally used to
change typographical aspects of the web with well known fonts such as Arial, Times New Roman and the like. Each glyph in a web font represents
one character of text. Icon fonts are a specific kind of web fonts where glyphs don't represent a character but an icon.

Image icons are very colorful most of the time, whereas font icons are always monochrome. The color of an image icons cannot be changed; the
color of a font icon can be adjusted by changing their text color. Icon fonts may be manipulated in many ways, most notably they can be scaled
to any size possible without losing their rendering quality. This is the main advantage over image icons that can only be delivered in a single
scale and a predefined coloring.

The IconService is able to make both kinds of icons available to the system likewise as far as possible with regards to their different nature (see above).
All icons are addressible by their unique _identifier_. All icons fall into at least one _category_ that describe their origin and nature.

---++ Definition image icons

Image icons are defined by being available on an "icon search path". This is a list of locations (on disk), where image files are looked up for a specific identifier.
The icon search path is [[%SCRIPTURLPATH{"configure"}%][configured]] by the ={JQueryPlugin}{IconSearchPath}= and
defaults to FamFamFamSilkIcons, FamFamFamSilkCompanion1Icons, FamFamFamFlagIcons, FamFamFamMiniIcons, FamFamFamMintIcons.
The named icon will be picked found first on this path of topics where icons are attached to.

---++ Definition of font icons

Font icons are defined by the ={JQueryPlugin}{IconFonts}= setting. This is a list of icon font definitions, i.e. how they are named, and which css file
must be loaded into a web page to make them available. The default setting is:

<verbatim>
$Foswiki::cfg{JQueryPlugin}{IconFonts} = {
'fontawesome' => {
'prefix' => 'fa',
'definition' => '$Foswiki::cfg{PubDir}/$Foswiki::cfg{SystemWebName}/JQueryPlugin/plugins/fontawesome/fontawesome.json',
'plugin' => 'fontawesome',
},
'material' => {
'prefix' => 'ma',
'definition' => '$Foswiki::cfg{PubDir}/$Foswiki::cfg{SystemWebName}/WebFontsContrib/material-icons/material.json',
'css' => '$Foswiki::cfg{PubUrlPath}/$Foswiki::cfg{SystemWebName}/WebFontsContrib/material-icons/font-face.css',
},
};
</verbatim>

Note that Foswiki does only ship Fontawesome icons by default. Material icons are part of the [[Foswiki:Extensions/WebFontsContrib][WebFontsContrib]] extension that you might want to install in addition.
Its definition section in the ={JQueryPlugin}{IconFonts}= setting is ignored in case of the definition file not being present.

Each entry is of the following format:

<verbatim>
'<fontName>' => {
'prefix' => '<string>',
'definition' => '<definitionFile>',
'plugin' => '<jQueryModule>',
'css' => '<cssUrl>'
}
</verbatim>

* =fontName=: unique identifier
* =definitionFile=: file path to a file holding a font definition (more about it below)
* =plugin= or =css=: either an icon font is loaded by means of a jquery module being loaded; this module then holds any further means to load the required assets into a web page; or the =css= url that is to be added to the page.

A =definitionFile= itself defines the individual icons themselves, i.e. it mapps icon identifier to the actual glyph in the icon font. The =definitionFille= lists all identifiers that might be used in a [[VarJQICON]] macro:

<verbatim>
%JQICON{"<prefix>-<identifier>"}%
</verbatim>

The =&lt;prefix>= part specifies which of the available icon fonts the =&lt;identifier>= relates to. For instance =fa-pagelines= load the =fontawesome= jQuery module and then generate the according markup to display the icon.

---++ Definition file for an icon font

A =definitionFile= refered to in an =fontName= entry of the ={JQueryPlugin}{IconFonts}= setting lists all available icon identifiers. It may also list aliases and categories that icons belong to grouping them into meaningful partitions.
JQueryFontAwesome comes with a certan set of categories such as:

* Accessibility Icons
* Brand Icons
* Chart Icons
* Currency Icons
* Directional Icons
* File Type Icons
* Form Control Icons
* Gender Icons
* Hand Icons
* Medical Icons
* Payment Icons
* Spinner Icons
* Text Editor Icons
* Transportation Icons
* Video Player Icons
* Web Application Icons

A definition file has got the format:

<verbatim class="js">
{
"icons": [
{
"id": "<string>",
"name": "<string>",
"unicode": "<codepoint>",
"categories": [
"<string>",
"<string>",
...
],
},
]
}
</verbatim>

* =id= (mandatory) defines the icon id unique among all icons of this font
* =name=: icon name in human readable form, defaults to =id= if not present
* =unicode=: codepoint as defined in the web font
* =categories= list of categories that the icon belongs to

Each icon in an icon font automatically is in the =fonticon= category as well as in the =fontName= category (e.g. =fonticon, fontawesome, Payment Icons=).

Each icon of an image icon automatically is added to the category naming the topic it is attached to, e.g. =FamFamFamSilkIcons=.
2 changes: 1 addition & 1 deletion JQueryPlugin/data/System/JQueryAnimate.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1528974892" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1547112854" format="1.1" version="1"}%
%META:TOPICPARENT{name="JQueryPlugin"}%
---+ %TOPIC%

Expand Down
2 changes: 1 addition & 1 deletion JQueryPlugin/data/System/JQueryLoader.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1529685209" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1547112854" format="1.1" version="1"}%
%META:TOPICPARENT{name="JQueryPlugin"}%
---+!! %TOPIC%
%JQPLUGINS{"loader"
Expand Down
4 changes: 3 additions & 1 deletion JQueryPlugin/data/System/JQueryPlugin.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1531233264" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1547112854" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -125,6 +125,8 @@ required for Foswiki 1.1 or later.

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 10 Jan 2019: | (9.00) - Item14767: implement a proper icon service |
| 01 Oct 2018: | (8.11) - Item14762: fixed jquery.loader not clearing timeouts properly |
| 20 Jun 2018: | (8.10) - Item14564: added jquery-3 and the matching migrate module <br />\
Item14567: added keyboard navigation to jquery.stars <br />\
Item14568: added chili recipes for autolisp and ini <br />\
Expand Down
92 changes: 51 additions & 41 deletions JQueryPlugin/data/System/VarJQICON.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1456220586" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1547112854" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
---+ JQICON -- render an image
Renders an icon image as found on an _icon search path_. The icon search path is [[%SCRIPTURLPATH{"configure"}%][configured]] Extensions tab, JQueryPlugin sub-tab in ={JQueryPlugin}{IconSearchPath}= and
defaults to FamFamFamSilkIcons, FamFamFamSilkCompanion1Icons, FamFamFamFlagIcons, FamFamFamMiniIcons, FamFamFamMintIcons'. The named icon will be picked
found first on this path of topics where icons are attached to.
When the name of the icon starts with =fa-= like in =fa-bold= then icons are taken from the [[http://fontawesome.io/icons/][font-awesome]] iconset.
Note that these icons use a different way to be inserted them into the page making resizable for one.
Renders an icon made availabe by the IconService.

---++ Parameters
%TABLE{sort="off"}%
| *Parameter* | *Description* | *Default* |
| ="name"= | name of the icon to display | |
| =class= | additional css class for the img tag | |
| =animate= | can be one of bounce, burst, flash, float, horizontal, passing, pulse, ring, shake, spin, tada, vertical, wrench |
| =alt= | | alt attribute |
| =title= | title attribute | |
| =style= | css style format to be added to the image element |
| =format= | format string used to render the icon; known variables to be used in the format string are: \
<ul>\
<li> =$iconName=: name as given to the =name= parameter</li> \
<li> =$iconPath=: url path</li> \
<li> =$iconClass=: css class as specified by the =class= parameter </li>\
<li> =$iconStyle=: css styles as specified by the =style= parameter </li>\
<li> =$iconAlt=: alt attribute-value; if the =alt= parameter to JQICON is set, this expands to =alt='...'= </li> \
<li> =$iconTitle=: title attribute-value; if the =title= parameter to JQICON is set, this expands to =title='...'= </li> \
</ul> | =&lt;img src='$iconPath' class='$iconClass' $iconAlt$iconTitle/>= |
Example for famfamfam icons:<verbatim class="tml">
%TABLE{sort="off"}%
| *Parameter* | *Description* | *Default* |
| ="name"= | name of the icon to display | |
| =class= | additional css class for the img tag | |
| =animate= | can be one of bounce, burst, flash, float, horizontal, passing, pulse, ring, shake, spin, tada, vertical, wrench |
| =alt= | | alt attribute |
| =title= | title attribute | |
| =style= | css style format to be added to the image element |
| =format= | format string used to render the icon; known variables to be used in the format string are: \
<ul>\
<li> =$iconName=: name as given to the =name= parameter</li> \
<li> =$iconPath=: url path</li> \
<li> =$iconClass=: css class as specified by the =class= parameter </li>\
<li> =$iconStyle=: css styles as specified by the =style= parameter </li>\
<li> =$iconAlt=: alt attribute-value; if the =alt= parameter to JQICON is set, this expands to =alt='...'= </li> \
<li> =$iconTitle=: title attribute-value; if the =title= parameter to JQICON is set, this expands to =title='...'= </li> \
</ul> | for image icons: =&lt;img src='$iconPath' class='$iconClass $iconName' $iconStyle $iconAlt$iconTitle/>=; for font icons: =&lti class='$iconClass' $iconStyle $iconTitle>&lt;/i>= |

Example for famfamfam icons:

<verbatim class="tml">
%JQICON{"tick" alt="alternative content" title="this is a tick icon"}%
%JQICON{"cross"}%
%JQICON{"disk"}%
Expand All @@ -33,28 +33,38 @@ Example for famfamfam icons:<verbatim class="tml">
%JQICON{"camera"}%
%JQICON{"date"}%
%JQICON{"heart" animate="bounce"}%
</verbatim> Produces:
%JQICON{"tick" alt="alternative content" title="this is a tick icon"}%
%JQICON{"cross"}%
%JQICON{"disk"}%
%JQICON{"star"}%
%JQICON{"lightbulb"}%
%JQICON{"camera"}%
%JQICON{"date"}%
%JQICON{"heart" animate="bounce"}%
Example for font-awesome icons:<verbatim class="tml">
</verbatim>

Produces:

%JQICON{"tick" alt="alternative content" title="this is a tick icon"}%
%JQICON{"cross"}%
%JQICON{"disk"}%
%JQICON{"star"}%
%JQICON{"lightbulb"}%
%JQICON{"camera"}%
%JQICON{"date"}%
%JQICON{"heart" animate="bounce"}%

Example for font-awesome icons:

<verbatim class="tml">
%JQICON{"fa-pagelines" style="font-size:1em;color:#00BF00"}%
%JQICON{"fa-pagelines" style="font-size:2em;color:#0FAF0F"}%
%JQICON{"fa-pagelines" style="font-size:3em;color:#1F9C1F"}%
%JQICON{"fa-pagelines" style="font-size:4em;color:#2D812D"}%
%JQICON{"fa-pagelines" style="font-size:5em;color:#315C31"}%
</verbatim> Produces:
%JQICON{"fa-pagelines" style="font-size:1em;color:#00BF00"}%
%JQICON{"fa-pagelines" style="font-size:2em;color:#0FAF0F"}%
%JQICON{"fa-pagelines" style="font-size:3em;color:#1F9C1F"}%
%JQICON{"fa-pagelines" style="font-size:4em;color:#2D812D"}%
%JQICON{"fa-pagelines" style="font-size:5em;color:#315C31"}%
</verbatim>

Produces:

%JQICON{"fa-pagelines" style="font-size:1em;color:#00BF00"}%
%JQICON{"fa-pagelines" style="font-size:2em;color:#0FAF0F"}%
%JQICON{"fa-pagelines" style="font-size:3em;color:#1F9C1F"}%
%JQICON{"fa-pagelines" style="font-size:4em;color:#2D812D"}%
%JQICON{"fa-pagelines" style="font-size:5em;color:#315C31"}%
%STOPINCLUDE%

---++ Related
[[VarJQICONPATH][JQICONPATH]], [[VarICON][ICON]], JQueryPlugin, FamFamFamSilkIcons
[[VarJQICONPATH][JQICONPATH]], [[VarICON][ICON]], JQueryPlugin, FamFamFamSilkIcons, IconService
<!--%JQREQUIRE{"chili"}%-->
20 changes: 14 additions & 6 deletions JQueryPlugin/data/System/VarJQICONPATH.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
%META:TOPICINFO{author="ProjectContributor" date="1456220586" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1547112854" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
---+ JQICONPATH -- render the urlpath to an image
This is a shortcut for
<verbatim class="tml">%JQICON{"name" format="$iconPath"}%</verbatim>
---+ JQICONPATH -- render the url path to an image icon
This is a shortcut for:

<verbatim class="tml">%JQICON{"name" format="$iconPath"}%</verbatim>

<div class="foswikiHelp">
Note that this macro only makes sense for __image icons__, those that refer to a single image file. It does _not_ work for __font icons__ such as those defined in [[JQueryFontAwesome]].
This web font holds all icons in one large font file and as such cannot be refered to individually by means of their url path the same way as images can.
</div>

---++ Examples
* =%<nop>JQICONPATH{"tick"}%= expands to =%JQICONPATH{"tick"}%=
=%<nop>JQICONPATH{"tick"}%= expands to =%JQICONPATH{"tick"}%=
%STOPINCLUDE%

---++ Related
[[VarJQICON][JQICON]], [[VarICONURL][ICONURL]], JQueryPlugin
[[VarJQICON][JQICON]], [[VarICONURL][ICONURL]], JQueryPlugin, IconService
<!--%JQREQUIRE{"chili"}%-->
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,38 @@ use File::Spec();
our @ISA = qw( Foswiki::Configure::Checker );

sub check {
my $this = shift;
my $e = '';
my $jqversion = $Foswiki::cfg{JQueryPlugin}{JQueryVersion};

if ( !$jqversion ) {
return $this->ERROR(<<'MESSAGE');
There is no configured jQuery version
MESSAGE
my $this = shift;
my $e = '';
my $jQueryVersion = $Foswiki::cfg{JQueryPlugin}{JQueryVersion};

if ( !$jQueryVersion ) {
return $this->ERROR("There is no configured jQuery version. ");
}

if ( $jqversion =~ /^jquery-(\d+)\.(\d+)/ && defined $1
and ( $1 * 1000 + $2 ) <= 1003 )
{
$e .= $this->WARN(<<'MESSAGE');
jQuery 1.3.x and earlier are not compatible with Foswiki default plugins
MESSAGE
if ( $jQueryVersion =~ /^jquery-(\d+)\.(\d+)\.(\d+)/ && defined $1 ) {
my $version = $1 * 10000 + $2 * 100 + $3;

if ( $version <= 20203 ) {
$e .= $this->WARN("jQuery 2.2.3 and earlier are deprecated. ");
}

if ( $version >= 30000 ) {
$e .= $this->WARN(
"jQuery 3 and later are not yet compatible with Foswiki. You might experience incompatibilities with other jQuery plugins. "
);
}
}

if (
not -f File::Spec->catfile(
File::Spec->splitdir( $Foswiki::cfg{PubDir} ),
$Foswiki::cfg{SystemWebName},
'JQueryPlugin',
$jqversion . '.js'
$jQueryVersion . '.js'
)
)
{
$e .= $this->ERROR(<<'MESSAGE');
The configured jQuery version does not exist
MESSAGE
}

# SMELL: Not sure if this is how to get a default value, but it works.
my $jqdefault = $this->{item}{default};
$jqdefault =~ s/'//g;
if ( $jqversion ne $jqdefault ) {
$e .= $this->WARN(
'The selected JQuery version is not the recommended version.');
$e .= $this->ERROR("The configured jQuery version does not exist. ");
}

return $e;
Expand Down
Loading

0 comments on commit 81e6285

Please sign in to comment.