r102903 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102902‎ | r102903 | r102904 >
Date:18:06, 13 November 2011
Author:yaron
Status:deferred
Tags:
Comment:
Changed 'combo box' input to use jQuery and jQuery UI files from ResourceLoader, for MediaWiki versions 1.17 and higher; modified highlighting of search term to work with more recent versions of jQuery UI
Modified paths:
  • /trunk/extensions/SemanticDrilldown/SemanticDrilldown.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/libs/SemanticDrilldown.js (modified) (history)
  • /trunk/extensions/SemanticDrilldown/skins/SD_jquery_ui_overrides.css (added) (history)
  • /trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php
@@ -590,17 +590,20 @@
591591 return $results_line;
592592 }
593593
594 - function printComboBoxInput( $filter_name, $filter_values, $cur_value = null ) {
595 - global $wgRequest, $smwgJQueryIncluded, $smwgJQueryUIIncluded,
596 - $sdgJQueryIncluded, $sdgScriptPath, $wgOut;
 594+ /**
 595+ * Uses the ResourceLoader (available with MediaWiki 1.17 and higher)
 596+ * to load all the necessary JS and CSS files for the combobox.
 597+ */
 598+ public static function loadJavascriptAndCSS() {
 599+ global $wgOut;
 600+ $wgOut->addModules( 'ext.semanticdrilldown.combobox' );
 601+ }
597602
598 - $filter_name = str_replace( ' ', '_', $filter_name );
599 - $input_id = "_search_$filter_name";
600 - $combobox_id = "c_search_$filter_name";
601 - if ( !$sdgJQueryIncluded ) {
602 - $wgOut->addExtensionStyle( "$sdgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" );
603 - }
 603+ function addJavascriptAndCSS() {
 604+ global $smwgJQueryIncluded, $smwgJQueryUIIncluded, $sdgScriptPath, $wgOut;
604605
 606+ $wgOut->addExtensionStyle( "$sdgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" );
 607+
605608 $scripts = array();
606609 if ( !$smwgJQueryIncluded ) {
607610 $scripts[] = "$sdgScriptPath/libs/jquery-1.4.2.min.js";
@@ -611,23 +614,35 @@
612615 $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.core.min.js";
613616 $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.widget.min.js";
614617 }
615 - if ( !$sdgJQueryIncluded ) {
616 - $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.button.min.js";
617 - }
 618+ $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.button.min.js";
618619 if ( !$smwgJQueryUIIncluded ) {
619620 $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.position.min.js";
620621 $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.autocomplete.min.js";
621622 $smwgJQueryUIIncluded = true;
622623 }
623 - if ( !$sdgJQueryIncluded ) {
624 - $scripts[] = "$sdgScriptPath/libs/SemanticDrilldown.js";
625 - $sdgJQueryIncluded = true;
626 - }
 624+ $scripts[] = "$sdgScriptPath/libs/SemanticDrilldown.js";
627625
628626 foreach ( $scripts as $script ) {
629627 $wgOut->addScriptFile( $script );
630628 }
 629+ }
631630
 631+ function printComboBoxInput( $filter_name, $filter_values, $cur_value = null ) {
 632+ global $wgRequest, $smwgJQueryIncluded, $smwgJQueryUIIncluded;
 633+ global $wgOut;
 634+
 635+ // MW 1.17 +
 636+ if ( class_exists( 'ResourceLoader' ) ) {
 637+ self::loadJavascriptAndCSS();
 638+ } elseif ( !$sdgJQueryIncluded ) {
 639+ $sdgJQueryIncluded = true;
 640+ self::addJavascriptAndCSS();
 641+ }
 642+
 643+ $filter_name = str_replace( ' ', '_', $filter_name );
 644+ $input_id = "_search_$filter_name";
 645+ $combobox_id = "c_search_$filter_name";
 646+
632647 $combobox_js =<<<END
633648 <script type="text/javascript">
634649 jQuery(document).ready(function(){
@@ -679,7 +694,7 @@
680695 wfMsgForContent( 'february' ),
681696 wfMsgForContent( 'march' ),
682697 wfMsgForContent( 'april' ),
683 - // Needed to avoid using 3-letter abbreviation
 698+ // Needed to avoid using 3-letter abbreviation
684699 wfMsgForContent( 'may_long' ),
685700 wfMsgForContent( 'june' ),
686701 wfMsgForContent( 'july' ),
@@ -1082,7 +1097,7 @@
10831098 SMW_OUTPUT_HTML
10841099 );
10851100
1086 - $prtext = is_array( $prresult ) ? $prresult[0] : $prresult;
 1101+ $prtext = is_array( $prresult ) ? $prresult[0] : $prresult;
10871102
10881103 SMWOutputs::commitToOutputPage( $out );
10891104
@@ -1105,7 +1120,7 @@
11061121 // Force one more parser function, so links appear.
11071122 $wgParser->replaceLinkHolders( $prtext );
11081123 }
1109 -
 1124+
11101125 $html = array();
11111126 $html[] = $prtext;
11121127
Index: trunk/extensions/SemanticDrilldown/skins/SD_jquery_ui_overrides.css
@@ -0,0 +1,41 @@
 2+/*
 3+ * Overrides the CSS for the jQuery UI libraries, for use by the 'combo box' input.
 4+ *
 5+ * Based on the file SF_jquery_ui_overrides.css, from the Semantic Forms extension.
 6+ */
 7+.ui-widget input, .ui-widget {
 8+ font-family: sans-serif;
 9+ font-size: 10pt;
 10+}
 11+
 12+.ui-widget input.ui-widget-content {
 13+ padding-left: 0.2em;
 14+ margin: 0 0 0 .1em;
 15+}
 16+
 17+.ui-menu-item .ui-state-hover {
 18+ background: #222288;
 19+ color: white;
 20+ border: none;
 21+}
 22+ul.ui-menu {
 23+ padding: 0 0 5px 0;
 24+ max-height: 200px;
 25+ overflow: auto;
 26+}
 27+.ui-menu .ui-menu-item a.ui-state-hover {
 28+ margin: auto;
 29+}
 30+
 31+.ui-corner-left, .ui-corner-right, .ui-corner-all {
 32+ border-radius: 0;
 33+ -moz-border-radius: 0;
 34+ -webkit-border-radius: 0;
 35+}
 36+
 37+/*
 38+button.ui-button-icon-only {
 39+ vertical-align: auto;
 40+}
 41+*/
 42+
Index: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php
@@ -237,3 +237,26 @@
238238 }
239239 return true;
240240 }
 241+
 242+// register client-side modules
 243+if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
 244+ $sfgResourceTemplate = array(
 245+ 'localBasePath' => $sdgIP,
 246+ 'remoteExtPath' => 'SemanticDrilldown'
 247+ );
 248+ $wgResourceModules += array(
 249+ 'ext.semanticdrilldown.combobox' => $sfgResourceTemplate + array(
 250+ 'scripts' => array(
 251+ 'libs/SemanticDrilldown.js',
 252+ ),
 253+ 'styles' => array(
 254+ 'skins/SD_jquery_ui_overrides.css',
 255+ ),
 256+ 'dependencies' => array(
 257+ 'jquery.ui.autocomplete',
 258+ 'jquery.ui.button',
 259+ ),
 260+ ),
 261+ );
 262+}
 263+
Index: trunk/extensions/SemanticDrilldown/libs/SemanticDrilldown.js
@@ -6,13 +6,27 @@
77 * @author Sanyam Goyal
88 */
99 (function(jQuery) {
 10+ jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) {
 11+ var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + this.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi");
 12+ var loc = item.label.search(re);
 13+ if (loc >= 0) {
 14+ var t = item.label.substr(0, loc) + '<strong>' + item.label.substr(loc, this.term.length) + '</strong>' + item.label.substr(loc + this.term.length);
 15+ } else {
 16+ var t = item.label;
 17+ }
 18+ return jQuery( "<li></li>" )
 19+ .data( "item.autocomplete", item )
 20+ .append( " <a>" + t + "</a>" )
 21+ .appendTo( ul );
 22+ };
 23+
1024 jQuery.widget("ui.combobox", {
1125 _create: function() {
1226 var self = this;
1327 var select = this.element.hide();
1428 var inp_id = select[0].options[0].value;
1529 var curval = select[0].name;
16 - var input = jQuery("<input id = \""+inp_id+"\" type=\"text\" name=\""+inp_id+"\" value=\""+curval+"\">")
 30+ var input = jQuery("<input id = \""+inp_id+"\" type=\"text\" name=\""+inp_id+"\" value=\""+curval+"\">")
1731 .insertAfter(select)
1832 .autocomplete({
1933 source: function(request, response) {
@@ -22,7 +36,7 @@
2337 if (this.value && (!request.term || matcher.test(text)))
2438 return {
2539 id: this.value,
26 - label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + jQuery.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
 40+ label: text,
2741 value: text
2842 };
2943 }));

Follow-up revisions

RevisionCommit summaryAuthorDate
r102935Fixed handling for filter names with non-Latin characters, fixes for r102903yaron03:32, 14 November 2011