11var spellers = { } , spellerData = { } ;
22var currentSpellCheckerRequest ;
33
4- /* exported getSpellers, populateSecondarySpellcheckerList */
4+ /* exported getSpellers, populateSecondarySpellCheckerList */
55/* global config, modeEnabled, persistChoices, readCache, ajaxSend, ajaxComplete, filterLangList, allowedLang, analyzers, cache,
66 localizeInterface, getLangByCode, restoreChoices, callApy */
77/* global ENTER_KEY_CODE */
@@ -11,14 +11,14 @@ function getSpellers() {
1111
1212 if ( config . SPELLERS ) {
1313 spellerData = config . SPELLERS ;
14- populatePrimarySpellcheckerList ( spellerData ) ;
14+ populatePrimarySpellCheckerList ( spellerData ) ;
1515 deferred . resolve ( ) ;
1616 }
1717 else {
1818 var spellers = readCache ( 'spellers' , 'LIST_REQUEST' ) ;
1919 if ( spellers ) {
2020 spellerData = spellers ;
21- populatePrimarySpellcheckerList ( spellerData ) ;
21+ populatePrimarySpellCheckerList ( spellerData ) ;
2222 deferred . resolve ( ) ;
2323 }
2424 else {
@@ -28,9 +28,9 @@ function getSpellers() {
2828 beforeSend : ajaxSend ,
2929 success : function ( data ) {
3030 spellerData = data ;
31- populatePrimarySpellcheckerList ( spellerData ) ;
31+ populatePrimarySpellCheckerList ( spellerData ) ;
3232 cache ( 'spellers' , data ) ;
33- populatePrimarySpellcheckerList ( data ) ;
33+ populatePrimarySpellCheckerList ( data ) ;
3434 } ,
3535 error : function ( ) {
3636 console . error ( 'Failed to get available spellers' ) ;
@@ -50,12 +50,12 @@ if(modeEnabled('spellchecker')) {
5050 $ ( document ) . ready ( function ( ) {
5151 restoreChoices ( 'spellchecker' ) ;
5252 var timer , timeout = 2000 ;
53- $ ( '#spellChekerForm ' ) . submit ( function ( ) {
53+ $ ( '#spellCheckerForm ' ) . submit ( function ( ) {
5454 clearTimeout ( timer ) ;
5555 check ( ) ;
5656 } ) ;
5757
58- $ ( '#spellcheckerInput ' ) . on ( 'input propertychange' , function ( ) {
58+ $ ( '#spellCheckerInput ' ) . on ( 'input propertychange' , function ( ) {
5959 if ( timer && $ ( '#instantChecking' ) . prop ( 'checked' ) ) {
6060 clearTimeout ( timer ) ;
6161 }
@@ -66,13 +66,13 @@ if(modeEnabled('spellchecker')) {
6666 } , timeout ) ;
6767 } ) ;
6868
69- $ ( '#primarySpellcheckerMode ' ) . change ( function ( ) {
70- populateSecondarySpellcheckerList ( ) ;
69+ $ ( '#primarySpellCheckerMode ' ) . change ( function ( ) {
70+ populateSecondarySpellCheckerList ( ) ;
7171 localizeInterface ( ) ;
7272 persistChoices ( 'spellchecker' ) ;
7373 } ) ;
7474
75- $ ( '#secondarySpellcheckerMode ' ) . change ( function ( ) {
75+ $ ( '#secondarySpellCheckerMode ' ) . change ( function ( ) {
7676 persistChoices ( 'spellchecker' ) ;
7777 } ) ;
7878
@@ -87,20 +87,20 @@ if(modeEnabled('spellchecker')) {
8787 persistChoices ( 'spellchecker' ) ;
8888 } ) ;
8989
90- $ ( '#spellcheckerInput ' ) . on ( 'input propertychange' , function ( ) {
91- $ ( '#spellcheckerInput ' ) . removeClass ( 'spellcheckVisible ' ) ;
90+ $ ( '#spellCheckerInput ' ) . on ( 'input propertychange' , function ( ) {
91+ $ ( '#spellCheckerInput ' ) . removeClass ( 'spellCheckerVisible ' ) ;
9292 $ ( '.spellError' ) . each ( function ( ) {
9393 $ ( this ) . popover ( 'hide' ) ;
9494 } ) ;
9595 persistChoices ( 'spellchecker' ) ;
9696 } ) ;
9797
98- $ ( '#spellcheckerInput ' ) . submit ( function ( ) {
98+ $ ( '#spellCheckerInput ' ) . submit ( function ( ) {
9999 clearTimeout ( timer ) ;
100100 check ( ) ;
101101 } ) ;
102102
103- $ ( document ) . on ( 'mouseover' , '.spellcheckVisible .spellError' , function ( ) {
103+ $ ( document ) . on ( 'mouseover' , '.spellCheckerVisible .spellError' , function ( ) {
104104 $ ( '.spellError' ) . each ( function ( ) {
105105 $ ( this ) . popover ( 'hide' ) ;
106106 } ) ;
@@ -123,7 +123,7 @@ if(modeEnabled('spellchecker')) {
123123 } ) ;
124124 } ) ;
125125
126- $ ( document ) . on ( 'click' , '.list-group-item ' , function ( ) {
126+ $ ( document ) . on ( 'click' , '.spellCheckerListItem ' , function ( ) {
127127 var e = $ ( this ) . parents ( '.popover' ) . prev ( ) ;
128128 e . text ( $ ( this ) . text ( ) ) ;
129129 e . removeClass ( 'spellError' ) ;
@@ -133,16 +133,16 @@ if(modeEnabled('spellchecker')) {
133133 } ) ;
134134}
135135
136- function populateSecondarySpellcheckerList ( ) {
137- var group = analyzers [ $ ( '#primarySpellcheckerMode ' ) . val ( ) ] ;
138- $ ( '#secondarySpellcheckerMode ' ) . empty ( ) ;
136+ function populateSecondarySpellCheckerList ( ) {
137+ var group = analyzers [ $ ( '#primarySpellCheckerMode ' ) . val ( ) ] ;
138+ $ ( '#secondarySpellCheckerMode ' ) . empty ( ) ;
139139
140140 if ( group ) {
141141 if ( group . length <= 1 ) {
142- $ ( '#secondarySpellcheckerMode ' ) . fadeOut ( 'fast' ) ;
142+ $ ( '#secondarySpellCheckerMode ' ) . fadeOut ( 'fast' ) ;
143143 }
144144 else {
145- $ ( '#secondarySpellcheckerMode ' ) . fadeIn ( 'fast' ) ;
145+ $ ( '#secondarySpellCheckerMode ' ) . fadeIn ( 'fast' ) ;
146146 }
147147
148148 group . sort ( function ( a , b ) {
@@ -154,15 +154,15 @@ function populateSecondarySpellcheckerList() {
154154 var langDisplay = lang . indexOf ( '-' ) !== - 1
155155 ? getLangByCode ( lang . split ( '-' ) [ 0 ] ) + '-' + getLangByCode ( lang . split ( '-' ) [ 1 ] )
156156 : getLangByCode ( lang ) ;
157- $ ( '#secondarySpellcheckerMode ' ) . append ( $ ( '<option></option' ) . val ( lang ) . text ( langDisplay ) ) ;
157+ $ ( '#secondarySpellCheckerMode ' ) . append ( $ ( '<option></option' ) . val ( lang ) . text ( langDisplay ) ) ;
158158 }
159159 }
160160 else {
161- $ ( '#secondarySpellcheckerMode ' ) . fadeOut ( 'fast' ) ;
161+ $ ( '#secondarySpellCheckerMode ' ) . fadeOut ( 'fast' ) ;
162162 }
163163}
164- function populatePrimarySpellcheckerList ( data ) {
165- $ ( '.spellcheckerMode ' ) . empty ( ) ;
164+ function populatePrimarySpellCheckerList ( data ) {
165+ $ ( '.spellCheckerMode ' ) . empty ( ) ;
166166
167167 spellers = { } ;
168168 for ( var lang in data ) {
@@ -189,7 +189,7 @@ function populatePrimarySpellcheckerList(data) {
189189
190190 for ( var i = 0 ; i < spellerArray . length ; i ++ ) {
191191 lang = spellerArray [ i ] [ 0 ] ;
192- $ ( '#primarySpellcheckerMode ' ) . append ( $ ( '<option></option>' ) . val ( lang ) . text ( getLangByCode ( lang ) ) ) ;
192+ $ ( '#primarySpellCheckerMode ' ) . append ( $ ( '<option></option>' ) . val ( lang ) . text ( getLangByCode ( lang ) ) ) ;
193193 }
194194
195195 restoreChoices ( 'spellerchecker' ) ;
@@ -199,47 +199,19 @@ function check() {
199199 if ( currentSpellCheckerRequest ) {
200200 currentSpellCheckerRequest . abort ( ) ;
201201 }
202- $ ( '#spellcheckerInput ' ) . addClass ( 'spellcheckVisible ' ) ;
203- $ ( '#spellcheckerInput ' ) . html ( $ ( '#spellcheckerInput ' ) . html ( ) . replace ( / b r / g, '\n' )
202+ $ ( '#spellCheckerInput ' ) . addClass ( 'spellCheckerVisible ' ) ;
203+ $ ( '#spellCheckerInput ' ) . html ( $ ( '#spellCheckerInput ' ) . html ( ) . replace ( / b r / g, '\n' )
204204 . replace ( / & n b s p ; / g, ' ' ) ) ;
205- var words = $ . trim ( $ ( '#spellcheckerInput ' ) . text ( ) ) ;
205+ var words = $ . trim ( $ ( '#spellCheckerInput ' ) . text ( ) ) ;
206206 var splitWords = words . split ( ' ' ) ;
207207 var content = { } ;
208- $ ( '#spellcheckerInput ' ) . html ( '' ) ;
208+ $ ( '#spellCheckerInput ' ) . html ( '' ) ;
209209 currentSpellCheckerRequest = callApy ( {
210210 data : {
211211 'q' : words ,
212- 'lang' : $ ( '#primarySpellcheckerMode' ) . val ( )
213- } ,
214- success : function ( data ) {
215- var originalWordsIndex = 0 ;
216- for ( var tokenIndex = 0 ; tokenIndex < data . length ; tokenIndex ++ ) {
217- if ( data [ tokenIndex ] . known === true ) {
218- $ ( '#spellcheckerInput' ) . html ( $ ( '#spellcheckerInput' ) . html ( ) + ' ' + splitWords [ originalWordsIndex ] ) ;
219- originalWordsIndex ++ ;
220- continue ;
221- }
222- $ ( '#spellcheckerInput' ) . html ( $ ( '#spellcheckerInput' ) . html ( ) + ' <span class="spellError" id=' +
223- splitWords [ originalWordsIndex ] + '>' + splitWords [ originalWordsIndex ] + '</span>' ) ;
224- content [ splitWords [ originalWordsIndex ] ] = '<div class="list-group">' ;
225- for ( var sugg = 0 ; sugg < data [ tokenIndex ] . sugg . length ; sugg ++ ) {
226- content [ splitWords [ originalWordsIndex ] ] += '<a href="#" class="list-group-item">' +
227- data [ tokenIndex ] . sugg [ sugg ] [ 0 ] + '</a>' ;
228- content [ splitWords [ originalWordsIndex ] ] += '</div>' ;
229- }
230- $ ( '.spellError' ) . each ( function ( ) {
231- var currentTokenId = this . id ;
232- $ ( this ) . popover ( {
233- animation : false ,
234- placement : 'bottom' ,
235- trigger : 'manual' ,
236- html : true ,
237- content : content [ currentTokenId ]
238- } ) ;
239- } ) ;
240- originalWordsIndex ++ ;
241- }
212+ 'lang' : $ ( '#primarySpellCheckerMode' ) . val ( )
242213 } ,
214+ success : handleSpellCheckerSuccessResponse ,
243215 error : handleSpellCheckerErrorResponse ,
244216 complete : function ( ) {
245217 ajaxComplete ( ) ;
@@ -248,12 +220,42 @@ function check() {
248220 } , '/speller' , true ) ;
249221}
250222
223+ function handleSpellCheckerSuccessResponse ( data ) {
224+ var originalWordsIndex = 0 ;
225+ for ( var tokenIndex = 0 ; tokenIndex < data . length ; tokenIndex ++ ) {
226+ if ( data [ tokenIndex ] . known === true ) {
227+ $ ( '#spellCheckerInput' ) . html ( $ ( '#spellCheckerInput' ) . html ( ) + ' ' + splitWords [ originalWordsIndex ] ) ;
228+ originalWordsIndex ++ ;
229+ continue ;
230+ }
231+ $ ( '#spellCheckerInput' ) . html ( $ ( '#spellCheckerInput' ) . html ( ) + ' <span class="spellError" id=' +
232+ splitWords [ originalWordsIndex ] + '>' + splitWords [ originalWordsIndex ] + '</span>' ) ;
233+ content [ splitWords [ originalWordsIndex ] ] = '<div class="spellCheckerList">' ;
234+ for ( var sugg = 0 ; sugg < data [ tokenIndex ] . sugg . length ; sugg ++ ) {
235+ content [ splitWords [ originalWordsIndex ] ] += '<a href="#" class="spellCheckerListItem">' +
236+ data [ tokenIndex ] . sugg [ sugg ] [ 0 ] + '</a>' ;
237+ content [ splitWords [ originalWordsIndex ] ] += '</div>' ;
238+ }
239+ $ ( '.spellError' ) . each ( function ( ) {
240+ var currentTokenId = this . id ;
241+ $ ( this ) . popover ( {
242+ animation : false ,
243+ placement : 'bottom' ,
244+ trigger : 'manual' ,
245+ html : true ,
246+ content : content [ currentTokenId ]
247+ } ) ;
248+ } ) ;
249+ originalWordsIndex ++ ;
250+ }
251+ }
252+
251253function handleSpellCheckerErrorResponse ( jqXHR ) {
252254 spellCheckerNotAvailable ( jqXHR . responseJSON ) ;
253255}
254256
255257function spellCheckerNotAvailable ( data ) {
256- $ ( '#spellcheckerInput ' ) . append ( $ ( '<div></div>' ) . text ( ' ' ) ) ;
257- $ ( '#spellcheckerInput ' ) . append ( $ ( '<div></div>' ) . text ( data . message ) ) ;
258- $ ( '#spellcheckerInput ' ) . append ( $ ( '<div></div>' ) . text ( data . explanation ) ) ;
258+ $ ( '#spellCheckerInput ' ) . append ( $ ( '<div></div>' ) . text ( ' ' ) ) ;
259+ $ ( '#spellCheckerInput ' ) . append ( $ ( '<div></div>' ) . text ( data . message ) ) ;
260+ $ ( '#spellCheckerInput ' ) . append ( $ ( '<div></div>' ) . text ( data . explanation ) ) ;
259261}
0 commit comments