Skip to content

Commit

Permalink
Item13286: rationalized params in jquery.wikiword
Browse files Browse the repository at this point in the history
- properly encode regexps as regexps when exporting them to javascript
  • Loading branch information
MichaelDaum committed Mar 2, 2015
1 parent 6b7c42d commit a1cf11d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin.pm
Expand Up @@ -24,8 +24,8 @@ BEGIN {
}
}

our $VERSION = '6.10';
our $RELEASE = '23 Feb 2015';
our $VERSION = '6.11';
our $RELEASE = '02 Mar 2015';
our $SHORTDESCRIPTION = 'jQuery <nop>JavaScript library for Foswiki';
our $NO_PREFS_IN_TOPIC = 1;

Expand Down
12 changes: 10 additions & 2 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
Expand Up @@ -29,7 +29,7 @@ sub new {
my $this = bless(
$class->SUPER::new(
name => 'Foswiki',
version => '2.01',
version => '2.02',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Extensions/JQueryPlugin',
javascript => ['jquery.foswiki.js'],
Expand Down Expand Up @@ -68,6 +68,7 @@ sub init {
$prefs .= ', TWISTYANIMATIONSPEED'
if $Foswiki::cfg{Plugins}{TwistyPlugin}
{Enabled}; # can't use context during init

}

# init NAMEFILTER
Expand All @@ -79,8 +80,15 @@ sub init {
# add exported preferences to head
my @prefs = ();
foreach my $pref ( split( /\s*,\s*/, $prefs ) ) {
my $quote = ( $pref =~ /^NAMEFILTER$/ ) ? '/' : '"';
push @prefs,
' "' . $pref . '": "%ENCODE{"%' . $pref . '%" type="quote"}%"';
' "'
. $pref . '": '
. $quote
. '%ENCODE{"%'
. $pref
. '%" type="quote"}%'
. $quote . '';
}
my $text =
"<script type='text/javascript'>\njQuery.extend(foswiki, {\n \"preferences\": {\n"
Expand Down
@@ -1,5 +1,5 @@
/*
* jQuery WikiWord plugin 3.00
* jQuery WikiWord plugin 3.01
*
* Copyright (c) 2008-2015 Foswiki Contributors http://foswiki.org
*
Expand Down Expand Up @@ -80,21 +80,23 @@ $.wikiword = {
/***********************************************************************
* constructor
*/
build: function(source, options) {
build: function(options) {

// build main options before element iteration
var opts = $.extend({}, $.wikiword.defaults, options),
$source = $(source);
var opts = $.extend({}, $.wikiword.defaults, options);

// iterate and reformat each matched element
return this.each(function() {
var $this = $(this),
thisOpts = $.meta ? $.extend({}, opts, $this.data()) : opts;
thisOpts = $.extend({}, opts, $this.data(), $this.metadata()),
$source = $(thisOpts.source);

// generate RegExp for filtered chars
if (typeof(thisOpts.allow) !== 'undefined') {
thisOpts.allowedRegex = new RegExp('['+thisOpts.allow+']+', "g");
thisOpts.forbiddenRegex = new RegExp('[^'+thisOpts.allow+']+', "g");
if (typeof(thisOpts.allowedRegex) === 'string') {
thisOpts.allowedRegex = new RegExp(thisOpts.allowedRegex, "g");
}
if (typeof(thisOpts.forbiddenRegex) === 'string') {
thisOpts.forbiddenRegex = new RegExp(thisOpts.forbiddenRegex, "g");
}

$source.change(function() {
Expand Down Expand Up @@ -159,9 +161,6 @@ $.wikiword = {
// remove all forbidden chars
result = result.replace(opts.forbiddenRegex, "");

// remove all spaces
result = result.replace(/\s/g, "");

return result;
},

Expand All @@ -172,8 +171,8 @@ $.wikiword = {
suffix: '',
prefix: '',
initial: '',
allowedRegex: new RegExp('[a-zA-Z\\d]+', "g"),
forbiddenRegex: new RegExp('[^a-zA-Z\\d]+', "g")
allowedRegex: '[a-zA-Z\\d]+',
forbiddenRegex: '[^a-zA-Z\\d]+'
}
};

Expand All @@ -183,10 +182,7 @@ $.fn.wikiword = $.wikiword.build;
/* init */
$(function() {
$(".jqWikiWord:not(.jqInitedWikiWord)").livequery(function() {
var $this = $(this), options;
$this.addClass("jqInitedWikiWord");
options = $.extend({}, $this.metadata());
$this.wikiword(options.source, options);
$(this).addClass("jqInitedWikiWord").wikiword();
});
});

Expand Down

0 comments on commit a1cf11d

Please sign in to comment.