ep_comments_page 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "Adds comments on sidebar and link it to the text. For no-skin use ep_page_view.",
3
3
  "name": "ep_comments_page",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "author": {
6
6
  "name": "Nicolas Lescop",
7
7
  "email": "limplementeur@gmail.com"
@@ -901,12 +901,6 @@ EpComments.prototype.displayNewCommentForm = function () {
901
901
  // Write the text to the changeFrom form
902
902
  $('#newComment').find('.from-value').text(selectedText);
903
903
 
904
- // Display form
905
- setTimeout(() => {
906
- const position = getXYOffsetOfRep(rep);
907
- newComment.showNewCommentPopup(position);
908
- });
909
-
910
904
  // Check if the first element selected is visible in the viewport
911
905
  const $firstSelectedElement = this.getFirstElementSelected();
912
906
  const firstSelectedElementInViewport = this.isElementInViewport($firstSelectedElement);
@@ -915,8 +909,9 @@ EpComments.prototype.displayNewCommentForm = function () {
915
909
  this.scrollViewportIfSelectedTextIsNotVisible($firstSelectedElement);
916
910
  }
917
911
 
918
- // Adjust focus on the form
919
- $('#newComment').find('.comment-content').focus();
912
+ // Display form
913
+ const position = getXYOffsetOfRep(rep);
914
+ newComment.showNewCommentPopup(position);
920
915
  };
921
916
 
922
917
  EpComments.prototype.scrollViewportIfSelectedTextIsNotVisible = function ($firstSelectedElement) {
@@ -2,6 +2,8 @@
2
2
 
3
3
  const commentL10n = require('ep_comments_page/static/js/commentL10n');
4
4
 
5
+ let $newComment = $();
6
+
5
7
  // Create a comment object with data filled on the given form
6
8
  const buildCommentFrom = (form) => {
7
9
  const text = form.find('.comment-content').val();
@@ -26,15 +28,16 @@ const cancelNewComment = () => {
26
28
  // Callback for new comment Submit
27
29
  const submitNewComment = (callback) => {
28
30
  const index = 0;
29
- const form = $('#newComment');
30
- const comment = buildCommentFrom(form);
31
+ const comment = buildCommentFrom($newComment);
31
32
  if (comment.text.length > 0 || comment.changeTo && comment.changeTo.length > 0) {
32
- form.find('.comment-content, .to-value').removeClass('error');
33
+ $newComment.find('.comment-content, .to-value').removeClass('error');
33
34
  hideNewCommentPopup();
34
35
  callback(comment, index);
35
36
  } else {
36
- if (comment.text.length === 0) form.find('.comment-content').addClass('error');
37
- if (comment.changeTo && comment.changeTo.length === 0) form.find('.to-value').addClass('error');
37
+ if (comment.text.length === 0) $newComment.find('.comment-content').addClass('error');
38
+ if (comment.changeTo && comment.changeTo.length === 0) {
39
+ $newComment.find('.to-value').addClass('error');
40
+ }
38
41
  }
39
42
  return false;
40
43
  };
@@ -42,36 +45,35 @@ const submitNewComment = (callback) => {
42
45
  /* ***** Public methods: ***** */
43
46
 
44
47
  const localizenewCommentPopup = () => {
45
- const newCommentPopup = $('#newComment');
46
- if (newCommentPopup.length !== 0) commentL10n.localize(newCommentPopup);
48
+ if ($newComment.length !== 0) commentL10n.localize($newComment);
47
49
  };
48
50
 
49
51
  // Insert new Comment Form
50
52
  const insertNewCommentPopupIfDontExist = (comment, callback) => {
51
- $('#newComment').remove();
53
+ $newComment.remove();
52
54
 
53
55
  comment.commentId = '';
54
- const newCommentPopup = $('#newCommentTemplate').tmpl(comment);
55
- newCommentPopup.appendTo($('#editorcontainerbox'));
56
+ $newComment = $('#newCommentTemplate').tmpl(comment);
57
+ $newComment.appendTo($('#editorcontainerbox'));
56
58
 
57
59
  localizenewCommentPopup();
58
60
 
59
61
  // Listen for include suggested change toggle
60
- $('#newComment').find('.suggestion-checkbox').change(function () {
61
- $('#newComment').find('.suggestion').toggle($(this).is(':checked'));
62
+ $newComment.find('.suggestion-checkbox').change(function () {
63
+ $newComment.find('.suggestion').toggle($(this).is(':checked'));
62
64
  });
63
65
 
64
66
  // Cancel btn
65
- newCommentPopup.find('#comment-reset').on('click', () => {
67
+ $newComment.find('#comment-reset').on('click', () => {
66
68
  cancelNewComment();
67
69
  });
68
70
  // Create btn
69
- $('#newComment').on('submit', (e) => {
71
+ $newComment.on('submit', (e) => {
70
72
  e.preventDefault();
71
73
  return submitNewComment(callback);
72
74
  });
73
75
 
74
- return newCommentPopup;
76
+ return $newComment;
75
77
  };
76
78
 
77
79
  const showNewCommentPopup = (position) => {
@@ -82,27 +84,28 @@ const showNewCommentPopup = (position) => {
82
84
  left = $('.toolbar .addComment').offset().left;
83
85
  }
84
86
  const top = position[1];
85
- $('#newComment').css('left', left);
87
+ $newComment.css('left', left);
86
88
  if (left === position[0]) {
87
- $('#newComment').css('top', top);
89
+ $newComment.css('top', top);
88
90
  }
89
91
  // Reset form to make sure it is all clear
90
- $('#newComment').find('.suggestion-checkbox').prop('checked', false).trigger('change');
91
- $('#newComment').find('textarea').val('');
92
- $('#newComment').find('.comment-content, .to-value').removeClass('error');
92
+ $newComment.find('.suggestion-checkbox').prop('checked', false).trigger('change');
93
+ $newComment.find('textarea').val('');
94
+ $newComment.find('.comment-content, .to-value').removeClass('error');
93
95
 
94
96
  // Show popup
95
- $('#newComment').addClass('popup-show');
97
+ $newComment.addClass('popup-show');
98
+ $newComment.find('.comment-content').focus();
96
99
 
97
100
  // mark selected text, so it is clear to user which text range the comment is being applied to
98
101
  pad.plugins.ep_comments_page.preCommentMarker.markSelectedText();
99
102
  };
100
103
 
101
104
  const hideNewCommentPopup = () => {
102
- $('#newComment').removeClass('popup-show');
105
+ $newComment.removeClass('popup-show');
103
106
 
104
107
  // force focus to be lost, so virtual keyboard is hidden on mobile devices
105
- $('#newComment').find(':focus').blur();
108
+ $newComment.find(':focus').blur();
106
109
 
107
110
  // unmark selected text, as now there is no text being commented
108
111
  pad.plugins.ep_comments_page.preCommentMarker.unmarkSelectedText();
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const utils = require('../utils');
4
+
5
+ before(async function () {
6
+ await utils.aNewPad();
7
+ helper.padInner$('div').first()
8
+ .sendkeys('{selectall}')
9
+ .sendkeys('{del}')
10
+ .text('commented text')
11
+ .sendkeys('{selectall}');
12
+ });
13
+
14
+ it('new comment button focuses on comment textarea', async function () {
15
+ helper.padChrome$('.addComment').click();
16
+ expect(helper.padChrome$.document.activeElement)
17
+ .to.be(helper.padChrome$('#newComment').find('.comment-content')[0]);
18
+ });