forked from merkhofer/image_2048
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbing.js
50 lines (47 loc) · 1.29 KB
/
bing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*! Bing Search Helper v1.0.0 - requires jQuery v1.7.2 */
$(function()
{
// Attaches a click handler to the button.
$('#bt_search').click(function(e)
{
e.preventDefault();
// Clear the results div.
$('#results').empty();
var query = $('#query').val();
if (query)
thumbs = search(query);
var actuated_bing = new BingActuator(thumbs);
new GameManager(4, KeyboardInputManager, actuated_bing, LocalStorageManager);
$("#game_title").text(query+' 2048');
$("#game").show();
$("#make_query").hide();
$('#new_query').show();
});
function search(query)
{
// Establish the data to pass to the proxy.
var data = { q: query,};
var hashOfThumbs = {};
// Calls the proxy, passing the query, service operation and market.
$.ajax({
type: 'GET',
url: 'bing_proxy.php',
dataType: 'json',
success: function(obj)
{
if (obj.d !== undefined)
{
var items = obj.d.results;
for (var k=0; k < 12; k++)
{
thisTile = (Math.pow(2, (k+1))).toString();
hashOfThumbs[thisTile] = items[k].Thumbnail.MediaUrl;
}
}
},
data: data,
async: false
});
return hashOfThumbs;
}
});