|
| 1 | +define( ["qlik", "text!./template.html","//cdn.rawgit.com/tsayen/dom-to-image/bfc00a6c5bba731027820199acd7b0a6e92149d8/dist/dom-to-image.min.js"], |
| 2 | + function ( qlik, template,toImage ) { |
| 3 | + $('<link rel="stylesheet" type="text/css" href="/extensions/codewander-screenshot/css/main.css">').appendTo("head"); |
| 4 | + $('<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">').appendTo("head"); |
| 5 | + |
| 6 | + return { |
| 7 | + template: template, |
| 8 | + support: { |
| 9 | + snapshot: true, |
| 10 | + export: true, |
| 11 | + exportData: false |
| 12 | + }, |
| 13 | + paint: function () { |
| 14 | + return qlik.Promise.resolve(); |
| 15 | + }, |
| 16 | + controller: ['$scope', function ( $scope ) { |
| 17 | + //add your rendering code here |
| 18 | + function convert(div){ |
| 19 | + return ((div.tagName=="CANVAS" &&( div.width==0 || div.height==0)) || $(div).hasClass("codewander-ssbutton") || $(div).hasClass("qv-object-codewander-screenshot") ) ? false : true; |
| 20 | + } |
| 21 | + $scope.viewmode=function(){ |
| 22 | + $(document).remove(".codewander-ssbutton") |
| 23 | + } |
| 24 | + $scope.mode="V"; |
| 25 | + $scope.modeToggle =function() |
| 26 | + { |
| 27 | + if ($scope.mode=="V") |
| 28 | + { |
| 29 | + ssmode(); |
| 30 | + |
| 31 | + } |
| 32 | + else{ |
| 33 | + viewmode(); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + viewmode=function() |
| 38 | + { |
| 39 | + $(".codewander-ssbutton").remove(); |
| 40 | + $("#codewander-setmode").html('<i class="fas fa-chart-area"></i>'); |
| 41 | + $scope.mode="V" |
| 42 | + } |
| 43 | + ssmode=function(){ |
| 44 | + |
| 45 | + $('.qv-object').prepend('<div class="qv-object-codewander-screenshot codewander-ssbutton"><button class="btn btn-primary active" ><i class="fas fa-camera"></i>Take screenshot</button></div>'); |
| 46 | + $('.qv-object-codewander-screenshot').find('.codewander-ssbutton').first().remove(); |
| 47 | + $('.codewander-ssbutton').click(function(){ |
| 48 | + var e= $(this).parent().first(); |
| 49 | + $(e).append('<span class="codewander-watermark">screenshot by www.codewander.com</span>'); |
| 50 | + domtoimage.toPng(e[0],{ height: $(e[0]).height(),width:$(e[0]).width(),filter:convert} ).then(function(i){ |
| 51 | + var sshot= new Image(); |
| 52 | + sshot.src=i; |
| 53 | + saveBase64AsFile(i,"codewander.com-chart.png"); |
| 54 | + $(".codewander-watermark").remove(); |
| 55 | + }) |
| 56 | + .catch(function(error){ |
| 57 | + console.log(error); |
| 58 | + $(".codewander-watermark").remove(); |
| 59 | + }); |
| 60 | + }) |
| 61 | + $scope.mode="S"; |
| 62 | + $("#codewander-setmode").html('<i class="fa fa-eye" aria-hidden="true"></i>'); |
| 63 | + |
| 64 | + } |
| 65 | + $scope.fullsheet = function(){ |
| 66 | + |
| 67 | + |
| 68 | + var divs= $(document).find(".qvt-sheet"); |
| 69 | + |
| 70 | + |
| 71 | + $.each(divs,function(i,e){ |
| 72 | + $(e).append('<span class="codewander-watermark">screenshot by www.codewander.com</span>'); |
| 73 | + domtoimage.toPng(e,{ height: $(e).height(),width:$(e).width(),filter:convert} ).then(function(i){ |
| 74 | + var sshot= new Image(); |
| 75 | + sshot.src=i; |
| 76 | + saveBase64AsFile(i,"codewander-fullsheet.PNG"); |
| 77 | + $(".codewander-watermark").remove(); |
| 78 | + |
| 79 | + }) |
| 80 | + .catch(function(error){ |
| 81 | + console.log(error); |
| 82 | + $(".codewander-watermark").remove(); |
| 83 | + }) |
| 84 | + |
| 85 | + }) |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + function saveBase64AsFile(base64, fileName) { |
| 90 | + |
| 91 | + var link = document.createElement("a"); |
| 92 | + |
| 93 | + link.setAttribute("href", base64); |
| 94 | + link.setAttribute("download", fileName); |
| 95 | + link.click(); |
| 96 | + } |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + ] |
| 104 | + }; |
| 105 | + |
| 106 | + } ); |
| 107 | + |
0 commit comments