Skip to content

Instantly share code, notes, and snippets.

@ppbntl19
Last active March 23, 2017 05:21
Show Gist options
  • Save ppbntl19/7008984ec7bcb89a2d9e9a38bb1df6ad to your computer and use it in GitHub Desktop.
Save ppbntl19/7008984ec7bcb89a2d9e9a38bb1df6ad to your computer and use it in GitHub Desktop.
Using Javascript MutationObserver
//More Details https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
//Will not work if more then one lookup is used on same page
//Please remove all comments for live
//Add Mututationobserver on selected component
$("#component-abca-2a71-4474").on("click",".search_for_salesforce_record,.lookup_salesforce_record ", function() {
new MutationObserver(function(mutations) {
// Do something here
if($('#component-abca-2a71-4474 .found_record_list li') && $('#component-abca-2a71-4474 .found_record_list li').length > 0) {
//Add css to change for lookup result
$('#component-abca-2a71-4474 .found_record_list li').append('<span class="glyphicon glyphicon-hand-up"></span><style>#select_icon{display:none}.found_record_list #select_icon{display:inline}</style>');
// Stop observing if needed:
this.disconnect();
}
if($('#component-abca-2a71-4474 .found_record_list').text()=='No records found'){
//Add css to change for Default message
$('#component-abca-2a71-4474 .found_record_list').text('Please try Again ... :)');
// Stop observing if needed:
this.disconnect();
}
// Stop observing if needed:
this.disconnect();
}).observe(document.querySelector('#component-abca-2a71-4474 .found_record_list'), {childList: true});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment