1
|
require([
|
2
|
// 'dojo/ready',
|
3
|
'dojo/_base/event',
|
4
|
'dojo/_base/html',
|
5
|
'dojo/_base/lang',
|
6
|
'dojo/_base/window',
|
7
|
'dojo/dom',
|
8
|
'dojo/dom-class',
|
9
|
'dojo/dom-construct',
|
10
|
'dojo/io/script',
|
11
|
'dojo/query',
|
12
|
// 'dijit/Dialog',
|
13
|
'dijit/TooltipDialog',
|
14
|
'dijit/form/DropDownButton',
|
15
|
'dojo/NodeList-dom'
|
16
|
], function(
|
17
|
/*ready,*/
|
18
|
event,
|
19
|
html,
|
20
|
lang,
|
21
|
win,
|
22
|
dom,
|
23
|
domClass,
|
24
|
domConstruct,
|
25
|
ioScript,
|
26
|
query,
|
27
|
/*Dialog,*/
|
28
|
TooltipDialog,
|
29
|
DropDownButton
|
30
|
){
|
31
|
|
32
|
var hasTundra = domClass.contains(win.body(), 'tundra');
|
33
|
|
34
|
function addStyle(){
|
35
|
if(!hasTundra){
|
36
|
domClass.add(win.body(), 'tundra');
|
37
|
}
|
38
|
}
|
39
|
|
40
|
function removeStyle(){
|
41
|
if(!hasTundra){
|
42
|
domClass.remove(win.body(), 'tundra');
|
43
|
}
|
44
|
}
|
45
|
|
46
|
function loadStylesheet(){
|
47
|
var head = win.doc.getElementsByTagName("head")[0];
|
48
|
|
49
|
var embedCss = domConstruct.create("link", {
|
50
|
type: "text/css",
|
51
|
rel: "stylesheet",
|
52
|
//href: "//docs.irigo.com/static/css/embed.css"
|
53
|
href: "/stabile/static/docs/style.css"
|
54
|
});
|
55
|
// add tundra css if not there!
|
56
|
// FIXME: copy paste the relevant parts from that stylesheet into embed.css
|
57
|
// and rename tundra.
|
58
|
if(!hasTundra){
|
59
|
var tundraCss = domConstruct.create("link", {
|
60
|
type: "text/css",
|
61
|
rel: "stylesheet",
|
62
|
href: "//ajax.googleapis.com/ajax/libs/dojo/1.7.2/dijit/themes/tundra/tundra.css"
|
63
|
});
|
64
|
head.appendChild(tundraCss);
|
65
|
}
|
66
|
head.appendChild(embedCss);
|
67
|
}
|
68
|
|
69
|
function getTopic(url){
|
70
|
if (url.indexOf('docs.irigo')!=-1) url += '/jsonp';
|
71
|
else if (url.indexOf('get_engines')!=-1) ;
|
72
|
else if (url.indexOf('https://www.origo.io')!=-1) url += '/?feed=json';
|
73
|
var args = {
|
74
|
// url: url + (url.indexOf('docs.irigo')!=-1?'/jsonp':'/?feed=json'),
|
75
|
url: url,
|
76
|
callbackParamName: 'callback'
|
77
|
};
|
78
|
return ioScript.get(args);
|
79
|
}
|
80
|
|
81
|
function tooltip(node, args){
|
82
|
node = dom.byId(node);
|
83
|
var topic_url = node.href;
|
84
|
|
85
|
var dialog = new TooltipDialog({
|
86
|
style:"width:300px;"
|
87
|
});
|
88
|
|
89
|
var button = new DropDownButton({
|
90
|
dropDown: dialog,
|
91
|
baseClass:"irigo-tooltip-base",
|
92
|
iconClass:"irigo-tooltip-base-icon",
|
93
|
onOpen: function(){
|
94
|
addStyle();
|
95
|
},
|
96
|
onClose: function(){
|
97
|
removeStyle();
|
98
|
},
|
99
|
onClick: function(e){
|
100
|
if(dialog.get('content') == ''){
|
101
|
var dfd = getTopic(topic_url);
|
102
|
dfd.then(function(js){
|
103
|
//console.log(js.excerpt instanceof Array);
|
104
|
//dialog.set('content', '<p>' + js.excerpt + ' (<a href="' + topic_url + '" target="_blank">more</a>)</p>');
|
105
|
var ihtml = '<p>' + (js instanceof Array?js[0].excerpt:js.excerpt) + ' (<a href="' + topic_url + '" target="_blank">more</a>)</p>';
|
106
|
dialog.set('content', ihtml);
|
107
|
});
|
108
|
}
|
109
|
// else, we've already loaded the content.
|
110
|
event.stop(e);
|
111
|
return false;
|
112
|
}
|
113
|
});
|
114
|
// replacing the a tag!
|
115
|
html.place(button.domNode, node, 'replace');
|
116
|
}
|
117
|
|
118
|
function text(node, args){
|
119
|
node = dom.byId(node);
|
120
|
|
121
|
var topic_url = node.href;
|
122
|
|
123
|
var dfd = getTopic(topic_url);
|
124
|
dfd.then(function(js){
|
125
|
var ihtml = '<!-- h3>' + (js instanceof Array?js[0].title:js.title) + '</h3 -->' + '<p>' + (js instanceof Array?js[0].excerpt:js.excerpt) + '</p>';
|
126
|
var wrapper = domConstruct.create('div', {
|
127
|
innerHTML: ihtml
|
128
|
});
|
129
|
// replacing the a tag!
|
130
|
html.place(wrapper, node, 'replace');
|
131
|
});
|
132
|
}
|
133
|
|
134
|
function loadSystem(node, args){
|
135
|
if (args) {
|
136
|
// var topic_url = "https://irigo.com/store/apps/" + args +
|
137
|
// "/?json=1&include=title,excerpt,custom_fields&custom_fields=master,vcpu,bschedule,start,instances,monitors,memory,networktype1,name,storagepool";
|
138
|
var topic_url = "https://irigo.com/app?p=" + args +
|
139
|
"&json=1&include=title,excerpt,custom_fields&custom_fields=master,vcpu,bschedule,start,instances,monitors,memory,networktype1,name,storagepool";
|
140
|
|
141
|
var topicargs = {
|
142
|
//url: url + '/jsonp',
|
143
|
url: topic_url,
|
144
|
callbackParamName: 'callback'
|
145
|
};
|
146
|
var dfd = ioScript.get(topicargs);
|
147
|
|
148
|
//var dfd = getTopic(topic_url);
|
149
|
|
150
|
dfd.then(function(js){
|
151
|
if (js && js.page && js.page.custom_fields) {
|
152
|
var sys = js.page.custom_fields;
|
153
|
sys.excerpt = js.page.excerpt;
|
154
|
sys.title = js.page.title;
|
155
|
systembuilder.system.loadSystem(sys);
|
156
|
} else {
|
157
|
systembuilder.system.loadSystem();
|
158
|
}
|
159
|
});
|
160
|
} else {
|
161
|
systembuilder.system.loadSystem();
|
162
|
}
|
163
|
}
|
164
|
|
165
|
loadStylesheet();
|
166
|
|
167
|
lang.extend(query.NodeList, {
|
168
|
irigoTooltip: query.NodeList._adaptAsForEach(tooltip),
|
169
|
irigoText: query.NodeList._adaptAsForEach(text),
|
170
|
irigoLoadSystem: query.NodeList._adaptAsForEach(loadSystem)
|
171
|
});
|
172
|
|
173
|
if (typeof IRIGO === 'undefined') IRIGO = [];
|
174
|
// IRIGO = {getTopic: getTopic};
|
175
|
IRIGO.getTopic = getTopic;
|
176
|
});
|
177
|
|