summaryrefslogtreecommitdiff
path: root/search-random.html
blob: 1d0959d0fa9aa831184532abeb2dc87690d3be6f (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!doctype html>
<html>
<head>
<title>Photoblaster Search Widget</title>
<style type="text/css">
  #images img { max-width: 200px; height: 90px; margin: 5px; }
</style>
<body>

<div id="ui">
  <input type="text" id="q">
  <button id="name">N</button>
  <button id="search">S</button>
  <button id="random">R</button>
  <div id="images"></div>
</div>

<div id="result">
  <input type="text" id="url">
  <div id="image"></div>
</div>

</body>
<script type="text/javascript" src="js/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript">

$("#random").click(random)
$(document).on("click", "#images img", choose)

random();

function choose(){
  $("#image").empty().append( $(this).clone() )
  $("#result #url").val(this.src);
}

function load(ims){
  $("#images").empty();
  for (var i = 0; i < ims.length; i++) {
    image(ims[i]);
  }
}
function image(im){
  var img = new Image ();
  img.onload = function(){
    $("#images").append(img);
  }
  img.src = im.url;
  if (img.complete) img.onload();
}

function random(){
  opt = {};
  opt.data = { random: 1 };
  opt.success = load;
  fetch(opt);
}

function fetch(opt){
  var params = {random:1};
  $.ajax({
    'url': "http://asdf.us/cgi-bin/im/list",
    'data': params,
    'dataType': "jsonp",
    'success': opt.success || function(data){
      console.log(data);
    },
    'error': opt.error || function(err){
      console.log(err);
    }
  });
}

</script>
</html>