Index: trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php |
— | — | @@ -590,17 +590,20 @@ |
591 | 591 | return $results_line; |
592 | 592 | } |
593 | 593 | |
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 | + } |
597 | 602 | |
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; |
604 | 605 | |
| 606 | + $wgOut->addExtensionStyle( "$sdgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" ); |
| 607 | + |
605 | 608 | $scripts = array(); |
606 | 609 | if ( !$smwgJQueryIncluded ) { |
607 | 610 | $scripts[] = "$sdgScriptPath/libs/jquery-1.4.2.min.js"; |
— | — | @@ -611,23 +614,35 @@ |
612 | 615 | $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.core.min.js"; |
613 | 616 | $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.widget.min.js"; |
614 | 617 | } |
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"; |
618 | 619 | if ( !$smwgJQueryUIIncluded ) { |
619 | 620 | $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.position.min.js"; |
620 | 621 | $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.autocomplete.min.js"; |
621 | 622 | $smwgJQueryUIIncluded = true; |
622 | 623 | } |
623 | | - if ( !$sdgJQueryIncluded ) { |
624 | | - $scripts[] = "$sdgScriptPath/libs/SemanticDrilldown.js"; |
625 | | - $sdgJQueryIncluded = true; |
626 | | - } |
| 624 | + $scripts[] = "$sdgScriptPath/libs/SemanticDrilldown.js"; |
627 | 625 | |
628 | 626 | foreach ( $scripts as $script ) { |
629 | 627 | $wgOut->addScriptFile( $script ); |
630 | 628 | } |
| 629 | + } |
631 | 630 | |
| 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 | + |
632 | 647 | $combobox_js =<<<END |
633 | 648 | <script type="text/javascript"> |
634 | 649 | jQuery(document).ready(function(){ |
— | — | @@ -679,7 +694,7 @@ |
680 | 695 | wfMsgForContent( 'february' ), |
681 | 696 | wfMsgForContent( 'march' ), |
682 | 697 | wfMsgForContent( 'april' ), |
683 | | - // Needed to avoid using 3-letter abbreviation |
| 698 | + // Needed to avoid using 3-letter abbreviation |
684 | 699 | wfMsgForContent( 'may_long' ), |
685 | 700 | wfMsgForContent( 'june' ), |
686 | 701 | wfMsgForContent( 'july' ), |
— | — | @@ -1082,7 +1097,7 @@ |
1083 | 1098 | SMW_OUTPUT_HTML |
1084 | 1099 | ); |
1085 | 1100 | |
1086 | | - $prtext = is_array( $prresult ) ? $prresult[0] : $prresult; |
| 1101 | + $prtext = is_array( $prresult ) ? $prresult[0] : $prresult; |
1087 | 1102 | |
1088 | 1103 | SMWOutputs::commitToOutputPage( $out ); |
1089 | 1104 | |
— | — | @@ -1105,7 +1120,7 @@ |
1106 | 1121 | // Force one more parser function, so links appear. |
1107 | 1122 | $wgParser->replaceLinkHolders( $prtext ); |
1108 | 1123 | } |
1109 | | - |
| 1124 | + |
1110 | 1125 | $html = array(); |
1111 | 1126 | $html[] = $prtext; |
1112 | 1127 | |
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 @@ |
238 | 238 | } |
239 | 239 | return true; |
240 | 240 | } |
| 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 @@ |
7 | 7 | * @author Sanyam Goyal |
8 | 8 | */ |
9 | 9 | (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 | + |
10 | 24 | jQuery.widget("ui.combobox", { |
11 | 25 | _create: function() { |
12 | 26 | var self = this; |
13 | 27 | var select = this.element.hide(); |
14 | 28 | var inp_id = select[0].options[0].value; |
15 | 29 | 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+"\">") |
17 | 31 | .insertAfter(select) |
18 | 32 | .autocomplete({ |
19 | 33 | source: function(request, response) { |
— | — | @@ -22,7 +36,7 @@ |
23 | 37 | if (this.value && (!request.term || matcher.test(text))) |
24 | 38 | return { |
25 | 39 | id: this.value, |
26 | | - label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + jQuery.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"), |
| 40 | + label: text, |
27 | 41 | value: text |
28 | 42 | }; |
29 | 43 | })); |