-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_library.html
371 lines (341 loc) · 12.6 KB
/
context_library.html
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<html>
<head>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.hero-unit {
padding: 10px 30px 5px 30px;
text-align: center;
background-color: #444;
}
.hero-unit h1 {
text-transform: uppercase;
font-size: 44px;
color: #fff;
}
#enter {
width: 100%;
height: 40px;
font-size: 30px;
}
.context_result {
background-color: #ccc;
margin-bottom: 5px;
padding: 10px;
}
.context_result:hover {
background-color: #ddd;
}
.item_icon {
float: left;
width: 60px;
margin-right: 6px;
}
.content_result_right {
float: left;
width: 300px;
}
.context_result_title {
font-weight: bold;
font-size: 18px;
}
.item_description {
font-weight: light;
color: #ddd;
}
#context_container {
min-width: 800px;
}
#context_left {
float: left;
width: 300px;
}
#context_right {
float: left;
width: 500px;
display: none;
}
#context_note {
width: 100%;
height: 250px;
}
#context_note_title {
font-weight: bold;
}
</style>
<script src="lib/underscore-1.3.1.min.js"></script>
<script src="lib/omni.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js"></script>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a href="javascript:void(0)" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="http://localhost/inst/">Omni: Context Browser</a>
<div class="nav-collapse">
<ul class="nav">
<!--
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
-->
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
<h1>Search for a context:</h1>
<br/>
<p><input type="text" id="enter" /></p>
</div>
<div class="row">
<div class="span16">
<div class="results">
</div>
<div id="context_container" style="display:none">
<h3 id="context_title">title</h3>
<div style="display:none">Created <span id="context_date"></span> </div>
This context is currently active
<a id="close_context" href="javascript:void(0)" class="btn" >close this context</a>
<br/>
<hr/>
<div id="context_left">
<strong>Notes:</strong>
<div id="context_notes">
</div>
New Note: <input type="text" name="newnote" id="newnote" style="width:150px"/>
<br/>
<strong>History:</strong>
<div id="context_history">
</div>
</div>
<div id="context_right">
<div id="context_note_title"></div>
<textarea id="context_note"></textarea>
</div>
<div style="clear:both"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var level = 0;
var current_context = "";
var switch_level = function(new_lvl) {
level = new_lvl;
$(".results").html("");
if(level == 0) {
$("#context_container").hide();
$(".hero-unit h1").html("Search for a context: ");
$(".hero-unit").show();
$("#enter").val("");
$("#enter").focus();
render_results("");
$(".exit_context").unbind();
}
else if(level == 1) {
$(".hero-unit").hide();
$("#context_container").show();
$(".hero-unit h1").html("");
$(".exit_context").click(function() {
switch_level(0);
});
$("#context_title").html("");
$("#context_notes").html("");
$("#context_history").html("");
$("#context_date").html("");
$("#context_right").hide();
}
}
var init = function() {
current_context = localStorage["GLOBAL_CURRENT_CONTEXT"];
if(!current_context) {
render_results("");
}
else {
load_context_default(current_context);
}
};
var query_match = function(query, text) {
return (query == "" || text.toLowerCase().indexOf(query.toLowerCase()) >= 0);
};
var render_context = function(index) {
};
var render_results = function(query) {
$(".results").html("");
var contexts = omni.Contexts.query(query);
$(".context_result").unbind();
for(var i = 0; i < contexts.length; i++) {
var numNotes = contexts[i].notes.length;
var numUrls = contexts[i].urls.length; //TODO: url
var img_src = "http://placekitten.com/60/60";
var item_html = "<div class='context_result' ctitle='" + contexts[i].title + "'>";
item_html += '<img class="item_icon" src="' + img_src + '" \/>';
item_html += '<div class="content_result_right">';
item_html += "<div class='context_result_title'>" + contexts[i].title + "<\/div>";
item_html += "<div class='context_result_text'>"
// + contexts[i].date_modified + "<br>" //TODO
+ numNotes + " notes, "
+ numUrls + " history items"
+ "<\/div>";
item_html += "<\/div>";
item_html += '<div style="clear:both"><\/div>';
item_html += "<\/div>";
$(".results").append(item_html);
}
$(".context_result").click(load_context);
};
var set_context = function(ctx) {
var port = chrome.extension.connect();
chrome.tabs.getCurrent(function(tab){
port.postMessage({context: ctx});
});
}
var load_context = function() {
switch_level(1);
var ctitle = $(this).attr("ctitle");
set_context(ctitle);
var context = omni.Contexts.get(ctitle);
$("#context_title").html(context.title);
$("#context_container").attr("ctitle", context.title);
$("#enter").val("");
//$("#context_date").html(context.date_modified);
var numNotes = context.notes.length;
var numUrls = context.urls.length; //TODO url
for(var j = 0; j < numNotes; j++) {
var item_html = "<div class='context_note_link_container'>";
item_html += "<a href='javascript:void(0)' class='context_note_link' noteindex='" + j + "'>"
item_html += context.notes[j].title;
item_html += "<\/a><\/div>";
$("#context_notes").append(item_html);
}
var seenUrls = [];
for(var j = 0; j < numUrls; j++) {
if(seenUrls.indexOf(context.urls[j].title) < 0) {
var item_html = "<div class='context_history_link'>";
item_html += "<a target='_blank' href='" + context.urls[j].url + "'>"
item_html += context.urls[j].title;
item_html += "<\/a><\/div>";
$("#context_history").append(item_html);
seenUrls.push(context.urls[j].title);
}
}
$(".context_note_link").click(function() {
var note_index = parseInt($(this).attr("noteindex"));
var ctitle = $("#context_container").attr("ctitle");
$("#context_note").attr("noteindex", note_index);
var msg = context.notes[note_index].text;
$("#context_note_title").html(context.notes[note_index].title);
$("#context_note").val(msg);
$("#context_right").show();
});
};
var load_context_default = function(ctitle) {
switch_level(1);
//TODO: set seleced browser-wide context to this context
var context = omni.Contexts.get(ctitle);
$("#context_title").html(context.title);
$("#context_container").attr("ctitle", context.title);
$("#enter").val("");
//$("#context_date").html(context.date_modified);
var numNotes = context.notes.length;
var numUrls = context.urls.length;
for(var j = 0; j < numNotes; j++) {
var item_html = "<div class='context_note_link_container'>";
item_html += "<a href='javascript:void(0)' class='context_note_link' noteindex='" + j + "'>"
item_html += context.notes[j].title;
item_html += "<\/a><\/div>";
$("#context_notes").append(item_html);
}
var seenUrls = [];
for(var j = 0; j < numUrls; j++) {
if(context.urls[j] != null) {
if(seenUrls.indexOf(context.urls[j].title) < 0) {
var item_html = "<div class='context_history_link'>";
item_html += "<a target='_blank' href='" + context.urls[j].url + "'>"
item_html += context.urls[j].title;
item_html += "<\/a><\/div>";
$("#context_history").append(item_html);
seenUrls.push(context.urls[j].title);
}
}
}
$(".context_note_link").click(function() {
var note_index = parseInt($(this).attr("noteindex"));
var ctitle = $("#context_container").attr("ctitle");
$("#context_note").attr("noteindex", note_index);
var msg = context.notes[note_index].text;
$("#context_note_title").html(context.notes[note_index].title);
$("#context_note").val(msg);
$("#context_right").show();
});
};
$("#enter").keyup(function(e) {
if(e.keyCode == 13) {
omni.Contexts.get($(this).val());
omni.Contexts.save();
}
if(level == 0) {
render_results($(this).val());
}
else if(level == 1) {
//TODO
}
});
$("#newnote").keyup(function(e) {
if(e.keyCode == 13) {
var ctitle = $("#context_container").attr("ctitle");
var context = omni.Contexts.get(ctitle);
var note_title = $(this).val();
var new_index = context.notes.push({title: note_title, text: ""}) - 1;
$(this).val("");
var item_html = "<div class='context_note_link_container'>";
item_html += "<a href='javascript:void(0)' class='context_note_link' noteindex='" + new_index + "'>"
item_html += note_title;
item_html += "<\/a><\/div>";
$("#context_notes").append(item_html);
$("#context_right").show();
$("#context_note_title").html(note_title);
$("#context_note").val("");
$("#context_note").attr("noteindex", new_index);
omni.Contexts.save();
$(".context_note_link").unbind();
$(".context_note_link").click(function() {
var note_index = parseInt($(this).attr("noteindex"));
var ctitle = $("#context_container").attr("ctitle");
$("#context_note").attr("noteindex", note_index);
var msg = context.notes[note_index].text;
$("#context_note_title").html(context.notes[note_index].title);
$("#context_note").val(msg);
$("#context_right").show();
});
}
});
$("#context_note").keyup(function() {
var note_index = parseInt($(this).attr("noteindex"));
var ctitle = $("#context_container").attr("ctitle");
var context = omni.Contexts.get(ctitle);
context.notes[note_index].text = $(this).val();
omni.Contexts.save();
});
$("#close_context").click(function() {
switch_level(0);
set_context("");
});
init();
</script>
</body>
</html>