11const handleTypoReporter = ( options ) => {
2- if ( ! options || ! options . authorizationToken && ! options . workSpaceId ) {
3- throw new Error ( 'Для работы модуля требуется указать workSpaceId и authorizationToken' ) ;
2+ if ( ! options || ( ! options . authorizationToken && ! options . workSpaceId ) ) {
3+ throw new Error (
4+ 'Для работы модуля требуется указать workSpaceId и authorizationToken' ,
5+ ) ;
46 }
5- const { workSpaceUrl = 'https://hexlet-correction.herokuapp.com/api/workspaces' , userName = null , authorizationToken, workSpaceId } = options ;
7+ const {
8+ workSpaceUrl = 'https://hexlet-correction.herokuapp.com/api/workspaces' ,
9+ userName = null ,
10+ authorizationToken,
11+ workSpaceId,
12+ } = options ;
613 const state = {
714 modalShown : false ,
815 } ;
@@ -52,16 +59,24 @@ const handleTypoReporter = (options) => {
5259
5360 const submitButton = document . createElement ( 'button' ) ;
5461 submitButton . type = 'button' ;
55- submitButton . id = 'hexlet-correction-modal_ReportTypo-submit'
62+ submitButton . id = 'hexlet-correction-modal_ReportTypo-submit' ;
5663 submitButton . textContent = 'Отправить' ;
5764
5865 const cancelButton = document . createElement ( 'button' ) ;
5966 cancelButton . type = 'button' ;
60- cancelButton . id = 'hexlet-correction-modal_ReportTypo-cancel'
67+ cancelButton . id = 'hexlet-correction-modal_ReportTypo-cancel' ;
6168 cancelButton . textContent = 'Отмена' ;
6269
6370 divButtons . append ( submitButton , cancelButton ) ;
64- divTypoReporter . append ( divHeader , divFirstLabel , divMessage , inputName , textareaComment , divSecondLabel , divButtons ) ;
71+ divTypoReporter . append (
72+ divHeader ,
73+ divFirstLabel ,
74+ divMessage ,
75+ inputName ,
76+ textareaComment ,
77+ divSecondLabel ,
78+ divButtons ,
79+ ) ;
6580 const body = document . querySelector ( 'body' ) ;
6681 body . append ( divModal ) ;
6782
@@ -175,7 +190,7 @@ const handleTypoReporter = (options) => {
175190 #hexlet-correction-modal_ReportTypo-cancel:hover {
176191 background-color: #e2e6ea;
177192 }
178- `
193+ ` ;
179194 document . head . append ( style ) ;
180195 } ;
181196
@@ -200,11 +215,21 @@ const handleTypoReporter = (options) => {
200215 renderModal ( ) ;
201216 }
202217 const modal = document . getElementById ( 'hexlet-correction-modal_modal' ) ;
203- const selectedText = document . getElementById ( 'hexlet-correction-modal_ReportTypo-message' ) ;
204- const commentField = document . getElementById ( 'hexlet-correction-modal_ReportTypo-comment' ) ;
205- const submitButton = document . getElementById ( 'hexlet-correction-modal_ReportTypo-submit' ) ;
206- const cancelBtn = document . getElementById ( 'hexlet-correction-modal_ReportTypo-cancel' ) ;
207- const name = document . getElementById ( 'hexlet-correction-modal_ReportTypo-name' ) ;
218+ const selectedText = document . getElementById (
219+ 'hexlet-correction-modal_ReportTypo-message' ,
220+ ) ;
221+ const commentField = document . getElementById (
222+ 'hexlet-correction-modal_ReportTypo-comment' ,
223+ ) ;
224+ const submitButton = document . getElementById (
225+ 'hexlet-correction-modal_ReportTypo-submit' ,
226+ ) ;
227+ const cancelBtn = document . getElementById (
228+ 'hexlet-correction-modal_ReportTypo-cancel' ,
229+ ) ;
230+ const name = document . getElementById (
231+ 'hexlet-correction-modal_ReportTypo-name' ,
232+ ) ;
208233
209234 const closeModal = ( ) => {
210235 modal . style . display = 'none' ;
@@ -214,7 +239,6 @@ const handleTypoReporter = (options) => {
214239 cancelBtn . removeEventListener ( 'click' , sendDataHandler ) ;
215240 } ;
216241
217-
218242 const sendData = async ( event ) => {
219243 event . preventDefault ( ) ;
220244 data . pageUrl = window . location . href ;
@@ -225,9 +249,9 @@ const handleTypoReporter = (options) => {
225249 method : 'POST' ,
226250 headers : {
227251 'Content-Type' : 'application/json' ,
228- ' Authorization' : `Basic ${ authorizationToken } `
252+ Authorization : `Basic ${ authorizationToken } ` ,
229253 } ,
230- body : JSON . stringify ( data )
254+ body : JSON . stringify ( data ) ,
231255 } ) ;
232256 closeModal ( ) ;
233257 } catch ( error ) {
@@ -243,8 +267,13 @@ const handleTypoReporter = (options) => {
243267 const maxLength = 50 ;
244268 const end = Math . min ( focusOffset + maxLength , anchorNode . length ) ;
245269 const start = Math . max ( anchorOffset - maxLength , 0 ) ;
246- const textBeforeSelection = anchorNode . textContent . substring ( start , anchorOffset ) ;
247- const textAfterSelection = anchorNode . substringData ? anchorNode . substringData ( focusOffset , end - focusOffset ) : '' ;
270+ const textBeforeSelection = anchorNode . textContent . substring (
271+ start ,
272+ anchorOffset ,
273+ ) ;
274+ const textAfterSelection = anchorNode . substringData
275+ ? anchorNode . substringData ( focusOffset , end - focusOffset )
276+ : '' ;
248277
249278 selectedText . innerHTML = `${ textBeforeSelection } <u id="hexlet-correction-modal_ReportTypo-highlight">${ selectionText } </u>${ textAfterSelection } ` ;
250279 commentField . focus ( ) ;
0 commit comments