Skip to content

Commit 3d5a7a7

Browse files
authored
Merge pull request #133 from docusign/fix/fix-example-href-in-search
Fix code example href in search
2 parents 3faa833 + a6cdb29 commit 3d5a7a7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

public/assets/search.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ let DS_SEARCH = (function () {
149149
$("#filtered_code_examples").append(
150150
"<h4 id="
151151
+ "example".concat("0".repeat(3 - example.ExampleNumber.toString().length)).concat(example.ExampleNumber) + ">"
152-
+ "<a href = 'index.php?page="
152+
+ "<a href = '" + getExampleUrlBase()
153153
+ linkToCodeExample.concat("0".repeat(3 - example.ExampleNumber.toString().length)).concat(example.ExampleNumber)
154154
+ "' >"
155155
+ example.ExampleName
@@ -204,13 +204,30 @@ let DS_SEARCH = (function () {
204204
$("#filtered_code_examples").append(processJSONData().SupportingTexts.SearchFailed);
205205
}
206206

207+
function getExampleUrlBase() {
208+
// Create a temporary link element
209+
let tempLink = document.createElement('a');
210+
211+
// Set the href property of the temporary link
212+
tempLink.href = 'index.php';
213+
214+
// Check if resolved URL contains 'public' in pathname
215+
const hasPublicInPathname = tempLink.href.includes('public');
216+
217+
// Remove the temporary link from the DOM
218+
tempLink.remove();
219+
220+
return hasPublicInPathname ? 'index.php?page=' : 'public/index.php?page=';
221+
}
222+
207223
return {
208224
processJSONData: processJSONData,
209225
getEnteredAPIType: getEnteredAPIType,
210226
getExamplesByAPIType: getExamplesByAPIType,
211227
findCodeExamplesByKeywords: findCodeExamplesByKeywords,
212228
textCouldNotBeFound: textCouldNotBeFound,
213-
addCodeExampleToHomepage: addCodeExampleToHomepage
229+
addCodeExampleToHomepage: addCodeExampleToHomepage,
230+
getExampleUrlBase: getExampleUrlBase,
214231
}
215232
})();
216233

0 commit comments

Comments
 (0)