Index: trunk/tools/wp-photocommons/search.js |
— | — | @@ -1,5 +1,6 @@ |
2 | | -// Debug |
3 | | -window.log = (console && console.log) ? console.log : function(){}; |
| 2 | +window.log = function(a){ |
| 3 | + console.log(a); |
| 4 | +} |
4 | 5 | |
5 | 6 | if ( !window.Photocommons ) { |
6 | 7 | window.Photocommons = {}; |
— | — | @@ -21,7 +22,8 @@ |
22 | 23 | 'action' : 'query', |
23 | 24 | 'prop' : 'images', |
24 | 25 | 'indexpageids' : '1', |
25 | | - 'titles' : q.title |
| 26 | + 'titles' : q.title, |
| 27 | + 'redirects' : '1' |
26 | 28 | }; |
27 | 29 | }, |
28 | 30 | |
— | — | @@ -32,13 +34,13 @@ |
33 | 35 | 'iiprop' : 'url', |
34 | 36 | 'iiurlwidth' : q.width, |
35 | 37 | 'indexpageids' : '1', |
36 | | - 'titles' : q.image |
| 38 | + 'titles' : q.images//.join( '|' ) |
37 | 39 | }; |
38 | 40 | } |
39 | 41 | }; |
40 | 42 | |
41 | 43 | if (!queries[type]) { |
42 | | - throw new Error('Unknown query type'); |
| 44 | + throw new Error( 'Unknown query type' ); |
43 | 45 | } |
44 | 46 | |
45 | 47 | return Photocommons.makeUrl(queries[type](args)); |
— | — | @@ -57,7 +59,7 @@ |
58 | 60 | url += (first) ? '?' : '&'; |
59 | 61 | first = false; |
60 | 62 | |
61 | | - if (value.indexOf('!noencode!') === 0 && typeof value === 'string') { |
| 63 | + if (value.indexOf( '!noencode!' ) === 0 && typeof value === 'string' ) { |
62 | 64 | value = value.slice(10); |
63 | 65 | } else { |
64 | 66 | value = encodeURIComponent(value); |
— | — | @@ -69,10 +71,10 @@ |
70 | 72 | }, |
71 | 73 | init: function() { |
72 | 74 | |
73 | | - $('#wp-photocommons-search').autocomplete({ |
| 75 | + $( '#wp-photocommons-search' ).autocomplete({ |
74 | 76 | source : function(request, response) { |
75 | | - var url = Photocommons.getQueryUrl('pagesearch', { |
76 | | - 'search' : $('#wp-photocommons-search').val() |
| 77 | + var url = Photocommons.getQueryUrl( 'pagesearch', { |
| 78 | + 'search' : $( '#wp-photocommons-search' ).val() |
77 | 79 | }); |
78 | 80 | |
79 | 81 | $.getJSON(url, function(data) { |
— | — | @@ -81,35 +83,45 @@ |
82 | 84 | }, |
83 | 85 | |
84 | 86 | select : function(event, ui) { |
85 | | - $('#wp-photocommons-images').empty(); |
86 | | - $('#wp-photocommons-loading').show(); |
| 87 | + $( '#wp-photocommons-images' ).empty(); |
| 88 | + $( '#wp-photocommons-loading' ).show(); |
87 | 89 | |
88 | | - var url = Photocommons.getQueryUrl('pageimages', { |
| 90 | + var url = Photocommons.getQueryUrl( 'pageimages', { |
89 | 91 | 'title' : ui.item.value |
90 | 92 | }); |
91 | 93 | |
92 | 94 | $.getJSON(url, function(data) { |
93 | | - var pageid = data.query.pageids[0], |
94 | | - query = data.query.pages[pageid].images; |
| 95 | + var pageid = data.query.pageids[0], |
| 96 | + pageimages = data.query.pages[pageid].images, |
| 97 | + titles = ''; |
95 | 98 | |
96 | | - if (!query) { |
97 | | - $('#wp-photocommons-images').html('No images found :('); |
| 99 | + if ( !pageimages.length ) { |
| 100 | + $( '#wp-photocommons-images' ).html( 'No images found :(' ); |
98 | 101 | } |
99 | 102 | |
100 | | - $.each(query, function() { |
101 | | - var url = Photocommons.getQueryUrl('thumbs', { |
102 | | - width : '200', |
103 | | - image : this.title |
104 | | - }); |
105 | | - |
106 | | - $.getJSON(url, function(data) { |
107 | | - var pageid = data.query.pageids[0], |
108 | | - src = data.query.pages[pageid].imageinfo[0].thumburl; |
109 | | - $('#wp-photocommons-images').append('<img src="' + src + '" style="display:none;"/>').find('img').fadeIn(); |
110 | | - }); |
| 103 | + $.each( pageimages, function() { |
| 104 | + titles += '|' + this.title; |
| 105 | + } ); |
| 106 | + |
| 107 | + var url = Photocommons.getQueryUrl( 'thumbs', { |
| 108 | + width : '200', |
| 109 | + images : titles |
111 | 110 | }); |
112 | 111 | |
113 | | - $('#wp-photocommons-loading').hide(); |
| 112 | + |
| 113 | + $.getJSON(url, function(data){ |
| 114 | + |
| 115 | + $.each(data.query.pageids, function(key,pageid){ |
| 116 | + var img = data.query.pages[pageid]; |
| 117 | + if ( img.imageinfo && img.imageinfo[0] ) { |
| 118 | + $( '#wp-photocommons-images' ).append( '<img src="' + img.imageinfo[0].thumburl + '" style="display:none;"/>' ).find( 'img' ).fadeIn(); |
| 119 | + |
| 120 | + } |
| 121 | + }) |
| 122 | + |
| 123 | + }); |
| 124 | + |
| 125 | + $( '#wp-photocommons-loading' ).hide(); |
114 | 126 | }); |
115 | 127 | } |
116 | 128 | }); |
Index: trunk/tools/wp-photocommons/search.php |
— | — | @@ -1,3 +1,5 @@ |
| 2 | +<?php |
| 3 | + if ( basename( $_SERVER['SCRIPT_FILENAME'] ) == 'search.php' ) : ?> |
2 | 4 | <!doctype html> |
3 | 5 | <html> |
4 | 6 | <head> |
— | — | @@ -8,7 +10,9 @@ |
9 | 11 | <link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.5.custom.css" /> |
10 | 12 | </head> |
11 | 13 | <body> |
| 14 | +<?php endif; ?> |
12 | 15 | |
| 16 | + |
13 | 17 | <input type="search" id="wp-photocommons-search" /> |
14 | 18 | |
15 | 19 | <ul id="wp-photocommons-results"></ul> |
— | — | @@ -17,5 +21,10 @@ |
18 | 22 | |
19 | 23 | <div id="wp-photocommons-images"></div> |
20 | 24 | |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +<?php if ( basename( $_SERVER['SCRIPT_FILENAME'] ) == 'search.php' ) : ?> |
21 | 29 | </body> |
22 | | -</html> |
\ No newline at end of file |
| 30 | +</html> |
| 31 | +<?php endif; ?> |
\ No newline at end of file |