@@ -5,18 +5,7 @@ const DS_SEARCH = (function () {
55 CLICK : "click" ,
66 ROOMS : "rooms" ,
77 ADMIN : "admin" ,
8- } ;
9-
10- function getHash ( value ) {
11- var hash = 0 ,
12- i , chr ;
13- if ( value . length === 0 ) return hash ;
14- for ( i = 0 ; i < value . length ; i ++ ) {
15- chr = value . charCodeAt ( i ) ;
16- hash = ( ( hash << 5 ) - hash ) + chr ;
17- hash |= 0 ; // Convert to 32bit integer
18- }
19- return hash ;
8+ CONNECT : "connect" ,
209 }
2110
2211 const processJSONData = function ( ) {
@@ -34,7 +23,7 @@ const DS_SEARCH = (function () {
3423 function checkIfExampleMatches ( example , matches ) {
3524 const name = example . ExampleName ;
3625 const description = example . ExampleDescription ;
37- const pathNames = example . LinksToAPIMethod . map ( ( a ) => a . PathName ) ;
26+ const pathNames = example . LinksToAPIMethod ? .map ( ( a ) => a . PathName ) ;
3827
3928 for ( let i = 0 ; i < matches . length ; i ++ ) {
4029 if (
@@ -85,9 +74,10 @@ const DS_SEARCH = (function () {
8574 ] ,
8675 } ;
8776
88- const fuse = new Fuse ( json , options ) ;
77+ const clearJSON = JSON . stringify ( json ) . replace ( / < \/ ? [ ^ > ] + ( > | $ ) / g, "" ) ;
78+ const fuse = new Fuse ( JSON . parse ( clearJSON ) , options ) ;
8979
90- var searchResults = fuse . search ( JSON . stringify ( pattern ) ) ;
80+ const searchResults = fuse . search ( JSON . stringify ( pattern ) ) ;
9181
9282 searchResults . forEach ( ( searchResult ) =>
9383 clearResultsAfterMatching ( searchResult . item , searchResult . matches )
@@ -137,17 +127,19 @@ const DS_SEARCH = (function () {
137127 return "meg" ;
138128 case API_TYPES . ESIGNATURE :
139129 return "eg" ;
130+ case API_TYPES . CONNECT :
131+ return "cneg" ;
140132 }
141133 }
142134
143135 const addCodeExampleToHomepage = function ( codeExamples ) {
144136 var cfrPart11 = processCFR11Value ( ) ;
145-
137+
146138 codeExamples . forEach ( ( element ) => {
147139 let linkToCodeExample = getLinkForApiType ( element . Name . toLowerCase ( ) ) ;
148140
149141 element . Groups . forEach ( ( group ) => {
150- $ ( "#filtered_code_examples" ) . append ( ` <h2 id=" ${ getHash ( group . Name ) } "> </h2>` ) ;
142+ $ ( "#filtered_code_examples" ) . append ( " <h2>" + group . Name + " </h2>" ) ;
151143
152144 group . Examples . forEach ( ( example ) => {
153145 if (
@@ -159,7 +151,6 @@ const DS_SEARCH = (function () {
159151 ( ( cfrPart11 == "enabled" ) && ( example . CFREnabled == "CFROnly" ) ) ||
160152 ( ( cfrPart11 != "enabled" ) && ( example . CFREnabled == "NonCFR" ) ) ) )
161153 {
162- $ ( `#${ getHash ( group . Name ) } ` ) . html ( group . Name ) ;
163154 $ ( "#filtered_code_examples" ) . append (
164155 "<h4 id=" +
165156 "example"
@@ -184,36 +175,37 @@ const DS_SEARCH = (function () {
184175 ) ;
185176
186177 $ ( "#filtered_code_examples" ) . append ( "<p>" ) ;
187-
188- if ( example . LinksToAPIMethod . length == 1 ) {
189- $ ( "#filtered_code_examples" ) . append (
190- processJSONData ( ) . SupportingTexts . APIMethodUsed
191- ) ;
192- } else {
193- $ ( "#filtered_code_examples" ) . append (
194- processJSONData ( ) . SupportingTexts . APIMethodUsedPlural
195- ) ;
196- }
197-
198- for (
199- let index = 0 ;
200- index < example . LinksToAPIMethod . length ;
201- index ++
202- ) {
203- $ ( "#filtered_code_examples" ) . append (
204- " <a target='_blank' href='" +
205- example . LinksToAPIMethod [ index ] . Path +
206- "'>" +
207- example . LinksToAPIMethod [ index ] . PathName +
208- "</a>"
209- ) ;
210-
211- if ( index + 1 === example . LinksToAPIMethod . length ) {
212- $ ( "#filtered_code_examples" ) . append ( "<span></span>" ) ;
213- } else if ( index + 1 === example . LinksToAPIMethod . length - 1 ) {
214- $ ( "#filtered_code_examples" ) . append ( "<span> and </span>" ) ;
178+ if ( example . LinksToAPIMethod && example . LinksToAPIMethod . length !== 0 ) {
179+ if ( example . LinksToAPIMethod . length == 1 ) {
180+ $ ( "#filtered_code_examples" ) . append (
181+ processJSONData ( ) . SupportingTexts . APIMethodUsed
182+ ) ;
215183 } else {
216- $ ( "#filtered_code_examples" ) . append ( "<span>, </span>" ) ;
184+ $ ( "#filtered_code_examples" ) . append (
185+ processJSONData ( ) . SupportingTexts . APIMethodUsedPlural
186+ ) ;
187+ }
188+
189+ for (
190+ let index = 0 ;
191+ index < example . LinksToAPIMethod . length ;
192+ index ++
193+ ) {
194+ $ ( "#filtered_code_examples" ) . append (
195+ " <a target='_blank' href='" +
196+ example . LinksToAPIMethod [ index ] . Path +
197+ "'>" +
198+ example . LinksToAPIMethod [ index ] . PathName +
199+ "</a>"
200+ ) ;
201+
202+ if ( index + 1 === example . LinksToAPIMethod . length ) {
203+ $ ( "#filtered_code_examples" ) . append ( "<span></span>" ) ;
204+ } else if ( index + 1 === example . LinksToAPIMethod . length - 1 ) {
205+ $ ( "#filtered_code_examples" ) . append ( "<span> and </span>" ) ;
206+ } else {
207+ $ ( "#filtered_code_examples" ) . append ( "<span>, </span>" ) ;
208+ }
217209 }
218210 }
219211
@@ -266,6 +258,25 @@ function updateValue(esearchPattern) {
266258 DS_SEARCH . textCouldNotBeFound ( ) ;
267259 } else {
268260 result . forEach ( ( x ) => {
261+ const api = json . filter ( ( api ) => {
262+ return api . Name === x . item . Name ;
263+ } ) [ 0 ] ;
264+
265+ x . item . Groups . forEach ( ( group , groupIndex ) => {
266+ const unfilteredGroup = api . Groups . filter ( ( apiGroup ) => {
267+ return apiGroup . Name === group . Name ;
268+ } ) [ 0 ] ;
269+
270+ group . Examples . forEach ( ( example , index ) => {
271+ const clearedExample = unfilteredGroup . Examples . filter (
272+ ( apiExample ) => {
273+ return apiExample . ExampleNumber === example . ExampleNumber ;
274+ }
275+ ) [ 0 ] ;
276+ x . item . Groups [ groupIndex ] . Examples [ index ] = clearedExample ;
277+ } ) ;
278+ } ) ;
279+
269280 DS_SEARCH . addCodeExampleToHomepage ( [ x . item ] ) ;
270281 } ) ;
271282 }
0 commit comments