-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_v1.js
223 lines (179 loc) · 6.61 KB
/
api_v1.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* FlowDynamics Embed Api | (c) 2018-2019 Upsilon Dynamics Inc.
Not for redistribution or use outside of the FlowDynamics platform
https://www.flowdynamics.ca | https://www.upsilondynamics.com
*/
var service_location;
var parameters;
var frame_width;
var frame_height;
var border_style;
var scroll_style;
var formid;
var frameid;
//Icon shown when pane is hidden
var icon_url_off = 'https://github.com/upsilondynamics/flowdynamics-embed-api/blob/master/images/ico_square.jpg?raw=true';
//Icon to show when pane is exposed
var icon_url_on = 'https://github.com/upsilondynamics/flowdynamics-embed-api/blob/master/images/ico_square.jpg?raw=true';
//Style location for Flow pane
var style_url = 'https://raw.githubusercontent.com/upsilondynamics/flowdynamics-embed-api/master/style/api_v1.css';
function setupStyles() {
$("<link/>", {
rel: "stylesheet",
type: "text/css",
href: style_url
}).appendTo("head");
}
function resetVariables() {
var base_url = $("#baseurl");
if ($(base_url).length) {
var v_url = base_url.val();
service_location = v_url + "/Engine/Flow/EmbedFlow";
} else {
service_location = "https://flowdynamicsdev.azurewebsites.net/Engine/Flow/EmbedFlow";
}
parameters = {};
frame_width = "100%";
frame_height = "";
border_style = "none";
scroll_style = "hidden";
formid = "FlowEmbedAction";
frameid = "FlowFrame";
setupStyles();
}
function generateid(len) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < len; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function resizeIframe(obj) {
//$(obj).height($(window).height() + "px");
}
//Initializes the Flow window inside of div as a slider object is on the screen
jQuery.fn.extend({
InitializeSlider: function (label, flow_id, api_key, flow_state_id = "", width = frame_width, height = frame_height, border = false, scroll = false, language = 'Eng') {
resetVariables();
var sliderDivId = $(this).attr('id');
//Empty contents
$(this).empty();
//Hide div
$(this).hide();
$(this).addClass('fd-embed-slider');
//Add a link to the body which will contain an image of the icon which will open the slider
$('<a>').attr({
id: 'flowdynamics-slider-grab',
class: 'fd-slider-grab',
onclick: function() {
var openWidth = 300;
var closeWidth = 30;
var isOpen = $("#" + sliderDivId).width() > closeWidth;
if (isOpen) {
$("#" + sliderDivId).animate({ width: closeWidth }, 'fast', function () {
$("#quick-dash").hide();
});
$("#flowdynamics-control-slider-img").attr("src", icon_url_off);
} else {
$("#flowdynamics-dash").show();
$("#" + sliderDivId).animate({ width: openWidth }, 'fast');
$("#flowdynamics-control-slider-img").attr("src", icon_url_on);
}
}
}).appendTo($("body"));
//Add image activator button, bottom right hand side of screen
$('<img>').attr({
src: icon_url,
id: 'flowdynamics-control-slider-img',
class: 'fd-control-slider-img',
title: label
}).appendTo($("#flowdynamics-slider-grab"));
//Add image activator button, bottom right hand side of screen
$('<div>').attr({
src: icon_url_off,
id: 'flowdynamics-dash',
class: 'fd-slider-dash'
}).appendTo($("#" + sliderDivId));
$("#flowdynamics-dash").Initialize(flow_id, api_key, flow_state_id, width, height, border, scroll, language, false);
}
});
//Initializes the Flow window inside of div as is on the screen
jQuery.fn.extend({
Initialize: function (flow_id, api_key, flow_state_id = "", width = frame_width, height = frame_height, border = false, scroll = false, language = 'Eng', empty = false) {
//Clear this div out of all junk inside
if (empty) {
$(this).empty();
}
resetVariables();
//Generate random id's for the objects
formid = generateid(10);
frameid = generateid(10);
//Setup some of these options - border and scroll bars
border_style = border ? "solid" : border_style;
scroll_style = scroll ? "auto" : scroll_style;
//Add main form object
$('<form>').attr({
action: service_location,
target: frameid,
id: formid,
method: 'post'
}).appendTo($(this));
//Add individual inputs required for the request
$('<input>').attr({
type: 'hidden',
id: 'FlowId',
name: 'FlowId',
value: flow_id
}).appendTo($("#" + formid));
$('<input>').attr({
type: 'hidden',
id: 'FlowStateId',
name: 'FlowStateId',
value: flow_state_id
}).appendTo($("#" + formid));
$('<input>').attr({
type: 'hidden',
id: 'ApiKey',
name: 'ApiKey',
value: api_key
}).appendTo($("#" + formid));
$('<input>').attr({
type: 'hidden',
id: 'Language',
name: 'Language',
value: language
}).appendTo($("#" + formid));
$('<input>').attr({
type: 'hidden',
id: 'Elements',
name: 'Elements',
value: ""
}).appendTo($("#" + formid));
//Add iFrame
$('<iframe>').attr({
name: frameid,
id: frameid,
scrolling: scroll ? "auto" : "no",
onload: (frame_height === '') ? "resizeIframe(this)" : "",
frameBorder:border ? "1" : "0",
style: `width:${width}; height:${height}; overflow:${scroll_style}; border-style:${border_style}; border-width:0px;`
}).appendTo($("#" + formid));
$("#" + frameid).width(width);
$("#" + frameid).height(height);
return this;
}
});
jQuery.fn.extend({
AddVariable: function (element_key, value) {
parameters[element_key] = value;
var serialized = JSON.stringify(parameters);
$("#Elements").val(serialized);
return this;
}
});
jQuery.fn.extend({
LoadFlowContent: function () {
$("#" + formid).submit();
return this;
}
});
resetVariables();