forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
82 lines (66 loc) · 1.99 KB
/
utils.js
File metadata and controls
82 lines (66 loc) · 1.99 KB
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
function ValidateEmbedUrl(embedUrl) {
var embedUrl = $('#txtReportEmbed').val();
if (!embedUrl)
{
alert("You must specify an embed url.");
return false;
}
var id = null;
var parts = embedUrl.split("reportId=");
if (parts && parts.length > 0)
{
var guidParts = parts[parts.length -1].split("&");
if (guidParts && guidParts.length > 0)
{
id = guidParts[0];
}
}
if (!id)
{
alert("Could not find report ID in url");
return false;
}
return true;
}
function BodyCodeOfFunction(func) {
var lines = func.toString().split('\n');
lines = lines.slice(1, lines.length-1);
for (var i = 0; i < lines.length; ++i)
{
// remove trailing spaces.
lines[i] = lines[i].substring(4);
}
return lines.join('\n');
}
function LoadCodeArea(divSelector, initialFunctionCode) {
$(divSelector).load("code_area.html", function() {
SetCode(initialFunctionCode);
});
}
function LoadLogWindow(divSelector) {
$(divSelector).load("log_window.html");
}
function SetCode(func) {
var codeHtml = '<pre id="txtCode" class="brush: js; gutter: false;">';
codeHtml = codeHtml + BodyCodeOfFunction(func) + '</pre><script type="text/javascript" src="syntaxHighlighter/syntaxhighlighter.js"></script>';
$("#highlighter").html(codeHtml);
var runFunc = mapFunc(func);
$('#btnRunCode').off('click');
$('#btnRunCode').click(runFunc);
}
function CopyCode() {
CopyTextArea("#txtCode", "#btnRunCopyCode");
}
function CopyResponseWindow() {
CopyTextArea("#txtResponse", "#btnCopyResponse");
}
function CopyTextArea(textAreaSelector, buttonSelector) {
$(textAreaSelector).select();
document.execCommand('copy');
window.getSelection().removeAllRanges();
// Set focus on copy button - this will deselect text in copied area.
$(buttonSelector).focus();
}
function ClearTextArea(textAreaSelector) {
$(textAreaSelector).val("");
}