summaryrefslogtreecommitdiff
path: root/js/gallery.js
blob: a9430fc1e478e0ab779775402359286ff8c427f1 (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
//
// gallery .. the most basic image picker

var gallery = {}

gallery.init = function(choose){
	if (choose) {
		gallery.choose = choose;
	}
  gallery.bind()
}

gallery.bind = function(){
  $("#gallery-random").click(asdf.random)
  $("#gallery-search").submit(dumpfm.search)
  $(document).on("click", "#gallery-images canvas", gallery.click)
  status("ready")
}

gallery.load = function(ims){
  status("loading " + ims.length + " images");
  $("#gallery-images").empty();
  for (var i = 0; i < ims.length; i++) {
    gallery.image(ims[i]);
  }
}

gallery.image = function(im){
  var img = new Image ();
  img.onload = function(){
    var tall = 100
    var aspect = img.naturalHeight / img.naturalWidth
    var side = ~~(tall/aspect)
    var thumb = cq(side,tall)
    thumb.drawImage(img,0,0,side,tall)
    $(img).hide()
    $("#gallery-images").append(thumb.canvas).append(img);
    $(thumb.canvas).mouseover(function(){
      $(thumb.canvas).hide()
      $(img).show()
    })
    img.width = side
    img.height = tall
    $(img).mouseout(function(){
      $(img).hide()
      $(thumb.canvas).show()
    })
    $(img).click(gallery.choose);
  }
  try { img.src = im.url; }
  catch(e){ return; }
  if (img.complete) img.onload();
}

gallery.click = function(){
  gallery.choose()
}

// template for choose function.. bound to an image object
gallery.choose = function(){
	var img = this
  var imageURL = this.src
}