~tempo-openerp/+junk/loewert-report-name

« back to all changes in this revision

Viewing changes to addons/web_graph/static/lib/flotr2/js/plugins/download.js

  • Committer: jbe at tempo-consulting
  • Date: 2013-08-21 08:48:11 UTC
  • Revision ID: jbe@tempo-consulting.fr-20130821084811-913uo4l7b5ayxq8m
[NEW] Création de la branche trunk Loewert

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function() {
 
2
 
 
3
var
 
4
  D = Flotr.DOM,
 
5
  _ = Flotr._;
 
6
 
 
7
function getImage (type, canvas, width, height) {
 
8
 
 
9
  // TODO add scaling for w / h
 
10
  var
 
11
    mime = 'image/'+type,
 
12
    data = canvas.toDataURL(mime),
 
13
    image = new Image();
 
14
  image.src = data;
 
15
  return image;
 
16
}
 
17
 
 
18
Flotr.addPlugin('download', {
 
19
 
 
20
  saveImage: function (type, width, height, replaceCanvas) {
 
21
    var image = null;
 
22
    if (Flotr.isIE && Flotr.isIE < 9) {
 
23
      image = '<html><body>'+this.canvas.firstChild.innerHTML+'</body></html>';
 
24
      return window.open().document.write(image);
 
25
    }
 
26
 
 
27
    if (type !== 'jpeg' && type !== 'png') return;
 
28
 
 
29
    image = getImage(type, this.canvas, width, height);
 
30
 
 
31
    if (_.isElement(image) && replaceCanvas) {
 
32
      this.download.restoreCanvas();
 
33
      D.hide(this.canvas);
 
34
      D.hide(this.overlay);
 
35
      D.setStyles({position: 'absolute'});
 
36
      D.insert(this.el, image);
 
37
      this.saveImageElement = image;
 
38
    } else {
 
39
      return window.open(image.src);
 
40
    }
 
41
  },
 
42
 
 
43
  restoreCanvas: function() {
 
44
    D.show(this.canvas);
 
45
    D.show(this.overlay);
 
46
    if (this.saveImageElement) this.el.removeChild(this.saveImageElement);
 
47
    this.saveImageElement = null;
 
48
  }
 
49
});
 
50
 
 
51
})();