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
|
var {{variable_name}} = {
element_id: "{{variable_name}}",
widgetToggle: function() {
element = document.getElementById({{variable_name}}.element_id);
element.style.visibility = (element.style.visibility == "visible") ? "hidden" : "visible";
if (element.style.visibility == "visible"){
$("#" + {{variable_name}}.element_id + " iframe").focus();
}
},
toHtml: function() {
var html = {{variable_name}}.createButton();
var link = document.createElement('link');
var protocol = document.location.protocol;
link.setAttribute("rel", "stylesheet");
link.setAttribute("href", protocol + '//{{host}}{%url render_ask_widget_css widget.id%}');
//creating the div
var motherDiv = document.createElement('div');
motherDiv.setAttribute("id", {{variable_name}}.element_id);
motherDiv.style.visibility = "hidden";
var containerDiv = document.createElement('div');
motherDiv.appendChild(containerDiv);
{%if widget.outer_style %}
outerStyle = document.createElement('style');
outerStyle.innerText = "{{widget.outer_style}}";
motherDiv.appendChild(outerStyle);
{%endif%}
var closeButton = document.createElement('a');
closeButton.setAttribute('href', '#');
closeButton.setAttribute('id', 'AskbotModalClose');
closeButton.setAttribute('onClick', '{{variable_name}}.widgetToggle();');
closeButton.innerHTML= 'Close';
containerDiv.appendChild(closeButton);
var iframe = document.createElement('iframe');
iframe.setAttribute('src', protocol + '//{{host}}{% url ask_by_widget widget.id %}');
containerDiv.appendChild(iframe);
var body = document.getElementsByTagName('body')[0];
if (body){
body.appendChild(link);
body.appendChild(motherDiv);
}
},
createButton: function() {
var label="{{widget.title}}"; //TODO: add to the model
var buttonDiv = document.createElement('div');
buttonDiv.setAttribute('id', "AskbotAskButton");
var closeButton = document.createElement('input');
closeButton.setAttribute('onClick', '{{variable_name}}.widgetToggle();');
closeButton.setAttribute('type', 'button');
closeButton.value = label;
buttonDiv.appendChild(closeButton);
return buttonDiv;
}
};
previous_function = window.onload;
var onload_functions = function(){
if (previous_function){
previous_function();
}
{{variable_name}}.toHtml();
}
window.onload = onload_functions();
document.write({{variable_name}}.createButton().outerHTML);
|