Skip to content

Commit

Permalink
Item12116:Item12511: use html5 data
Browse files Browse the repository at this point in the history
... instead of jquery.metadata

also:
- fix loading order of select2 and its init script
- added i18n support
- some css fixes
  • Loading branch information
MichaelDaum committed Aug 29, 2014
1 parent 424f840 commit 326df1e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 23 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.gz
*.swp
pub/System/JQSelect2Contrib/jquery.select2.init.js
pub/System/JQSelect2Contrib/jquery.select2.css
pub/System/JQSelect2Contrib/jquery.select2.js
JQSelect2Contrib.md5
JQSelect2Contrib.sha1
JQSelect2Contrib.tgz
JQSelect2Contrib.txt
JQSelect2Contrib.zip
JQSelect2Contrib_installer
JQSelect2Contrib_installer.pl
6 changes: 3 additions & 3 deletions data/System/JQSelect2Contrib.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1349362185" format="1.1" reprev="1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="autosave" date="1366373896" format="1.1" version="2"}%
---+ %TOPIC%

%JQPLUGINS{"select2"
Expand Down Expand Up @@ -29,7 +29,7 @@ Add the =jqSelect2= CSS class to a select tag to make it turn into a Select2 wid
<verbatim class="tml">
%JQREQUIRE{"select2"}%

<select class='jqSelect2 {placeholder: "Select a burger", width: "element"}'>
<select class='jqSelect2' data-placeholder='Select a burger' data-width='element'>
<option>Hamburger</option>
<option>Hamburger deluxe with gold plating</option>
<option>Cheeseburger</option>
Expand All @@ -40,7 +40,7 @@ Add the =jqSelect2= CSS class to a select tag to make it turn into a Select2 wid
If Select2 is enabled, you will see the result below:

%JQREQUIRE{"select2"}%
<select class='jqSelect2 {placeholder: "Select a burger", width: "element"}'>
<select class='jqSelect2' data-placeholder='Select a burger' data-width='element'>
<option>Hamburger</option>
<option>Hamburger deluxe with gold plating</option>
<option>Cheeseburger</option>
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Contrib/JQSelect2Contrib.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package Foswiki::Contrib::JQSelect2Contrib;
use strict;
use warnings;

our $VERSION = '$Rev$';
our $VERSION = '0.1';
our $RELEASE = '0.1';
our $SHORTDESCRIPTION = 'Select2 jQuery widget for Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
Expand Down
12 changes: 6 additions & 6 deletions lib/Foswiki/Contrib/JQSelect2Contrib/MANIFEST
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
data/System/JQSelect2Contrib.txt 0644
lib/Foswiki/Contrib/JQSelect2Contrib.pm 0644
lib/Foswiki/Contrib/JQSelect2Contrib/Config.spec 0644
lib/Foswiki/Contrib/JQSelect2Contrib.pm 0644
lib/Foswiki/Contrib/JQSelect2Contrib/SELECT2.pm 0644
pub/System/JQSelect2Contrib/jquery.select2.css 0644
pub/System/JQSelect2Contrib/jquery.select2.css.gz 0644
pub/System/JQSelect2Contrib/jquery.select2.init.js 0644
pub/System/JQSelect2Contrib/jquery.select2.init.js.gz 0644
pub/System/JQSelect2Contrib/jquery.select2.init.uncompressed.js 0644
pub/System/JQSelect2Contrib/jquery.select2.js 0644
pub/System/JQSelect2Contrib/jquery.select2.js.gz 0644
pub/System/JQSelect2Contrib/jquery.select2.uncompressed.css 0644
pub/System/JQSelect2Contrib/jquery.select2.uncompressed.js 0644
pub/System/JQSelect2Contrib/jquery.select2.init.js 0644
pub/System/JQSelect2Contrib/jquery.select2.init.js.gz 0644
pub/System/JQSelect2Contrib/jquery.select2.init.uncompressed.js 0644
pub/System/JQSelect2Contrib/LICENSE
pub/System/JQSelect2Contrib/LICENSE 0644
pub/System/JQSelect2Contrib/Makefile 0644
pub/System/JQSelect2Contrib/select2.png 0644
pub/System/JQSelect2Contrib/select2x2.png 0644
pub/System/JQSelect2Contrib/spinner.gif 0644

36 changes: 34 additions & 2 deletions lib/Foswiki/Contrib/JQSelect2Contrib/SELECT2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,46 @@ sub new {
homepage => 'http://ivaynberg.github.com/select2/',
puburl => '%PUBURLPATH%/%SYSTEMWEB%/JQSelect2Contrib',
documentation => "$Foswiki::cfg{SystemWebName}.JQSelect2Contrib",
javascript => ['jquery.select2.init.js', 'jquery.select2.js'],
javascript => ['jquery.select2.js', 'jquery.select2.init.js', ],
css => ['jquery.select2.css'],
dependencies => ['livequery', 'metadata'],
dependencies => ['livequery'],
@_
), $class);

return $this;
}

=begin TML
---++ ClassMethod init( $this )
Initialize this plugin by adding the required static files to the page
=cut

sub init {
my $this = shift;

return unless $this->SUPER::init();

# open matching localization file if it exists
my $session = $Foswiki::Plugins::SESSION;
my $langTag = $session->i18n->language();
my $messagePath =
$Foswiki::cfg{SystemWebName}
. '/JQSelect2Contrib/select2_locale_'
. $langTag . '.js';
my $messageFile = $Foswiki::cfg{PubDir} . '/' . $messagePath;
if ( -f $messageFile ) {
my $text .=
"<script type='text/javascript' src='$Foswiki::cfg{PubUrlPath}/$messagePath'></script>\n";
Foswiki::Func::addToZone(
'script', "JQUERYPLUGIN::SELECT2::LANG",
$text, 'JQUERYPLUGIN::SELECT2'
);
}

}

1;

18 changes: 12 additions & 6 deletions pub/System/JQSelect2Contrib/LICENSE
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
Copyright 2012 Igor Vaynberg

Version: @@ver@@ Timestamp: @@timestamp@@

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in
compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
General Public License version 2 (the "GPL License"). You may choose either license to govern your
use of this software only upon the condition that you accept all of the terms of either the Apache
License or the GPL License.

You may obtain a copy of the Apache License and the GPL License at:

http://www.apache.org/licenses/LICENSE-2.0
http://www.gnu.org/licenses/gpl-2.0.html

Unless required by applicable law or agreed to in writing, software distributed under the License is
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the Apache License
or the GPL Licesnse is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the Apache License and the GPL License for the specific language governing
permissions and limitations under the Apache License and the GPL License.
10 changes: 10 additions & 0 deletions pub/System/JQSelect2Contrib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FOSWIKI_ROOT?=~/foswiki/core
TARGET=\
jquery.select2.js \
jquery.select2.init.js \
jquery.select2.css

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include

clean:
rm $(TARGET) *.gz
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// initializer for the select2 plugin
jQuery(function($) {
$(".jqSelect2").livequery(function() {
var $this = $(this), opts = $.extend({}, $this.metadata());
$this.removeClass("jqSelect2").select2(opts);
var defaults = {};

$(".jqSelect2:not(.jqSelect2Inited)").livequery(function() {
var $this = $(this), opts = $.extend({}, defaults, $this.data());
$this.addClass("jqSelect2Inited").select2(opts);
});
});
8 changes: 6 additions & 2 deletions pub/System/JQSelect2Contrib/jquery.select2.uncompressed.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Version: 3.2 Timestamp: Mon Sep 10 10:38:04 PDT 2012
display: block;
position: absolute;
right: 26px;
top: 8px;
top: 7px;
width: 12px;
height: 12px;
font-size: 1px;
Expand Down Expand Up @@ -221,6 +221,7 @@ Version: 3.2 Timestamp: Mon Sep 10 10:38:04 PDT 2012
}


/*
.select2-container-active .select2-choice,
.select2-container-active .select2-choices {
-webkit-box-shadow: 0 0 5px rgba(0,0,0,.3);
Expand All @@ -230,6 +231,7 @@ Version: 3.2 Timestamp: Mon Sep 10 10:38:04 PDT 2012
border: 1px solid #5897fb;
outline: none;
}
*/

.select2-dropdown-open .select2-choice {
border: 1px solid #aaa;
Expand Down Expand Up @@ -274,6 +276,7 @@ Version: 3.2 Timestamp: Mon Sep 10 10:38:04 PDT 2012

.select2-results ul.select2-result-sub {
margin: 0 0 0 0;
padding:0;
}

.select2-results ul.select2-result-sub > li .select2-result-label { padding-left: 20px }
Expand Down Expand Up @@ -384,6 +387,7 @@ disabled look for already selected choices in the results dropdown
min-height: 26px;
}

/*
.select2-container-multi.select2-container-active .select2-choices {
-webkit-box-shadow: 0 0 5px rgba(0,0,0,.3);
-moz-box-shadow : 0 0 5px rgba(0,0,0,.3);
Expand All @@ -392,6 +396,7 @@ disabled look for already selected choices in the results dropdown
border: 1px solid #5897fb;
outline: none;
}
*/
.select2-container-multi .select2-choices li {
float: left;
list-style: none;
Expand All @@ -407,7 +412,6 @@ disabled look for already selected choices in the results dropdown
background: transparent !important;
font-family: sans-serif;
font-size: 100%;
height: 15px;
padding: 5px;
margin: 1px 0;
outline: 0;
Expand Down

0 comments on commit 326df1e

Please sign in to comment.