Item12933: Make filtered characters configurable in JQueryWikiWord
Priority: Enhancement
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Extension
Component: JQueryPlugin
Branches: trunk
Sometimes it would be helpful if one could allow additional characters for jqWikiWord, for example a "-" with
TopicTranslationPlugin.
Proposed patch:
Index: JQueryPlugin/data/System/JQueryWikiWord.txt
===================================================================
--- JQueryPlugin/data/System/JQueryWikiWord.txt (revision 17744)
+++ JQueryPlugin/data/System/JQueryWikiWord.txt (working copy)
@@ -25,7 +25,8 @@
source:'selector', /* e.g. '#projectTitle' */
initial:'initial value', /* e.g. 'Project...' */
prefix:'string to be prefixed to the wiki word', /* e.g. 'Project' */
- suffix:'string to be appended to the wiki word' /* e.g. 'AUTOINC0' */
+ suffix:'string to be appended to the wiki word', /* e.g. 'AUTOINC0' */
+ forbidden:'RegEx for characters to be removed' /* e.g. '[^a-zA-Z\\d]' */
}
</verbatim>
Index: JQueryPlugin/pub/System/JQueryPlugin/plugins/wikiword/jquery.wikiword.uncompressed.js
===================================================================
--- JQueryPlugin/pub/System/JQueryPlugin/plugins/wikiword/jquery.wikiword.uncompressed.js (revision 17744)
+++ JQueryPlugin/pub/System/JQueryPlugin/plugins/wikiword/jquery.wikiword.uncompressed.js (working copy)
@@ -92,6 +92,10 @@
var $this = $(this),
thisOpts = $.meta ? $.extend({}, opts, $this.data()) : opts;
+ // generate RegExp for filtered chars
+ var forbidden = thisOpts.forbidden || "[^a-zA-Z\\d]";
+ thisOpts.forbiddenChars = new RegExp(forbidden, "g");
+
$source.change(function() {
$.wikiword.handleChange($source, $this, thisOpts);
}).keyup(function() {
@@ -110,7 +114,7 @@
});
if (result || !thisOpts.initial) {
- result = $.wikiword.wikify(result);
+ result = $.wikiword.wikify(result, thisOpts);
if (thisOpts.suffix && result.indexOf(thisOpts.suffix, result.length - thisOpts.suffix.length) == -1) {
result += thisOpts.suffix;
@@ -134,7 +138,7 @@
/***************************************************************************
* convert a source string to a valid WikiWord
*/
- wikify: function (source) {
+ wikify: function (source, thisOpts) {
var result = '', c, i;
@@ -150,7 +154,7 @@
});
// remove all non-mixedalphanums
- result = result.replace(/[^a-zA-Z\d]/g, "");
+ result = result.replace(thisOpts.forbiddenChars, "");
// remove all spaces
result = result.replace(/\s/g, "");
--
StephanOsthold - 05 Jun 2014
This is a very useful feature.
However I reverted the logic a bit: instead of specifying the forbidden characters it requires to list those that are acceptable in a wiki word. So instead of writing
forbidden: '[^a-zA-Z\\d]'
you'd now write
allow:'a-zA-Z\\d'
This change is required as the same character class is used to (a) gather good substrings that are then capitalized each before concatenating them and (b) filter out all bad substrings from the result. Your patch only did the latter, so capitalization won't happen on the correct boundaries.
Btw in how far is this feature related to
TopicTranslationsPlugin?
--
MichaelDaum - 06 Jun 2014
Cool, thanks.
Regarding
TopicTranslationsPlugin: You need a suffix for different languages and you probably want it to contain a disallowed char, like this: "MyTopic-EN". An issue comes up when you use wikiword plugin for the rename dialog.
--
StephanOsthold - 06 Jun 2014