Skip to content

Commit 26b9e3c

Browse files
committed
Note adding / viewing UX updates
Summary: * Disable viewing through annotator popup * Clicking a highlight opens it in the panel * Update note adder styling to match bootstrap * Remove "edit" option from note adder Resolves T256 Test Plan: * Make sure adding notes still works * Provide any feedback you have on style of adder button and editor * Click a note, make sure it opens that note in the panel * Make sure note does not show on hover * Make sure note actions still work in the panel * Make sure "edit" functionality is gone from adder Reviewers: doshitan Reviewed By: doshitan Maniphest Tasks: T256 Differential Revision: https://phabricator.opengovfoundation.org/D152
1 parent b69f5b0 commit 26b9e3c

File tree

4 files changed

+165
-163
lines changed

4 files changed

+165
-163
lines changed

gulpfile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ elixir((mix) => {
2727
)
2828
.copy('resources/assets/img', 'public/img')
2929
.copy('resources/assets/icons', 'public/')
30-
.copy('resources/assets/vendor/css/annotator.min.css', 'public/css/')
3130
.copy('node_modules/font-awesome/fonts/', 'public/fonts/')
3231
.version([
3332
'css/app.css',

resources/assets/js/annotator-madison.js

Lines changed: 31 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/*global Annotator*/
2-
/*global diff_match_patch*/
32
/*jslint newcap: true*/
43
Annotator.Plugin.Madison = function (element, options) {
54
Annotator.Plugin.apply(this, arguments);
@@ -96,31 +95,6 @@ $.extend(Annotator.Plugin.Madison.prototype, new Annotator.Plugin(), {
9695
$('#current-comments').collapse(true);
9796
});
9897

99-
this.annotator.subscribe('annotationViewerTextField', function (field, annotation) {
100-
if (annotation.tags.length === 0) {
101-
return;
102-
}
103-
104-
annotation.tags.forEach(function (tag) {
105-
// TODO: support edits?
106-
// if (tag === 'edit') {
107-
// var jField = $(field);
108-
// var differ = new diff_match_patch();
109-
// var diffs = differ.diff_main(annotation.quote, annotation.text);
110-
// var html = differ.diff_prettyHtml(diffs);
111-
// jField.find('p').html(html);
112-
// }
113-
});
114-
});
115-
116-
// Add Madison-specific fields to the viewer when Annotator loads it
117-
this.annotator.viewer.addField({
118-
load: function (field, annotation) {
119-
this.addNoteActions(field, annotation);
120-
this.addComments(field, annotation);
121-
}.bind(this)
122-
});
123-
12498
this.annotator.editor.submit = function (e) {
12599
// Clear previous errors
126100
this.annotation._error = false;
@@ -142,49 +116,38 @@ $.extend(Annotator.Plugin.Madison.prototype, new Annotator.Plugin(), {
142116
}
143117
};
144118

145-
this.annotator.editor.addField({
146-
load: function (field, annotation) {
147-
this.addEditFields(field, annotation);
148-
}.bind(this),
149-
submit: function (field, annotation) {
150-
// check it is tagged 'edit'
151-
if (this.hasEditTag(annotation.tags)) {
152-
// check we have explanatory content
153-
var explanation = $(field).find('#explanation').val();
154-
155-
// If no explanatory content, show message and don't submit
156-
if ('' === explanation.trim()) {
157-
$('#annotation-error').text("Explanation required for edits.").toggle(true);
158-
159-
annotation._error = true;
160-
return false;
161-
}
119+
// We want document events even on readOnly, which isn't the default
120+
// behavior.
121+
if (this.annotator.options.readOnly && !this.annotator.options.discussionClosed) {
122+
this.annotator._setupDocumentEvents();
123+
}
162124

163-
annotation.explanation = explanation;
164-
}
165-
},
166-
hasEditTag: function (tags) {
167-
var hasEditTag = false;
125+
// Disable viewing annotations through mouseover
126+
this.annotator.onHighlightMouseover = function (event) {
127+
return false;
128+
};
168129

169-
if (tags === undefined || tags.length === 0) {
170-
return false;
171-
}
130+
// Clicking a highlight opens the panel for that annotation group
131+
$('.annotator-wrapper').delegate('.annotator-hl', 'click', function (event) {
132+
$(event.target).trigger('madison.showNotes');
133+
});
172134

173-
tags.forEach(function (tag) {
174-
if (tag === 'edit') {
175-
hasEditTag = true;
135+
// If the area outside of the editor is clicked, close it.
136+
this.annotator.subscribe('annotationEditorShown', function () {
137+
setTimeout(function() {
138+
$(document).one('click.annotationEditor', function (e) {
139+
let clickIsOutsideEditor = !$(e.target).closest('.annotator-editor').length;
140+
if (clickIsOutsideEditor) {
141+
$('.annotator-editor:not(.annotator-hide) .annotator-controls .annotator-cancel').trigger('click');
176142
}
177143
});
178-
179-
return hasEditTag;
180-
}
144+
}, 500);
181145
});
182146

183-
// We want document events even on readOnly, which isn't the default
184-
// behavior.
185-
if (this.annotator.options.readOnly && !this.annotator.options.discussionClosed) {
186-
this.annotator._setupDocumentEvents();
187-
}
147+
// Just in case we close the editor with "cancel", clean up the single event binding
148+
this.annotator.subscribe('annotationEditorHidden', function () {
149+
$(document).off('click.annotationEditor');
150+
});
188151

189152
this.onAdderClickOld = this.annotator.onAdderClick;
190153
this.annotator.onAdderClick = function (event) {
@@ -254,100 +217,6 @@ $.extend(Annotator.Plugin.Madison.prototype, new Annotator.Plugin(), {
254217
}
255218
},
256219

257-
addEditFields: function (field, annotation) {
258-
var newField = $(field);
259-
var toAdd = $('<div class="annotator-editor-edit-wrapper"></div>');
260-
261-
var buttonGroup = $('<div class="btn-group"></div>');
262-
263-
var explanation = $('<input id="explanation" type="text" name="explanation" placeholder="'+window.trans['messages.document.note_edit_explanation_prompt']+'" style="display:none;" />');
264-
var annotationError = $('<p id="annotation-error" style="display:none; color:red;"></p>');
265-
266-
var annotateButton = $('<button type="button" class="btn btn-default active">'+window.trans['messages.document.note']+'</button>').click(function () {
267-
$(this).addClass('active');
268-
$(this).siblings().each(function (sibling) {
269-
$(this).removeClass('active');
270-
});
271-
$('#annotator-field-0').val('');
272-
$('#annotator-field-1').val('');
273-
$('#explanation').toggle(false);
274-
$('#explanation').prop('required', false);
275-
$('#annotator-error').text('').toggle(false);
276-
$('#annotator-field-0').focus();
277-
});
278-
279-
var editButton = $('<button type="button" class="btn btn-default">'+window.trans['messages.edit']+'</button>').click(function () {
280-
$(this).addClass('active');
281-
$(this).siblings().each(function (sibling) {
282-
$(this).removeClass('active');
283-
});
284-
$('#annotator-field-0').val(annotation.quote);
285-
$('#annotator-field-1').val('edit ');
286-
$('#explanation').toggle(true);
287-
$('#explanation').prop('required', true);
288-
$('#annotator-field-0').focus();
289-
});
290-
291-
buttonGroup.append(annotateButton, editButton);
292-
toAdd.append(buttonGroup);
293-
toAdd.append(explanation);
294-
toAdd.append(annotationError);
295-
newField.html(toAdd);
296-
},
297-
298-
addComments: function (field, annotation) {
299-
var userId = this.options.userId;
300-
301-
// Add comment wrapper and collapse the comment thread
302-
var commentsHeader = $('<div class="comment-toggle" data-toggle-"collapse" data-target="#current-comments">Comments <span id="comment-caret" class="caret caret-right"></span></button>').click(function () {
303-
$('#current-comments').collapse('toggle');
304-
$('#comment-caret').toggleClass('caret-right');
305-
});
306-
307-
// If there are no comments, hide the comment wrapper
308-
if ($(annotation.comments).length === 0) {
309-
commentsHeader.addClass('hidden');
310-
}
311-
312-
// Add all current comments to the annotation viewer
313-
var currentComments = $('<div id="current-comments" class="current-comments collapse"></div>');
314-
315-
/*jslint unparam: true*/
316-
$.each(annotation.comments, function (index, comment) {
317-
comment = $('<div class="existing-comment"><blockquote>' + comment.text + '<div class="comment-author">' + comment.user.display_name + '</div></blockquote></div>');
318-
currentComments.append(comment);
319-
});
320-
/*jslint unparam: false*/
321-
322-
// Collapse the comment thread on load
323-
currentComments.ready(function () {
324-
$('#existing-comments').collapse({
325-
toggle: false
326-
});
327-
});
328-
329-
// If the user is logged in, allow them to comment
330-
if (userId) {
331-
var annotationComments = $('<div class="annotation-comments"></div>');
332-
var commentText = $('<input type="text" class="form-control" />');
333-
var commentSubmit = $('<button type="button" class="btn btn-primary" >Submit</button>');
334-
commentSubmit.click(function () {
335-
this.createComment(commentText, annotation);
336-
}.bind(this));
337-
annotationComments.append(commentText);
338-
339-
annotationComments.append(commentSubmit);
340-
341-
$(field).append(annotationComments);
342-
}
343-
344-
$(field).append(commentsHeader, currentComments);
345-
},
346-
347-
addNoteActions: function (field, annotation) {
348-
$(field).append(this.noteActionsString(annotation));
349-
},
350-
351220
noteActionsString: function (comment) {
352221
let actions = '<div class="activity-actions">';
353222
actions += '<a class="thumbs-up" onclick=$(this).trigger("madison.addAction")'
@@ -543,12 +412,18 @@ $.extend(Annotator.Plugin.Madison.prototype, new Annotator.Plugin(), {
543412
var annotationParentId;
544413
if (annotationParent.prop('id')) {
545414
annotationParentId = annotationParent.prop('id');
415+
annotationGroupCount = parseInt(annotationParentId.replace('annotationGroup-', ''));
546416
} else {
547417
annotationGroupCount++;
548418
annotationParentId = 'annotationGroup-' + annotationGroupCount;
549419
annotationParent.prop('id', annotationParentId);
550420
}
551421

422+
// Set data-group-id on highlights so they can trigger notes pane
423+
annotation.highlights.forEach(function (highlight) {
424+
$(highlight).data('groupId', annotationParentId);
425+
});
426+
552427
if ((typeof(annotationGroups[annotationParentId])).toLowerCase() === 'undefined') {
553428
var parentTop = annotationParent.offset().top;
554429
var containerTop = $(this.options.annotationContainerElem).offset().top;

resources/assets/sass/annotation.scss

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,141 @@
201201
}
202202
}
203203

204+
.annotator-hide { display: none; }
205+
204206
.annotator-adder, .annotator-outer, .annotator-notice, .annotator-filter {
205207
z-index: 1000 !important;
206208
}
207209

210+
.annotator-wrapper .annotator-adder {
211+
position: absolute;
212+
padding-left: 15px;
213+
padding-top: 7px;
214+
215+
button {
216+
@extend .btn;
217+
@extend .btn-default;
218+
@extend .fa;
219+
@extend .fa-pencil;
220+
221+
// Styling for the pencil
222+
&:before {
223+
text-indent: 0;
224+
color: $gray;
225+
font-size: 16px;
226+
position: absolute;
227+
top: 6px;
228+
left: 8px;
229+
}
230+
231+
text-indent: -9999px;
232+
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
233+
margin-left: 5px;
234+
height: 30px;
235+
width: 30px;
236+
position: absolute;
237+
top: -40px;
238+
left: -20px;
239+
}
240+
}
241+
242+
.annotator-outer.annotator-editor {
243+
position: absolute;
244+
}
245+
246+
.annotator-wrapper .annotator-widget {
247+
@extend .panel;
248+
249+
position: absolute;
250+
top: -180px;
251+
left: -150px;
252+
253+
border: 1px solid #eee;
254+
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
255+
256+
&:after { background-image: none; }
257+
258+
.annotator-listing {
259+
@extend .panel-body;
260+
261+
padding-bottom: 0;
262+
list-style: none;
263+
264+
.annotator-item textarea {
265+
padding: 0;
266+
border: none;
267+
width: 300px;
268+
min-height: 80px;
269+
270+
&:focus { outline: none; }
271+
}
272+
}
273+
274+
.annotator-controls {
275+
@extend .panel-footer;
276+
277+
a {
278+
@extend .btn;
279+
280+
&.annotator-save {
281+
@extend .btn-primary;
282+
float: right;
283+
}
284+
&.annotator-cancel {
285+
@extend .btn-default;
286+
}
287+
}
288+
}
289+
290+
}
291+
292+
.annotator-notice {
293+
@extend .alert;
294+
295+
position: fixed;
296+
top: -54px;
297+
left: 0;
298+
299+
width: 100%;
300+
text-align: center;
301+
302+
.ie6 & {
303+
position: absolute;
304+
}
305+
306+
}
307+
308+
.annotator-notice-success {
309+
@extend .alert-success;
310+
}
311+
312+
.annotator-notice-error {
313+
@extend .alert-danger;
314+
}
315+
316+
.annotator-notice-show {
317+
top: 0;
318+
}
319+
320+
321+
322+
.annotator-hl {
323+
background: rgba(255,255,10,0.3);
324+
cursor: pointer;
325+
}
326+
327+
.annotator-hl-temporary {
328+
background: rgba(0,124,255,0.3);
329+
}
330+
331+
.annotator-hl-active {
332+
background: rgba(255,255,10,0.8);
333+
}
334+
335+
.annotator-hl-filtered {
336+
background-color: transparent;
337+
}
338+
208339
.mobile-annotation-message {
209340
display: none;
210341
}
@@ -243,8 +374,9 @@
243374
}
244375

245376
// Hide all inline annotations for now.
246-
.annotator-outer {
247-
display: none;
377+
.annotator-outer,
378+
.annotator-adder {
379+
display: none !important;
248380
}
249381
}
250382

0 commit comments

Comments
 (0)