Blame view

vendor/bower/bootstrap-datepicker/docs/_screenshots/script/screenshot.js 2.23 KB
021728bd   Administrator   Importers CRUD
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
  /* jshint phantom:true, devel:true */
  /* Usage: phantomjs screenshot.js in.html out.png */
  
  var sys = require('system'),
      page = new WebPage();
  page.viewportSize = {
      width: 800,
      height: 600
  };
  
  page.open(sys.args[1], function(status){
      if (status !== 'success'){
          console.log('Bad status: %s', status);
          phantom.exit(1);
      }
      window.setTimeout(function(){
          var box = page.evaluate(function(){
              var lefts, rights, tops, bottoms,
                  padding = 10, // px
                  selection, show;
  
              // Call setup method
              if (window.setup)
                  window.setup();
              // Show all pickers, or only those marked for showing
              show = $('body').data('show');
              show = show ? $(show) : $('*');
              show
                  .filter(function(){
                      return 'datepicker' in $(this).data();
                  })
                  .datepicker('show');
  
              // Get bounds of selected elements
              selection = $($('body').data('capture'));
              tops = selection.map(function(){
                  return $(this).offset().top;
              }).toArray();
              lefts = selection.map(function(){
                  return $(this).offset().left;
              }).toArray();
              bottoms = selection.map(function(){
                  return $(this).offset().top + $(this).outerHeight();
              }).toArray();
              rights = selection.map(function(){
                  return $(this).offset().left + $(this).outerWidth();
              }).toArray();
  
              // Convert bounds to single bounding box
              var b = {
                  top: Math.min.apply(Math, tops),
                  left: Math.min.apply(Math, lefts)
              };
              b['width'] = Math.max.apply(Math, rights) - b.left;
              b['height'] = Math.max.apply(Math, bottoms) - b.top;
  
              // Return bounding box
              return {
                  top: Math.max(b.top - padding, 0),
                  left: Math.max(b.left - padding, 0),
                  width: b.width + 2 * padding,
                  height: b.height + 2 * padding
              };
          });
          page.clipRect = box;
          page.render(sys.args[2]);
          phantom.exit();
      }, 1);
  });