-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodewander-screenshot.js
156 lines (131 loc) · 4.84 KB
/
codewander-screenshot.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
define( ["qlik", "text!./template.html","//cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js"],
function ( qlik, template,toImage ) {
$('<link rel="stylesheet" type="text/css" href="/extensions/codewander-screenshot/css/main.css">').appendTo("head");
$('<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">').appendTo("head");
return {
template: template,
support: {
snapshot: true,
export: true,
exportData: false
},
definition: {
type: "items",
component: "accordion",
items: {
settings:{
uses: "settings",
items:{
watermarkText:{
ref:"watermarkText",
label: "Watermark Text",
type: "string",
defaultValue:"screenshot by codewander.com",
expression: "optional"
},
watermarkTextColor:{
ref:"watermarkTextColor",
label: "Watermark Text Color (hex)",
type: "string",
defaultValue:"#00000"
},
Container:{
ref:"Container",
label: "Container Identifier",
type: "string",
defaultValue:".qvt-sheet"
},
bgColor:{
ref:"bgColor",
label: "Background Color (hex)",
type: "string",
defaultValue:"#ffff"
}
}
},
sorting: {
uses: "sorting"
}
}
},
paint: function () {
return qlik.Promise.resolve();
},
controller: ['$scope', function ( $scope ) {
//add your rendering code here
function convert(div){
return ((div.tagName=="CANVAS" &&( div.width==0 || div.height==0)) || $(div).hasClass("codewander-ssbutton") || $(div).hasClass("qv-object-codewander-screenshot") ) ? false : true;
}
$scope.viewmode=function(){
$(document).remove(".codewander-ssbutton")
}
$scope.mode="V";
$scope.modeToggle =function()
{
if ($scope.mode=="V")
{
ssmode();
}
else{
viewmode();
}
}
viewmode=function()
{
$(".codewander-ssbutton").remove();
$("#codewander-setmode").html('<i class="fas fa-chart-area"></i>');
$scope.mode="V"
}
ssmode=function(){
$('.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>');
$('.qv-object-codewander-screenshot').find('.codewander-ssbutton').first().remove();
$('.codewander-ssbutton').click(function(){
var containerIdentifier= $scope.layout.Container == null ? ".qvt-sheet" : $scope.layout.Container;
var bgColor= $scope.layout.bgColor == null ? "#ffff" : $scope.layout.bgColor;
var watermarkText= $scope.layout.watermarkText == null ? "screenshot by www.codewander.com" : $scope.layout.watermarkText;
var watermarkTextColor= $scope.layout.watermarkTextColor == null ? "#00000" : $scope.layout.watermarkTextColor;
var e= $(this).parent().first();
$(e).append('<span class="codewander-watermark" style="color:'+ watermarkTextColor +'">'+watermarkText +'</span>');
domtoimage.toPng(e[0],{ height: $(e[0]).height(),width:$(e[0]).width(),bgcolor:bgColor,filter:convert} ).then(function(i){
var sshot= new Image();
sshot.src=i;
saveBase64AsFile(i,"codewander.com-chart.png");
$(".codewander-watermark").remove();
})
.catch(function(error){
console.log(error);
$(".codewander-watermark").remove();
});
})
$scope.mode="S";
$("#codewander-setmode").html('<i class="fa fa-eye" aria-hidden="true"></i>');
}
$scope.fullsheet = function(){
var containerIdentifier= $scope.layout.Container == null ? ".qvt-sheet" : $scope.layout.Container;
//var containerIdentifier= ".qvt-sheet";
var bgColor= $scope.layout.bgColor == null ? "#ffff" : $scope.layout.bgColor;
var divs= $(document).find(containerIdentifier);
$.each(divs,function(i,e){
$(e).append('<span class="codewander-watermark">screenshot by www.codewander.com</span>');
domtoimage.toPng(e,{ height: $(e).height(),width:$(e).width(),bgcolor:bgColor,filter:convert} ).then(function(i){
var sshot= new Image();
sshot.src=i;
saveBase64AsFile(i,"codewander-fullsheet.PNG");
$(".codewander-watermark").remove();
})
.catch(function(error){
console.log(error);
$(".codewander-watermark").remove();
})
})
}
function saveBase64AsFile(base64, fileName) {
var link = document.createElement("a");
link.setAttribute("href", base64);
link.setAttribute("download", fileName);
link.click();
}
}
]
};
} );