-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluidy-hood.js
203 lines (182 loc) · 5.88 KB
/
fluidy-hood.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
/*
* Fluidy-hood
* author: Emanuel Carnevale
* http://github.com/ecarnevale/fluidy-hood
*
* an underground interwho
* aiming at the awesomeness of Hoodwink.d by _why the Lucky Stiff
*
* version 0.00001 a.k.a. Proof of Concept
* PUT and POST on the go
*/
jetpack.future.import("slideBar");
//var fluidDBURL = "http://fluiddb.fluidinfo.com/";
var fluidDBURL = "http://sandbox.fluidinfo.com/";
//BEGIN FluidDB REST LIB
fluidDB = new Object();
fluidDB.ajax = function(type, url, payload, callback, async_req){
if(async_req == undefined){
async_req = true;
}
$.ajax({
async: async_req,
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Accept","application/json");
xhrObj.setRequestHeader("Content-Type","application/json");
},
contentType: "application/json",
type: type,
url: url,
data: payload,
processData: false,
success: callback
});
}
//END FluidDB REST LIB
function createNewTag(name,value){
return "<p><b>"+ name +"</b>: "+value+"</p>";
}
// BEGIN onReady EVENT
jetpack.tabs.onReady(function() {
checkAboutPage(this.url);
});
// END onReady EVENT
// BEGIN onFocus EVENT
jetpack.tabs.onFocus(function(){
checkAboutPage(this.url);
});
// END onFocus EVENT
// BEGIN SLIDEBAR CREATION
jetpack.slideBar.append({
width: 250,
persist: true,
icon: 'http://www.fluidinfo.com/favicon.ico',
onReady: function(slide) {
// Creates a new object for the current url when the user clicks on the button
$("#createObjButton", slide.contentDocument).click(function () {
var pageURL = jetpack.tabs.focused.url;
fluidDB.ajax("POST",fluidDBURL + "objects", '{about : "'+pageURL+'"}', function(json){
//TODO extract tags function from checkAboutPage saving in this way a GET ;)
//checkAboutPage(pageURL);
jetpack.notifications.show(json);
});
});
cb = slide;
},
onSelect: function(slide) {
//displayMemos($(slide.contentDocument).find("#content"));
},
html: <>
<style><![CDATA[
body {
font-family: sans-serif;
font-size: 10pt;
overflow-x: hidden;
}
div.tag {
background-color: rgba(255, 255, 255, 0.3);
position: relative;
padding: 0.3em 6px;
margin: 0.75em 10px 0.75em 0;
-moz-border-radius: 5px;
cursor: pointer;
}
div.tag.focused, div.tag.focusedClosing {
background-color: rgba(255, 255, 255, 0.8);
font-weight: bold;
margin-right: -20px;
padding-right: 30px;
}
div.tag:hover {
background-color: rgba(255, 255, 255, 0.6);
}
div.tag.focused:hover, div.tag.focusedClosing:hover {
background-color: rgba(255, 255, 255, 0.9);
}
img.favicon {
width: 16px;
height: 16px;
position: absolute;
top: 50%;
float: left;
margin-top: -8px;
opacity: 0.7;
}
div.tag:hover img.favicon,
div.tag.focused img.favicon,
div.tag.focusedClosing img.favicon {
opacity: 1;
}
div.title {
margin-left: 24px;
}
img.closeButton {
display: none;
}
div.tag:hover img.closeButton {
display: block;
position: absolute;
top: -5px;
right: -5px;
}
div.tag.focused:hover img.closeButton {
right: 25px;
}
]]></style>
<body><h4>Tag along</h4>
<div id="tabList"></div>
<div id="createObjButton" style="display:none">Create an object for this page</div>
<div id="content"></div>
</body>
</>
});
// END SLIDEBAR CREATION
function makeTagWidget(tagName, tagValue) {
var tagWidget = $("<div />", cb.contentDocument.body);
tagWidget.addClass("tag");
var name = $("<div />", cb.contentDocument.body);
name.addClass("tagname");
name.text(tagName);
tagWidget.append(name);
var value = $("<div />", cb.contentDocument.body);
value.addClass("tagvalue");
value.addClass("show");
value.text(tagValue);
tagWidget.append(value);
var editValue = $("<div />", cb.contentDocument.body);
editValue.addClass("tageditvalue");
editValue.addClass("show");
editValue.attr("style", "display:none;");
editValue.text(tagValue);
tagWidget.append(editValue);
return tagWidget;
}
function checkAboutPage(pageURL) {
$(cb.contentDocument).find("#content").empty();
var query = escape('fluidDB/about="'+pageURL+'"');
var finalURL = fluidDBURL + "objects?query=" + query;
fluidDB.ajax("GET",finalURL, {}, function(json){
var objectID = JSON.parse(json).ids[0];
if(objectID){
$(cb.contentDocument).find("#createObjButton").hide();
cb.notify();
var objectURL = fluidDBURL + "objects/" + objectID;
fluidDB.ajax("GET", objectURL, {}, function(jsonTags){
let tags = JSON.parse(jsonTags);
for(let i = 0; i < tags.tagPaths.length; i++){
var tagName = tags.tagPaths[i];
fluidDB.ajax("GET", fluidDBURL + "objects/" + objectID +"/" + tagName, {}, function(tagValue){
//jetpack.notifications.show(i);
//$(cb.contentDocument).find("#content").append("<p><b>"+ tagName +"</b>: "+tagValue+"</p>");
var newTag = makeTagWidget(tagName,tagValue);
newTag.appendTo($(cb.contentDocument).find("#content"));
}, false);
}
});
//jetpack.notifications.show(objectID);
}else{
//jetpack.notifications.show("you got nothing, loser...");
$(cb.contentDocument).find("#createObjButton").show();
}
})
}