http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73798
Revision: 73798
Author: yaron
Date: 2010-09-27 01:02:29 +0000 (Mon, 27 Sep 2010)
Log Message:
-----------
Added handling for new $sfgAutocompleteOnAllChars global variable - especially
important for non-ASCII (Unicode) characters, because the Javascript code that
matches only on the beginnings of words fails for them
Modified Paths:
--------------
trunk/extensions/SemanticForms/includes/SF_FormUtils.php
trunk/extensions/SemanticForms/includes/SF_Settings.php
trunk/extensions/SemanticForms/libs/SemanticForms.js
Modified: trunk/extensions/SemanticForms/includes/SF_FormUtils.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_FormUtils.php 2010-09-27
01:00:50 UTC (rev 73797)
+++ trunk/extensions/SemanticForms/includes/SF_FormUtils.php 2010-09-27
01:02:29 UTC (rev 73798)
@@ -329,12 +329,24 @@
static function autocompletionJavascript() {
global $wgScriptPath, $wgOut, $smwgScriptPath,
$smwgJQueryIncluded;
+ global $sfgAutocompleteOnAllChars;
+
if ( !$smwgJQueryIncluded ) {
$wgOut->addScriptFile(
"$smwgScriptPath/libs/jquery-1.4.2.min.js" );
$smwgJQueryIncluded = true;
}
+ // set a Javascript variable so that the matcher knows
+ // whether to match on characters anywhere within each string,
+ // or just (as is the default) the beginning of each word
+ if ( $sfgAutocompleteOnAllChars ) {
+ $autocompleteOnAllCharsStr = 'true';
+ } else {
+ $autocompleteOnAllCharsStr = 'false';
+ }
+
$javascript_text = <<<END
+var autocompleteOnAllChars = $autocompleteOnAllCharsStr;
var autocompletemappings = new Array();
var autocompletestrings = new Array();
var autocompletedatatypes = new Array();
Modified: trunk/extensions/SemanticForms/includes/SF_Settings.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_Settings.php 2010-09-27
01:00:50 UTC (rev 73797)
+++ trunk/extensions/SemanticForms/includes/SF_Settings.php 2010-09-27
01:02:29 UTC (rev 73798)
@@ -40,6 +40,14 @@
$sfgMaxAutocompleteValues = 1000;
# ##
+# Whether to autocomplete on all characters in a string, not just the
+# beginning of words - this is especially important for Unicode strings,
+# since the use of the '\b' regexp character to match on the beginnings
+# of words fails for them.
+# ##
+$sfgAutocompleteOnAllChars = false;
+
+# ##
# Global variables for handling the two edit tabs (for traditional editing
# and for editing with a form):
# $sfgRenameEditTabs renames the edit-with-form tab to just "Edit", and
Modified: trunk/extensions/SemanticForms/libs/SemanticForms.js
===================================================================
--- trunk/extensions/SemanticForms/libs/SemanticForms.js 2010-09-27
01:00:50 UTC (rev 73797)
+++ trunk/extensions/SemanticForms/libs/SemanticForms.js 2010-09-27
01:02:29 UTC (rev 73798)
@@ -38,7 +38,11 @@
/* extending jquery functions */
jQuery.extend( jQuery.ui.autocomplete, {
filter: function(array, term) {
- var matcher = new RegExp("\\b"+
jQuery.ui.autocomplete.escapeRegex(term), "i" );
+ if ( autocompleteOnAllChars ) {
+ var matcher = new
RegExp(jQuery.ui.autocomplete.escapeRegex(term), "i" );
+ } else {
+ var matcher = new RegExp("\\b" +
jQuery.ui.autocomplete.escapeRegex(term), "i" );
+ }
return jQuery.grep( array, function(value) {
return matcher.test( value.label || value.value ||
value );
});
@@ -239,7 +243,11 @@
.insertAfter(select)
.autocomplete({
source: function(request, response) {
- var matcher = new
RegExp("\\b"+request.term, "i");
+ if ( autocompleteOnAllChars ) {
+ var matcher = new
RegExp(request.term, "i");
+ } else {
+ var matcher = new
RegExp("\\b" + request.term, "i");
+ }
response(select.children("option").map(function() {
var text =
jQuery(this).text();
if (this.value &&
(!request.term || matcher.test(text))) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs