Skip to content

Commit 57617ac

Browse files
author
System Administrator
committed
Arbitrary floating notes
1 parent 0a29e8b commit 57617ac

File tree

3 files changed

+144
-12
lines changed

3 files changed

+144
-12
lines changed

app/models/draft.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def reviewify
2323
sent = sentences[i] = sent.gsub("<p>", "")
2424
strt = true
2525
end
26-
sentences[i] = '<a class="sentence" href="#" id="sent-' + i.to_s + '">' + sent.strip + '</a>'
26+
sentences[i] = '<a class="sentence" href="#" id="sent-' + (i + 1).to_s + '">' + sent.strip + '</a>'
2727
if brk then sentences[i] = sentences[i].insert(0, "</p><p>") end
2828
if strt then sentences[i] = sentences[i].insert(0, "<p>") end
2929
end

app/views/drafts/review.html.erb

Lines changed: 143 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ a.sentence.down.has_note .heading {
112112
height: 90px;
113113
}
114114

115+
.flote {
116+
padding: 10px;
117+
font-family: Courier;
118+
height: 90px;
119+
}
120+
121+
.mark {
122+
cursor: pointer;
123+
}
124+
115125
#tooltip {
116126
position: absolute;
117127
z-index: 3000;
@@ -132,6 +142,26 @@ a.sentence.down.has_note .heading {
132142
font-weight: bold;
133143
}
134144

145+
#tooltipflote {
146+
position: absolute;
147+
z-index: 3000;
148+
border: 1px solid #86acc1;
149+
background-color: #fff;
150+
opacity: 0.85;
151+
max-width: 450px;
152+
}
153+
#tooltipflote .contain {
154+
background: #cde9f8;
155+
border: 2px solid #fff;
156+
color: black;
157+
padding: 5px;
158+
}
159+
#tooltipflote h3, #tooltipflote div {
160+
margin: 0;
161+
font-size: 12px;
162+
font-weight: bold;
163+
}
164+
135165
</style>
136166

137167
<script type="text/javascript">
@@ -140,18 +170,22 @@ var t = null;
140170

141171
var save_review = function(continuous) {
142172
var content = $("#draft_content").html();
143-
$.post("/drafts/save_review", {authenticity_token: AUTH_TOKEN, draft_id: <%= @draft.id %>, content: content, signature: $("#signature").attr("value"), general_comments: $("#general_comments").val()},
144-
function(ret) {
145-
var ret = JSON.parse(ret);
146-
var now = new Date();
147-
document.title = "(saved at " + now.format("h:MM:sstt") + " on " + now.format("dddd dS, yyyy") + ")";
148-
}
149-
)
173+
$.post("/drafts/save_review", {
174+
authenticity_token: AUTH_TOKEN,
175+
draft_id: <%= @draft.id %>,
176+
content: content,
177+
signature: $("#signature").attr("value"),
178+
general_comments: $("#general_comments").val()
179+
},
180+
function(ret) {
181+
var ret = JSON.parse(ret);
182+
var now = new Date();
183+
document.title = "[draft]back » saved at " + now.format("h:MM:sstt") + " on " + now.format("dddd dS, yyyy") + "";
184+
});
185+
150186
if (continuous) {
151187
setTimeout("save_review(true)", 1000 * 30) // Save every thirty seconds.
152-
} else {
153-
return false;
154-
}
188+
} else { return false; }
155189
};
156190

157191
var hide_notes = function(affect) {
@@ -166,6 +200,58 @@ var hide_notes = function(affect) {
166200
};
167201

168202
$(document).ready(function() {
203+
var flote_count = 0;
204+
$("#draft").click(function(ev) {
205+
if (ev.shiftKey) {
206+
$flote = $("#flote").clone();
207+
$flote.appendTo("#draft_content");
208+
$flote.attr("id", "flote-" + flote_count);
209+
flote_count += 1;
210+
$flote.val($flote.val().replace("\n", ""));
211+
$flote.css("top", (ev.pageY - 10) + "px");
212+
$flote.css("left", (ev.pageX - 10) + "px");
213+
$flote.show();
214+
$flote.focus();
215+
}
216+
});
217+
218+
$(".mark").live("mouseover",
219+
function(ev) {
220+
var id = $(this).attr("id").split("-")[1];
221+
if ($("#flote-" + id).html() != "" && $("#flote-" + id).html() != null) {
222+
$("#show-flote").html($("#flote-" + id).html());
223+
$("#tooltipflote").css("top", ev.pageY - 30 + "px");
224+
$("#tooltipflote").css("left", ev.pageX + 20 + "px");
225+
//$("#note-" + id).css("height", $("#note-" + id)[0].scrollHeight);
226+
$("#tooltipflote").show();
227+
} else {
228+
$("#tooltipflote").hide();
229+
}
230+
}
231+
);
232+
233+
$(".mark").live("mouseout",
234+
function(ev) {
235+
var id = $(this).attr("id").split("-")[1];
236+
$("#tooltipflote").hide();
237+
}
238+
);
239+
240+
$(".mark").live("mousemove",
241+
function(ev) {
242+
$("#tooltipflote").css("top", ev.pageY - 30 + "px");
243+
$("#tooltipflote").css("left", ev.pageX + 20 + "px");
244+
}
245+
);
246+
247+
$(".mark").live("click",
248+
function(ev) {
249+
var id = $(this).attr("id").split("-")[1];
250+
$("#flote-" + id).show();
251+
$("#flote-" + id).focus();
252+
}
253+
);
254+
169255
$(".note").live("keydown", function(e) {
170256
if (e.keyCode == 13) {
171257
$(this).hide();
@@ -214,7 +300,50 @@ $(document).ready(function() {
214300
return false;
215301
}
216302

303+
$(".flote").live("keydown", function(e) {
304+
if (e.keyCode == 13) {
305+
if ($(this).val() == "") {
306+
if ($(this).attr("id") != "flote") {
307+
$(this).remove();
308+
$(this).hide();
309+
}
310+
} else {
311+
$(this).html($(this).val());
312+
$(this).hide();
313+
$mark = $("#mark-" + $(this).attr("id").split("-")[1]);
314+
if ($mark.length == 0) {
315+
$mark = $("#mark").clone();
316+
$mark.appendTo("#draft_content");
317+
$mark.attr("id", "mark-" + $(this).attr("id").split("-")[1]);
318+
};
319+
$mark.css("top", $(this).css("top"));
320+
$mark.css("left", $(this).css("left"));
321+
$mark.show();
322+
}
323+
};
324+
});
325+
217326
$(".sentence").click(function(ev) {
327+
$(".flote").each(function() {
328+
if ($(this).val() == "") {
329+
if ($(this).attr("id") != "flote") {
330+
$(this).remove();
331+
$(this).hide();
332+
}
333+
} else {
334+
$(this).html($(this).val());
335+
$(this).hide();
336+
$mark = $("#mark-" + $(this).attr("id").split("-")[1]);
337+
if ($mark.length == 0) {
338+
$mark = $("#mark").clone();
339+
$mark.appendTo("#draft_content");
340+
$mark.attr("id", "mark-" + $(this).attr("id").split("-")[1]);
341+
};
342+
$mark.css("top", $(this).css("top"));
343+
$mark.css("left", $(this).css("left"));
344+
$mark.show();
345+
}
346+
});
218347
clearTimeout(t);
219348
$(".note").each(function(e) {
220349
$(this).hide();
@@ -276,7 +405,10 @@ $(document).ready(function() {
276405
});
277406
</script>
278407
<div id="tooltip" style="display: none; right: auto;"><div class="contain"><h3><span id="show-note"></span></h3></div></div>
408+
<div id="tooltipflote" style="display: none; right: auto;"><div class="contain"><h3><span id="show-flote"></span></h3></div></div>
409+
<textarea id="flote" class="flote" affect="neutral" style="width: 250px; position: absolute; display: none; z-index: 999"></textarea>
279410
<textarea id="note" class="note" affect="neutral" style="width: 250px; position: absolute; display: none;"></textarea>
411+
<div id="mark" class="mark" style="position: absolute; display: none; font-size: 12px; color: #ff5544; z-index: 10">&#9679;</div>
280412
<div class="instructions">
281413
<h2 style="margin: 2px 0px 5px 0px;">Instructions:</h2>
282414
<ol style="font-size: 11px;">
@@ -288,7 +420,7 @@ $(document).ready(function() {
288420

289421
<div id="draft">
290422
<div style="float: right; margin-top: 10px;"><a href="/drafts/refresh_review?public_url=<%= params[:id] %>&amp;draft_id=<%= @draft.id %>">Refresh latest draft and start over</a></div>
291-
<h1 style="font-family: Arial; font-size: 22px; margin-top: 20px; line-height: 1.2em;"><%= @draft.title %></h1>
423+
<h1 style="font-family: Arial; font-size: 22px; margin-top: 20px; line-height: 1.2em;"><a class="sentence" href="#" id="sent-0"><%= @draft.title %></a></h1>
292424
<div id="draft_content">
293425
<% if @content.nil? %>
294426
Whoops, it looks like something's gone horribly wrong and we've lost your work.

db/development.sqlite3

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)