Last active
January 8, 2020 20:56
-
-
Save salsalabs/e15d6dc0e2180615f30dc4b07bc42bc3 to your computer and use it in GitHub Desktop.
Zendesk "submit a request" mod to make suggestions appear in their own windows. Avoids a scan of the doc hijacking the "submit a request" window where someone may have typed something. Put this into script.js in the Zendesk theme.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Wait for suggestion links on a submit a request page. Called after DOM is loaded. | |
function modifySuggestionLinks() { | |
if (!RegExp('/requests(/new)*$').test(window.location.href)) { | |
return | |
} | |
const target = document.querySelector('div.suggestion-list'); | |
if (target == null) { | |
return | |
} | |
//Create and configure a mutuation observer. Observe changes in div.suggestion-list's structure. | |
const observer = new MutationObserver(suggestionSubscriber); | |
const config = { | |
childList: true, | |
subtree: true, | |
}; | |
//Begin observing. | |
observer.observe(target, config); | |
} | |
//Subscriber that handles mutuations made on the submit a request page. | |
function suggestionSubscriber(mutations) { | |
mutations.forEach((mutation) => { | |
mutation.addedNodes.forEach((e) => { | |
var anchors = e.querySelectorAll('a'); | |
anchors.forEach((a) => { | |
if (a instanceof HTMLAnchorElement) { | |
if (a.hasAttribute('target')) { | |
} else { | |
a.setAttribute("target", "_blank"); | |
} | |
} else { | |
} | |
}); | |
}); | |
}); | |
}; | |
$(document).ready(function() { | |
// Make clicks on suggestions in the "submit a request" page open in a separate window. | |
modifySuggestionLinks(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment