r80336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80335‎ | r80336 | r80337 >
Date:22:26, 14 January 2011
Author:krinkle
Status:deferred
Tags:
Comment:
using jquery.sugestions instead of jquery.ui.autocomplete due to it being too new for the jquery.ui that wordpress uses
Modified paths:
  • /trunk/tools/wp-photocommons/js/jquery.suggestions.js (modified) (history)
  • /trunk/tools/wp-photocommons/js/search.js (modified) (history)
  • /trunk/tools/wp-photocommons/search.php (modified) (history)

Diff [purge]

Index: trunk/tools/wp-photocommons/search.php
@@ -5,6 +5,7 @@
66 <head>
77 <meta charset="utf-8" />
88 <link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.5.custom.css" />
 9+ <link rel="stylesheet" href="css/jquery.suggestions.css" />
910 </head>
1011 <body>
1112 <?php endif; ?>
@@ -22,6 +23,7 @@
2324 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
2425 <script src="js/jquery-ui-1.8.5.custom.min.js"></script>
2526 <script src="js/search.js"></script>
 27+ <script src="js/jquery.suggestions.js"></script>
2628 </body>
2729 </html>
2830 <?php endif; ?>
\ No newline at end of file
Index: trunk/tools/wp-photocommons/js/search.js
@@ -57,17 +57,18 @@
5858 'callback' : '!noencode!?'
5959 }, args);
6060
61 - var url = 'http://commons.wikimedia.org/w/api.php';
62 - var first = true;
63 - for (var key in args) {
 61+ var url = 'http://commons.wikimedia.org/w/api.php',
 62+ first = true,
 63+ key;
 64+ for ( key in args ) {
6465 var value = args[key];
6566 url += (first) ? '?' : '&';
6667 first = false;
6768
68 - if (value.indexOf( '!noencode!' ) === 0 && typeof value === 'string' ) {
69 - value = value.slice(10);
 69+ if ( value.indexOf( '!noencode!' ) === 0 && typeof value === 'string' ) {
 70+ value = value.slice( 10 );
7071 } else {
71 - value = encodeURIComponent(value);
 72+ value = encodeURIComponent( value );
7273 }
7374
7475 url += key + '=' + value;
@@ -75,19 +76,60 @@
7677 return url;
7778 },
7879 init: function() {
79 -
80 - $( '#wp-photocommons-search' ).autocomplete({
81 - source : function(request, response) {
 80+
 81+ /* jQuery suggestions */
 82+ $( '#wp-photocommons-search' ).suggestions( {
 83+ fetch: function( query ) {
8284 var url = Photocommons.getQueryUrl( 'pagesearch', {
83 - 'search' : $( '#wp-photocommons-search' ).val()
 85+ 'search' : query
8486 });
85 -
86 - $.getJSON(url, function(data) {
87 - response(data[1]);
 87+ log('query', query);
 88+ log('url', url);
 89+ $.getJSON( url, function( data ) {
 90+ $( '#wp-photocommons-search' ).suggestions( 'suggestions', data[1] );
8891 });
8992 },
 93+ cancel: function() {
 94+ //...
 95+ },
 96+ maxRows: 0,
 97+ result: {
 98+ select: function( $result ) {
 99+ var value = $result.val(),
 100+ url = Photocommons.getQueryUrl( 'pageimages', {
 101+ 'title' : value,
 102+ 'width' : '200'
 103+ });
90104
91 - select : function(event, ui) {
 105+ $( '#wp-photocommons-images' ).empty();
 106+ $( '#wp-photocommons-loading' ).show();
 107+ $.getJSON( url, function( data ) {
 108+
 109+ if ( !data.query.pageids.length ) {
 110+ $( '#wp-photocommons-images' ).html( 'No images found :(' );
 111+ } else {
 112+ $.each( data.query.pageids, function( key, pageid ) {
 113+ var img = data.query.pages[pageid];
 114+ if ( img.imageinfo && img.imageinfo[0] ) {
 115+ $( '#wp-photocommons-images' ).append( '<img src="' + img.imageinfo[0].thumburl + '" style="display:none;"/>' ).find( 'img' ).fadeIn();
 116+
 117+ }
 118+ });
 119+
 120+ }
 121+
 122+ $( '#wp-photocommons-loading' ).hide();
 123+ });
 124+ }
 125+ }
 126+
 127+ } );
 128+
 129+ /* jQuery UI Autosuggest*/
 130+ /*
 131+ $( '#wp-photocommons-search' ).autocomplete({
 132+
 133+ select : function( event, ui ) {
92134 $( '#wp-photocommons-images' ).empty();
93135 $( '#wp-photocommons-loading' ).show();
94136
@@ -96,18 +138,18 @@
97139 'width' : '200'
98140 });
99141
100 - $.getJSON(url, function(data) {
 142+ $.getJSON( url, function( data ) {
101143
102144 if ( !data.query.pageids.length ) {
103145 $( '#wp-photocommons-images' ).html( 'No images found :(' );
104146 } else {
105 - $.each(data.query.pageids, function(key,pageid){
 147+ $.each( data.query.pageids, function( key, pageid ) {
106148 var img = data.query.pages[pageid];
107149 if ( img.imageinfo && img.imageinfo[0] ) {
108150 $( '#wp-photocommons-images' ).append( '<img src="' + img.imageinfo[0].thumburl + '" style="display:none;"/>' ).find( 'img' ).fadeIn();
109151
110152 }
111 - })
 153+ });
112154
113155 }
114156
@@ -115,6 +157,7 @@
116158 });
117159 }
118160 });
 161+ */
119162 }
120163 });
121164
Index: trunk/tools/wp-photocommons/js/jquery.suggestions.js
@@ -145,7 +145,6 @@
146146 var $results = context.data.$container.children( '.suggestions-results' );
147147 $results.empty();
148148 var expWidth = -1;
149 - var $autoEllipseMe = $( [] );
150149 var matchedText = null;
151150 for ( var i = 0; i < context.config.suggestions.length; i++ ) {
152151 var text = context.config.suggestions[i];
@@ -180,7 +179,6 @@
181180 // factor in any padding, margin, or border space on the parent
182181 expWidth = $span.outerWidth() + ( context.data.$container.width() - $span.parent().width());
183182 }
184 - $autoEllipseMe = $autoEllipseMe.add( $result );
185183 }
186184 }
187185 // Apply new width for results box, if any
@@ -188,8 +186,6 @@
189187 var maxWidth = context.config.maxExpandFactor*context.data.$textbox.width();
190188 context.data.$container.width( Math.min( expWidth, maxWidth ) );
191189 }
192 - // autoEllipse the results. Has to be done after changing the width
193 - $autoEllipseMe.autoEllipsis( { hasSpan: true, tooltip: true, matchText: matchedText } );
194190 }
195191 }
196192 break;
@@ -303,6 +299,8 @@
304300 break;
305301 // Enter
306302 case 13:
 303+ console.log('case 13');
 304+ //debugger;
307305 context.data.$container.hide();
308306 preventDefault = wasVisible;
309307 selected = context.data.$container.find( '.suggestions-result-current' );

Status & tagging log