Blame view

sources/apps/gallery/js/thumbnail.js 1.72 KB
d1bafeea1   Kload   [fix] Upgrade to ...
1
2
3
4
5
6
  function Thumbnail (path, square) {
  	this.square = square;
  	this.path = path;
  	this.url = Thumbnail.getUrl(path, square);
  	this.image = null;
  	this.loadingDeferred = new $.Deferred();
6d9380f96   Cédric Dupont   Update sources OC...
7
  	this.ratio = null;
d1bafeea1   Kload   [fix] Upgrade to ...
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
  }
  
  Thumbnail.map = {};
  Thumbnail.squareMap = {};
  
  Thumbnail.get = function (path, square) {
  	var map = (square) ? Thumbnail.squareMap : Thumbnail.map;
  	if (!map[path]) {
  		map[path] = new Thumbnail(path, square);
  	}
  	return map[path];
  };
  
  Thumbnail.getUrl = function (path, square) {
  	if (square) {
  		return OC.filePath('gallery', 'ajax', 'thumbnail.php') + '?file=' + encodeURIComponent(path) + '&square=1';
  	} else {
  		return OC.filePath('gallery', 'ajax', 'thumbnail.php') + '?file=' + encodeURIComponent(path);
  	}
  };
  
  Thumbnail.prototype.load = function () {
  	var that = this;
  	if (!this.image) {
  		this.image = new Image();
  		this.image.onload = function () {
  			Thumbnail.loadingCount--;
6d9380f96   Cédric Dupont   Update sources OC...
35
  			that.image.ratio = that.image.width / that.image.height;
d1bafeea1   Kload   [fix] Upgrade to ...
36
37
38
39
40
  			that.loadingDeferred.resolve(that.image);
  			Thumbnail.processQueue();
  		};
  		this.image.onerror = function () {
  			Thumbnail.loadingCount--;
6d9380f96   Cédric Dupont   Update sources OC...
41
  			that.loadingDeferred.reject(that.image);
d1bafeea1   Kload   [fix] Upgrade to ...
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
  			Thumbnail.processQueue();
  		};
  		Thumbnail.loadingCount++;
  		this.image.src = this.url;
  	}
  	return this.loadingDeferred;
  };
  
  Thumbnail.queue = [];
  Thumbnail.loadingCount = 0;
  Thumbnail.concurrent = 3;
  Thumbnail.paused = false;
  
  Thumbnail.processQueue = function () {
  	if (!Thumbnail.paused && Thumbnail.queue.length && Thumbnail.loadingCount < Thumbnail.concurrent) {
  		var next = Thumbnail.queue.shift();
  		next.load();
  		Thumbnail.processQueue();
  	}
  };
  
  Thumbnail.prototype.queue = function () {
  	if (!this.image) {
  		Thumbnail.queue.push(this);
  	}
  	Thumbnail.processQueue();
  	return this.loadingDeferred;
  };